Exemplo n.º 1
0
        /// <summary>
        /// Take a snapshot of a video at the provided time.
        /// </summary>
        public static void takeSnapshotFromVideo(string inFile, DateTime snapTime, ImageSize size, ImageCrop crop, string outFile)
        {
            string startTimeArg = UtilsVideo.formatStartTimeArg(snapTime);
            string videoSizeArg = UtilsVideo.formatVideoSizeArg(inFile, size, crop, 2, 2);
            string cropArg      = UtilsVideo.formatCropArg(inFile, size, crop);

            string ffmpegSnapshotProgArgs = "";

            // Example format:
            // -y -an -ss 00:03:33.370 -i "G:\Temp\input.mkv" -s 358x202 -f image2 -vf crop=358:202:0:0 -vframes 1 "output.jpg"
            ffmpegSnapshotProgArgs = String.Format("-y -an {0} -i \"{1}\" -f image2 -vf \"{2}, {3}\" -vframes 1 \"{4}\"",
                                                                 // Time to take snapshot at
                                                   startTimeArg, // {0}

                                                                 // Filename
                                                   inFile,       // {1}

                                                                 // Filters
                                                   videoSizeArg, // {2}
                                                   cropArg,      // {3}

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

            UtilsCommon.startFFmpeg(ffmpegSnapshotProgArgs, false, true);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Take a snapshot of a video at the provided time.
        /// </summary>
        public static void takeSnapshotFromVideo(string inFile, DateTime snapTime, ImageSize size, ImageCrop crop,
                                                 string outFile)
        {
            string startTimeArg = UtilsVideo.formatStartTimeArg(snapTime);
            string videoSizeArg = UtilsVideo.formatVideoSizeArg(inFile, size, crop, 2, 2);
            string cropArg      = UtilsVideo.formatCropArg(inFile, size, crop);

            string ffmpegSnapshotProgArgs = "";

            // Example format:
            // -y -an -ss 00:03:33.370 -i "G:\Temp\input.mkv" -s 358x202 -f image2 -vf crop=358:202:0:0 -vframes 1 "output.jpg"
            ffmpegSnapshotProgArgs =
                $"-y -an {startTimeArg} -i \"{inFile}\" -f image2 -vf \"{videoSizeArg}, {cropArg}\" -vframes 1 \"{outFile}\""; // {4}

            UtilsCommon.startFFmpeg(ffmpegSnapshotProgArgs, false, true);
        }