Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static void Convert(FFMpegConvertTask task)
        {
            var handler = new ConsoleApplicationHandler();

            handler.ExePath = EnvironmentInfo.GetExecutablePath("ffmpeg");

            var sb = new StringBuilder();

            sb.Append(" -i ");
            sb.Append(task.SourceFile);
            sb.Append(" -acodec aac -strict -2 -b:a 128k -vcodec libx264 -b:v 1200k -y ");
            if (task.Height != 0 && task.Width != 0)
            {
                sb.Append(" -s ");
                sb.Append(task.Width);
                sb.Append("x");
                sb.Append(task.Height);
            }
            sb.Append(" -ss ");
            sb.Append(task.StartTime);
            sb.Append(" -t ");
            if (task.Duration.TotalMilliseconds < 100)
            {
                sb.Append("05:00:00");
            }
            else
            {
                sb.Append(task.Duration);
            }
            sb.Append(" -flags +aic+mv4 ");
            sb.Append(" \"");
            sb.Append(task.TargetFile);
            sb.Append("\"");
            handler.Arguments = sb.ToString();
            var result = handler.RunSync();

            if (!result.IsOK)
            {
                throw new Exception(result.Output + result.Error, result.Exception);
            }
        }
Exemplo n.º 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);
     }
 }