2020-08-04 14:20:52 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2020-08-20 10:16:24 +00:00
|
|
|
using System;
|
2023-02-03 19:03:55 +00:00
|
|
|
using System.Collections.Generic;
|
2020-08-07 17:26:28 +00:00
|
|
|
using System.Globalization;
|
2023-02-03 19:03: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
|
|
|
|
{
|
2020-10-01 20:20:28 +00:00
|
|
|
public static string GetInputArgument(string inputPrefix, string inputFile, MediaProtocol protocol)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
|
|
|
if (protocol != MediaProtocol.File)
|
|
|
|
{
|
2020-10-01 20:20:28 +00:00
|
|
|
return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", inputFile);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 19:03:55 +00: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 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the concat input argument.
|
|
|
|
/// </summary>
|
2023-02-03 19:03:55 +00:00
|
|
|
/// <param name="inputFiles">The input files.</param>
|
2020-09-24 06:41:42 +00:00
|
|
|
/// <param name="inputPrefix">The input prefix.</param>
|
2018-12-14 09:40:55 +00:00
|
|
|
/// <returns>System.String.</returns>
|
2023-02-03 19:03:55 +00:00
|
|
|
private static string GetConcatInputArgument(IReadOnlyList<string> inputFiles, string inputPrefix)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
|
|
|
// Get all streams
|
|
|
|
// If there's more than one we'll need to use the concat command
|
2023-02-03 19:03:55 +00:00
|
|
|
if (inputFiles.Count > 1)
|
|
|
|
{
|
|
|
|
var files = string.Join("|", inputFiles.Select(NormalizePath));
|
|
|
|
|
|
|
|
return string.Format(CultureInfo.InvariantCulture, "concat:\"{0}\"", files);
|
|
|
|
}
|
|
|
|
|
2018-12-14 09:40:55 +00:00
|
|
|
// Determine the input path for video files
|
2023-02-03 19:03:55 +00:00
|
|
|
return GetFileInputArgument(inputFiles[0], inputPrefix);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the file input argument.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path.</param>
|
2020-09-24 06:41:42 +00:00
|
|
|
/// <param name="inputPrefix">The path prefix.</param>
|
2018-12-14 09:40:55 +00:00
|
|
|
/// <returns>System.String.</returns>
|
2020-09-24 06:41:42 +00:00
|
|
|
private static string GetFileInputArgument(string path, string inputPrefix)
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2023-11-14 19:21:34 +00:00
|
|
|
if (path.Contains("://", StringComparison.Ordinal))
|
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-09-24 06:41:42 +00:00
|
|
|
return string.Format(CultureInfo.InvariantCulture, "{1}:\"{0}\"", path, inputPrefix);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Normalizes the path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="path">The path.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
2023-03-10 00:29:39 +00:00
|
|
|
public static string NormalizePath(string 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 \
|
2020-08-20 10:16:24 +00:00
|
|
|
return path.Replace("\"", "\\\"", StringComparison.Ordinal);
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|