|
@@ -81,17 +81,6 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|
|
// Get the output codec name
|
|
|
var videoCodec = GetVideoCodec(state.VideoRequest);
|
|
|
|
|
|
- var graphicalSubtitleParam = string.Empty;
|
|
|
-
|
|
|
- if (state.SubtitleStream != null)
|
|
|
- {
|
|
|
- // This is for internal graphical subs
|
|
|
- if (!state.SubtitleStream.IsExternal && (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1))
|
|
|
- {
|
|
|
- graphicalSubtitleParam = GetInternalGraphicalSubtitleParam(state, videoCodec);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
var format = string.Empty;
|
|
|
var keyFrame = string.Empty;
|
|
|
|
|
@@ -106,7 +95,7 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|
|
keyFrame = " -g " + Math.Round(framerate);
|
|
|
}
|
|
|
|
|
|
- return string.Format("{0} {1} -i {2}{3}{4} -threads 0 {5} {6}{7} {8}{9} \"{10}\"",
|
|
|
+ return string.Format("{0} {1} -i {2}{3}{4} -threads 0 {5} {6} {7}{8} \"{9}\"",
|
|
|
probeSize,
|
|
|
GetFastSeekCommandLineParameter(state.Request),
|
|
|
GetInputArgument(video, state.IsoMount),
|
|
@@ -114,7 +103,6 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|
|
keyFrame,
|
|
|
GetMapArgs(state),
|
|
|
GetVideoArguments(state, videoCodec),
|
|
|
- graphicalSubtitleParam,
|
|
|
GetAudioArguments(state),
|
|
|
format,
|
|
|
outputPath
|
|
@@ -125,42 +113,62 @@ namespace MediaBrowser.Api.Playback.Progressive
|
|
|
/// Gets video arguments to pass to ffmpeg
|
|
|
/// </summary>
|
|
|
/// <param name="state">The state.</param>
|
|
|
- /// <param name="videoCodec">The video codec.</param>
|
|
|
+ /// <param name="codec">The video codec.</param>
|
|
|
/// <returns>System.String.</returns>
|
|
|
- private string GetVideoArguments(StreamState state, string videoCodec)
|
|
|
+ private string GetVideoArguments(StreamState state, string codec)
|
|
|
{
|
|
|
- var args = "-vcodec " + videoCodec;
|
|
|
+ var args = "-vcodec " + codec;
|
|
|
+
|
|
|
+ // See if we can save come cpu cycles by avoiding encoding
|
|
|
+ if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ return IsH264(state.VideoStream) ? args + " -bsf h264_mp4toannexb" : args;
|
|
|
+ }
|
|
|
+
|
|
|
+ const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+2))";
|
|
|
+
|
|
|
+ args += keyFrameArg;
|
|
|
|
|
|
var request = state.VideoRequest;
|
|
|
|
|
|
- // If we're encoding video, add additional params
|
|
|
- if (!videoCodec.Equals("copy", StringComparison.OrdinalIgnoreCase))
|
|
|
+ // Add resolution params, if specified
|
|
|
+ if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue)
|
|
|
{
|
|
|
- // Add resolution params, if specified
|
|
|
- if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue)
|
|
|
- {
|
|
|
- args += GetOutputSizeParam(state, videoCodec);
|
|
|
- }
|
|
|
+ args += GetOutputSizeParam(state, codec);
|
|
|
+ }
|
|
|
|
|
|
- if (request.Framerate.HasValue)
|
|
|
- {
|
|
|
- args += string.Format(" -r {0}", request.Framerate.Value);
|
|
|
- }
|
|
|
+ if (request.Framerate.HasValue)
|
|
|
+ {
|
|
|
+ args += string.Format(" -r {0}", request.Framerate.Value);
|
|
|
+ }
|
|
|
|
|
|
- // Add the audio bitrate
|
|
|
- var qualityParam = GetVideoQualityParam(request, videoCodec);
|
|
|
+ // Add the audio bitrate
|
|
|
+ var qualityParam = GetVideoQualityParam(request, codec);
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(qualityParam))
|
|
|
- {
|
|
|
- args += " " + qualityParam;
|
|
|
- }
|
|
|
+ if (!string.IsNullOrEmpty(qualityParam))
|
|
|
+ {
|
|
|
+ args += " " + qualityParam;
|
|
|
+ }
|
|
|
|
|
|
- args += " -vsync vfr";
|
|
|
+ args += " -vsync vfr";
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
|
|
+ {
|
|
|
+ args += " -profile:v" + state.VideoRequest.Profile;
|
|
|
}
|
|
|
- else if (IsH264(state.VideoStream))
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(state.VideoRequest.Level))
|
|
|
+ {
|
|
|
+ args += " -level 3" + state.VideoRequest.Level;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.SubtitleStream != null)
|
|
|
{
|
|
|
- // FFmpeg will fail to convert and give h264 bitstream malformated error if it isn't used when converting mp4 to transport stream.
|
|
|
- args += " -bsf h264_mp4toannexb";
|
|
|
+ // This is for internal graphical subs
|
|
|
+ if (!state.SubtitleStream.IsExternal && (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1))
|
|
|
+ {
|
|
|
+ args += GetInternalGraphicalSubtitleParam(state, codec);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return args;
|