#73 - added audio/video sync

This commit is contained in:
LukePulverenti 2013-03-20 10:27:56 -04:00
parent 9ecd2bbf91
commit 095896fa49
2 changed files with 11 additions and 10 deletions

View File

@ -56,13 +56,13 @@ namespace MediaBrowser.Api.Playback.Hls
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
protected override string GetAudioArguments(StreamState state) protected override string GetAudioArguments(StreamState state)
{ {
if (!state.Request.AudioCodec.HasValue) var codec = GetAudioCodec(state.Request);
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
{ {
return "-codec:a:0 copy"; return "-codec:a:0 copy";
} }
var codec = GetAudioCodec(state.Request);
var args = "-codec:a:0 " + codec; var args = "-codec:a:0 " + codec;
if (state.AudioStream != null) if (state.AudioStream != null)
@ -84,6 +84,8 @@ namespace MediaBrowser.Api.Playback.Hls
args += " -ab " + state.Request.AudioBitRate.Value; args += " -ab " + state.Request.AudioBitRate.Value;
} }
args += " -af \"aresample=async=1000\"";
return args; return args;
} }
@ -99,12 +101,6 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
var codec = GetVideoCodec(state.VideoRequest); var codec = GetVideoCodec(state.VideoRequest);
// Right now all we support is either h264 or copy
if (!codec.Equals("copy", StringComparison.OrdinalIgnoreCase) && !codec.Equals("libx264", StringComparison.OrdinalIgnoreCase))
{
codec = "libx264";
}
// See if we can save come cpu cycles by avoiding encoding // See if we can save come cpu cycles by avoiding encoding
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase)) if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
{ {
@ -125,7 +121,7 @@ namespace MediaBrowser.Api.Playback.Hls
} }
// Get the output framerate based on the FrameRate param // Get the output framerate based on the FrameRate param
double framerate = state.VideoRequest.Framerate ?? 0; var framerate = state.VideoRequest.Framerate ?? 0;
// We have to supply a framerate for hls, so if it's null, account for that here // We have to supply a framerate for hls, so if it's null, account for that here
if (framerate.Equals(0)) if (framerate.Equals(0))
@ -146,6 +142,9 @@ namespace MediaBrowser.Api.Playback.Hls
// Needed to ensure segments stay under 10 seconds // Needed to ensure segments stay under 10 seconds
args += string.Format(" -g {0}", framerate); args += string.Format(" -g {0}", framerate);
args += " -vsync vfr";
return args; return args;
} }

View File

@ -154,6 +154,8 @@ namespace MediaBrowser.Api.Playback.Progressive
{ {
args += " " + qualityParam; args += " " + qualityParam;
} }
args += " -vsync vfr";
} }
else if (IsH264(state.VideoStream)) else if (IsH264(state.VideoStream))
{ {