/// <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); }
/// <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); }
/// <summary> /// Format a video crop argument for ffmpeg. /// </summary> public static string formatCropArg(string file, ImageSize size, ImageCrop crop) { ImageSize outSize = UtilsVideo.getResolutionToUseWithCrop(file, size, crop); string cropArg = String.Format("crop={0}:{1}:{2}:{3}", outSize.Width - crop.Left - crop.Right, // {0} outSize.Height - crop.Top - crop.Bottom, // {1} crop.Left, // {2} crop.Top); // {3} return(cropArg); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// When using a crop, get the resolution to pass to ffmpeg in order to preserve aspect ratio. /// </summary> public static ImageSize getResolutionToUseWithCrop(string file, ImageSize desiredSize, ImageCrop crop) { ImageSize outSize; int totalCropWidth = crop.Left + crop.Right; int totalCropHeight = crop.Top + crop.Bottom; if (totalCropWidth == 0 && totalCropHeight == 0) { outSize = desiredSize; } else { ImageSize origSize = UtilsVideo.getVideoResolution(file); // output_resolution = desired_resolution + (total_crop - (desired_resolution/orig_resolution) * total_crop)) outSize = new ImageSize(); outSize.Width = desiredSize.Width + (totalCropWidth - (int)((desiredSize.Width / (float)origSize.Width) * totalCropWidth)); outSize.Height = desiredSize.Height + (totalCropHeight - (int)((desiredSize.Height / (float)origSize.Height) * totalCropHeight)); } return(outSize); }
private void textBoxMediaFile_TextChanged(object sender, EventArgs e) { string filePattern = this.textBoxMediaFile.Text.Trim(); string[] files = UtilsCommon.getNonHiddenFiles(filePattern); this.comboBoxStreamAudioFromVideo.Enabled = true; this.labelAudioStream.Enabled = true; this.comboBoxStreamAudioFromVideo.Items.Clear(); if (files.Length != 0) { // Based on the first video file in the file pattern, get the list of available streams. string firstFile = files[0]; List <InfoStream> audioStreams = UtilsVideo.getAvailableAudioStreams(firstFile); if (audioStreams.Count > 0) { foreach (InfoStream stream in audioStreams) { this.comboBoxStreamAudioFromVideo.Items.Add(stream); } } else { // Show the default stream when the available streams cannot be detected this.comboBoxStreamAudioFromVideo.Items.Add(new InfoStream()); } this.comboBoxStreamAudioFromVideo.SelectedIndex = 0; } else { this.comboBoxStreamAudioFromVideo.Enabled = false; this.labelAudioStream.Enabled = false; } }
/// <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); } }
/// <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); }
/// <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); } }
/// <summary> /// Generate video clips for all episodes. /// </summary> public bool genVideoClip(WorkerVars workerVars, DialogProgress dialogProgress) { int progessCount = 0; int episodeCount = 0; int totalEpisodes = workerVars.CombinedAll.Count; int totalLines = UtilsSubs.getTotalLineCount(workerVars.CombinedAll); DateTime lastTime = UtilsSubs.getLastTime(workerVars.CombinedAll); UtilsName name = new UtilsName(Settings.Instance.DeckName, totalEpisodes, totalLines, lastTime, Settings.Instance.VideoClips.Size.Width, Settings.Instance.VideoClips.Size.Height); DialogProgress.updateProgressInvoke(dialogProgress, 0, "Creating video clips."); // For each episode foreach (List <InfoCombined> combArray in workerVars.CombinedAll) { episodeCount++; // It is possible for all lines in an episode to be set to inactive if (combArray.Count == 0) { // Skip this episode continue; } string progressText = String.Format("Converting video file {0} of {1}", episodeCount, totalEpisodes); DialogProgress.updateProgressInvoke(dialogProgress, progressText); DateTime entireClipStartTime = combArray[0].Subs1.StartTime; DateTime entireClipEndTime = combArray[combArray.Count - 1].Subs1.EndTime; // Apply pad to entire clip timings (if requested) if (Settings.Instance.VideoClips.PadEnabled) { entireClipStartTime = UtilsSubs.applyTimePad(entireClipStartTime, -Settings.Instance.VideoClips.PadStart); entireClipEndTime = UtilsSubs.applyTimePad(entireClipEndTime, Settings.Instance.VideoClips.PadEnd); } // Enable detail mode in progress dialog DialogProgress.enableDetailInvoke(dialogProgress, true); // Set the duration of the clip in the progress dialog (for detail mode) DateTime entireClipDuration = UtilsSubs.getDurationTime(entireClipStartTime, entireClipEndTime); DialogProgress.setDuration(dialogProgress, entireClipDuration); string tempVideoFilename = Path.GetTempPath() + ConstantSettings.TempVideoFilename; string videoExtension = ".avi"; // Convert entire video (from first line to last line) based on user settings (size, crop, bitrate, etc). // It will be cut into smaller video clips later. if (Settings.Instance.VideoClips.IPodSupport) { videoExtension = ".mp4"; tempVideoFilename += videoExtension; UtilsVideo.convertVideo(Settings.Instance.VideoClips.Files[episodeCount - 1], Settings.Instance.VideoClips.AudioStream.Num, entireClipStartTime, entireClipEndTime, Settings.Instance.VideoClips.Size, Settings.Instance.VideoClips.Crop, Settings.Instance.VideoClips.BitrateVideo, Settings.Instance.VideoClips.BitrateAudio, UtilsVideo.VideoCodec.h264, UtilsVideo.AudioCodec.AAC, UtilsVideo.Profilex264.IPod640, UtilsVideo.Presetx264.SuperFast, tempVideoFilename, dialogProgress); } else { tempVideoFilename += videoExtension; UtilsVideo.convertVideo(Settings.Instance.VideoClips.Files[episodeCount - 1], Settings.Instance.VideoClips.AudioStream.Num, entireClipStartTime, entireClipEndTime, Settings.Instance.VideoClips.Size, Settings.Instance.VideoClips.Crop, Settings.Instance.VideoClips.BitrateVideo, Settings.Instance.VideoClips.BitrateAudio, UtilsVideo.VideoCodec.MPEG4, UtilsVideo.AudioCodec.MP3, UtilsVideo.Profilex264.None, UtilsVideo.Presetx264.None, tempVideoFilename, dialogProgress); } DialogProgress.enableDetailInvoke(dialogProgress, false); // Generate a video clip for each line of the episode foreach (InfoCombined comb in combArray) { progessCount++; progressText = string.Format("Generating video clip: {0} of {1}", progessCount.ToString(), totalLines.ToString()); int progress = Convert.ToInt32(progessCount * (100.0 / totalLines)); // Update the progress dialog DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText); // Did the user press the cancel button? if (dialogProgress.Cancel) { File.Delete(tempVideoFilename); return(false); } // Adjust timing to sync with the start of the converted video (which starts at the episode's first line of dialog) DateTime startTime = UtilsSubs.shiftTiming(comb.Subs1.StartTime, -((int)entireClipStartTime.TimeOfDay.TotalMilliseconds)); DateTime endTime = UtilsSubs.shiftTiming(comb.Subs1.EndTime, -((int)entireClipStartTime.TimeOfDay.TotalMilliseconds)); // Times used in the filename DateTime filenameStartTime = comb.Subs1.StartTime; DateTime filenameEndTime = comb.Subs1.EndTime; // Apply pad (if requested) if (Settings.Instance.VideoClips.PadEnabled) { startTime = UtilsSubs.applyTimePad(startTime, -Settings.Instance.VideoClips.PadStart); endTime = UtilsSubs.applyTimePad(endTime, Settings.Instance.VideoClips.PadEnd); filenameStartTime = UtilsSubs.applyTimePad(comb.Subs1.StartTime, -Settings.Instance.VideoClips.PadStart); filenameEndTime = UtilsSubs.applyTimePad(comb.Subs1.EndTime, Settings.Instance.VideoClips.PadEnd); } // Create output filename string nameStr = name.createName(ConstantSettings.VideoFilenameFormat, (int)episodeCount + Settings.Instance.EpisodeStartNumber - 1, progessCount, filenameStartTime, filenameEndTime, comb.Subs1.Text, comb.Subs2.Text); string outFile = string.Format("{0}{1}{2}{3}", workerVars.MediaDir, // {0} Path.DirectorySeparatorChar, // {1} nameStr, // {2} videoExtension); // {3} // Cut video clip for current line UtilsVideo.cutVideo(tempVideoFilename, startTime, endTime, outFile); } File.Delete(tempVideoFilename); } return(true); }
/// <summary> /// Performs the work of the audio extraction thread. /// </summary> private void splitAudio(object sender, DoWorkEventArgs e) { WorkerVars workerVars = e.Argument as WorkerVars; List <List <InfoCombined> > combinedAll = new List <List <InfoCombined> >(); WorkerSubs subsWorker = new WorkerSubs(); if (groupBoxCheckLyrics.Checked) { // Parse and combine the subtitles try { combinedAll = subsWorker.combineAllSubs(workerVars, dialogProgress); if (combinedAll != null) { workerVars.CombinedAll = combinedAll; } else { e.Cancel = true; return; } } catch (Exception e1) { UtilsMsg.showErrMsg("Something went wrong before processing could start.\n" + e1); e.Cancel = true; return; } } DateTime mediaStartime = new DateTime(); DateTime mediaEndtime = new DateTime(); DateTime mediaDuration = new DateTime(); int episode = 0; DialogProgress.updateProgressInvoke(dialogProgress, 0, "Starting..."); foreach (string file in mediaFiles) { episode++; try { mediaEndtime = UtilsVideo.getVideoLength(file); } catch (Exception e1) { UtilsMsg.showErrMsg("Something went wrong while determining duration of the media:\n" + e1); return; } if (useSpan) { mediaStartime = spanStart; // If the span end time if not greater than the actual duration of the media if (spanEnd < mediaEndtime) { mediaEndtime = spanEnd; } } UtilsName name = new UtilsName( deckName, mediaFiles.Length, // Total number of episodes 1, // Total number of lines (Note: not filled out here) mediaEndtime, // Last time 0, 0 // Width and height (Note: not filled out anywhere) ); mediaDuration = UtilsSubs.getDurationTime(mediaStartime, mediaEndtime); string progressText = String.Format("Processing audio from media file {0} of {1}", episode, mediaFiles.Length); int progress = Convert.ToInt32((episode - 1) * (100.0 / mediaFiles.Length)); DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText); // Enable detail mode in progress dialog DialogProgress.enableDetailInvoke(dialogProgress, true); // Set the duration of the clip in the progress dialog (for detail mode) DialogProgress.setDuration(dialogProgress, mediaDuration); string tempMp3Filename = Path.GetTempPath() + ConstantSettings.TempAudioFilename; UtilsAudio.ripAudioFromVideo(mediaFiles[episode - 1], audioStream.Num, mediaStartime, mediaEndtime, bitrate, tempMp3Filename, dialogProgress); DialogProgress.enableDetailInvoke(dialogProgress, false); if (dialogProgress.Cancel) { e.Cancel = true; File.Delete(tempMp3Filename); return; } int numClips = 1; if (!isSingleFile) { numClips = (int)Math.Ceiling((mediaDuration.TimeOfDay.TotalMilliseconds / (clipLength.TimeOfDay.TotalSeconds * 1000.0))); } for (int clipIdx = 0; clipIdx < numClips; clipIdx++) { progressText = String.Format("Splitting segment {0} of {1} from media file {2} of {3}", clipIdx + 1, numClips, episode, mediaFiles.Length); progress = Convert.ToInt32((episode - 1) * (100.0 / mediaFiles.Length)); DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText); if (dialogProgress.Cancel) { e.Cancel = true; File.Delete(tempMp3Filename); return; } // The start and end times used for processing DateTime startTime = new DateTime(); DateTime endTime = new DateTime(); if (isSingleFile) { endTime = mediaDuration; } else { startTime = startTime.AddSeconds((double)(clipLength.TimeOfDay.TotalSeconds * clipIdx)); endTime = endTime.AddSeconds((double)(clipLength.TimeOfDay.TotalSeconds * (clipIdx + 1))); if (endTime.TimeOfDay.TotalMilliseconds >= mediaDuration.TimeOfDay.TotalMilliseconds) { endTime = mediaDuration; } } // The start and end times that will be displayed DateTime startTimeName = startTime.AddMilliseconds(mediaStartime.TimeOfDay.TotalMilliseconds); DateTime endTimeName = endTime.AddMilliseconds(mediaStartime.TimeOfDay.TotalMilliseconds); // Fill in the total number of lines with the total number of clips name.TotalNumLines = numClips; string nameStr = name.createName(ConstantSettings.ExtractMediaAudioFilenameFormat, episode + episodeStartNumber - 1, clipIdx + 1, startTimeName, endTimeName, "", ""); string outName = String.Format("{0}{1}{2}", outputDir, // {0} Path.DirectorySeparatorChar, // {1} nameStr); // {2} UtilsAudio.cutAudio(tempMp3Filename, startTime, endTime, outName); nameStr = name.createName(ConstantSettings.AudioId3Artist, episode + episodeStartNumber - 1, clipIdx + 1, startTimeName, endTimeName, "", ""); string tagArtist = String.Format("{0}", nameStr); // {0} nameStr = name.createName(ConstantSettings.AudioId3Album, episode + episodeStartNumber - 1, clipIdx + 1, startTimeName, endTimeName, "", ""); string tagAlbum = String.Format("{0}", nameStr); // {0} nameStr = name.createName(ConstantSettings.AudioId3Title, episode + episodeStartNumber - 1, clipIdx + 1, startTimeName, endTimeName, "", ""); string tagTitle = String.Format("{0}", nameStr); // {0} nameStr = name.createName(ConstantSettings.AudioId3Genre, episode + episodeStartNumber - 1, clipIdx + 1, startTimeName, endTimeName, "", ""); string tagGenre = String.Format("{0}", nameStr); // {0} string tagLyrics = ""; if (groupBoxCheckLyrics.Checked) { int totalLyricsLines = 0; int curLyricsNum = 1; // Precount the number of lyrics lines foreach (InfoCombined comb in combinedAll[episode - 1]) { if (comb.Subs1.StartTime.TimeOfDay.TotalMilliseconds >= startTimeName.TimeOfDay.TotalMilliseconds && comb.Subs1.StartTime.TimeOfDay.TotalMilliseconds <= endTimeName.TimeOfDay.TotalMilliseconds) { totalLyricsLines++; } } // Fill in the total number of lyrics lines name.TotalNumLines = curLyricsNum; // Foreach comb in the current episode, if the comb lies within the // current clip, add it to the lryics tag foreach (InfoCombined comb in combinedAll[episode - 1]) { if (comb.Subs1.StartTime.TimeOfDay.TotalMilliseconds >= startTimeName.TimeOfDay.TotalMilliseconds && comb.Subs1.StartTime.TimeOfDay.TotalMilliseconds <= endTimeName.TimeOfDay.TotalMilliseconds) { tagLyrics += formatLyricsPair(comb, name, startTimeName, episode + episodeStartNumber - 1, curLyricsNum) + "\r\n"; curLyricsNum++; } } } UtilsAudio.tagAudio(outName, tagArtist, tagAlbum, tagTitle, tagGenre, tagLyrics, clipIdx + 1, numClips); } } return; }
/// <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); } }