diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-03-30 12:49:40 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-03-30 12:49:40 -0400 |
| commit | f756e39b9d5b461e6bcaa4e71006038983d28213 (patch) | |
| tree | 997f476e118787cb65d219192a00458707c872fc /MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs | |
| parent | a90d892ecab78a8f11fa7a4efda65ee70eceafe1 (diff) | |
restored live tv playback in the web client
Diffstat (limited to 'MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs new file mode 100644 index 000000000..08b7fbe49 --- /dev/null +++ b/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs @@ -0,0 +1,91 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Logging; +using System.Collections.Generic; +using System.Globalization; +using System.Threading.Tasks; + +namespace MediaBrowser.MediaEncoding.Encoder +{ + public class AudioEncoder + { + private readonly string _ffmpegPath; + private readonly ILogger _logger; + private readonly IFileSystem _fileSystem; + private readonly IApplicationPaths _appPaths; + private readonly IIsoManager _isoManager; + private readonly ILiveTvManager _liveTvManager; + + private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + + public AudioEncoder(string ffmpegPath, ILogger logger, IFileSystem fileSystem, IApplicationPaths appPaths, IIsoManager isoManager, ILiveTvManager liveTvManager) + { + _ffmpegPath = ffmpegPath; + _logger = logger; + _fileSystem = fileSystem; + _appPaths = appPaths; + _isoManager = isoManager; + _liveTvManager = liveTvManager; + } + + public Task BeginEncoding(InternalEncodingTask task) + { + return new FFMpegProcess(_ffmpegPath, _logger, _fileSystem, _appPaths, _isoManager, _liveTvManager).Start(task, GetArguments); + } + + private string GetArguments(InternalEncodingTask task, string mountedPath) + { + var options = task.Request; + + return string.Format("{0} -i {1} {2} -id3v2_version 3 -write_id3v1 1 \"{3}\"", + GetInputModifier(task), + GetInputArgument(task), + GetOutputModifier(task), + options.OutputPath).Trim(); + } + + private string GetInputModifier(InternalEncodingTask task) + { + return EncodingUtils.GetInputModifier(task); + } + + private string GetInputArgument(InternalEncodingTask task) + { + return EncodingUtils.GetInputArgument(new List<string> { task.MediaPath }, task.IsInputRemote); + } + + private string GetOutputModifier(InternalEncodingTask task) + { + var options = task.Request; + + var audioTranscodeParams = new List<string> + { + "-threads " + EncodingUtils.GetNumberOfThreads(task, false).ToString(_usCulture), + "-vn" + }; + + var bitrate = EncodingUtils.GetAudioBitrateParam(task); + + if (bitrate.HasValue) + { + audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(_usCulture)); + } + + var channels = EncodingUtils.GetNumAudioChannelsParam(options, task.AudioStream); + + if (channels.HasValue) + { + audioTranscodeParams.Add("-ac " + channels.Value); + } + + if (options.AudioSampleRate.HasValue) + { + audioTranscodeParams.Add("-ar " + options.AudioSampleRate.Value); + } + + return string.Join(" ", audioTranscodeParams.ToArray()); + } + } +} |
