예제 #1
0
        public string GetFFmpegArgs()
        {
            StringBuilder args = new StringBuilder();

            // Input file path
            args.Append($"-i \"{InputFilePath}\" ");

            // Video codec
            switch (VideoCodec)
            {
            case ConverterVideoCodecs.x264:                            // https://trac.ffmpeg.org/wiki/Encode/H.264
                args.Append($"-c:v libx264 -preset medium -crf {VideoQuality.Clamp(0, 51)} ");
                args.Append("-pix_fmt yuv420p -movflags +faststart "); // For browser support
                break;

            case ConverterVideoCodecs.x265:     // https://trac.ffmpeg.org/wiki/Encode/H.265
                args.Append($"-c:v libx265 -preset medium -crf {VideoQuality.Clamp(0, 51)} ");
                break;

            case ConverterVideoCodecs.vp8:     // https://trac.ffmpeg.org/wiki/Encode/VP8
                args.Append($"-c:v libvpx -crf {VideoQuality.Clamp(0, 63)} -b:v 0 ");
                break;

            case ConverterVideoCodecs.vp9:     // https://trac.ffmpeg.org/wiki/Encode/VP9
                args.Append($"-c:v libvpx-vp9 -crf {VideoQuality.Clamp(0, 63)} -b:v 0 ");
                break;

            case ConverterVideoCodecs.xvid:     // https://trac.ffmpeg.org/wiki/Encode/MPEG-4
                args.Append($"-c:v libxvid -q:v {VideoQuality.Clamp(1, 31)} ");
                break;

            case ConverterVideoCodecs.gif:     // https://ffmpeg.org/ffmpeg-filters.html#palettegen-1
                args.Append("-lavfi \"palettegen=stats_mode=full[palette],[0:v][palette]paletteuse=dither=sierra2_4a\" ");
                break;

            case ConverterVideoCodecs.webp:     // https://www.ffmpeg.org/ffmpeg-codecs.html#libwebp
                args.Append("-c:v libwebp -lossless 0 -preset default -loop 0 ");
                break;

            case ConverterVideoCodecs.apng:
                args.Append("-f apng -plays 0 ");
                break;
            }

            // Audio codec
            switch (VideoCodec)
            {
            case ConverterVideoCodecs.x264:     // https://trac.ffmpeg.org/wiki/Encode/AAC
            case ConverterVideoCodecs.x265:
                args.Append("-c:a aac -b:a 128k ");
                break;

            case ConverterVideoCodecs.vp8:     // https://trac.ffmpeg.org/wiki/TheoraVorbisEncodingGuide
            case ConverterVideoCodecs.vp9:
                args.Append("-c:a libvorbis -q:a 3 ");
                break;

            case ConverterVideoCodecs.xvid:     // https://trac.ffmpeg.org/wiki/Encode/MP3
                args.Append("-c:a libmp3lame -q:a 4 ");
                break;
            }

            // Output file path
            args.Append($"-y \"{OutputFilePath}\"");

            return(args.ToString());
        }