2020-08-04 14:20:52 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2020-08-20 10:16:24 +00:00
|
|
|
using System;
|
2019-01-13 20:02:23 +00:00
|
|
|
using System.Collections.Generic;
|
2020-08-07 17:26:28 +00:00
|
|
|
using System.Globalization;
|
2018-12-14 09:40:55 +00:00
|
|
|
using System.Linq;
|
2019-01-13 19:26:04 +00:00
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.MediaEncoding.Encoder
|
|
|
|
{
|
|
|
|
public static class EncodingUtils
|
|
|
|
{
|
2019-02-24 14:47:59 +00:00
|
|
|
public static string GetInputArgument(IReadOnlyList<string> inputFiles, MediaProtocol protocol)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
|
|
|
if (protocol != MediaProtocol.File)
|
|
|
|
{
|
2019-02-24 14:47:59 +00:00
|
|
|
var url = inputFiles[0];
|
2018-12-14 09:40:55 +00:00
|
|
|
|
2020-08-07 17:26:28 +00:00
|
|
|
return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", url);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GetConcatInputArgument(inputFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the concat input argument.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="inputFiles">The input files.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
private static string GetConcatInputArgument(IReadOnlyList<string> inputFiles)
|
|
|
|
{
|
|
|
|
// Get all streams
|
|
|
|
// If there's more than one we'll need to use the concat command
|
|
|
|
if (inputFiles.Count > 1)
|
|
|
|
{
|
2019-02-24 14:47:59 +00:00
|
|
|
var files = string.Join("|", inputFiles.Select(NormalizePath));
|
2018-12-14 09:40:55 +00:00
|
|
|
|
2020-08-07 17:26:28 +00:00
|
|
|
return string.Format(CultureInfo.InvariantCulture, "concat:\"{0}\"", files);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the input path for video files
|
|
|
|
return GetFileInputArgument(inputFiles[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the file input argument.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
private static string GetFileInputArgument(string path)
|
|
|
|
{
|
2020-08-20 10:16:24 +00:00
|
|
|
if (path.IndexOf("://", StringComparison.Ordinal) != -1)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2020-08-07 17:26:28 +00:00
|
|
|
return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", path);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Quotes are valid path characters in linux and they need to be escaped here with a leading \
|
|
|
|
path = NormalizePath(path);
|
|
|
|
|
2020-08-07 17:26:28 +00:00
|
|
|
return string.Format(CultureInfo.InvariantCulture, "file:\"{0}\"", path);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Normalizes the path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
private static string NormalizePath(string path)
|
|
|
|
{
|
|
|
|
// Quotes are valid path characters in linux and they need to be escaped here with a leading \
|
2020-08-20 10:16:24 +00:00
|
|
|
return path.Replace("\"", "\\\"", StringComparison.Ordinal);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|