reference-libobs-media-io.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. Media I/O API Reference (libobs/media-io)
  2. =========================================
  3. .. code:: cpp
  4. #include <obs.h>
  5. Video Handler
  6. -------------
  7. .. type:: video_t
  8. Video output handler object
  9. ---------------------
  10. .. enum:: video_format
  11. Video format. Can be one of the following values:
  12. - VIDEO_FORMAT_I420
  13. - VIDEO_FORMAT_NV12
  14. - VIDEO_FORMAT_YVYU
  15. - VIDEO_FORMAT_YUY2
  16. - VIDEO_FORMAT_UYVY
  17. - VIDEO_FORMAT_RGBA
  18. - VIDEO_FORMAT_BGRA
  19. - VIDEO_FORMAT_BGRX
  20. - VIDEO_FORMAT_Y800
  21. - VIDEO_FORMAT_I444
  22. - VIDEO_FORMAT_BGR3
  23. - VIDEO_FORMAT_I422
  24. - VIDEO_FORMAT_I40A
  25. - VIDEO_FORMAT_I42A
  26. - VIDEO_FORMAT_YUVA
  27. - VIDEO_FORMAT_AYUV
  28. - VIDEO_FORMAT_I010
  29. - VIDEO_FORMAT_P010
  30. - VIDEO_FORMAT_I210
  31. - VIDEO_FORMAT_I412
  32. - VIDEO_FORMAT_YA2L
  33. - VIDEO_FORMAT_P216
  34. - VIDEO_FORMAT_P416
  35. ---------------------
  36. .. enum:: video_trc
  37. Transfer characteristics. Can be one of the following values:
  38. - VIDEO_TRC_DEFAULT - sRGB TRC for SDR, PQ TRC for HDR
  39. - VIDEO_TRC_SRGB - sRGB TRC
  40. - VIDEO_TRC_PQ - PQ
  41. - VIDEO_TRC_HLG - HLG
  42. ---------------------
  43. .. enum:: video_colorspace
  44. YUV color space. Can be one of the following values:
  45. - VIDEO_CS_DEFAULT - Equivalent to VIDEO_CS_709
  46. - VIDEO_CS_601 - Rec. 601 color space
  47. - VIDEO_CS_709 - Rec. 709 color space
  48. - VIDEO_CS_SRGB - sRGB color space
  49. - VIDEO_CS_2100_PQ - Rec. 2100 color space, PQ transfer
  50. - VIDEO_CS_2100_HLG - Rec. 2100 color space, HLG transfer
  51. ---------------------
  52. .. enum:: video_range_type
  53. YUV color range.
  54. - VIDEO_RANGE_DEFAULT - Equivalent to VIDEO_RANGE_PARTIAL
  55. - VIDEO_RANGE_PARTIAL - Partial range
  56. - VIDEO_RANGE_FULL - Full range
  57. ---------------------
  58. .. struct:: video_data
  59. Video frame structure.
  60. .. member:: uint8_t *video_data.data[MAX_AV_PLANES]
  61. .. member:: uint32_t video_data.linesize[MAX_AV_PLANES]
  62. .. member:: uint64_t video_data.timestamp
  63. ---------------------
  64. .. struct:: video_output_info
  65. Video output handler information
  66. .. member:: const char *video_output_info.name
  67. .. member:: enum video_format video_output_info.format
  68. .. member:: uint32_t video_output_info.fps_num
  69. .. member:: uint32_t video_output_info.fps_den
  70. .. member:: uint32_t video_output_info.width
  71. .. member:: uint32_t video_output_info.height
  72. .. member:: size_t video_output_info.cache_size
  73. .. member:: enum video_colorspace video_output_info.colorspace
  74. .. member:: enum video_range_type video_output_info.range
  75. ---------------------
  76. .. function:: enum video_format video_format_from_fourcc(uint32_t fourcc)
  77. Converts a fourcc value to a video format.
  78. :param forcecc: Fourcc value
  79. :return: Video format
  80. ---------------------
  81. .. function:: bool video_format_get_parameters(enum video_colorspace color_space, enum video_range_type range, float matrix[16], float min_range[3], float max_range[3])
  82. Converts a color space/range to matrix/min/max values.
  83. :param color_space: Color space to convert
  84. :param range: Color range to convert
  85. :param matrix: Pointer to the matrix
  86. :param min_range: Pointer to get the minimum range value
  87. :param max_range: Pointer to get the maximum range value
  88. ---------------------
  89. .. function:: bool video_format_get_parameters_for_format(enum video_colorspace color_space, enum video_range_type range, enum video_format format, float matrix[16], float min_range[3], float max_range[3])
  90. Converts a color space/range to matrix/min/max values for a given video format.
  91. :param color_space: Color space to convert
  92. :param range: Color range to convert
  93. :param format: Video format
  94. :param matrix: Pointer to the matrix
  95. :param min_range: Pointer to get the minimum range value
  96. :param max_range: Pointer to get the maximum range value
  97. ---------------------
  98. .. function:: bool video_output_connect(video_t *video, const struct video_scale_info *conversion, void (*callback)(void *param, struct video_data *frame), void *param)
  99. Connects a raw video callback to the video output handler.
  100. :param video: Video output handler object
  101. :param callback: Callback to receive video data
  102. :param param: Private data to pass to the callback
  103. ---------------------
  104. .. function:: void video_output_disconnect(video_t *video, void (*callback)(void *param, struct video_data *frame), void *param)
  105. Disconnects a raw video callback from the video output handler.
  106. :param video: Video output handler object
  107. :param callback: Callback
  108. :param param: Private data
  109. ---------------------
  110. .. function:: const struct video_output_info *video_output_get_info(const video_t *video)
  111. Gets the full video information of the video output handler.
  112. :param video: Video output handler object
  113. :return: Video output info structure pointer
  114. ---------------------
  115. .. function:: uint64_t video_output_get_frame_time(const video_t *video)
  116. Gets the frame interval of the video output handler.
  117. :param video: Video output handler object
  118. :return: Video frame interval in nanoseconds
  119. ---------------------
  120. .. function:: enum video_format video_output_get_format(const video_t *video)
  121. Gets the video format of the video output handler.
  122. :param video: Video output handler object
  123. :return: Video format
  124. ---------------------
  125. .. function:: uint32_t video_output_get_width(const video_t *video)
  126. .. function:: uint32_t video_output_get_height(const video_t *video)
  127. Gets the width/height of the video output handler.
  128. :param video: Video output handler object
  129. :return: Width/height
  130. ---------------------
  131. .. function:: double video_output_get_frame_rate(const video_t *video)
  132. Gets the frame rate (as a floating point) of the video output
  133. handler.
  134. :param video: Video output handler object
  135. :return: Frame rate
  136. ---------------------
  137. .. function:: uint32_t video_output_get_skipped_frames(const video_t *video)
  138. Gets the skipped frame count of the video output handler.
  139. :param video: Video output handler object
  140. :return: Skipped frame count
  141. ---------------------
  142. .. function:: uint32_t video_output_get_total_frames(const video_t *video)
  143. Gets the total frames processed of the video output handler.
  144. :param video: Video output handler object
  145. :return: Total frames processed
  146. ---------------------
  147. Audio Handler
  148. -------------
  149. .. type:: audio_t
  150. ---------------------
  151. .. enum:: audio_format
  152. Audio format. Can be one of the following values:
  153. - AUDIO_FORMAT_UNKNOWN
  154. - AUDIO_FORMAT_U8BIT
  155. - AUDIO_FORMAT_16BIT
  156. - AUDIO_FORMAT_32BIT
  157. - AUDIO_FORMAT_FLOAT
  158. - AUDIO_FORMAT_U8BIT_PLANAR
  159. - AUDIO_FORMAT_16BIT_PLANAR
  160. - AUDIO_FORMAT_32BIT_PLANAR
  161. - AUDIO_FORMAT_FLOAT_PLANAR
  162. ---------------------
  163. .. enum:: speaker_layout
  164. Speaker layout. Can be one of the following values:
  165. - SPEAKERS_UNKNOWN
  166. - SPEAKERS_MONO
  167. - SPEAKERS_STEREO
  168. - SPEAKERS_2POINT1
  169. - SPEAKERS_4POINT0
  170. - SPEAKERS_4POINT1
  171. - SPEAKERS_5POINT1
  172. - SPEAKERS_7POINT1
  173. ---------------------
  174. .. struct:: audio_data
  175. Audio data structure.
  176. .. member:: uint8_t *audio_data.data[MAX_AV_PLANES]
  177. .. member:: uint32_t audio_data.frames
  178. .. member:: uint64_t audio_data.timestamp
  179. ---------------------
  180. .. struct:: audio_output_data
  181. .. member:: float *audio_output_data.data[MAX_AUDIO_CHANNELS]
  182. ---------------------
  183. .. struct:: audio_output_info
  184. .. member:: const char *audio_output_info.name
  185. .. member:: uint32_t audio_output_info.samples_per_sec
  186. .. member:: enum audio_format audio_output_info.format
  187. .. member:: enum speaker_layout audio_output_info.speakers
  188. .. member:: audio_input_callback_t audio_output_info.input_callback
  189. .. member:: void *audio_output_info.input_param
  190. ---------------------
  191. .. struct:: audio_convert_info
  192. .. member:: uint32_t audio_convert_info.samples_per_sec
  193. .. member:: enum audio_format audio_convert_info.format
  194. .. member:: enum speaker_layout audio_convert_info.speakers
  195. ---------------------
  196. .. type:: bool (*audio_input_callback_t)(void *param, uint64_t start_ts, uint64_t end_ts, uint64_t *new_ts, uint32_t active_mixers, struct audio_output_data *mixes)
  197. Audio input callback (typically used internally).
  198. ---------------------
  199. .. function:: uint32_t get_audio_channels(enum speaker_layout speakers)
  200. Converts a speaker layout to its audio channel count.
  201. :param speakers: Speaker layout enumeration
  202. :return: Channel count
  203. ---------------------
  204. .. function:: size_t get_audio_bytes_per_channel(enum audio_format format)
  205. Gets the audio bytes per channel for a specific audio format.
  206. :param format: Audio format
  207. :return: Bytes per channel
  208. ---------------------
  209. .. function:: bool is_audio_planar(enum audio_format format)
  210. Returns whether the audio format is a planar format.
  211. :param format: Audio format
  212. :return: *true* if audio is planar, *false* otherwise
  213. ---------------------
  214. .. function:: size_t get_audio_planes(enum audio_format format, enum speaker_layout speakers)
  215. Gets the number of audio planes for a specific audio format and
  216. speaker layout.
  217. :param format: Audio format
  218. :param speakers: Speaker layout
  219. :return: Number of audio planes
  220. ---------------------
  221. .. function:: size_t get_audio_size(enum audio_format format, enum speaker_layout speakers, uint32_t frames)
  222. Gets the audio block size for a specific frame out with the given
  223. format and speaker layout.
  224. :param format: Audio format
  225. :param speakers: Speaker layout
  226. :param frames: Audio frame count
  227. :return: Audio block size
  228. ---------------------
  229. .. function:: uint64_t audio_frames_to_ns(size_t sample_rate, uint64_t frames)
  230. Helper function to convert a specific number of audio frames to
  231. nanoseconds based upon its sample rate.
  232. :param sample_rate: Sample rate
  233. :param frames: Frame count
  234. :return: Nanoseconds
  235. ---------------------
  236. .. function:: uint64_t ns_to_audio_frames(size_t sample_rate, uint64_t ns)
  237. Helper function to convert a specific number of nanoseconds to audio
  238. frame count based upon its sample rate.
  239. :param sample_rate: Sample rate
  240. :param ns: Nanoseconds
  241. :return: Frame count
  242. ---------------------
  243. .. type:: void (*audio_output_callback_t)(void *param, size_t mix_idx, struct audio_data *data)
  244. Audio output callback. Typically used internally.
  245. ---------------------
  246. .. function:: bool audio_output_connect(audio_t *audio, size_t mix_idx, const struct audio_convert_info *conversion, audio_output_callback_t callback, void *param)
  247. Connects a raw audio callback to the audio output handler.
  248. Optionally allows audio conversion if necessary.
  249. :param audio: Audio output handler object
  250. :param mix_idx: Mix index to get raw audio from
  251. :param conversion: Audio conversion information, or *NULL* for no
  252. conversion
  253. :param callback: Raw audio callback
  254. :param param: Private data to pass to the callback
  255. ---------------------
  256. .. function:: void audio_output_disconnect(audio_t *audio, size_t mix_idx, audio_output_callback_t callback, void *param)
  257. Disconnects a raw audio callback from the audio output handler.
  258. :param audio: Audio output handler object
  259. :param mix_idx: Mix index to get raw audio from
  260. :param callback: Raw audio callback
  261. :param param: Private data to pass to the callback
  262. ---------------------
  263. .. function:: size_t audio_output_get_block_size(const audio_t *audio)
  264. Gets the audio block size of an audio output handler.
  265. :param audio: Audio output handler object
  266. :return: Audio block size
  267. ---------------------
  268. .. function:: size_t audio_output_get_planes(const audio_t *audio)
  269. Gets the plane count of an audio output handler.
  270. :param audio: Audio output handler object
  271. :return: Audio plane count
  272. ---------------------
  273. .. function:: size_t audio_output_get_channels(const audio_t *audio)
  274. Gets the channel count of an audio output handler.
  275. :param audio: Audio output handler object
  276. :return: Audio channel count
  277. ---------------------
  278. .. function:: uint32_t audio_output_get_sample_rate(const audio_t *audio)
  279. Gets the sample rate of an audio output handler.
  280. :param audio: Audio output handler object
  281. :return: Audio sample rate
  282. ---------------------
  283. .. function:: const struct audio_output_info *audio_output_get_info(const audio_t *audio)
  284. Gets all audio information for an audio output handler.
  285. :param audio: Audio output handler object
  286. :return: Pointer to audio output information structure
  287. ---------------------
  288. Resampler
  289. ---------
  290. FFmpeg wrapper to resample audio.
  291. .. type:: struct audio_resampler audio_resampler_t
  292. ---------------------
  293. .. struct:: resample_info
  294. .. member:: uint32_t resample_info.samples_per_sec
  295. .. member:: enum audio_format resample_info.format
  296. .. member:: enum speaker_layout resample_info.speakers
  297. ---------------------
  298. .. function:: audio_resampler_t *audio_resampler_create(const struct resample_info *dst, const struct resample_info *src)
  299. Creates an audio resampler.
  300. :param dst: Destination audio information
  301. :param src: Source audio information
  302. :return: Audio resampler object
  303. ---------------------
  304. .. function:: void audio_resampler_destroy(audio_resampler_t *resampler)
  305. Destroys an audio resampler.
  306. :param resampler: Audio resampler object
  307. ---------------------
  308. .. function:: bool audio_resampler_resample(audio_resampler_t *resampler, uint8_t *output[], uint32_t *out_frames, uint64_t *ts_offset, const uint8_t *const input[], uint32_t in_frames)
  309. Resamples audio frames.
  310. :param resampler: Audio resampler object
  311. :param output: Pointer to receive converted audio frames
  312. :param out_frames: Pointer to receive converted audio frame count
  313. :param ts_offset: Pointer to receive timestamp offset (in
  314. nanoseconds)
  315. :param input: Input frames to convert
  316. :param in_frames: Input frame count