unify audio conversion

This commit is contained in:
Luke Pulverenti 2017-04-27 14:13:16 -04:00
parent da39d9a5bf
commit fc7ab45fb3
5 changed files with 72 additions and 96 deletions

View File

@ -720,6 +720,13 @@ namespace MediaBrowser.Api.Playback
state.IsInputVideo = string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase);
var primaryImage = item.GetImageInfo(ImageType.Primary, 0) ??
item.Parents.Select(i => i.GetImageInfo(ImageType.Primary, 0)).FirstOrDefault(i => i != null);
if (primaryImage != null)
{
state.AlbumCoverPath = primaryImage.Path;
}
MediaSourceInfo mediaSource = null;
if (string.IsNullOrWhiteSpace(request.LiveStreamId))
{

View File

@ -59,42 +59,7 @@ namespace MediaBrowser.Api.Playback.Progressive
{
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
var audioTranscodeParams = new List<string>();
var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue)
{
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
}
if (state.OutputAudioChannels.HasValue)
{
audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
}
// opus will fail on 44100
if (!string.Equals(state.OutputAudioCodec, "opus", global::System.StringComparison.OrdinalIgnoreCase))
{
if (state.OutputAudioSampleRate.HasValue)
{
audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
}
}
const string vn = " -vn";
var threads = EncodingHelper.GetNumberOfThreads(state, encodingOptions, false);
var inputModifier = EncodingHelper.GetInputModifier(state, encodingOptions);
return string.Format("{0} {1} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1 -y \"{5}\"",
inputModifier,
EncodingHelper.GetInputArgument(state, encodingOptions),
threads,
vn,
string.Join(" ", audioTranscodeParams.ToArray()),
outputPath).Trim();
return EncodingHelper.GetProgressiveAudioFullCommandLine(state, encodingOptions, outputPath);
}
public AudioService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer, IAuthorizationContext authorizationContext, IImageProcessor imageProcessor) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer, authorizationContext, imageProcessor)

View File

@ -1979,5 +1979,66 @@ namespace MediaBrowser.Controller.MediaEncoding
return args;
}
public string GetProgressiveAudioFullCommandLine(EncodingJobInfo state, EncodingOptions encodingOptions, string outputPath)
{
var audioTranscodeParams = new List<string>();
var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue)
{
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(_usCulture));
}
if (state.OutputAudioChannels.HasValue)
{
audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(_usCulture));
}
// opus will fail on 44100
if (!string.Equals(state.OutputAudioCodec, "opus", StringComparison.OrdinalIgnoreCase))
{
if (state.OutputAudioSampleRate.HasValue)
{
audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(_usCulture));
}
}
var albumCoverInput = string.Empty;
var mapArgs = string.Empty;
var metadata = string.Empty;
var vn = string.Empty;
var hasArt = !string.IsNullOrWhiteSpace(state.AlbumCoverPath);
hasArt = false;
if (hasArt)
{
albumCoverInput = " -i \"" + state.AlbumCoverPath + "\"";
mapArgs = " -map 0:a -map 1:v -c:v copy";
metadata = " -metadata:s:v title=\"Album cover\" -metadata:s:v comment=\"Cover(Front)\"";
}
else
{
vn = " -vn";
}
var threads = GetNumberOfThreads(state, encodingOptions, false);
var inputModifier = GetInputModifier(state, encodingOptions);
return string.Format("{0} {1}{7}{8} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1{6} -y \"{5}\"",
inputModifier,
GetInputArgument(state, encodingOptions),
threads,
vn,
string.Join(" ", audioTranscodeParams.ToArray()),
outputPath,
metadata,
albumCoverInput,
mapArgs).Trim();
}
}
}

View File

@ -56,6 +56,8 @@ namespace MediaBrowser.Controller.MediaEncoding
}
}
public string AlbumCoverPath { get; set; }
public string InputAudioSync { get; set; }
public string InputVideoSync { get; set; }
public TransportStreamTimestamp InputTimestamp { get; set; }

View File

@ -5,8 +5,6 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MediaBrowser.Model.Diagnostics;
namespace MediaBrowser.MediaEncoding.Encoder
@ -19,66 +17,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
protected override string GetCommandLineArguments(EncodingJob state)
{
var audioTranscodeParams = new List<string>();
var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue)
{
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
}
if (state.OutputAudioChannels.HasValue)
{
audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
}
// opus will fail on 44100
if (!string.Equals(state.OutputAudioCodec, "opus", StringComparison.OrdinalIgnoreCase))
{
if (state.OutputAudioSampleRate.HasValue)
{
audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
}
}
var encodingOptions = GetEncodingOptions();
var threads = EncodingHelper.GetNumberOfThreads(state, encodingOptions, false);
var inputModifier = EncodingHelper.GetInputModifier(state, encodingOptions);
var albumCoverInput = string.Empty;
var mapArgs = string.Empty;
var metadata = string.Empty;
var vn = string.Empty;
var hasArt = !string.IsNullOrWhiteSpace(state.AlbumCoverPath);
hasArt = false;
if (hasArt)
{
albumCoverInput = " -i \"" + state.AlbumCoverPath + "\"";
mapArgs = " -map 0:a -map 1:v -c:v copy";
metadata = " -metadata:s:v title=\"Album cover\" -metadata:s:v comment=\"Cover(Front)\"";
}
else
{
vn = " -vn";
}
var result = string.Format("{0} {1}{6}{7} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1{8} -y \"{5}\"",
inputModifier,
EncodingHelper.GetInputArgument(state, GetEncodingOptions()),
threads,
vn,
string.Join(" ", audioTranscodeParams.ToArray()),
state.OutputFilePath,
albumCoverInput,
mapArgs,
metadata).Trim();
return result;
return EncodingHelper.GetProgressiveAudioFullCommandLine(state, encodingOptions, state.OutputFilePath);
}
protected override string GetOutputFileExtension(EncodingJob state)