protected void ComposeFFMpegOutputArgs(StringBuilder outputArgs, string outputFormat, OutputSettings settings) { if (settings != null) { if (settings.MaxDuration.HasValue) { outputArgs.AppendFormat(CultureInfo.InvariantCulture, " -t {0}", settings.MaxDuration); } if (outputFormat != null) { outputArgs.AppendFormat(" -f {0} ", outputFormat); } if (settings.AudioSampleRate.HasValue) { outputArgs.AppendFormat(" -ar {0}", settings.AudioSampleRate); } if (settings.AudioCodec != null) { outputArgs.AppendFormat(" -acodec {0}", settings.AudioCodec); } if (settings.VideoFrameCount.HasValue) { outputArgs.AppendFormat(" -vframes {0}", settings.VideoFrameCount); } if (settings.VideoFrameRate.HasValue) { outputArgs.AppendFormat(" -r {0}", settings.VideoFrameRate); } if (settings.VideoCodec != null) { outputArgs.AppendFormat(" -vcodec {0}", settings.VideoCodec); } if (settings.VideoFrameSize != null) { outputArgs.AppendFormat(" -s {0}", settings.VideoFrameSize); } if (settings.CustomOutputArgs != null) { outputArgs.AppendFormat(" {0} ", settings.CustomOutputArgs); } } }
public void ConvertMedia(FFMpegInput[] inputs, string output, string outputFormat, OutputSettings settings) { if (inputs == null || inputs.Length == 0) { throw new ArgumentException("At least one ffmpeg input should be specified"); } FFMpegInput fFMpegInput = inputs[inputs.Length - 1]; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < inputs.Length - 1; i++) { FFMpegInput fFMpegInput2 = inputs[i]; if (fFMpegInput2.Format != null) { stringBuilder.Append(" -f " + fFMpegInput2.Format); } if (fFMpegInput2.CustomInputArgs != null) { stringBuilder.AppendFormat(" {0} ", fFMpegInput2.CustomInputArgs); } stringBuilder.AppendFormat(" -i {0} ", CommandArgParameter(fFMpegInput2.Input)); } ConvertSettings convertSettings = new ConvertSettings(); settings.CopyTo(convertSettings); convertSettings.CustomInputArgs = stringBuilder.ToString() + fFMpegInput.CustomInputArgs; if (fFMpegInput.Format != null) { convertSettings.CustomInputArgs = convertSettings.CustomInputArgs + " -f " + fFMpegInput.Format; } ConvertMedia(fFMpegInput.Input, null, output, outputFormat, convertSettings); }