EncodingJobOptions.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using MediaBrowser.Model.Dlna;
  7. namespace MediaBrowser.Controller.MediaEncoding
  8. {
  9. public class EncodingJobOptions : BaseEncodingJobOptions
  10. {
  11. public string OutputDirectory { get; set; }
  12. public string ItemId { get; set; }
  13. public string TempDirectory { 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 => Width.HasValue || Height.HasValue;
  20. public DeviceProfile DeviceProfile { get; set; }
  21. public EncodingJobOptions(StreamInfo info, DeviceProfile deviceProfile)
  22. {
  23. Container = info.Container;
  24. StartTimeTicks = info.StartPositionTicks;
  25. MaxWidth = info.MaxWidth;
  26. MaxHeight = info.MaxHeight;
  27. MaxFramerate = info.MaxFramerate;
  28. Id = info.ItemId;
  29. MediaSourceId = info.MediaSourceId;
  30. AudioCodec = info.TargetAudioCodec.FirstOrDefault();
  31. MaxAudioChannels = info.GlobalMaxAudioChannels;
  32. AudioBitRate = info.AudioBitrate;
  33. AudioSampleRate = info.TargetAudioSampleRate;
  34. DeviceProfile = deviceProfile;
  35. VideoCodec = info.TargetVideoCodec.FirstOrDefault();
  36. VideoBitRate = info.VideoBitrate;
  37. AudioStreamIndex = info.AudioStreamIndex;
  38. SubtitleMethod = info.SubtitleDeliveryMethod;
  39. Context = info.Context;
  40. TranscodingMaxAudioChannels = info.TranscodingMaxAudioChannels;
  41. if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External)
  42. {
  43. SubtitleStreamIndex = info.SubtitleStreamIndex;
  44. }
  45. StreamOptions = info.StreamOptions;
  46. }
  47. }
  48. // For now until api and media encoding layers are unified
  49. public class BaseEncodingJobOptions
  50. {
  51. /// <summary>
  52. /// Gets or sets the id.
  53. /// </summary>
  54. /// <value>The id.</value>
  55. public Guid Id { get; set; }
  56. public string MediaSourceId { get; set; }
  57. public string DeviceId { get; set; }
  58. public string Container { get; set; }
  59. /// <summary>
  60. /// Gets or sets the audio codec.
  61. /// </summary>
  62. /// <value>The audio codec.</value>
  63. public string AudioCodec { get; set; }
  64. public bool EnableAutoStreamCopy { get; set; }
  65. public bool AllowVideoStreamCopy { get; set; }
  66. public bool AllowAudioStreamCopy { get; set; }
  67. public bool BreakOnNonKeyFrames { get; set; }
  68. /// <summary>
  69. /// Gets or sets the audio sample rate.
  70. /// </summary>
  71. /// <value>The audio sample rate.</value>
  72. public int? AudioSampleRate { get; set; }
  73. public int? MaxAudioBitDepth { get; set; }
  74. /// <summary>
  75. /// Gets or sets the audio bit rate.
  76. /// </summary>
  77. /// <value>The audio bit rate.</value>
  78. public int? AudioBitRate { get; set; }
  79. /// <summary>
  80. /// Gets or sets the audio channels.
  81. /// </summary>
  82. /// <value>The audio channels.</value>
  83. public int? AudioChannels { get; set; }
  84. public int? MaxAudioChannels { get; set; }
  85. public bool Static { get; set; }
  86. /// <summary>
  87. /// Gets or sets the profile.
  88. /// </summary>
  89. /// <value>The profile.</value>
  90. public string Profile { get; set; }
  91. /// <summary>
  92. /// Gets or sets the level.
  93. /// </summary>
  94. /// <value>The level.</value>
  95. public string Level { get; set; }
  96. /// <summary>
  97. /// Gets or sets the framerate.
  98. /// </summary>
  99. /// <value>The framerate.</value>
  100. public float? Framerate { get; set; }
  101. public float? MaxFramerate { get; set; }
  102. public bool CopyTimestamps { get; set; }
  103. /// <summary>
  104. /// Gets or sets the start time ticks.
  105. /// </summary>
  106. /// <value>The start time ticks.</value>
  107. public long? StartTimeTicks { get; set; }
  108. /// <summary>
  109. /// Gets or sets the width.
  110. /// </summary>
  111. /// <value>The width.</value>
  112. public int? Width { get; set; }
  113. /// <summary>
  114. /// Gets or sets the height.
  115. /// </summary>
  116. /// <value>The height.</value>
  117. public int? Height { get; set; }
  118. /// <summary>
  119. /// Gets or sets the width of the max.
  120. /// </summary>
  121. /// <value>The width of the max.</value>
  122. public int? MaxWidth { get; set; }
  123. /// <summary>
  124. /// Gets or sets the height of the max.
  125. /// </summary>
  126. /// <value>The height of the max.</value>
  127. public int? MaxHeight { get; set; }
  128. /// <summary>
  129. /// Gets or sets the video bit rate.
  130. /// </summary>
  131. /// <value>The video bit rate.</value>
  132. public int? VideoBitRate { get; set; }
  133. /// <summary>
  134. /// Gets or sets the index of the subtitle stream.
  135. /// </summary>
  136. /// <value>The index of the subtitle stream.</value>
  137. public int? SubtitleStreamIndex { get; set; }
  138. public SubtitleDeliveryMethod SubtitleMethod { get; set; }
  139. public int? MaxRefFrames { get; set; }
  140. public int? MaxVideoBitDepth { get; set; }
  141. public bool RequireAvc { get; set; }
  142. public bool DeInterlace { get; set; }
  143. public bool RequireNonAnamorphic { get; set; }
  144. public int? TranscodingMaxAudioChannels { get; set; }
  145. public int? CpuCoreLimit { get; set; }
  146. public string LiveStreamId { get; set; }
  147. public bool EnableMpegtsM2TsMode { get; set; }
  148. /// <summary>
  149. /// Gets or sets the video codec.
  150. /// </summary>
  151. /// <value>The video codec.</value>
  152. public string VideoCodec { get; set; }
  153. public string SubtitleCodec { get; set; }
  154. public string TranscodeReasons { get; set; }
  155. /// <summary>
  156. /// Gets or sets the index of the audio stream.
  157. /// </summary>
  158. /// <value>The index of the audio stream.</value>
  159. public int? AudioStreamIndex { get; set; }
  160. /// <summary>
  161. /// Gets or sets the index of the video stream.
  162. /// </summary>
  163. /// <value>The index of the video stream.</value>
  164. public int? VideoStreamIndex { get; set; }
  165. public EncodingContext Context { get; set; }
  166. public Dictionary<string, string> StreamOptions { get; set; }
  167. public string GetOption(string qualifier, string name)
  168. {
  169. var value = GetOption(qualifier + "-" + name);
  170. if (string.IsNullOrEmpty(value))
  171. {
  172. value = GetOption(name);
  173. }
  174. return value;
  175. }
  176. public string GetOption(string name)
  177. {
  178. if (StreamOptions.TryGetValue(name, out var value))
  179. {
  180. return value;
  181. }
  182. return null;
  183. }
  184. public BaseEncodingJobOptions()
  185. {
  186. EnableAutoStreamCopy = true;
  187. AllowVideoStreamCopy = true;
  188. AllowAudioStreamCopy = true;
  189. Context = EncodingContext.Streaming;
  190. StreamOptions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  191. }
  192. }
  193. }