Beispiel #1
0
        /// <summary>
        /// Extract a video clip from a longer video clip without re-encoding.
        /// </summary>
        public static void cutVideo(string inFile, DateTime startTime, DateTime endTime, string outFile)
        {
            string startTimeArg = UtilsVideo.formatStartTimeArg(startTime);
            string durationArg  = UtilsVideo.formatDurationArg(startTime, endTime);
            string timeArg      = formatStartTimeAndDurationArg(startTime, endTime);

            string ffmpegCutArgs = "";

            // Example format:
            // -y -i -ss 00:00:00.000 -t "input.avi" -t 00:00:01.900 -c copy "output.avi"
            // Note: The order of the arguments is strange, but unless -ss comes before -i,
            //       the video will SOMETIMES fail to copy and the output will consist
            //       of only the audio. Lots of experimentation involved.
            ffmpegCutArgs = String.Format("-y {0} -i \"{1}\" {2} -c copy \"{3}\"",
                                                        // Start time
                                          startTimeArg, // {0}

                                                        // Input video file name
                                          inFile,       // {1}

                                                        // Duration
                                          durationArg,  // {2}

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

            UtilsCommon.startFFmpeg(ffmpegCutArgs, false, true);
        }
Beispiel #2
0
        /// <summary>
        /// Format a start time and duration argument for ffmpeg.
        /// </summary>
        public static string formatStartTimeAndDurationArg(DateTime startTime, DateTime endTime)
        {
            string startTimeArg = UtilsVideo.formatStartTimeArg(startTime);
            string durationArg  = UtilsVideo.formatDurationArg(startTime, endTime);

            DateTime diffTime = UtilsSubs.getDurationTime(startTime, endTime);

            // Example: -ss 00:00:07.920 -t 00:24:35.120
            string timeArg = String.Format("{0} {1}",
                                           startTimeArg, // {0}
                                           durationArg); // {1}

            return(timeArg);
        }