EncodingUtils.cs 2.2 KB

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