Beispiel #1
0
        /// <summary>
        /// Format a x264 profile argument for ffmpeg.
        /// </summary>
        public static string formatProfileFileArg(Profilex264 preset)
        {
            string presetCommand = "-fpre";
            string profileArg    = "";
            string profileFile   = "";
            string profilePath   = "";

            switch (preset)
            {
            case Profilex264.IPod320: profileFile = "libx264-ipod320.ffpreset"; break;

            case Profilex264.IPod640: profileFile = "libx264-ipod640.ffpreset"; break;

            case Profilex264.Baseline: profileFile = "libx264-baseline.ffpreset"; break;

            case Profilex264.Main: profileFile = "libx264-main.ffpreset"; break;

            case Profilex264.High: profileFile = ""; break;

            case Profilex264.None: profileFile = ""; break;

            default: profileFile = ""; break;
            }

            if (profileFile.Length > 0)
            {
                profilePath = Path.Combine(ConstantSettings.PathFFmpegPresetsFull, profileFile);

                // Example: -fpre "E:\subs2srs\subs2srs\bin\Release\Utils\ffmpeg\presets\libx264-ipod640.ffpreset"
                profileArg = String.Format("{0} \"{1}\"", presetCommand, profilePath);
            }

            return(profileArg);
        }
Beispiel #2
0
        /// <summary>
        /// Convert the input video using the specified options.
        ///
        /// Note:
        /// h.264 and .mp4 have timing/cutting issues. h.264 only cuts on the last keyframe,
        /// which could be several seconds before the time that you actually want to cut.
        ///
        /// When cutting an .mp4 (even with MPEG4 video and MP3 audio), the cut will take place
        /// ~0.5 seconds before it should.
        ///
        /// (Is this still true?)
        /// </summary>
        public static void convertVideo(string inFile, string audioStream, DateTime startTime, DateTime endTime,
                                        ImageSize size, ImageCrop crop, int bitrateVideo, int bitrateAudio, VideoCodec videoCodec,
                                        AudioCodec audioCodec,
                                        Profilex264 profile, Presetx264 preset, string outFile, DialogProgress dialogProgress)
        {
            string videoMapArg = formatVideoMapArg();
            string audioMapArg = formatAudioMapArg(audioStream);

            string videoCodecArg = formatVideoCodecArg(videoCodec);

            string presetArg          = formatPresetFileArg(preset);
            string keyframeOptionsArg = formatKeyframeOptionsArg(videoCodec);
            string profileArg         = formatProfileFileArg(profile);

            string videoSizeArg    = formatVideoSizeArg(inFile, size, crop, 16, 2);
            string videoBitrateArg = $"-b:v {bitrateVideo}k";

            string audioCodecArg   = formatAudioCodecArg(audioCodec);
            string audioBitrateArg = formatAudioBitrateArg(bitrateAudio);

            string timeArg = formatStartTimeAndDurationArg(startTime, endTime);

            string cropArg = formatCropArg(inFile, size, crop);

            string threadsArg = "-threads 0";

            string ffmpegConvertArgs = "";

            // Good ffmpeg resource: http://howto-pages.org/ffmpeg/
            // 0:0 is assumed to be the video stream
            // Audio stream: 0:n where n is the number of the audio stream (usually 1)
            //
            // Example format:
            // -y -i "G:\Temp\input.mkv" -ac 2 -map 0:v:0 -map 0:a:0 -codec:v libx264 -preset superfast -g 6 -keyint_min 6
            // -fpre "E:\subs2srs\subs2srs\bin\Release\Utils\ffmpeg\presets\libx264-ipod640.ffpreset"
            // -b:v 800k -codec:a aac -b:a 128k -ss 00:03:32.420 -t 00:02:03.650 -vf "scale 352:202, crop=352:202:0:0" -threads 0
            // "C:\Documents and Settings\cb4960\Local Settings\Temp\~subs2srs_temp.mp4"
            ffmpegConvertArgs =
                $"-y -i \"{inFile}\" -ac 2 {videoMapArg} {audioMapArg} {videoCodecArg} {presetArg} {keyframeOptionsArg} {profileArg} {videoBitrateArg} {audioCodecArg} {audioBitrateArg}" +
                $" {timeArg} -vf \"{videoSizeArg}, {cropArg}\" {threadsArg} \"{outFile}\" "; // {14}


            if (dialogProgress == null)
            {
                UtilsCommon.startFFmpeg(ffmpegConvertArgs, true, true);
            }
            else
            {
                UtilsCommon.startFFmpegProgress(ffmpegConvertArgs, dialogProgress);
            }
        }