/// <summary> /// Generate single encoded video stream based on JOB and OUTPUT DEFINITION /// </summary> /// <param name="v">Defines the video stream being generated</param> /// <param name="j">The overall job for this encode run</param> /// <param name="xEncoder">libx264 or libx265</param> public void EncodeX(VideoOutputDefinition v, VideoEncodeJob j, string xEncoder) { MediaProperties ma = j.InputMedia[0]; MediaStream vs = ma.Streams[ma.FirstVideoIndex]; //implicitly set frame rate. //To do: this needs to be rationals, not floats var rateString = vs.VideoFrameRate > 0 ? $"-r {((j.MatchRate != 0) ? j.MatchRate : vs.VideoFrameRate)}" : String.Empty; //Select proper prefix based on input media. //MPEG files require a specific syntax on the input to prevent time-code issues. var FFRoot = this.MpegFiles.Contains(Path.GetExtension(ma.MediaFile).ToLower()) ? this.FFRootCmdMpg : this.FFRootCmdDefault; FilterChain f = this.ConfigureFilters(v, j); for (int pass = 1; pass <= v.NumPasses; pass++) { var FFCmd = $"{FFRoot} -i {j.InputMedia[0].MediaFile} {f.GetVideoFilters()} " + $"-pix_fmt {this.PixelFormatMap[j.PixelFmt]} " + $"-preset {this.EncoderPresetMap[j.Preset]} " + $"-an -c:v lib{xEncoder} " + $"-metadata:s:v:0 language={j.Language} " + //ToDo: this needs to be a rational like "24000/1001" to prevent rate drift during sitching or concetnation. $"{rateString} " + $"{this.BuildX26xEncOptions(v, j, pass, xEncoder)} " + $"{Path.Combine(j.OutputFolder, v.OutputFileName)}"; //Run this.utils.LogProxy($"\r\nSTARTING {xEncoder} Encode pass {pass} of {v.NumPasses}", Utilities.LogLevel.Info); this.ExecuteFFMpeg_LogProgress(FFCmd, ma.MediaDuration); } }
private string RunScan(MediaProperties ma, FilterChain fc, int startSeconds = 0, int scanDuration = 0) { var videoStream = ma.Streams.FirstOrDefault(m => m.StreamType == StreamType.Video); if (scanDuration == 0) { scanDuration = Convert.ToInt32(ma.MediaDuration); } var scanCmd = $" -ss {startSeconds} -y -i {ma.MediaFile} -pix_fmt yuv420p -t {scanDuration} {fc.GetVideoFilters()} -an -f null NUL"; return(this.ExecuteFFMpeg_LogProgress(scanCmd, scanDuration).StdErr); }