Example #1
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;

            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;
        }
 private void btnExtract_Click(object sender, RoutedEventArgs e)
 {
     error = false;
     FileInformation.copiedFileName = null;
     lblStatus.Visibility = System.Windows.Visibility.Visible;
     textBlock1.Visibility = System.Windows.Visibility.Hidden;
     try
     {
         if (System.IO.Path.GetExtension(FileInformation.fileName[0]) == ".flv")
         {
             JDP.FLVFile f = new JDP.FLVFile(FileInformation.fileName[0]);
             f.ExtractStreams(true, false, false, null);
             lblStatus.Visibility = System.Windows.Visibility.Hidden;
             textBlock1.Visibility = System.Windows.Visibility.Visible;
         }
         else
         {
             if (FileInformation.fileName[0].Contains(" "))
             {
                 FileInformation.FN fnDel = (x) =>
                 {
                     FileInformation.copiedFileName = FileInformation.fileName[0].Replace(" ", "_");
                     return FileInformation.copiedFileName;
                 };
                 FileInformation.CopyFile(fnDel);
                 backgroundWorker1.RunWorkerAsync(FileInformation.copiedFileName);
             }
             else
                 backgroundWorker1.RunWorkerAsync(FileInformation.fileName[0]);                   
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show("Error: " + exc.Message + "\nCannot extract audio from the " + System.IO.Path.GetExtension(FileInformation.fileName[0]) + " filetype", "Error"); 
     }
 }
Example #3
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;
                                       });
        }