EncodingUtils.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Quotes are valid path characters in linux and they need to be escaped here with a leading \
  42. path = NormalizePath(path);
  43. return string.Format("file:\"{0}\"", path);
  44. }
  45. /// <summary>
  46. /// Normalizes the path.
  47. /// </summary>
  48. /// <param name="path">The path.</param>
  49. /// <returns>System.String.</returns>
  50. private static string NormalizePath(string path)
  51. {
  52. // Quotes are valid path characters in linux and they need to be escaped here with a leading \
  53. return path.Replace("\"", "\\\"");
  54. }
  55. }
  56. }