예제 #1
0
        // method 1: add preview as separate track with slightly bigger resolution (via Pituz)
        static void GeneratePreview(string filePath)
        {
            OutputProcessor sp = new SimpleProcessor();
            ProcessingUnit  pu = sp.CreateOne();

            string fileName      = Path.GetFileName(filePath),
                   output        = filePath.Substring(0, filePath.LastIndexOf('.') + 1) + "preview.webm",
                   previewSource = ArgList.Get(Arg.PREVIEW_SOURCE) ? GetFullPath(ArgList.Get(Arg.PREVIEW_SOURCE).AsString()) : filePath,
                   previewTiming = ArgList.Get(Arg.PREVIEW).AsString();

            // Preview
            long   time        = DateTime.Now.ToFileTimeUtc();
            string previewWebm = GetFolder(filePath) + "\\preview_" + time.ToString() + ".webm";

            // Same scale
            Ffprober.Result result = Ffprober.Probe(filePath);
            string          scale  = result.Scale;

            scale = scale == null ? string.Empty : $",scale={result.WidthPix + 1}:-1";
            scale = $"-filter:v:1 \"trim=end_frame=2{scale}\"";
            string args = $"-hide_banner -i \"{filePath}\" -ss {previewTiming} -i \"{previewSource}\" -c copy -map 0:v -map 0:a -map 1:v -c:v:1 vp9 -b:v:1 0 -crf 8 -speed 1 {scale} \"{output}\"";

            ExecuteFFMPEG(args, pu);

            sp.Destroy(pu);
        }
예제 #2
0
        static void GeneratePreviewOld(string filePath)
        {
            OutputProcessor sp = new SimpleProcessor();
            ProcessingUnit  pu = sp.CreateOne();

            string fileName      = Path.GetFileName(filePath),
                   output        = filePath.Substring(0, filePath.LastIndexOf('.') + 1) + "preview.webm",
                   previewSource = ArgList.Get(Arg.PREVIEW_SOURCE) ? GetFullPath(ArgList.Get(Arg.PREVIEW_SOURCE).AsString()) : filePath,
                   previewTiming = ArgList.Get(Arg.PREVIEW).AsString();

            // Preview
            long   time        = DateTime.Now.ToFileTimeUtc();
            string previewWebm = GetFolder(filePath) + "\\preview_" + time.ToString() + ".webm";

            // Same scale
            Ffprober.Result result = Ffprober.Probe(filePath);
            string          scale  = result.Scale;

            scale = scale == null ? string.Empty : (",scale=" + scale);
            scale = $"-vf \"trim=end_frame=2{scale}\"";
            string args = $"-hide_banner -ss {previewTiming} -i \"{previewSource}\" -c:v vp9 -pix_fmt +yuv420p -b:v 0 -crf 8 -speed 1 -an -sn {scale} \"{previewWebm}\"";

            ExecuteFFMPEG(args, pu);

            // Bad muxing fix
            string videoOnly = $"video_{time}.webm";

            args = $"-hide_banner -i \"{filePath}\" -c copy -map 0:v \"{videoOnly}\"";
            ExecuteFFMPEG(args, pu);

            // Concat
            string concatedWebm = $"concat_{time}.webm";
            string concatFile   = $"concat_{time}.txt";

            File.WriteAllText(concatFile, $"file '{previewWebm}'\r\nfile '{videoOnly}'", Encoding.Default);
            string fps = result.Framerate;
            string dur = Ffprober.Probe(previewWebm).EndTime;

            if (dur == null)
            {
                dur = "0.042";
            }
            args = $"-hide_banner -f concat -i \"{concatFile}\" -c copy \"{concatedWebm}\"";
            ExecuteFFMPEG(args, pu);
            args = $"-hide_banner -y -itsoffset 0.5 -i \"{filePath}\" -i \"{concatedWebm}\" -map 1:v -map 0:a -c copy \"{output}\"";
            ExecuteFFMPEG(args, pu);

            // Delete
            File.Delete(concatFile);
            File.Delete(previewWebm);
            File.Delete(concatedWebm);
            File.Delete(videoOnly);

            sp.Destroy(pu);
        }