Beispiel #1
0
        /// <summary>
        /// Rip (and re-encode) the entire audio from a video file.
        /// </summary>
        public static void ripAudioFromVideo(string inFile, int bitrate, string outFile)
        {
            string audioBitrateArg = UtilsVideo.formatAudioBitrateArg(bitrate);

            string ffmpegAudioProgArgs = "";

            // Example format:
            // -vn -y -i "G:\Temp\inputs.mkv" -ac 2 -b:a 128k "output.mp3"
            ffmpegAudioProgArgs = String.Format("-vn -y -i \"{1}\" -ac 2 {1} -threads 0 \"{2}\"",
                                                inFile,          // {0}
                                                audioBitrateArg, // {1}
                                                outFile);        // {2}

            UtilsCommon.startFFmpeg(ffmpegAudioProgArgs, true, true);
        }
Beispiel #2
0
        /// <summary>
        /// Rip (and re-encode) a portion of the audio from a video file.
        /// </summary>
        public static void ripAudioFromVideo(string inFile, string stream, DateTime startTime,
                                             DateTime endTime, int bitrate, string outFile, DialogProgress dialogProgress)
        {
            string audioBitrateArg = UtilsVideo.formatAudioBitrateArg(bitrate);
            string audioMapArg     = UtilsVideo.formatAudioMapArg(stream);
            string timeArg         = UtilsVideo.formatStartTimeAndDurationArg(startTime, endTime);

            string ffmpegAudioProgArgs = "";

            // Example format:
            // -vn -y -i "G:\Temp\inputs.mkv" -ac 2 -map 0:1 -ss 00:03:32.420 -t 00:02:03.650 -b:a 128k -threads 0 "output.mp3"
            ffmpegAudioProgArgs =
                $"-vn -y -i \"{inFile}\" -ac 2 {audioMapArg} {timeArg} {audioBitrateArg} -threads 0 \"{outFile}\""; // {4}

            if (dialogProgress == null)
            {
                UtilsCommon.startFFmpeg(ffmpegAudioProgArgs, false, true);
            }
            else
            {
                UtilsCommon.startFFmpegProgress(ffmpegAudioProgArgs, dialogProgress);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Rip (and re-encode) a portion of the audio from a video file.
        /// </summary>
        public static void ripAudioFromVideo(string inFile, string stream, DateTime startTime,
                                             DateTime endTime, int bitrate, string outFile, DialogProgress dialogProgress)
        {
            string audioBitrateArg = UtilsVideo.formatAudioBitrateArg(bitrate);
            string audioMapArg     = UtilsVideo.formatAudioMapArg(stream);
            string timeArg         = UtilsVideo.formatStartTimeAndDurationArg(startTime, endTime);

            string ffmpegAudioProgArgs = "";

            // Example format:
            // -vn -y -i "G:\Temp\inputs.mkv" -ac 2 -map 0:1 -ss 00:03:32.420 -t 00:02:03.650 -b:a 128k -threads 0 "output.mp3"
            ffmpegAudioProgArgs = String.Format("-vn -y -i \"{0}\" -ac 2 {1} {2} {3} -threads 0 \"{4}\"",
                                                                 // Video file
                                                inFile,          // {0}

                                                                 // Mapping
                                                audioMapArg,     // {1}

                                                                 // Time span
                                                timeArg,         // {2}

                                                                 // Bitrate
                                                audioBitrateArg, // {3}

                                                                 // Output file name
                                                outFile);        // {4}

            if (dialogProgress == null)
            {
                UtilsCommon.startFFmpeg(ffmpegAudioProgArgs, false, true);
            }
            else
            {
                UtilsCommon.startFFmpegProgress(ffmpegAudioProgArgs, dialogProgress);
            }
        }
Beispiel #4
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 = UtilsVideo.formatVideoMapArg();
            string audioMapArg = UtilsVideo.formatAudioMapArg(audioStream);

            string videoCodecArg = UtilsVideo.formatVideoCodecArg(videoCodec);

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

            string videoSizeArg    = UtilsVideo.formatVideoSizeArg(inFile, size, crop, 16, 2);
            string videoBitrateArg = String.Format("-b:v {0}k", bitrateVideo);

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

            string timeArg = UtilsVideo.formatStartTimeAndDurationArg(startTime, endTime);

            string cropArg = UtilsVideo.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 = String.Format("-y -i \"{0}\" -ac 2 {1} {2} {3} {4} {5} {6} {7} {8} {9}" +
                                              " {10} -vf \"{11}, {12}\" {13} \"{14}\" ",
                                                                  // Input video file name
                                              inFile,             // {0}

                                                                  // Mapping
                                              videoMapArg,        // {1}
                                              audioMapArg,        // {2}

                                                                  // Video
                                              videoCodecArg,      // {3}
                                              presetArg,          // {4}
                                              keyframeOptionsArg, // {5}
                                              profileArg,         // {6}
                                              videoBitrateArg,    // {7}

                                                                  // Audio
                                              audioCodecArg,      // {8}
                                              audioBitrateArg,    // {9}

                                                                  // Time span
                                              timeArg,            // {10}

                                                                  // Filters
                                              videoSizeArg,       // {11}
                                              cropArg,            // {12}

                                                                  // Threads
                                              threadsArg,         // {13}

                                                                  // Output video file name
                                              outFile);           // {14}


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