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