Пример #1
0
        private void ExtractFilesThread()
        {
            ListViewItem item = null;

            for (int i = 0; (i < _paths.Length) && !_stop; i++)
            {
                Invoke((MethodInvoker) delegate() {
                    item = lvStatus.Items.Add(new ListViewItem(new string[] { String.Empty,
                                                                              Path.GetFileName(_paths[i]), String.Empty, String.Empty, String.Empty }));
                    item.EnsureVisible();
                });

                try {
                    using (FLVFile flvFile = new FLVFile(_paths[i])) {
                        flvFile.ExtractStreams(_extractAudio, _extractVideo, _extractTimeCodes, PromptOverwrite);

                        Invoke((MethodInvoker) delegate() {
                            if (flvFile.TrueFrameRate != null)
                            {
                                item.SubItems[2].Text = flvFile.TrueFrameRate.Value.ToString(false);
                                item.SubItems[2].Tag  = flvFile.TrueFrameRate;
                            }
                            if (flvFile.AverageFrameRate != null)
                            {
                                item.SubItems[3].Text = flvFile.AverageFrameRate.Value.ToString(false);
                                item.SubItems[3].Tag  = flvFile.AverageFrameRate;
                            }
                            if (flvFile.Warnings.Length == 0)
                            {
                                item.ImageIndex = (int)IconIndex.OK;
                            }
                            else
                            {
                                item.ImageIndex       = (int)IconIndex.Warning;
                                item.SubItems[4].Text = String.Join("  ", flvFile.Warnings);
                            }
                        });
                    }
                }
                catch (Exception ex) {
                    Invoke((MethodInvoker) delegate() {
                        item.ImageIndex       = (int)IconIndex.Error;
                        item.SubItems[4].Text = ex.Message;
                        item.SubItems[4].Tag  = ex.StackTrace;
                    });
                }
            }

            Invoke((MethodInvoker) delegate() {
                btnStop.Visible           = false;
                btnCopyFrameRates.Enabled = true;
                btnOK.Enabled             = true;
            });
        }
Пример #2
0
        private static void extractFLV()
        {
            var newline = Environment.NewLine;

            Console.WriteLine("Welcome to FLV Extract" + newline + "##########################" + newline + "You have to put exe file in flv file folder" + newline + "##########################" + newline);


            Console.WriteLine("Do you want to save audio? Y/N");
            bool audio = (Console.ReadLine().ToUpper()) == "Y" ? true : false;

            Console.WriteLine("Do you want to save video? Y/N");
            bool video = (Console.ReadLine().ToUpper()) == "Y" ? true : false;

            Console.WriteLine("Do you want to save timecode? Y/N");
            bool timecode = (Console.ReadLine().ToUpper()) == "Y" ? true : false;

            string        currentPath = Environment.CurrentDirectory;
            DirectoryInfo di          = new DirectoryInfo(currentPath);

            if (di.GetFiles("*.flv").Count() == 0)
            {
                Console.WriteLine("Cannot find FLV file here");
            }

            foreach (FileInfo file in di.GetFiles("*.flv"))
            {
                Console.WriteLine("Total Files:" + di.GetFiles("*.flv").Count() + " Selected File: ");
                Console.WriteLine(file.Name);
                FLVFile flvFile = new FLVFile(file.FullName);
                // first param is whether or not to extract audio streams (true)
                // second param is whether or not to extract video streams (false)
                // third param is whether or not to extract timecodes (false)
                // fourth param is the delegate that gets called in case of an overwrite prompt (leave null in case you want to overwrite automatically)
                flvFile.ExtractStreams(audio, video, timecode, null);
                Console.WriteLine("Completed" + Environment.NewLine);
            }
        }
Пример #3
0
        private static int Main(string[] args)
        {
            int    argCount         = args.Length;
            int    argIndex         = 0;
            bool   extractVideo     = false;
            bool   extractAudio     = false;
            bool   extractTimeCodes = false;
            string outputDirectory  = null;
            string inputPath        = null;

            Console.WriteLine("FLV Extract CL v" + General.Version);
            Console.WriteLine("Copyright 2006-2011 J.D. Purcell");
            Console.WriteLine("http://www.moitah.net/");
            Console.WriteLine();

            try
            {
                while (argIndex < argCount)
                {
                    switch (args[argIndex])
                    {
                    case "-v":
                        extractVideo = true;
                        break;

                    case "-a":
                        extractAudio = true;
                        break;

                    case "-t":
                        extractTimeCodes = true;
                        break;

                    case "-o":
                        _autoOverwrite = true;
                        break;

                    case "-d":
                        outputDirectory = args[++argIndex];
                        break;

                    default:
                        goto BreakArgLoop;
                    }
                    argIndex++;
                }
BreakArgLoop:

                if (argIndex != (argCount - 1))
                {
                    throw new Exception();
                }
                inputPath = args[argIndex];
            }
            catch
            {
                Console.WriteLine("Arguments: [switches] source_path");
                Console.WriteLine();
                Console.WriteLine("Switches:");
                Console.WriteLine("  -v         Extract video.");
                Console.WriteLine("  -a         Extract audio.");
                Console.WriteLine("  -t         Extract timecodes.");
                Console.WriteLine("  -o         Overwrite output files without prompting.");
                Console.WriteLine("  -d <dir>   Output directory.  If not specified, output files will be written");
                Console.WriteLine("             in the same directory as the source file.");
                return(1);
            }

            try
            {
                using (var flvFile = new FLVFile(Path.GetFullPath(inputPath)))
                {
                    if (outputDirectory != null)
                    {
                        flvFile.OutputDirectory = Path.GetFullPath(outputDirectory);
                    }
                    flvFile.ExtractStreams(extractAudio, extractVideo, extractTimeCodes, PromptOverwrite);
                    if ((flvFile.TrueFrameRate != null) || (flvFile.AverageFrameRate != null))
                    {
                        if (flvFile.TrueFrameRate != null)
                        {
                            Console.WriteLine("True Frame Rate: " + flvFile.TrueFrameRate.ToString());
                        }
                        if (flvFile.AverageFrameRate != null)
                        {
                            Console.WriteLine("Average Frame Rate: " + flvFile.AverageFrameRate.ToString());
                        }
                        Console.WriteLine();
                    }
                    if (flvFile.Warnings.Length != 0)
                    {
                        foreach (string warning in flvFile.Warnings)
                        {
                            Console.WriteLine("Warning: " + warning);
                        }
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return(1);
            }

            Console.WriteLine("Finished.");
            return(0);
        }
Пример #4
0
        static int Main(string[] args)
        {
            int    argCount         = args.Length;
            int    argIndex         = 0;
            bool   extractVideo     = false;
            bool   extractAudio     = false;
            bool   extractTimeCodes = false;
            string outputDirectory  = null;

            Console.WriteLine();
            Console.WriteLine("QiyiFLV2MP4 v" + General.Version);
            Console.WriteLine("Copyright 2016 风漠兮");
            Console.WriteLine("http://www.fengmoxi.com/");
            Console.WriteLine();

            if (!File.Exists("js.dll"))
            {
                byte[]       buffer  = Properties.Resources.js;
                string       path    = AppDomain.CurrentDomain.BaseDirectory + "js.dll";
                FileStream   FS      = new FileStream(path, FileMode.Create);
                BinaryWriter BWriter = new BinaryWriter(FS);
                BWriter.Write(buffer, 0, buffer.Length);
                BWriter.Close();
            }

            if (!File.Exists("js32.dll"))
            {
                byte[]       buffer  = Properties.Resources.js32;
                string       path    = AppDomain.CurrentDomain.BaseDirectory + "js32.dll";
                FileStream   FS      = new FileStream(path, FileMode.Create);
                BinaryWriter BWriter = new BinaryWriter(FS);
                BWriter.Write(buffer, 0, buffer.Length);
                BWriter.Close();
            }

            if (!File.Exists("libgpac.dll"))
            {
                byte[]       buffer  = Properties.Resources.libgpac;
                string       path    = AppDomain.CurrentDomain.BaseDirectory + "libgpac.dll";
                FileStream   FS      = new FileStream(path, FileMode.Create);
                BinaryWriter BWriter = new BinaryWriter(FS);
                BWriter.Write(buffer, 0, buffer.Length);
                BWriter.Close();
            }

            if (!File.Exists("MP4Box.exe"))
            {
                byte[]       buffer  = Properties.Resources.MP4Box;
                string       path    = AppDomain.CurrentDomain.BaseDirectory + "MP4Box.exe";
                FileStream   FS      = new FileStream(path, FileMode.Create);
                BinaryWriter BWriter = new BinaryWriter(FS);
                BWriter.Write(buffer, 0, buffer.Length);
                BWriter.Close();
            }

            try
            {
                _autoOverwrite = true;
                extractVideo   = true;
                extractAudio   = true;

                if (argIndex != (argCount - 1))
                {
                    throw new Exception();
                }
                inputPath = args[argIndex];
            }
            catch
            {
                Console.WriteLine("Arguments: source_path");
                Console.WriteLine();
                return(1);
            }

            try
            {
                using (FLVFile flvFile = new FLVFile(Path.GetFullPath(inputPath)))
                {
                    if (outputDirectory != null)
                    {
                        flvFile.OutputDirectory = Path.GetFullPath(outputDirectory);
                    }
                    flvFile.ExtractStreams(extractAudio, extractVideo, extractTimeCodes, PromptOverwrite);
                    if ((flvFile.TrueFrameRate != null) || (flvFile.AverageFrameRate != null))
                    {
                        if (flvFile.TrueFrameRate != null)
                        {
                            Console.WriteLine("True Frame Rate: " + flvFile.TrueFrameRate.ToString());
                        }
                        if (flvFile.AverageFrameRate != null)
                        {
                            Console.WriteLine("Average Frame Rate: " + flvFile.AverageFrameRate.ToString());
                        }
                        Console.WriteLine();
                    }
                    if (flvFile.Warnings.Length != 0)
                    {
                        foreach (string warning in flvFile.Warnings)
                        {
                            Console.WriteLine("Warning: " + warning);
                        }
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return(1);
            }

            Process sortProcess;

            sortProcess = new Process();
            sortOutput  = new StringBuilder("");
            sortProcess.StartInfo.FileName               = "cmd.exe";
            sortProcess.StartInfo.UseShellExecute        = false;                                                                                                                                                                                                                                               // 必须禁用操作系统外壳程序
            sortProcess.StartInfo.RedirectStandardOutput = true;
            sortProcess.StartInfo.RedirectStandardError  = true;                                                                                                                                                                                                                                                //重定向错误输出
            sortProcess.StartInfo.CreateNoWindow         = true;                                                                                                                                                                                                                                                //设置不显示窗口
            sortProcess.StartInfo.RedirectStandardInput  = true;
            sortProcess.StartInfo.Arguments              = "/c mp4box.exe -add \"" + inputPath.Substring(0, inputPath.Length - 4) + ".264#trackID=1:par=1:1:name=\" -add \"" + inputPath.Substring(0, inputPath.Length - 4) + ".aac:name=\" -new \"" + inputPath.Substring(0, inputPath.Length - 4) + ".mp4\""; //设定程式执行参数
            sortProcess.Start();
            sortProcess.BeginOutputReadLine();                                                                                                                                                                                                                                                                  // 异步获取命令行内容
            sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
            Console.WriteLine("Packaging!Please wait with patience!");
            sortProcess.WaitForExit();//等待程序执行完退出进程
            sortProcess.Close();
            if (File.Exists(inputPath.Substring(0, inputPath.Length - 4) + ".aac"))
            {
                File.Delete(inputPath.Substring(0, inputPath.Length - 4) + ".aac");
            }
            if (File.Exists(inputPath.Substring(0, inputPath.Length - 4) + ".264"))
            {
                File.Delete(inputPath.Substring(0, inputPath.Length - 4) + ".264");
            }
            Console.WriteLine("Congratulations! " + inputPath + " has been converted to " + inputPath.Substring(0, inputPath.Length - 4) + ".mp4 successfully!");
            return(0);
        }
Пример #5
0
        /// <summary>
        /// Extracts the files thread.
        /// </summary>
        private void ExtractFilesThread()
        {
            ListViewItem item = null;

            //string mode = frmMain.rbtFLV;

            for (var i = 0; (i < _paths.Length) && !_stop; i++)
            {
                var i1 = i;
                Invoke((MethodInvoker) delegate
                {
                    item = lvStatus.Items.Add(new ListViewItem(new[]
                    {
                        String.Empty,
                        Path.GetFileName(
                            _paths[i1]),
                        String.Empty,
                        String.Empty,
                        String.Empty
                    }));
                    item.EnsureVisible();
                });

                string videoSource = "";
                string videoCmd    = "";
                string audioSource = "";
                string audioCmd    = "";
                string target      = "";
                string fps         = "";
                string ratio       = "";
                string arg         = "";

                try
                {
                    switch (frmMain.Mode)
                    {
                        #region "FLV"

                    case "FLV":
                        using (var flvFile = new FLVFile(_paths[i]))
                        {
                            flvFile.ExtractStreams(_extractAudio, _extractVideo, _extractTimeCodes,
                                                   PromptOverwrite);

                            Invoke((MethodInvoker)(delegate
                            {
                                //txtStatus.Text = "Extracting...";
                                if (flvFile.TrueFrameRate != null)
                                {
                                    item.SubItems[2].Text =
                                        flvFile.TrueFrameRate.Value.ToString(false);
                                    item.SubItems[2].Tag = flvFile.TrueFrameRate;
                                }
                                if (flvFile.AverageFrameRate != null)
                                {
                                    item.SubItems[3].Text =
                                        flvFile.AverageFrameRate.Value.ToString(
                                            false);
                                    item.SubItems[3].Tag = flvFile.AverageFrameRate;
                                }
                                if (flvFile.Warnings.Length == 0)
                                {
                                    item.ImageIndex = (int)IconIndex.OK;
                                }
                                else
                                {
                                    item.ImageIndex = (int)IconIndex.Warning;
                                    item.SubItems[4].Text = String.Join("  ",
                                                                        flvFile.
                                                                        Warnings);
                                }

                                //txtStatus.Text = "Done extracting.";
                            }));
                        }
                        break;

                        // Case FLV

                        #endregion "FLV"

                        #region "MP4"
                    case "MP4":
                        using (var flvFile = new FLVFile(_paths[i]))
                        {
                            flvFile.ExtractStreams(_extractAudio, _extractVideo, _extractTimeCodes, PromptOverwrite);

                            Invoke((MethodInvoker) delegate
                            {
                                txtStatus.Text = "Extracting...";
                                if (flvFile != null && flvFile.TrueFrameRate != null)
                                {
                                    item.SubItems[2].Text =
                                        flvFile.TrueFrameRate.Value.ToString(false);
                                    item.SubItems[2].Tag = flvFile.TrueFrameRate;
                                }
                                if (flvFile.AverageFrameRate != null)
                                {
                                    item.SubItems[3].Text =
                                        flvFile.AverageFrameRate.Value.ToString(false);
                                    item.SubItems[3].Tag = flvFile.AverageFrameRate;
                                }
                                if (flvFile.Warnings.Length == 0)
                                {
                                    item.ImageIndex = (int)IconIndex.OK;
                                }
                                else
                                {
                                    item.ImageIndex       = (int)IconIndex.Warning;
                                    item.SubItems[4].Text = String.Join("  ", flvFile.Warnings);
                                }
                                txtStatus.Visible = true;
                                txtStatus.Text    = "Remuxing to mp4 file...";

                                // command for video
                                if (frmMain.AudioMuxing && frmMain.VideoMuxing == false)
                                {
                                    fps      = "";
                                    videoCmd = "";
                                    // no video muxing

                                    // command for audio
                                    audioSource = Path.ChangeExtension(_paths[i], ".aac");
                                    audioCmd    = "-add \"" + audioSource + "#audio" + "\" ";
                                    if (!File.Exists(audioSource))
                                    {
                                        audioSource = Path.ChangeExtension(_paths[i], ".mp3");
                                        audioCmd    = "-add \"" + audioSource + "#audio" + "\" ";
                                        if (!File.Exists(audioSource))
                                        {
                                            item.SubItems[4].Text = audioSource + " does not exits, please check the video directory/extract setting, or output video will have not audio.";
                                            audioCmd = "";
                                        }
                                    }
                                }

                                else if (frmMain.AudioMuxing == false && frmMain.VideoMuxing)
                                {
                                    audioCmd = "";

                                    fps = (frmMain.Fps.Equals("") || frmMain.Fps.Equals("Auto")) ? ":fps=" + flvFile.TrueFrameRate.ToString() : ":fps=" + frmMain.Fps;

                                    if ("Original".Equals(frmMain.Ratio))
                                    {
                                        ratio = "";
                                    }
                                    else if ("4:3".Equals(frmMain.Ratio))
                                    {
                                        ratio = ":par=1:1";
                                    }
                                    else if ("16:9".Equals(frmMain.Ratio))
                                    {
                                        ratio = ":par=1.78:1.33";
                                    }
                                    videoSource = Path.ChangeExtension(_paths[i], ".264");
                                    videoCmd    = "-add \"" + videoSource + "#video" + fps + ratio + "\" ";

                                    if (!File.Exists(videoSource))
                                    {
                                        videoSource = Path.ChangeExtension(_paths[i], ".avi");
                                        videoCmd    = "-add \"" + videoSource + "#video" + fps + ratio + "\" ";
                                        if (!File.Exists(videoSource))
                                        {
                                            item.SubItems[4].Text = "Video does not exits, please check the video directory or extract setting.";
                                        }
                                    }
                                }

                                else if (frmMain.AudioMuxing && frmMain.VideoMuxing)
                                {
                                    // command for audio
                                    audioSource = Path.ChangeExtension(_paths[i], ".aac");
                                    audioCmd    = "-add \"" + audioSource + "#audio" + "\" ";

                                    if (!File.Exists(audioSource))
                                    {
                                        audioSource = Path.ChangeExtension(_paths[i], ".mp3");
                                        audioCmd    = "-add \"" + audioSource + "#audio" + "\" ";
                                        if (!File.Exists(audioSource))
                                        {
                                            item.SubItems[4].Text = audioSource + " does not exits, please check the video directory/extract setting, or output video will have not audio.";
                                            audioCmd = "";
                                        }
                                    }

                                    // end command for audio
                                    if (frmMain.Fps.Equals("") ||
                                        frmMain.Fps.Equals("Auto"))
                                    {
                                        //fps = ":fps=" + Math.Round(flvFile.TrueFrameRate.Value.ToDouble(), 3).ToString();
                                        fps = ":fps=" + flvFile.TrueFrameRate.ToString();
                                    }
                                    else
                                    {
                                        fps = ":fps=" + frmMain.Fps;
                                    }
                                    if (frmMain.Ratio.Equals("Original"))
                                    {
                                        ratio = "";
                                    }
                                    else if (frmMain.Ratio.Equals("4:3"))
                                    {
                                        ratio = ":par=1:1";
                                    }
                                    else if (frmMain.Ratio.Equals("16:9"))
                                    {
                                        ratio = ":par=1.78:1.33";
                                    }

                                    videoSource = Path.ChangeExtension(_paths[i], ".264");
                                    videoCmd    = "-add \"" + videoSource + "#video" + fps + ratio + "\" ";

                                    if (!File.Exists(videoSource))
                                    {
                                        videoSource = Path.ChangeExtension(_paths[i], ".avi");
                                        videoCmd    = "-add \"" + videoSource + "#video" + fps + ratio + "\" ";
                                        if (!File.Exists(videoSource))
                                        {
                                            item.SubItems[4].Text = "Video does not exits, please check the video directory or extract setting.";
                                        }
                                    }
                                }                                // else if has video / audio
                                else
                                {
                                    return;
                                }

                                // command for output
                                target = Path.ChangeExtension(_paths[i], frmMain.VideoMuxing ? ".mp4" : ".m4a");

                                if (File.Exists(target))
                                {
                                    var mes =
                                        MessageBox.Show(
                                            string.Format("{0} has already existed, rewrite or save with new name?", target),
                                            "Warning", MessageBoxButtons.YesNoCancel,
                                            MessageBoxIcon.Question);
                                    if (mes == DialogResult.Yes)
                                    {
                                        File.Delete(target);

                                        // build final command and mux files
                                        arg = videoCmd + audioCmd + "\"" + target + "\"";
                                        Mp4Muxing(arg);
                                    }                                // Yes rewrite

                                    switch (mes)
                                    {
                                    case DialogResult.No:
                                        target = target.Insert(target.LastIndexOf(".", StringComparison.Ordinal),
                                                               "_new");
                                        File.Delete(target);
                                        arg = videoCmd + audioCmd + "\"" + target + "\"";
                                        Mp4Muxing(arg);
                                        break;

                                    case DialogResult.Cancel:
                                        item.SubItems[4].Text = "Skipped";
                                        break;
                                    }
                                }
                                else                                // no exist
                                {
                                    arg = videoCmd + audioCmd + "\"" + target + "\"";
                                    Mp4Muxing(arg);
                                }

                                // end command for output

                                if (frmMain.Remove)
                                {
                                    try
                                    {
                                        if (frmMain.AudioMuxing)
                                        {
                                            File.Delete(audioSource);
                                        }
                                        if (frmMain.VideoMuxing)
                                        {
                                            File.Delete(videoSource);
                                        }
                                        File.Delete(Path.ChangeExtension(_paths[i], ".txt"));
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }
                                }

                                txtStatus.Text = "Done.";

                                /** End here */
                            });
                        }      // using
                        break; // case MP4

                        #endregion "MP4"

                        #region "MKV"

                    case "MKV":

                        //MessageBox.Show("Not now", "Information");
                        using (var flvFile = new FLVFile(_paths[i]))
                        {
                            flvFile.ExtractStreams(_extractAudio, _extractVideo, _extractTimeCodes, PromptOverwrite);

                            Invoke((MethodInvoker) delegate
                            {
                                txtStatus.Text = "Extracting...";
                                if (flvFile.TrueFrameRate != null)
                                {
                                    item.SubItems[2].Text =
                                        flvFile.TrueFrameRate.Value.ToString(false);
                                    item.SubItems[2].Tag = flvFile.TrueFrameRate;
                                }
                                if (flvFile.AverageFrameRate != null)
                                {
                                    item.SubItems[3].Text =
                                        flvFile.AverageFrameRate.Value.ToString(false);
                                    item.SubItems[3].Tag = flvFile.AverageFrameRate;
                                }
                                if (flvFile.Warnings.Length == 0)
                                {
                                    item.ImageIndex = (int)IconIndex.OK;
                                }
                                else
                                {
                                    item.ImageIndex       = (int)IconIndex.Warning;
                                    item.SubItems[4].Text = String.Join("  ",
                                                                        flvFile.Warnings);
                                }
                                txtStatus.Visible = true;
                                txtStatus.Text    = "Remuxing to mkv file...";
                                /** Extracting process ends here */

                                /** Start muxing process here*/

                                // mkvmerge.exe -o "F:\\Anime\\Full Metal Panic! Fumoffu\\[A4VF]Full_Metal_Panic_Fumoffu-01.mkv"  "--default-duration" "0:23.976fps" " "--aspect-ratio" "0:4/3" "-d" "(" "F:\\Anime\\Full Metal Panic! Fumoffu\\[A4VF]Full_Metal_Panic_Fumoffu-01.264" ")" "(" "F:\\Anime\\Full Metal Panic! Fumoffu\\[A4VF]Full_Metal_Panic_Fumoffu-01.aac" ")"

                                /** Checking codes go here**/

                                // command for video
                                if (frmMain.AudioMuxing && frmMain.VideoMuxing == false)
                                {
                                    fps      = "";
                                    ratio    = "";
                                    videoCmd = "";

                                    // command for audio
                                    audioSource = Path.ChangeExtension(_paths[i], ".aac");
                                    audioCmd    = "\"" + audioSource + "\"";
                                    if (!File.Exists(audioSource))
                                    {
                                        audioSource = Path.ChangeExtension(_paths[i], ".mp3");
                                        audioCmd    = "\"" + audioSource + "\"";
                                        if (!File.Exists(audioSource))
                                        {
                                            item.SubItems[4].Text = string.Format("{0} does not exist, please check the video directory/extract setting, or output video will have not audio.", audioSource);
                                            audioCmd = "";
                                        }
                                    }
                                }

                                else if (frmMain.AudioMuxing == false && frmMain.VideoMuxing)
                                {
                                    audioCmd = "";

                                    fps   = ("".Equals(frmMain.Fps) || "Auto".Equals(frmMain.Fps)) ? "" : "\"--default-duration\" \"0:" + frmMain.Fps + "fps\" ";
                                    ratio = ("".Equals(frmMain.Ratio) || "Original".Equals(frmMain.Ratio)) ? "" : "\"--aspect-ratio\" \"0:" + frmMain.Ratio.Replace(":", "/") + "\" ";

                                    videoSource = Path.ChangeExtension(_paths[i], ".264");
                                    videoCmd    = fps + ratio + "\"(\" " + videoSource + "\" \")\" ";
                                    if (!File.Exists(videoSource))
                                    {
                                        videoSource = Path.ChangeExtension(_paths[i], ".avi");
                                        videoCmd    = fps + ratio + "\"(\" \"" + videoSource + "\" \")\" ";
                                        if (!File.Exists(videoSource))
                                        {
                                            item.SubItems[4].Text = "Video does not exist, please check the video directory or extract setting.";

                                            //return;
                                        }
                                    }
                                }
                                else if (frmMain.AudioMuxing && frmMain.VideoMuxing)
                                {
                                    // command for audio
                                    audioSource = Path.ChangeExtension(_paths[i], ".aac");
                                    audioCmd    = "\"" + audioSource + "\"";

                                    if (!File.Exists(audioSource))
                                    {
                                        audioSource = Path.ChangeExtension(_paths[i], ".mp3");
                                        audioCmd    = "\"" + audioSource + "\"";
                                        if (!File.Exists(audioSource))
                                        {
                                            item.SubItems[4].Text =
                                                string.Format(
                                                    "{0} does not exist, please check the video directory/extract setting, or output video will have not audio.",
                                                    audioSource);
                                            audioCmd = "";
                                        }
                                    }

                                    fps   = ("".Equals(frmMain.Fps) || "Auto".Equals(frmMain.Fps)) ? "" : "\"--default-duration\" \"0:" + frmMain.Fps + "fps\" ";
                                    ratio = ("".Equals(frmMain.Ratio) || "Original".Equals(frmMain.Ratio)) ? "" : "\"--aspect-ratio\" \"0:" + frmMain.Ratio.Replace(":", "/") + "\" ";

                                    videoSource = Path.ChangeExtension(_paths[i], ".264");
                                    videoCmd    = fps + ratio + "\"" + videoSource + "\" ";
                                    if (!File.Exists(videoSource))
                                    {
                                        videoSource = Path.ChangeExtension(_paths[i], ".avi");
                                        videoCmd    = fps + ratio + "\"(\" \"" + videoSource + "\" \")\" ";

                                        if (!File.Exists(videoSource))
                                        {
                                            MessageBox.Show("Video does not exist, please check the video directory or extract setting.");
                                        }
                                    }
                                }                                // end video / audio command

                                // command for output
                                target = Path.ChangeExtension(_paths[i], frmMain.VideoMuxing ? ".mkv" : ".mka");

                                if (File.Exists(target))
                                {
                                    var mes =
                                        MessageBox.Show(
                                            string.Format("{0} has already existed, rewrite or save with new name?", target),
                                            "Warning", MessageBoxButtons.YesNoCancel,
                                            MessageBoxIcon.Question);
                                    switch (mes)
                                    {
                                    case DialogResult.Yes:
                                        File.Delete(target);
                                        arg = " -o \"" + target + "\" " + videoCmd + audioCmd;
                                        MkvMuxing(arg);
                                        break;

                                    case DialogResult.No:
                                        target = target.Insert(target.LastIndexOf(".", System.StringComparison.Ordinal), "_new");
                                        File.Delete(target);
                                        arg = " -o \"" + target + "\" " + videoCmd + audioCmd;
                                        MkvMuxing(arg);
                                        break;

                                    case DialogResult.Cancel:
                                        item.SubItems[4].Text = "Skipped";
                                        break;
                                    }
                                }
                                else
                                {
                                    arg = " -o \"" + target + "\" " + videoCmd + audioCmd;
                                    MkvMuxing(arg);
                                }

                                if (frmMain.Remove)
                                {
                                    try
                                    {
                                        if (frmMain.AudioMuxing)
                                        {
                                            File.Delete(audioSource);
                                        }
                                        if (frmMain.VideoMuxing)
                                        {
                                            File.Delete(videoSource);
                                        }
                                        File.Delete(Path.ChangeExtension(_paths[i], ".txt"));
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }
                                }

                                txtStatus.Text = "Done.";

                                /** End here */
                            });
                        }     // using
                        break;

                        // case Mkv

                        #endregion "MKV"

                    default:
                        MessageBox.Show("Not now", "Information");
                        break;
                    }
                } // try
                catch (Exception ex)
                {
                    Invoke((MethodInvoker)(() =>
                    {
                        item.ImageIndex = (int)IconIndex.Error;
                        item.SubItems[4].Text = ex.Message;
                        item.SubItems[4].Tag = ex.StackTrace;
                    }));
                }
            }

            Invoke((MethodInvoker) delegate
            {
                btnStop.Visible           = false;
                btnCopyFrameRates.Enabled = true;
                btnOK.Enabled             = true;
            });
        }
Пример #6
0
        private bool convert(string args, bool delete)
        {
            if (File.Exists(args.Substring(0, args.Length - 4) + ".mp4"))
            {
                DialogResult dr = MessageBox.Show("发现重名文件 " + args.Substring(0, args.Length - 4) + ".mp4 ,是否删除?", "提示", MessageBoxButtons.OKCancel);
                if (dr == DialogResult.OK)
                {
                    File.Delete(args.Substring(0, args.Length - 4) + ".mp4");
                }
                else if (dr == DialogResult.Cancel)
                {
                    return(false);
                }
            }
            bool   extractVideo     = false;
            bool   extractAudio     = false;
            bool   extractTimeCodes = false;
            string outputDirectory  = null;

            try
            {
                _autoOverwrite = true;
                extractVideo   = true;
                extractAudio   = true;
                inputPath      = args;
            }
            catch
            {
                Console.WriteLine("Arguments: source_path");
                Console.WriteLine();
                return(false);
            }

            richTextBox1.Text += "正在抽取视音频数据!\r\n";
            try
            {
                using (FLVFile flvFile = new FLVFile(Path.GetFullPath(inputPath)))
                {
                    if (outputDirectory != null)
                    {
                        flvFile.OutputDirectory = Path.GetFullPath(outputDirectory);
                    }
                    flvFile.ExtractStreams(extractAudio, extractVideo, extractTimeCodes, PromptOverwrite);
                    if ((flvFile.TrueFrameRate != null) || (flvFile.AverageFrameRate != null))
                    {
                        if (flvFile.TrueFrameRate != null)
                        {
                            richTextBox1.Text += "True Frame Rate: " + flvFile.TrueFrameRate.ToString() + "\r\n";
                        }
                        if (flvFile.AverageFrameRate != null)
                        {
                            richTextBox1.Text += "Average Frame Rate: " + flvFile.AverageFrameRate.ToString() + "\r\n";
                        }
                    }
                    if (flvFile.Warnings.Length != 0)
                    {
                        foreach (string warning in flvFile.Warnings)
                        {
                            richTextBox1.Text += "Warning: " + warning + "\r\n";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                richTextBox1.Text += "Error: " + ex.Message + "\r\n";
                return(false);
            }

            if (!File.Exists(inputPath.Substring(0, inputPath.Length - 4) + ".aac"))
            {
                MessageBox.Show("数据文件异常,请检查FLV文件后尝试!", "温馨提示");
                return(false);
            }
            if (!File.Exists(inputPath.Substring(0, inputPath.Length - 4) + ".264"))
            {
                MessageBox.Show("数据文件异常,请检查FLV文件后尝试!", "温馨提示");
                return(false);
            }

            Process sortProcess;

            sortProcess = new Process();
            sortOutput  = new StringBuilder("");
            sortProcess.StartInfo.FileName               = "cmd.exe";
            sortProcess.StartInfo.UseShellExecute        = false;                                                                                                                                                                                                                                               // 必须禁用操作系统外壳程序
            sortProcess.StartInfo.RedirectStandardOutput = true;
            sortProcess.StartInfo.RedirectStandardError  = true;                                                                                                                                                                                                                                                //重定向错误输出
            sortProcess.StartInfo.CreateNoWindow         = true;                                                                                                                                                                                                                                                //设置不显示窗口
            sortProcess.StartInfo.RedirectStandardInput  = true;
            sortProcess.StartInfo.Arguments              = "/c mp4box.exe -add \"" + inputPath.Substring(0, inputPath.Length - 4) + ".264#trackID=1:par=1:1:name=\" -add \"" + inputPath.Substring(0, inputPath.Length - 4) + ".aac:name=\" -new \"" + inputPath.Substring(0, inputPath.Length - 4) + ".mp4\""; //设定程式执行参数
            sortProcess.Start();
            richTextBox1.Text += "封装为MP4中!请耐心等待!\r\n";
            sortProcess.BeginOutputReadLine();                                                 // 异步获取命令行内容
            sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler); // 为异步获取订阅事件
            sortProcess.WaitForExit();                                                         //等待程序执行完退出进程
            sortProcess.Close();
            if (File.Exists(inputPath.Substring(0, inputPath.Length - 4) + ".aac"))
            {
                File.Delete(inputPath.Substring(0, inputPath.Length - 4) + ".aac");
            }
            if (File.Exists(inputPath.Substring(0, inputPath.Length - 4) + ".264"))
            {
                File.Delete(inputPath.Substring(0, inputPath.Length - 4) + ".264");
            }
            if (!richTextBox1.Text.Contains("ISO File Writing"))
            {
                MessageBox.Show("文件路径中可能存在非法字符,请重命名 " + args + " 后重试!", "温馨提示");
                return(false);
            }
            if (delete)
            {
                File.Delete(inputPath);
            }
            richTextBox1.Text = "";
            ConvertSuccess++;
            return(true);
        }
 private void toMp3(string inputPath)
 {
     try
     {
         using (FLVFile flvFile = new FLVFile(Path.GetFullPath(inputPath)))
         {
             flvFile.ExtractStreams(PromptOverwrite);
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show("Error: " + exc.Message + Environment.NewLine);
         LogFile.WriteToLogFile(LogFile.Operation.app_error, null, exc.Message);
     }
 }