EncodingUtils.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.Http)
  11. {
  12. var url = inputFiles.First();
  13. return string.Format("\"{0}\"", url);
  14. }
  15. if (protocol == MediaProtocol.Rtmp)
  16. {
  17. var url = inputFiles.First();
  18. return string.Format("\"{0}\"", url);
  19. }
  20. if (protocol == MediaProtocol.Rtsp)
  21. {
  22. var url = inputFiles.First();
  23. return string.Format("\"{0}\"", url);
  24. }
  25. return GetConcatInputArgument(inputFiles);
  26. }
  27. /// <summary>
  28. /// Gets the concat input argument.
  29. /// </summary>
  30. /// <param name="inputFiles">The input files.</param>
  31. /// <returns>System.String.</returns>
  32. private static string GetConcatInputArgument(IReadOnlyList<string> inputFiles)
  33. {
  34. // Get all streams
  35. // If there's more than one we'll need to use the concat command
  36. if (inputFiles.Count > 1)
  37. {
  38. var files = string.Join("|", inputFiles.Select(NormalizePath).ToArray());
  39. return string.Format("concat:\"{0}\"", files);
  40. }
  41. // Determine the input path for video files
  42. return GetFileInputArgument(inputFiles[0]);
  43. }
  44. /// <summary>
  45. /// Gets the file input argument.
  46. /// </summary>
  47. /// <param name="path">The path.</param>
  48. /// <returns>System.String.</returns>
  49. private static string GetFileInputArgument(string path)
  50. {
  51. // Quotes are valid path characters in linux and they need to be escaped here with a leading \
  52. path = NormalizePath(path);
  53. return string.Format("file:\"{0}\"", path);
  54. }
  55. /// <summary>
  56. /// Normalizes the path.
  57. /// </summary>
  58. /// <param name="path">The path.</param>
  59. /// <returns>System.String.</returns>
  60. private static string NormalizePath(string path)
  61. {
  62. // Quotes are valid path characters in linux and they need to be escaped here with a leading \
  63. return path.Replace("\"", "\\\"");
  64. }
  65. public static string GetProbeSizeArgument(bool isDvd)
  66. {
  67. return isDvd ? "-probesize 1G -analyzeduration 200M" : " -analyzeduration 2M";
  68. }
  69. }
  70. }