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
        private static string CreateConcatFile(FFMpegVideoJoinTask joiner)
        {
            var dir     = joiner.WorkingFolder;
            var tmpfile = joiner.JoinFileName;

            if (string.IsNullOrWhiteSpace(tmpfile))
            {
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    tmpfile = Path.Combine(dir, "join-config.tmp");
                    if (File.Exists(tmpfile))
                    {
                        tmpfile = Path.Combine(dir, "join-config-" + Environment.TickCount + ".tmp");
                    }
                }
                else
                {
                    tmpfile = Path.GetTempFileName();
                }
            }
            else
            {
                if (!Path.IsPathRooted(tmpfile))
                {
                    if (string.IsNullOrWhiteSpace(dir))
                    {
                        dir = Environment.CurrentDirectory;
                    }
                    tmpfile = Path.Combine(dir, tmpfile);
                }
            }
            if (null != joiner.FileList && 0 != joiner.FileList.Length)
            {
                File.AppendAllLines(tmpfile, joiner.FileList.Select(_ => "file " + _.Replace("\\", "/")));
            }
            else
            {
                if (string.IsNullOrWhiteSpace(dir))
                {
                    dir = Environment.CurrentDirectory;
                }
                var files = Directory.GetFiles(dir, joiner.FileNameBase + "*.mp4");
                files =
                    files.Where(
                        _ =>
                        Regex.IsMatch(Path.GetFileNameWithoutExtension(_),
                                      joiner.FileNameBase + "\\d{" + joiner.DigitCount + "}")).ToArray();
                files = files.OrderBy(_ => Path.GetFileNameWithoutExtension(_)).ToArray();
                File.AppendAllLines(tmpfile, files.Select(_ => "file " + _.Replace("\\", "/")));
            }
            return(tmpfile);
        }
Beispiel #3
0
        public static void Join(FFMpegVideoJoinTask joiner)
        {
            var joinfile = CreateConcatFile(joiner);
            var handler  = new ConsoleApplicationHandler();

            handler.ExePath = EnvironmentInfo.GetExecutablePath("ffmpeg");
            var sb = new StringBuilder();

            sb.Append(" -f concat");
            sb.Append(" -i \"" + joinfile + "\" ");
            sb.Append(" -c copy ");
            sb.Append(" \"");
            sb.Append(joiner.TargetFile);
            sb.Append("\"");
            handler.Arguments = sb.ToString();
            var result = handler.RunSync();

            if (!result.IsOK)
            {
                throw new Exception(result.Output + result.Error, result.Exception);
            }
        }