예제 #1
0
 object ICloneablePlus.Clone()
 {
     FFMpegMediaMetadataFlac t = new FFMpegMediaMetadataFlac(this);
     return t;
 }
예제 #2
0
        private void I_OnEnd2(IndexFile i)
        {

            FileSystemNodePlus<MyAddittionalData> n = i.RootFileSystem.FindFirst((x) => { return x.Name.StartsWith("Summertime"); });

            ConvertionEntity s = new ConvertionEntity(i.RootFileSystem.GetFullPath(n), n.AddittionalData.Metadata.MediaMetadata);
            FFMpegMediaMetadataFlac mm = new FFMpegMediaMetadataFlac(n.AddittionalData.Metadata.MediaMetadata);
            mm.SamplingRate = SamplingRateInfo._44100;
            mm.Bit = BitInfo._24;
            ConvertionEntity d = new ConvertionEntity(SystemService.ChangeExtension(i.RootFileSystem.GetFullPath(n), "flac"),mm);
            
            
            FFmpeg.ConvertTo(s, d, true, true, 
                (status, source, dest) => 
                {
                    if (status == FFmpegStatus.Stop)
                        MessageBox.Show(source + " -> " + dest + "\r\n FINE!");
            }, 
                (percent, source, dest, error) => 
                {

            }, false);

        }
예제 #3
0
        public static bool Mp3ToFlac(String Input, String Output, FFMpegMediaMetadataFlac ConversionParameters, bool OverrideIfExist, FFmpegConvertStatusChanged OnStatusChanged = null, FFmpegConvertProgressChanged OnProgressChanged = null, bool Async = true)
        {
            bool ret = true;
            Thread t = new Thread(() =>
            {
                if (!_Loaded)
                {
                    ret = false; return;
                }

                if (ConversionParameters == null || ConversionParameters.SamplingRate == SamplingRateInfo.nul || ConversionParameters.SamplingRate == 0 || ConversionParameters.Bit == BitInfo.nul)
                {
                    ret = false; return;
                }

                if (CheckValidInput(Input) && CheckValidOutput(Output))
                {
                    if (File.Exists(Output))
                    {
                        if (OverrideIfExist)
                            File.Delete(Output);
                        else
                        {
                            ret = false; return;
                        }
                    }

                    if (OnStatusChanged != null)
                    {
                        OnStatusChanged(FFmpegStatus.Running, Input, Output);
                    }
                    MyProcess p = new MyProcess(_PathFFmpeg, "-i \"" + Input + "\" -map 0:1? -c copy " + JpgNameTemp+" -y");
                    p.UseShellExecute = false;
                    p.RedirectStandardOutput = false;
                    p.RedirectStandardError = false;

                    p.CreateNoWindow = true;
                    p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    p.Async = false;
                    p.Start();

                    p = new MyProcess(_PathFFmpeg, "-i \"" + Input + "\" -map 0:0 -c:a:0 flac -map_metadata 0 -id3v2_version 3  -ar " + ConversionParameters.SamplingRate.ToStringReplace("_", "") + " \"" + Output + "\"");

                    if (OnProgressChanged != null)
                    {
                        bool AspettaLaDurata = false;
                        bool AspettaProgress = false;
                        long TotalMilliSec = 0;
                        p.OnNewLine += (string line) =>
                        {
                            if (line == null)
                                return;
                            else if (line.StartsWith("Input"))
                            {
                                AspettaLaDurata = true;
                                AspettaProgress = false;
                            }
                            else if (AspettaLaDurata && line.StartsWith("  Duration:"))
                            {
                                line = line.RemoveLeft("  Duration: ");
                                line = line.SplitAndGetFirst(',');

                                string[] ss = line.Split(':', '.');
                                if (ss.Length == 4)
                                {
                                    AspettaLaDurata = false;
                                    AspettaProgress = true;
                                    TotalMilliSec = ss[3].ParseInt() * 10 + ss[2].ParseInt() * 1000 + ss[1].ParseInt() * 60000 + ss[0].ParseInt() * 3600000;
                                }
                                else
                                {
                                    TotalMilliSec = -1;
                                    AspettaLaDurata = false;
                                    AspettaProgress = false;
                                }
                            }
                            else if (AspettaProgress && line.Contains("No such file or directory"))
                            {
                                OnProgressChanged(-1, Input, Output, FFmpegError.DestFolderNotFound);
                            }
                            else if (AspettaProgress && (line.StartsWith("frame") || line.StartsWith("size")))
                            {

                                line = line.Substring(line.IndexOf("time=") + 5, 11);
                                string[] ss = line.Split(':', '.');
                                if (ss.Length == 4)
                                {
                                    long current = ss[3].ParseInt() * 10 + ss[2].ParseInt() * 1000 + ss[1].ParseInt() * 60000 + ss[0].ParseInt() * 3600000;
                                    OnProgressChanged((int)((double)current / TotalMilliSec * 100), Input, Output);
                                }
                            }

                        };
                    }

                    p.UseShellExecute = false;
                    p.RedirectStandardOutput = true;
                    p.RedirectStandardError = true;
                    p.CreateNoWindow = true;
                    p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    SystemService.CreateFolderSecure(SystemService.GetParent(Output));

                    p.Async = false;
                    p.Start();

                    if (SystemService.FileExist(JpgNameTemp))
                    {
                        p = new MyProcess(_PathMetaflac, "--import-picture-from=\"" + JpgNameTemp + "\" \"" + Output+"\"");
                        p.UseShellExecute = false;
                        p.RedirectStandardOutput = false;
                        p.RedirectStandardError = false;
                        p.CreateNoWindow = true;
                        p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                        p.Async = false;
                        p.Start();
                    }

                    if (OnStatusChanged != null)
                    {
                        OnStatusChanged(FFmpegStatus.Stop, Input, Output);
                    }

                }
                else
                {
                    ret = false; return;
                }

                ret = true;

            });
            t.Start();

            if (!Async)
                t.Join();

            return ret;

            /*

            ffmpeg.exe -i "07. Magic Box - Scream My Name (Radio  Edit).mp3" -map 0:1? -c copy OUT.jpg
            ffmpeg.exe -i "07. Magic Box - Scream My Name (Radio  Edit).mp3" -map 0:0 -c:a: 0 flac -map_metadata 0 -id3v2_version 3  out.flac
            metaflac --import-picture-from="OUT.jpg" out.flac

             */
        }