2012-08-11 18:07:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.HttpHandlers
|
|
|
|
|
{
|
2012-08-12 17:05:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supported output formats: mkv,m4v,mp4,asf,wmv,mov,webm,ogv,3gp,avi,ts,flv
|
|
|
|
|
/// </summary>
|
2012-08-11 18:07:07 +00:00
|
|
|
|
class VideoHandler : BaseMediaHandler<Video>
|
|
|
|
|
{
|
2012-08-12 17:05:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// We can output these files directly, but we can't encode them
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override IEnumerable<string> UnsupportedOutputEncodingFormats
|
2012-08-11 18:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-12 17:05:51 +00:00
|
|
|
|
return new string[] { "mp4", "wmv" };
|
2012-08-11 18:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool RequiresConversion()
|
|
|
|
|
{
|
2012-08-12 17:05:51 +00:00
|
|
|
|
if (base.RequiresConversion())
|
2012-08-11 18:07:07 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-08-12 04:03:19 +00:00
|
|
|
|
|
2012-08-11 18:07:07 +00:00
|
|
|
|
AudioStream audio = LibraryItem.AudioStreams.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (audio != null)
|
|
|
|
|
{
|
|
|
|
|
// If the number of channels is greater than our desired channels, we need to transcode
|
|
|
|
|
if (AudioChannels.HasValue && AudioChannels.Value < audio.Channels)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Yay
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-12 13:59:09 +00:00
|
|
|
|
private string GetFFMpegOutputFormat(string outputFormat)
|
|
|
|
|
{
|
|
|
|
|
if (outputFormat.Equals("mkv", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return "matroska";
|
|
|
|
|
}
|
2012-08-12 17:05:51 +00:00
|
|
|
|
else if (outputFormat.Equals("ts", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return "mpegts";
|
|
|
|
|
}
|
|
|
|
|
else if (outputFormat.Equals("ogv", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return "ogg";
|
|
|
|
|
}
|
2012-08-12 13:59:09 +00:00
|
|
|
|
|
|
|
|
|
return outputFormat;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-12 04:03:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates arguments to pass to ffmpeg
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override string GetCommandLineArguments()
|
2012-08-11 18:07:07 +00:00
|
|
|
|
{
|
2012-08-12 04:03:19 +00:00
|
|
|
|
List<string> audioTranscodeParams = new List<string>();
|
|
|
|
|
|
2012-08-12 17:05:51 +00:00
|
|
|
|
string outputFormat = GetConversionOutputFormat();
|
2012-08-12 13:59:09 +00:00
|
|
|
|
|
2012-08-12 17:05:51 +00:00
|
|
|
|
return string.Format("-i \"{0}\" {1} {2} -f {3} -",
|
2012-08-12 13:59:09 +00:00
|
|
|
|
LibraryItem.Path,
|
|
|
|
|
GetVideoArguments(),
|
|
|
|
|
GetAudioArguments(),
|
|
|
|
|
GetFFMpegOutputFormat(outputFormat)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetVideoArguments()
|
|
|
|
|
{
|
2012-08-12 17:05:51 +00:00
|
|
|
|
return "-vcodec copy";
|
2012-08-12 13:59:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetAudioArguments()
|
|
|
|
|
{
|
2012-08-12 17:05:51 +00:00
|
|
|
|
return "-acodec copy";
|
2012-08-11 18:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|