/// <summary> /// Execute the FFmpeg utility with the given <paramref name="mediaSettings"/> and return the text output generated by it. /// See http://www.ffmpeg.org for documentation. /// </summary> /// <param name="mediaSettings">The media settings.</param> /// <returns> /// Returns the text output from the execution of the FFmpeg utility. This data can be parsed to learn more about the media file. /// </returns> private static string ExecuteFFmpeg(MediaConversionSettings mediaSettings) { FFmpeg ffmpeg = new FFmpeg(mediaSettings); ffmpeg.Execute(); mediaSettings.FFmpegOutput = ffmpeg.Output; return(mediaSettings.FFmpegOutput); }
private static string ReplaceTokens(string encoderArguments, MediaConversionSettings mediaSettings) { encoderArguments = encoderArguments.Replace("{SourceFilePath}", mediaSettings.FilePathSource); encoderArguments = encoderArguments.Replace("{Width}", mediaSettings.TargetWidth.ToString(CultureInfo.InvariantCulture)); encoderArguments = encoderArguments.Replace("{Height}", mediaSettings.TargetHeight.ToString(CultureInfo.InvariantCulture)); encoderArguments = encoderArguments.Replace(AutoRotateFilterName, GetAutoRotationFilter(MediaConversionQueue.Instance.Get(mediaSettings.MediaQueueId).RotateFlipAmount, encoderArguments)); encoderArguments = encoderArguments.Replace("{AspectRatio}", Math.Round(mediaSettings.TargetWidth / (double)mediaSettings.TargetHeight, 2).ToString(CultureInfo.InvariantCulture)); encoderArguments = encoderArguments.Replace("{DestinationFilePath}", mediaSettings.FilePathDestination); encoderArguments = encoderArguments.Replace("{BinPath}", Path.Combine(AppSetting.Instance.PhysicalApplicationPath, "bin")); encoderArguments = encoderArguments.Replace("{GalleryResourcesPath}", Path.Combine(AppSetting.Instance.PhysicalApplicationPath, AppSetting.Instance.GalleryResourcesPath)); // If the above changes result in an empty filter setting, remove it altogether. encoderArguments = encoderArguments.Replace(@"-vf """"", String.Empty); return(encoderArguments); }
/// <summary> /// Execute the FFmpeg utility with the given <paramref name="arguments"/> and return the text output generated by it. /// A default timeout value of 3 seconds is used, which can be overridden with the <paramref name="timeoutMs" /> parameter. /// See http://www.ffmpeg.org for documentation. /// </summary> /// <param name="arguments">The argument values to pass to the FFmpeg utility. /// Example: -ss 00:00:03 -i "D:\media\video\myvideo.flv" -an -vframes 1 -y "D:\media\video\zThumb_myvideo.jpg"</param> /// <param name="galleryId">The gallery ID.</param> /// <param name="timeoutMs">Gets or sets the timeout to apply to FFmpeg, in milliseconds. Defaults to 3 seconds if not /// specified.</param> /// <returns>Returns the text output from the execution of the FFmpeg utility. This data can be parsed to learn more about the media file.</returns> private static string ExecuteFFmpeg(string arguments, int galleryId, int timeoutMs = 3000) { var mediaSettings = new MediaConversionSettings { FilePathSource = String.Empty, FilePathDestination = String.Empty, EncoderSetting = null, GalleryId = galleryId, MediaQueueId = int.MinValue, TimeoutMs = timeoutMs, MediaObjectId = int.MinValue, FFmpegArgs = arguments, FFmpegOutput = String.Empty }; return(ExecuteFFmpeg(mediaSettings)); }
/// <summary> /// Creates a media file based on an existing one using the values in the /// <paramref name="mediaSettings" /> parameter. The output from FFmpeg is returned. The /// arguments passed to FFmpeg are stored on the /// <see cref="MediaConversionSettings.FFmpegArgs" /> property. /// </summary> /// <param name="mediaSettings">The settings which dicate the media file creation process.</param> /// <returns>Returns the text output from FFmpeg.</returns> public static string CreateMedia(MediaConversionSettings mediaSettings) { if (!IsAvailable) { return(String.Empty); } if (mediaSettings == null) { throw new ArgumentNullException("mediaSettings"); } if (mediaSettings.EncoderSetting == null) { throw new ArgumentNullException("mediaSettings", "The EncoderSetting property on the mediaSettings parameter was null."); } mediaSettings.FFmpegArgs = ReplaceTokens(mediaSettings.EncoderSetting.EncoderArguments, mediaSettings); return(ExecuteFFmpeg(mediaSettings)); }
private FFmpeg(MediaConversionSettings mediaSettings) { MediaSettings = mediaSettings; _output = new StringBuilder(); }