Exemplo n.º 1
0
        /// <summary>
        /// Extract an audio clip from a longer audio clip without re-encoding.
        /// </summary>
        public static void cutAudio(string fileToCut, DateTime startTime, DateTime endTime, string outFile)
        {
            string timeArg       = UtilsVideo.formatStartTimeAndDurationArg(startTime, endTime);
            string audioCodecArg = UtilsVideo.formatAudioCodecArg(UtilsVideo.AudioCodec.COPY);

            string ffmpegAudioProgArgs = "";

            // Example format:
            //-y -i "input.mp3" -ss 00:00:00.000 -t 00:00:01.900 -codec:a copy "output.mp3"
            ffmpegAudioProgArgs = $"-y -i \"{fileToCut}\" {timeArg} {audioCodecArg} \"{outFile}\""; // {3}

            UtilsCommon.startFFmpeg(ffmpegAudioProgArgs, false, true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extract an audio clip from a longer audio clip without re-encoding.
        /// </summary>
        public static void cutAudio(string fileToCut, DateTime startTime, DateTime endTime, string outFile)
        {
            string timeArg       = UtilsVideo.formatStartTimeAndDurationArg(startTime, endTime);
            string audioCodecArg = UtilsVideo.formatAudioCodecArg(UtilsVideo.AudioCodec.COPY);

            string ffmpegAudioProgArgs = "";

            // Example format:
            //-y -i "input.mp3" -ss 00:00:00.000 -t 00:00:01.900 -codec:a copy "output.mp3"
            ffmpegAudioProgArgs = String.Format("-y -i \"{0}\" {1} {2} \"{3}\"",
                                                               // Input file
                                                fileToCut,     // {0}

                                                               // Time span
                                                timeArg,       // {1}

                                                               // Audio codec
                                                audioCodecArg, // {2}

                                                               // Output file (including full path)
                                                outFile);      // {3}

            UtilsCommon.startFFmpeg(ffmpegAudioProgArgs, false, true);
        }
Exemplo n.º 3
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);
            }
        }