jellyfin/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs

122 lines
4.2 KiB
C#
Raw Normal View History

2016-03-27 14:11:27 -07:00
using MediaBrowser.Controller.Configuration;
2015-01-01 23:12:58 -07:00
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
2016-06-18 23:18:29 -07:00
using System.Threading.Tasks;
2016-10-31 21:07:12 -07:00
using MediaBrowser.Model.Diagnostics;
2015-01-01 23:12:58 -07:00
namespace MediaBrowser.MediaEncoding.Encoder
{
public class AudioEncoder : BaseEncoder
{
2016-10-31 21:07:12 -07:00
public AudioEncoder(MediaEncoder mediaEncoder, ILogger logger, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IIsoManager isoManager, ILibraryManager libraryManager, ISessionManager sessionManager, ISubtitleEncoder subtitleEncoder, IMediaSourceManager mediaSourceManager, IProcessFactory processFactory) : base(mediaEncoder, logger, configurationManager, fileSystem, isoManager, libraryManager, sessionManager, subtitleEncoder, mediaSourceManager, processFactory)
2015-01-01 23:12:58 -07:00
{
}
2017-03-19 11:59:05 -07:00
protected override string GetCommandLineArguments(EncodingJob state)
2015-01-01 23:12:58 -07:00
{
var audioTranscodeParams = new List<string>();
var bitrate = state.OutputAudioBitrate;
2015-01-01 23:12:58 -07:00
if (bitrate.HasValue)
{
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
}
if (state.OutputAudioChannels.HasValue)
2015-01-01 23:12:58 -07:00
{
audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
2015-01-01 23:12:58 -07:00
}
2016-03-05 11:29:32 -07:00
// opus will fail on 44100
if (!string.Equals(state.OutputAudioCodec, "opus", StringComparison.OrdinalIgnoreCase))
2015-01-01 23:12:58 -07:00
{
2016-03-05 11:29:32 -07:00
if (state.OutputAudioSampleRate.HasValue)
{
audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
}
2015-01-01 23:12:58 -07:00
}
var encodingOptions = GetEncodingOptions();
var threads = EncodingHelper.GetNumberOfThreads(state, encodingOptions, false);
var inputModifier = EncodingHelper.GetInputModifier(state, encodingOptions);
2015-01-01 23:12:58 -07:00
var albumCoverInput = string.Empty;
var mapArgs = string.Empty;
var metadata = string.Empty;
var vn = string.Empty;
2016-08-18 22:58:35 -07:00
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";
}
2016-06-18 23:18:29 -07:00
var result = string.Format("{0} {1}{6}{7} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1{8} -y \"{5}\"",
2015-01-01 23:12:58 -07:00
inputModifier,
EncodingHelper.GetInputArgument(state, GetEncodingOptions()),
2015-01-01 23:12:58 -07:00
threads,
vn,
2015-01-01 23:12:58 -07:00
string.Join(" ", audioTranscodeParams.ToArray()),
state.OutputFilePath,
albumCoverInput,
mapArgs,
metadata).Trim();
2016-06-18 23:18:29 -07:00
2017-03-19 11:59:05 -07:00
return result;
2015-01-01 23:12:58 -07:00
}
protected override string GetOutputFileExtension(EncodingJob state)
{
var ext = base.GetOutputFileExtension(state);
if (!string.IsNullOrEmpty(ext))
{
return ext;
}
var audioCodec = state.Options.AudioCodec;
if (string.Equals("aac", audioCodec, StringComparison.OrdinalIgnoreCase))
{
return ".aac";
}
if (string.Equals("mp3", audioCodec, StringComparison.OrdinalIgnoreCase))
{
return ".mp3";
}
if (string.Equals("vorbis", audioCodec, StringComparison.OrdinalIgnoreCase))
{
return ".ogg";
}
if (string.Equals("wma", audioCodec, StringComparison.OrdinalIgnoreCase))
{
return ".wma";
}
return null;
}
2015-01-04 23:00:13 -07:00
protected override bool IsVideoEncoder
{
get { return false; }
}
2016-10-31 21:07:12 -07:00
2015-01-01 23:12:58 -07:00
}
}