EncodingJobOptions.cs 7.5 KB

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