EncodingUtils.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using MediaBrowser.Controller.MediaEncoding;
  2. using MediaBrowser.Model.Entities;
  3. using MediaBrowser.Model.MediaInfo;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace MediaBrowser.MediaEncoding.Encoder
  8. {
  9. public static class EncodingUtils
  10. {
  11. public static string GetInputArgument(List<string> inputFiles, MediaProtocol protocol)
  12. {
  13. if (protocol == MediaProtocol.Http)
  14. {
  15. var url = inputFiles.First();
  16. return string.Format("\"{0}\"", url);
  17. }
  18. if (protocol == MediaProtocol.Rtmp)
  19. {
  20. var url = inputFiles.First();
  21. return string.Format("\"{0}\"", url);
  22. }
  23. return GetConcatInputArgument(inputFiles);
  24. }
  25. /// <summary>
  26. /// Gets the concat input argument.
  27. /// </summary>
  28. /// <param name="inputFiles">The input files.</param>
  29. /// <returns>System.String.</returns>
  30. private static string GetConcatInputArgument(IReadOnlyList<string> inputFiles)
  31. {
  32. // Get all streams
  33. // If there's more than one we'll need to use the concat command
  34. if (inputFiles.Count > 1)
  35. {
  36. var files = string.Join("|", inputFiles);
  37. return string.Format("concat:\"{0}\"", files);
  38. }
  39. // Determine the input path for video files
  40. return GetFileInputArgument(inputFiles[0]);
  41. }
  42. /// <summary>
  43. /// Gets the file input argument.
  44. /// </summary>
  45. /// <param name="path">The path.</param>
  46. /// <returns>System.String.</returns>
  47. private static string GetFileInputArgument(string path)
  48. {
  49. return string.Format("file:\"{0}\"", path);
  50. }
  51. public static string GetProbeSizeArgument(bool isDvd)
  52. {
  53. return isDvd ? "-probesize 1G -analyzeduration 200M" : string.Empty;
  54. }
  55. /// <summary>
  56. /// Gets the number of audio channels to specify on the command line
  57. /// </summary>
  58. /// <param name="request">The request.</param>
  59. /// <param name="audioStream">The audio stream.</param>
  60. /// <returns>System.Nullable{System.Int32}.</returns>
  61. public static int? GetNumAudioChannelsParam(EncodingOptions request, MediaStream audioStream)
  62. {
  63. if (audioStream != null)
  64. {
  65. var codec = request.AudioCodec ?? string.Empty;
  66. if (audioStream.Channels > 2 && codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1)
  67. {
  68. // wmav2 currently only supports two channel output
  69. return 2;
  70. }
  71. }
  72. if (request.MaxAudioChannels.HasValue)
  73. {
  74. if (audioStream != null && audioStream.Channels.HasValue)
  75. {
  76. return Math.Min(request.MaxAudioChannels.Value, audioStream.Channels.Value);
  77. }
  78. return request.MaxAudioChannels.Value;
  79. }
  80. return request.AudioChannels;
  81. }
  82. }
  83. }