Beispiel #1
0
        public static void CreateMovie(FFMpegCreateMovieTask task)
        {
            task.Normalize();
            Directory.CreateDirectory(task.WorkingFolder);
            var convert = new FFMpegConvertTask();

            convert.SourceFile = task.SourceFile;
            convert.Height     = task.Height;
            convert.Width      = task.Width;
            convert.StartTime  = task.StartTime;
            convert.Duration   = task.Duration;
            convert.TargetFile = Path.Combine(task.WorkingFolder, task.TmpFileBasis + "rawmovie.mp4");
            Convert(convert);
            var splitter = new FFMpegVideoSplitTask();

            splitter.SourceFile    = convert.TargetFile;
            splitter.Frames        = task.Frames;
            splitter.FileNameBase  = task.TmpFileBasis;
            splitter.WorkingFolder = task.WorkingFolder;
            Split(splitter);
            var joiner = new FFMpegVideoJoinTask();

            joiner.TargetFile    = task.TargetFile;
            joiner.FileNameBase  = task.TmpFileBasis;
            joiner.JoinFileName  = task.TmpFileBasis + "movieset.tmp";
            joiner.WorkingFolder = task.WorkingFolder;
            Join(joiner);
        }
Beispiel #2
0
 public static void SplitImages(FFMpegVideoSplitTask splitter)
 {
     if (string.IsNullOrWhiteSpace(splitter.WorkingFolder))
     {
         splitter.WorkingFolder = Path.GetDirectoryName(splitter.SourceFile);
     }
     Directory.CreateDirectory(splitter.WorkingFolder);
     for (var i = 0; i < splitter.Frames.Count; i++)
     {
         var frame    = splitter.Frames[i];
         var num      = (i + 1).ToString("00");
         var filename = splitter.FileNameBase + num + ".png";
         if (splitter.DigitCount == 0 && splitter.Frames.Count == 1)
         {
             filename = splitter.FileNameBase + ".png";
         }
         filename = Path.Combine(splitter.WorkingFolder, filename);
         var handler = new ConsoleApplicationHandler();
         handler.ExePath = EnvironmentInfo.GetExecutablePath("ffmpeg");
         var sb = new StringBuilder();
         sb.Append(" -ss ");
         sb.Append(frame.StartTime);
         sb.Append(" -i ");
         sb.Append("\"");
         sb.Append(splitter.SourceFile);
         sb.Append("\" ");
         sb.Append(" -vframes 1 ");
         if (splitter.Height != 0 && splitter.Width != 0)
         {
             sb.Append(" -s ");
             sb.Append(splitter.Width);
             sb.Append("x");
             sb.Append(splitter.Height);
         }
         sb.Append(" -y -f image2 ");
         sb.Append("\"");
         sb.Append(filename);
         sb.Append("\"");
         handler.Arguments = sb.ToString();
         var result = handler.RunSync();
         if (!result.IsOK)
         {
             throw new Exception(result.Output + result.Error, result.Exception);
         }
     }
 }
Beispiel #3
0
 public static void Split(FFMpegVideoSplitTask splitter)
 {
     if (string.IsNullOrWhiteSpace(splitter.WorkingFolder))
     {
         splitter.WorkingFolder = Path.GetDirectoryName(splitter.SourceFile);
     }
     Directory.CreateDirectory(splitter.WorkingFolder);
     for (var i = 0; i < splitter.Frames.Count; i++)
     {
         var frame    = splitter.Frames[i];
         var num      = (i + 1).ToString("00");
         var filename = splitter.FileNameBase + num + ".mp4";
         var convert  = new FFMpegConvertTask {
             SourceFile = splitter.SourceFile,
             TargetFile = Path.Combine(splitter.WorkingFolder, filename),
             StartTime  = frame.StartTime,
             Duration   = frame.Duration,
             Width      = splitter.Width,
             Height     = splitter.Height
         };
         Convert(convert);
     }
 }