EncodingJobOptions.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System.Globalization;
  2. using MediaBrowser.Model.Dlna;
  3. using MediaBrowser.Model.Services;
  4. namespace MediaBrowser.Controller.MediaEncoding
  5. {
  6. public class EncodingJobOptions : BaseEncodingJobOptions
  7. {
  8. public string OutputDirectory { get; set; }
  9. public string DeviceId { get; set; }
  10. public string ItemId { get; set; }
  11. public string MediaSourceId { get; set; }
  12. public string AudioCodec { get; set; }
  13. public DeviceProfile DeviceProfile { get; set; }
  14. public bool ReadInputAtNativeFramerate { get; set; }
  15. /// <summary>
  16. /// Gets a value indicating whether this instance has fixed resolution.
  17. /// </summary>
  18. /// <value><c>true</c> if this instance has fixed resolution; otherwise, <c>false</c>.</value>
  19. public bool HasFixedResolution
  20. {
  21. get
  22. {
  23. return Width.HasValue || Height.HasValue;
  24. }
  25. }
  26. private readonly CultureInfo _usCulture = new CultureInfo("en-US");
  27. public EncodingJobOptions(StreamInfo info, DeviceProfile deviceProfile)
  28. {
  29. OutputContainer = info.Container;
  30. StartTimeTicks = info.StartPositionTicks;
  31. MaxWidth = info.MaxWidth;
  32. MaxHeight = info.MaxHeight;
  33. MaxFramerate = info.MaxFramerate;
  34. Profile = info.VideoProfile;
  35. ItemId = info.ItemId;
  36. MediaSourceId = info.MediaSourceId;
  37. AudioCodec = info.TargetAudioCodec;
  38. MaxAudioChannels = info.MaxAudioChannels;
  39. AudioBitRate = info.AudioBitrate;
  40. AudioSampleRate = info.TargetAudioSampleRate;
  41. DeviceProfile = deviceProfile;
  42. VideoCodec = info.TargetVideoCodec;
  43. VideoBitRate = info.VideoBitrate;
  44. AudioStreamIndex = info.AudioStreamIndex;
  45. MaxRefFrames = info.MaxRefFrames;
  46. MaxVideoBitDepth = info.MaxVideoBitDepth;
  47. SubtitleMethod = info.SubtitleDeliveryMethod;
  48. Context = info.Context;
  49. TranscodingMaxAudioChannels = info.TranscodingMaxAudioChannels;
  50. if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External)
  51. {
  52. SubtitleStreamIndex = info.SubtitleStreamIndex;
  53. }
  54. if (info.VideoLevel.HasValue)
  55. {
  56. Level = info.VideoLevel.Value.ToString(_usCulture);
  57. }
  58. }
  59. }
  60. // For now until api and media encoding layers are unified
  61. public class BaseEncodingJobOptions
  62. {
  63. [ApiMember(Name = "EnableAutoStreamCopy", Description = "Whether or not to allow automatic stream copy if requested values match the original source. Defaults to true.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  64. public bool EnableAutoStreamCopy { get; set; }
  65. /// <summary>
  66. /// Gets or sets the audio sample rate.
  67. /// </summary>
  68. /// <value>The audio sample rate.</value>
  69. [ApiMember(Name = "AudioSampleRate", Description = "Optional. Specify a specific audio sample rate, e.g. 44100", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  70. public int? AudioSampleRate { get; set; }
  71. /// <summary>
  72. /// Gets or sets the audio bit rate.
  73. /// </summary>
  74. /// <value>The audio bit rate.</value>
  75. [ApiMember(Name = "AudioBitRate", Description = "Optional. Specify an audio bitrate to encode to, e.g. 128000. If omitted this will be left to encoder defaults.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  76. public int? AudioBitRate { get; set; }
  77. /// <summary>
  78. /// Gets or sets the audio channels.
  79. /// </summary>
  80. /// <value>The audio channels.</value>
  81. [ApiMember(Name = "AudioChannels", Description = "Optional. Specify a specific number of audio channels to encode to, e.g. 2", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  82. public int? AudioChannels { get; set; }
  83. [ApiMember(Name = "MaxAudioChannels", Description = "Optional. Specify a maximum number of audio channels to encode to, e.g. 2", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  84. public int? MaxAudioChannels { get; set; }
  85. [ApiMember(Name = "Static", Description = "Optional. If true, the original file will be streamed statically without any encoding. Use either no url extension or the original file extension. true/false", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  86. public bool Static { get; set; }
  87. /// <summary>
  88. /// Gets or sets the profile.
  89. /// </summary>
  90. /// <value>The profile.</value>
  91. [ApiMember(Name = "Profile", Description = "Optional. Specify a specific h264 profile, e.g. main, baseline, high.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  92. public string Profile { get; set; }
  93. /// <summary>
  94. /// Gets or sets the level.
  95. /// </summary>
  96. /// <value>The level.</value>
  97. [ApiMember(Name = "Level", Description = "Optional. Specify a level for the h264 profile, e.g. 3, 3.1.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  98. public string Level { get; set; }
  99. /// <summary>
  100. /// Gets or sets the framerate.
  101. /// </summary>
  102. /// <value>The framerate.</value>
  103. [ApiMember(Name = "Framerate", Description = "Optional. A specific video framerate to encode to, e.g. 23.976. Generally this should be omitted unless the device has specific requirements.", IsRequired = false, DataType = "double", ParameterType = "query", Verb = "GET")]
  104. public float? Framerate { get; set; }
  105. [ApiMember(Name = "MaxFramerate", Description = "Optional. A specific maximum video framerate to encode to, e.g. 23.976. Generally this should be omitted unless the device has specific requirements.", IsRequired = false, DataType = "double", ParameterType = "query", Verb = "GET")]
  106. public float? MaxFramerate { get; set; }
  107. [ApiMember(Name = "CopyTimestamps", Description = "Whether or not to copy timestamps when transcoding with an offset. Defaults to false.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  108. public bool CopyTimestamps { get; set; }
  109. /// <summary>
  110. /// Gets or sets the start time ticks.
  111. /// </summary>
  112. /// <value>The start time ticks.</value>
  113. [ApiMember(Name = "StartTimeTicks", Description = "Optional. Specify a starting offset, in ticks. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  114. public long? StartTimeTicks { get; set; }
  115. /// <summary>
  116. /// Gets or sets the width.
  117. /// </summary>
  118. /// <value>The width.</value>
  119. [ApiMember(Name = "Width", Description = "Optional. The fixed horizontal resolution of the encoded video.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  120. public int? Width { get; set; }
  121. /// <summary>
  122. /// Gets or sets the height.
  123. /// </summary>
  124. /// <value>The height.</value>
  125. [ApiMember(Name = "Height", Description = "Optional. The fixed vertical resolution of the encoded video.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  126. public int? Height { get; set; }
  127. /// <summary>
  128. /// Gets or sets the width of the max.
  129. /// </summary>
  130. /// <value>The width of the max.</value>
  131. [ApiMember(Name = "MaxWidth", Description = "Optional. The maximum horizontal resolution of the encoded video.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  132. public int? MaxWidth { get; set; }
  133. /// <summary>
  134. /// Gets or sets the height of the max.
  135. /// </summary>
  136. /// <value>The height of the max.</value>
  137. [ApiMember(Name = "MaxHeight", Description = "Optional. The maximum vertical resolution of the encoded video.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  138. public int? MaxHeight { get; set; }
  139. /// <summary>
  140. /// Gets or sets the video bit rate.
  141. /// </summary>
  142. /// <value>The video bit rate.</value>
  143. [ApiMember(Name = "VideoBitRate", Description = "Optional. Specify a video bitrate to encode to, e.g. 500000. If omitted this will be left to encoder defaults.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  144. public int? VideoBitRate { get; set; }
  145. /// <summary>
  146. /// Gets or sets the index of the subtitle stream.
  147. /// </summary>
  148. /// <value>The index of the subtitle stream.</value>
  149. [ApiMember(Name = "SubtitleStreamIndex", Description = "Optional. The index of the subtitle stream to use. If omitted no subtitles will be used.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  150. public int? SubtitleStreamIndex { get; set; }
  151. [ApiMember(Name = "SubtitleMethod", Description = "Optional. Specify the subtitle delivery method.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  152. public SubtitleDeliveryMethod SubtitleMethod { get; set; }
  153. [ApiMember(Name = "MaxRefFrames", Description = "Optional.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  154. public int? MaxRefFrames { get; set; }
  155. [ApiMember(Name = "MaxVideoBitDepth", Description = "Optional.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  156. public int? MaxVideoBitDepth { get; set; }
  157. public bool RequireAvc { get; set; }
  158. public bool DeInterlace { get; set; }
  159. public bool RequireNonAnamorphic { get; set; }
  160. public int? TranscodingMaxAudioChannels { get; set; }
  161. public int? CpuCoreLimit { get; set; }
  162. public string OutputContainer { get; set; }
  163. /// <summary>
  164. /// Gets or sets the video codec.
  165. /// </summary>
  166. /// <value>The video codec.</value>
  167. [ApiMember(Name = "VideoCodec", Description = "Optional. Specify a video codec to encode to, e.g. h264. If omitted the server will auto-select using the url's extension. Options: h264, mpeg4, theora, vpx, wmv.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  168. public string VideoCodec { get; set; }
  169. public string SubtitleCodec { get; set; }
  170. /// <summary>
  171. /// Gets or sets the index of the audio stream.
  172. /// </summary>
  173. /// <value>The index of the audio stream.</value>
  174. [ApiMember(Name = "AudioStreamIndex", Description = "Optional. The index of the audio stream to use. If omitted the first audio stream will be used.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  175. public int? AudioStreamIndex { get; set; }
  176. /// <summary>
  177. /// Gets or sets the index of the video stream.
  178. /// </summary>
  179. /// <value>The index of the video stream.</value>
  180. [ApiMember(Name = "VideoStreamIndex", Description = "Optional. The index of the video stream to use. If omitted the first video stream will be used.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  181. public int? VideoStreamIndex { get; set; }
  182. public EncodingContext Context { get; set; }
  183. public BaseEncodingJobOptions()
  184. {
  185. EnableAutoStreamCopy = true;
  186. Context = EncodingContext.Streaming;
  187. }
  188. }
  189. }