EncodingUtils.cs 2.3 KB

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