EncodingUtils.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma warning disable CS1591
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using MediaBrowser.Model.MediaInfo;
  6. namespace MediaBrowser.MediaEncoding.Encoder
  7. {
  8. public static class EncodingUtils
  9. {
  10. public static string GetInputArgument(IReadOnlyList<string> inputFiles, MediaProtocol protocol)
  11. {
  12. if (protocol != MediaProtocol.File)
  13. {
  14. var url = inputFiles[0];
  15. return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", url);
  16. }
  17. return GetConcatInputArgument(inputFiles);
  18. }
  19. /// <summary>
  20. /// Gets the concat input argument.
  21. /// </summary>
  22. /// <param name="inputFiles">The input files.</param>
  23. /// <returns>System.String.</returns>
  24. private static string GetConcatInputArgument(IReadOnlyList<string> inputFiles)
  25. {
  26. // Get all streams
  27. // If there's more than one we'll need to use the concat command
  28. if (inputFiles.Count > 1)
  29. {
  30. var files = string.Join("|", inputFiles.Select(NormalizePath));
  31. return string.Format(CultureInfo.InvariantCulture, "concat:\"{0}\"", files);
  32. }
  33. // Determine the input path for video files
  34. return GetFileInputArgument(inputFiles[0]);
  35. }
  36. /// <summary>
  37. /// Gets the file input argument.
  38. /// </summary>
  39. /// <param name="path">The path.</param>
  40. /// <returns>System.String.</returns>
  41. private static string GetFileInputArgument(string path)
  42. {
  43. if (path.IndexOf("://") != -1)
  44. {
  45. return string.Format(CultureInfo.InvariantCulture, "\"{0}\"", path);
  46. }
  47. // Quotes are valid path characters in linux and they need to be escaped here with a leading \
  48. path = NormalizePath(path);
  49. return string.Format(CultureInfo.InvariantCulture, "file:\"{0}\"", path);
  50. }
  51. /// <summary>
  52. /// Normalizes the path.
  53. /// </summary>
  54. /// <param name="path">The path.</param>
  55. /// <returns>System.String.</returns>
  56. private static string NormalizePath(string path)
  57. {
  58. // Quotes are valid path characters in linux and they need to be escaped here with a leading \
  59. return path.Replace("\"", "\\\"");
  60. }
  61. }
  62. }