EncodingUtils.cs 2.3 KB

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