obs-ffmpeg-output.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /******************************************************************************
  2. Copyright (C) 2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <obs-module.h>
  15. #include <util/circlebuf.h>
  16. #include <util/threading.h>
  17. #include <util/dstr.h>
  18. #include <util/darray.h>
  19. #include <util/platform.h>
  20. #include "obs-ffmpeg-output.h"
  21. #include "obs-ffmpeg-formats.h"
  22. #include "obs-ffmpeg-compat.h"
  23. #include <libavutil/channel_layout.h>
  24. #include <libavutil/mastering_display_metadata.h>
  25. /* ------------------------------------------------------------------------- */
  26. static void ffmpeg_output_set_last_error(struct ffmpeg_data *data,
  27. const char *error)
  28. {
  29. if (data->last_error)
  30. bfree(data->last_error);
  31. data->last_error = bstrdup(error);
  32. }
  33. void ffmpeg_log_error(int log_level, struct ffmpeg_data *data,
  34. const char *format, ...)
  35. {
  36. va_list args;
  37. char out[4096];
  38. va_start(args, format);
  39. vsnprintf(out, sizeof(out), format, args);
  40. va_end(args);
  41. ffmpeg_output_set_last_error(data, out);
  42. blog(log_level, "%s", out);
  43. }
  44. static bool new_stream(struct ffmpeg_data *data, AVStream **stream,
  45. const AVCodec **codec, enum AVCodecID id,
  46. const char *name)
  47. {
  48. *codec = (!!name && *name) ? avcodec_find_encoder_by_name(name)
  49. : avcodec_find_encoder(id);
  50. if (!*codec) {
  51. ffmpeg_log_error(LOG_WARNING, data,
  52. "Couldn't find encoder '%s'",
  53. avcodec_get_name(id));
  54. return false;
  55. }
  56. *stream = avformat_new_stream(data->output, *codec);
  57. if (!*stream) {
  58. ffmpeg_log_error(LOG_WARNING, data,
  59. "Couldn't create stream for encoder '%s'",
  60. avcodec_get_name(id));
  61. return false;
  62. }
  63. (*stream)->id = data->output->nb_streams - 1;
  64. return true;
  65. }
  66. static bool parse_params(AVCodecContext *context, char **opts)
  67. {
  68. bool ret = true;
  69. if (!context || !context->priv_data)
  70. return true;
  71. while (*opts) {
  72. char *opt = *opts;
  73. char *assign = strchr(opt, '=');
  74. if (assign) {
  75. char *name = opt;
  76. char *value;
  77. *assign = 0;
  78. value = assign + 1;
  79. if (av_opt_set(context, name, value,
  80. AV_OPT_SEARCH_CHILDREN)) {
  81. blog(LOG_WARNING, "Failed to set %s=%s", name,
  82. value);
  83. ret = false;
  84. }
  85. }
  86. opts++;
  87. }
  88. return ret;
  89. }
  90. static bool open_video_codec(struct ffmpeg_data *data)
  91. {
  92. AVCodecContext *const context = data->video_ctx;
  93. char **opts = strlist_split(data->config.video_settings, ' ', false);
  94. int ret;
  95. if (strcmp(data->vcodec->name, "libx264") == 0)
  96. av_opt_set(context->priv_data, "preset", "veryfast", 0);
  97. if (opts) {
  98. // libav requires x264 parameters in a special format which may be non-obvious
  99. if (!parse_params(context, opts) &&
  100. strcmp(data->vcodec->name, "libx264") == 0)
  101. blog(LOG_WARNING,
  102. "If you're trying to set x264 parameters, use x264-params=name=value:name=value");
  103. strlist_free(opts);
  104. }
  105. ret = avcodec_open2(context, data->vcodec, NULL);
  106. if (ret < 0) {
  107. ffmpeg_log_error(LOG_WARNING, data,
  108. "Failed to open video codec: %s",
  109. av_err2str(ret));
  110. return false;
  111. }
  112. data->vframe = av_frame_alloc();
  113. if (!data->vframe) {
  114. ffmpeg_log_error(LOG_WARNING, data,
  115. "Failed to allocate video frame");
  116. return false;
  117. }
  118. data->vframe->format = context->pix_fmt;
  119. data->vframe->width = context->width;
  120. data->vframe->height = context->height;
  121. data->vframe->color_range = data->config.color_range;
  122. data->vframe->color_primaries = data->config.color_primaries;
  123. data->vframe->color_trc = data->config.color_trc;
  124. data->vframe->colorspace = data->config.colorspace;
  125. data->vframe->chroma_location =
  126. (data->config.colorspace == AVCOL_SPC_BT2020_NCL)
  127. ? AVCHROMA_LOC_TOPLEFT
  128. : AVCHROMA_LOC_LEFT;
  129. ret = av_frame_get_buffer(data->vframe, base_get_alignment());
  130. if (ret < 0) {
  131. ffmpeg_log_error(LOG_WARNING, data,
  132. "Failed to allocate vframe: %s",
  133. av_err2str(ret));
  134. return false;
  135. }
  136. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
  137. avcodec_parameters_from_context(data->video->codecpar, context);
  138. #endif
  139. return true;
  140. }
  141. static bool init_swscale(struct ffmpeg_data *data, AVCodecContext *context)
  142. {
  143. data->swscale = sws_getContext(
  144. data->config.width, data->config.height, data->config.format,
  145. data->config.scale_width, data->config.scale_height,
  146. context->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);
  147. if (!data->swscale) {
  148. ffmpeg_log_error(LOG_WARNING, data,
  149. "Could not initialize swscale");
  150. return false;
  151. }
  152. return true;
  153. }
  154. static bool create_video_stream(struct ffmpeg_data *data)
  155. {
  156. enum AVPixelFormat closest_format;
  157. AVCodecContext *context;
  158. struct obs_video_info ovi;
  159. if (!obs_get_video_info(&ovi)) {
  160. ffmpeg_log_error(LOG_WARNING, data, "No active video");
  161. return false;
  162. }
  163. if (!new_stream(data, &data->video, &data->vcodec,
  164. data->output->oformat->video_codec,
  165. data->config.video_encoder))
  166. return false;
  167. const enum AVColorTransferCharacteristic trc = data->config.color_trc;
  168. const bool pq = trc == AVCOL_TRC_SMPTE2084;
  169. const bool hlg = trc == AVCOL_TRC_ARIB_STD_B67;
  170. if (pq || hlg) {
  171. const int hdr_nominal_peak_level =
  172. pq ? (int)obs_get_video_hdr_nominal_peak_level()
  173. : (hlg ? 1000 : 0);
  174. size_t content_size;
  175. AVContentLightMetadata *const content =
  176. av_content_light_metadata_alloc(&content_size);
  177. content->MaxCLL = hdr_nominal_peak_level;
  178. content->MaxFALL = hdr_nominal_peak_level;
  179. av_stream_add_side_data(data->video,
  180. AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
  181. (uint8_t *)content, content_size);
  182. AVMasteringDisplayMetadata *const mastering =
  183. av_mastering_display_metadata_alloc();
  184. mastering->display_primaries[0][0] = av_make_q(17, 25);
  185. mastering->display_primaries[0][1] = av_make_q(8, 25);
  186. mastering->display_primaries[1][0] = av_make_q(53, 200);
  187. mastering->display_primaries[1][1] = av_make_q(69, 100);
  188. mastering->display_primaries[2][0] = av_make_q(3, 20);
  189. mastering->display_primaries[2][1] = av_make_q(3, 50);
  190. mastering->white_point[0] = av_make_q(3127, 10000);
  191. mastering->white_point[1] = av_make_q(329, 1000);
  192. mastering->min_luminance = av_make_q(0, 1);
  193. mastering->max_luminance = av_make_q(hdr_nominal_peak_level, 1);
  194. mastering->has_primaries = 1;
  195. mastering->has_luminance = 1;
  196. av_stream_add_side_data(data->video,
  197. AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
  198. (uint8_t *)mastering,
  199. sizeof(*mastering));
  200. }
  201. closest_format = data->config.format;
  202. if (data->vcodec->pix_fmts) {
  203. closest_format = avcodec_find_best_pix_fmt_of_list(
  204. data->vcodec->pix_fmts, data->config.format, 0, NULL);
  205. }
  206. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
  207. context = avcodec_alloc_context3(data->vcodec);
  208. #else
  209. context = data->video->codec;
  210. #endif
  211. context->bit_rate = (int64_t)data->config.video_bitrate * 1000;
  212. context->width = data->config.scale_width;
  213. context->height = data->config.scale_height;
  214. context->time_base = (AVRational){ovi.fps_den, ovi.fps_num};
  215. context->gop_size = data->config.gop_size;
  216. context->pix_fmt = closest_format;
  217. context->color_range = data->config.color_range;
  218. context->color_primaries = data->config.color_primaries;
  219. context->color_trc = data->config.color_trc;
  220. context->colorspace = data->config.colorspace;
  221. context->chroma_sample_location =
  222. (data->config.colorspace == AVCOL_SPC_BT2020_NCL)
  223. ? AVCHROMA_LOC_TOPLEFT
  224. : AVCHROMA_LOC_LEFT;
  225. context->thread_count = 0;
  226. data->video->time_base = context->time_base;
  227. if (data->output->oformat->flags & AVFMT_GLOBALHEADER)
  228. context->flags |= CODEC_FLAG_GLOBAL_H;
  229. data->video_ctx = context;
  230. if (!open_video_codec(data))
  231. return false;
  232. if (context->pix_fmt != data->config.format ||
  233. data->config.width != data->config.scale_width ||
  234. data->config.height != data->config.scale_height) {
  235. if (!init_swscale(data, context))
  236. return false;
  237. }
  238. return true;
  239. }
  240. static bool open_audio_codec(struct ffmpeg_data *data, int idx)
  241. {
  242. AVCodecContext *const context = data->audio_infos[idx].ctx;
  243. char **opts = strlist_split(data->config.audio_settings, ' ', false);
  244. int ret;
  245. if (opts) {
  246. parse_params(context, opts);
  247. strlist_free(opts);
  248. }
  249. data->aframe[idx] = av_frame_alloc();
  250. if (!data->aframe[idx]) {
  251. ffmpeg_log_error(LOG_WARNING, data,
  252. "Failed to allocate audio frame");
  253. return false;
  254. }
  255. data->aframe[idx]->format = context->sample_fmt;
  256. data->aframe[idx]->channels = context->channels;
  257. #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 24, 100)
  258. data->aframe[idx]->channel_layout = context->channel_layout;
  259. #else
  260. data->aframe[idx]->ch_layout = context->ch_layout;
  261. #endif
  262. data->aframe[idx]->sample_rate = context->sample_rate;
  263. context->strict_std_compliance = -2;
  264. ret = avcodec_open2(context, data->acodec, NULL);
  265. if (ret < 0) {
  266. ffmpeg_log_error(LOG_WARNING, data,
  267. "Failed to open audio codec: %s",
  268. av_err2str(ret));
  269. return false;
  270. }
  271. data->frame_size = context->frame_size ? context->frame_size : 1024;
  272. ret = av_samples_alloc(data->samples[idx], NULL, context->channels,
  273. data->frame_size, context->sample_fmt, 0);
  274. if (ret < 0) {
  275. ffmpeg_log_error(LOG_WARNING, data,
  276. "Failed to create audio buffer: %s",
  277. av_err2str(ret));
  278. return false;
  279. }
  280. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
  281. avcodec_parameters_from_context(data->audio_infos[idx].stream->codecpar,
  282. context);
  283. #endif
  284. return true;
  285. }
  286. static bool create_audio_stream(struct ffmpeg_data *data, int idx)
  287. {
  288. AVCodecContext *context;
  289. AVStream *stream;
  290. struct obs_audio_info aoi;
  291. if (!obs_get_audio_info(&aoi)) {
  292. ffmpeg_log_error(LOG_WARNING, data, "No active audio");
  293. return false;
  294. }
  295. if (!new_stream(data, &stream, &data->acodec,
  296. data->output->oformat->audio_codec,
  297. data->config.audio_encoder))
  298. return false;
  299. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
  300. context = avcodec_alloc_context3(data->acodec);
  301. #else
  302. context = stream->codec;
  303. #endif
  304. context->bit_rate = (int64_t)data->config.audio_bitrate * 1000;
  305. context->time_base = (AVRational){1, aoi.samples_per_sec};
  306. context->channels = get_audio_channels(aoi.speakers);
  307. context->sample_rate = aoi.samples_per_sec;
  308. #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
  309. context->channel_layout =
  310. av_get_default_channel_layout(context->channels);
  311. //avutil default channel layout for 5 channels is 5.0 ; fix for 4.1
  312. if (aoi.speakers == SPEAKERS_4POINT1)
  313. context->channel_layout = av_get_channel_layout("4.1");
  314. #else
  315. av_channel_layout_default(&context->ch_layout, context->channels);
  316. if (aoi.speakers == SPEAKERS_4POINT1)
  317. context->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT1;
  318. #endif
  319. context->sample_fmt = data->acodec->sample_fmts
  320. ? data->acodec->sample_fmts[0]
  321. : AV_SAMPLE_FMT_FLTP;
  322. stream->time_base = context->time_base;
  323. data->audio_samplerate = aoi.samples_per_sec;
  324. data->audio_format = convert_ffmpeg_sample_format(context->sample_fmt);
  325. data->audio_planes = get_audio_planes(data->audio_format, aoi.speakers);
  326. data->audio_size = get_audio_size(data->audio_format, aoi.speakers, 1);
  327. if (data->output->oformat->flags & AVFMT_GLOBALHEADER)
  328. context->flags |= CODEC_FLAG_GLOBAL_H;
  329. data->audio_infos[idx].stream = stream;
  330. data->audio_infos[idx].ctx = context;
  331. return open_audio_codec(data, idx);
  332. }
  333. static inline bool init_streams(struct ffmpeg_data *data)
  334. {
  335. const AVOutputFormat *format = data->output->oformat;
  336. if (format->video_codec != AV_CODEC_ID_NONE)
  337. if (!create_video_stream(data))
  338. return false;
  339. if (format->audio_codec != AV_CODEC_ID_NONE &&
  340. data->num_audio_streams) {
  341. data->audio_infos = calloc(data->num_audio_streams,
  342. sizeof(*data->audio_infos));
  343. for (int i = 0; i < data->num_audio_streams; i++) {
  344. if (!create_audio_stream(data, i))
  345. return false;
  346. }
  347. }
  348. return true;
  349. }
  350. static inline bool open_output_file(struct ffmpeg_data *data)
  351. {
  352. const AVOutputFormat *format = data->output->oformat;
  353. int ret;
  354. AVDictionary *dict = NULL;
  355. if ((ret = av_dict_parse_string(&dict, data->config.muxer_settings, "=",
  356. " ", 0))) {
  357. ffmpeg_log_error(LOG_WARNING, data,
  358. "Failed to parse muxer settings: %s\n%s",
  359. av_err2str(ret), data->config.muxer_settings);
  360. av_dict_free(&dict);
  361. return false;
  362. }
  363. if (av_dict_count(dict) > 0) {
  364. struct dstr str = {0};
  365. AVDictionaryEntry *entry = NULL;
  366. while ((entry = av_dict_get(dict, "", entry,
  367. AV_DICT_IGNORE_SUFFIX)))
  368. dstr_catf(&str, "\n\t%s=%s", entry->key, entry->value);
  369. blog(LOG_INFO, "Using muxer settings: %s", str.array);
  370. dstr_free(&str);
  371. }
  372. if ((format->flags & AVFMT_NOFILE) == 0) {
  373. ret = avio_open2(&data->output->pb, data->config.url,
  374. AVIO_FLAG_WRITE, NULL, &dict);
  375. if (ret < 0) {
  376. ffmpeg_log_error(LOG_WARNING, data,
  377. "Couldn't open '%s', %s",
  378. data->config.url, av_err2str(ret));
  379. av_dict_free(&dict);
  380. return false;
  381. }
  382. }
  383. ret = avformat_write_header(data->output, &dict);
  384. if (ret < 0) {
  385. ffmpeg_log_error(LOG_WARNING, data, "Error opening '%s': %s",
  386. data->config.url, av_err2str(ret));
  387. return false;
  388. }
  389. if (av_dict_count(dict) > 0) {
  390. struct dstr str = {0};
  391. AVDictionaryEntry *entry = NULL;
  392. while ((entry = av_dict_get(dict, "", entry,
  393. AV_DICT_IGNORE_SUFFIX)))
  394. dstr_catf(&str, "\n\t%s=%s", entry->key, entry->value);
  395. blog(LOG_INFO, "Invalid muxer settings: %s", str.array);
  396. dstr_free(&str);
  397. }
  398. av_dict_free(&dict);
  399. return true;
  400. }
  401. static void close_video(struct ffmpeg_data *data)
  402. {
  403. avcodec_free_context(&data->video_ctx);
  404. av_frame_unref(data->vframe);
  405. // This format for some reason derefs video frame
  406. // too many times
  407. if (data->vcodec->id == AV_CODEC_ID_A64_MULTI ||
  408. data->vcodec->id == AV_CODEC_ID_A64_MULTI5)
  409. return;
  410. av_frame_free(&data->vframe);
  411. }
  412. static void close_audio(struct ffmpeg_data *data)
  413. {
  414. for (int idx = 0; idx < data->num_audio_streams; idx++) {
  415. for (size_t i = 0; i < MAX_AV_PLANES; i++)
  416. circlebuf_free(&data->excess_frames[idx][i]);
  417. if (data->samples[idx][0])
  418. av_freep(&data->samples[idx][0]);
  419. if (data->audio_infos[idx].ctx)
  420. avcodec_free_context(&data->audio_infos[idx].ctx);
  421. if (data->aframe[idx])
  422. av_frame_free(&data->aframe[idx]);
  423. }
  424. }
  425. void ffmpeg_data_free(struct ffmpeg_data *data)
  426. {
  427. if (data->initialized)
  428. av_write_trailer(data->output);
  429. if (data->video)
  430. close_video(data);
  431. if (data->audio_infos) {
  432. close_audio(data);
  433. free(data->audio_infos);
  434. data->audio_infos = NULL;
  435. }
  436. if (data->output) {
  437. if ((data->output->oformat->flags & AVFMT_NOFILE) == 0)
  438. avio_close(data->output->pb);
  439. avformat_free_context(data->output);
  440. }
  441. if (data->last_error)
  442. bfree(data->last_error);
  443. memset(data, 0, sizeof(struct ffmpeg_data));
  444. }
  445. static inline const char *safe_str(const char *s)
  446. {
  447. if (s == NULL)
  448. return "(NULL)";
  449. else
  450. return s;
  451. }
  452. static enum AVCodecID get_codec_id(const char *name, int id)
  453. {
  454. const AVCodec *codec;
  455. if (id != 0)
  456. return (enum AVCodecID)id;
  457. if (!name || !*name)
  458. return AV_CODEC_ID_NONE;
  459. codec = avcodec_find_encoder_by_name(name);
  460. if (!codec)
  461. return AV_CODEC_ID_NONE;
  462. return codec->id;
  463. }
  464. #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
  465. static void set_encoder_ids(struct ffmpeg_data *data)
  466. {
  467. data->output->oformat->video_codec = get_codec_id(
  468. data->config.video_encoder, data->config.video_encoder_id);
  469. data->output->oformat->audio_codec = get_codec_id(
  470. data->config.audio_encoder, data->config.audio_encoder_id);
  471. }
  472. #endif
  473. bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config)
  474. {
  475. bool is_rtmp = false;
  476. memset(data, 0, sizeof(struct ffmpeg_data));
  477. data->config = *config;
  478. data->num_audio_streams = config->audio_mix_count;
  479. data->audio_tracks = config->audio_tracks;
  480. if (!config->url || !*config->url)
  481. return false;
  482. #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
  483. av_register_all();
  484. #endif
  485. avformat_network_init();
  486. is_rtmp = (astrcmpi_n(config->url, "rtmp://", 7) == 0);
  487. #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
  488. AVOutputFormat *output_format;
  489. #else
  490. const AVOutputFormat *output_format;
  491. #endif
  492. output_format = av_guess_format(
  493. is_rtmp ? "flv" : data->config.format_name, data->config.url,
  494. is_rtmp ? NULL : data->config.format_mime_type);
  495. if (output_format == NULL) {
  496. ffmpeg_log_error(
  497. LOG_WARNING, data,
  498. "Couldn't find matching output format with "
  499. "parameters: name=%s, url=%s, mime=%s",
  500. safe_str(is_rtmp ? "flv" : data->config.format_name),
  501. safe_str(data->config.url),
  502. safe_str(is_rtmp ? NULL
  503. : data->config.format_mime_type));
  504. goto fail;
  505. }
  506. avformat_alloc_output_context2(&data->output, output_format, NULL,
  507. data->config.url);
  508. if (!data->output) {
  509. ffmpeg_log_error(LOG_WARNING, data,
  510. "Couldn't create avformat context");
  511. goto fail;
  512. }
  513. #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59, 0, 100)
  514. if (is_rtmp) {
  515. data->output->oformat->video_codec = AV_CODEC_ID_H264;
  516. data->output->oformat->audio_codec = AV_CODEC_ID_AAC;
  517. } else {
  518. if (data->config.format_name)
  519. set_encoder_ids(data);
  520. }
  521. #else
  522. if (is_rtmp) {
  523. data->config.audio_encoder = "aac";
  524. data->config.audio_encoder_id = AV_CODEC_ID_AAC;
  525. data->config.video_encoder = "libx264";
  526. data->config.video_encoder_id = AV_CODEC_ID_H264;
  527. }
  528. #endif
  529. if (!init_streams(data))
  530. goto fail;
  531. if (!open_output_file(data))
  532. goto fail;
  533. av_dump_format(data->output, 0, NULL, 1);
  534. data->initialized = true;
  535. return true;
  536. fail:
  537. blog(LOG_WARNING, "ffmpeg_data_init failed");
  538. return false;
  539. }
  540. /* ------------------------------------------------------------------------- */
  541. static inline bool stopping(struct ffmpeg_output *output)
  542. {
  543. return os_atomic_load_bool(&output->stopping);
  544. }
  545. static const char *ffmpeg_output_getname(void *unused)
  546. {
  547. UNUSED_PARAMETER(unused);
  548. return obs_module_text("FFmpegOutput");
  549. }
  550. static void ffmpeg_log_callback(void *param, int level, const char *format,
  551. va_list args)
  552. {
  553. if (level <= AV_LOG_INFO)
  554. blogva(LOG_DEBUG, format, args);
  555. UNUSED_PARAMETER(param);
  556. }
  557. static void *ffmpeg_output_create(obs_data_t *settings, obs_output_t *output)
  558. {
  559. struct ffmpeg_output *data = bzalloc(sizeof(struct ffmpeg_output));
  560. pthread_mutex_init_value(&data->write_mutex);
  561. data->output = output;
  562. if (pthread_mutex_init(&data->write_mutex, NULL) != 0)
  563. goto fail;
  564. if (os_event_init(&data->stop_event, OS_EVENT_TYPE_AUTO) != 0)
  565. goto fail;
  566. if (os_sem_init(&data->write_sem, 0) != 0)
  567. goto fail;
  568. av_log_set_callback(ffmpeg_log_callback);
  569. UNUSED_PARAMETER(settings);
  570. return data;
  571. fail:
  572. pthread_mutex_destroy(&data->write_mutex);
  573. os_event_destroy(data->stop_event);
  574. bfree(data);
  575. return NULL;
  576. }
  577. static void ffmpeg_output_full_stop(void *data);
  578. static void ffmpeg_deactivate(struct ffmpeg_output *output);
  579. static void ffmpeg_output_destroy(void *data)
  580. {
  581. struct ffmpeg_output *output = data;
  582. if (output) {
  583. if (output->connecting)
  584. pthread_join(output->start_thread, NULL);
  585. ffmpeg_output_full_stop(output);
  586. pthread_mutex_destroy(&output->write_mutex);
  587. os_sem_destroy(output->write_sem);
  588. os_event_destroy(output->stop_event);
  589. bfree(data);
  590. }
  591. }
  592. static inline void copy_data(AVFrame *pic, const struct video_data *frame,
  593. int height, enum AVPixelFormat format)
  594. {
  595. int h_chroma_shift, v_chroma_shift;
  596. av_pix_fmt_get_chroma_sub_sample(format, &h_chroma_shift,
  597. &v_chroma_shift);
  598. for (int plane = 0; plane < MAX_AV_PLANES; plane++) {
  599. if (!frame->data[plane])
  600. continue;
  601. int frame_rowsize = (int)frame->linesize[plane];
  602. int pic_rowsize = pic->linesize[plane];
  603. int bytes = frame_rowsize < pic_rowsize ? frame_rowsize
  604. : pic_rowsize;
  605. int plane_height = height >> (plane ? v_chroma_shift : 0);
  606. for (int y = 0; y < plane_height; y++) {
  607. int pos_frame = y * frame_rowsize;
  608. int pos_pic = y * pic_rowsize;
  609. memcpy(pic->data[plane] + pos_pic,
  610. frame->data[plane] + pos_frame, bytes);
  611. }
  612. }
  613. }
  614. static void receive_video(void *param, struct video_data *frame)
  615. {
  616. struct ffmpeg_output *output = param;
  617. struct ffmpeg_data *data = &output->ff_data;
  618. // codec doesn't support video or none configured
  619. if (!data->video)
  620. return;
  621. AVCodecContext *context = data->video_ctx;
  622. AVPacket *packet = NULL;
  623. int ret = 0, got_packet;
  624. if (!output->video_start_ts)
  625. output->video_start_ts = frame->timestamp;
  626. if (!data->start_timestamp)
  627. data->start_timestamp = frame->timestamp;
  628. ret = av_frame_make_writable(data->vframe);
  629. if (ret < 0) {
  630. blog(LOG_WARNING,
  631. "receive_video: Error obtaining writable "
  632. "AVFrame: %s",
  633. av_err2str(ret));
  634. //FIXME: stop the encode with an error
  635. return;
  636. }
  637. if (!!data->swscale)
  638. sws_scale(data->swscale, (const uint8_t *const *)frame->data,
  639. (const int *)frame->linesize, 0, data->config.height,
  640. data->vframe->data, data->vframe->linesize);
  641. else
  642. copy_data(data->vframe, frame, context->height,
  643. context->pix_fmt);
  644. packet = av_packet_alloc();
  645. #if LIBAVFORMAT_VERSION_MAJOR < 58
  646. if (data->output->flags & AVFMT_RAWPICTURE) {
  647. packet->flags |= AV_PKT_FLAG_KEY;
  648. packet->stream_index = data->video->index;
  649. packet->data = data->vframe->data[0];
  650. packet->size = sizeof(AVPicture);
  651. pthread_mutex_lock(&output->write_mutex);
  652. da_push_back(output->packets, &packet);
  653. packet = NULL;
  654. pthread_mutex_unlock(&output->write_mutex);
  655. os_sem_post(output->write_sem);
  656. } else {
  657. #endif
  658. data->vframe->pts = data->total_frames;
  659. #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 40, 101)
  660. ret = avcodec_send_frame(context, data->vframe);
  661. if (ret == 0)
  662. ret = avcodec_receive_packet(context, packet);
  663. got_packet = (ret == 0);
  664. if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
  665. ret = 0;
  666. #else
  667. ret = avcodec_encode_video2(context, packet, data->vframe, &got_packet);
  668. #endif
  669. if (ret < 0) {
  670. blog(LOG_WARNING,
  671. "receive_video: Error encoding "
  672. "video: %s",
  673. av_err2str(ret));
  674. //FIXME: stop the encode with an error
  675. goto fail;
  676. }
  677. if (!ret && got_packet && packet->size) {
  678. packet->pts = rescale_ts(packet->pts, context,
  679. data->video->time_base);
  680. packet->dts = rescale_ts(packet->dts, context,
  681. data->video->time_base);
  682. packet->duration = (int)av_rescale_q(
  683. packet->duration, context->time_base,
  684. data->video->time_base);
  685. pthread_mutex_lock(&output->write_mutex);
  686. da_push_back(output->packets, &packet);
  687. packet = NULL;
  688. pthread_mutex_unlock(&output->write_mutex);
  689. os_sem_post(output->write_sem);
  690. } else {
  691. ret = 0;
  692. }
  693. #if LIBAVFORMAT_VERSION_MAJOR < 58
  694. }
  695. #endif
  696. if (ret != 0) {
  697. blog(LOG_WARNING, "receive_video: Error writing video: %s",
  698. av_err2str(ret));
  699. //FIXME: stop the encode with an error
  700. }
  701. data->total_frames++;
  702. fail:
  703. av_packet_free(&packet);
  704. }
  705. static void encode_audio(struct ffmpeg_output *output, int idx,
  706. struct AVCodecContext *context, size_t block_size)
  707. {
  708. struct ffmpeg_data *data = &output->ff_data;
  709. AVPacket *packet = NULL;
  710. int ret, got_packet;
  711. size_t total_size = data->frame_size * block_size * context->channels;
  712. data->aframe[idx]->nb_samples = data->frame_size;
  713. data->aframe[idx]->pts = av_rescale_q(
  714. data->total_samples[idx], (AVRational){1, context->sample_rate},
  715. context->time_base);
  716. ret = avcodec_fill_audio_frame(data->aframe[idx], context->channels,
  717. context->sample_fmt,
  718. data->samples[idx][0], (int)total_size,
  719. 1);
  720. if (ret < 0) {
  721. blog(LOG_WARNING,
  722. "encode_audio: avcodec_fill_audio_frame "
  723. "failed: %s",
  724. av_err2str(ret));
  725. //FIXME: stop the encode with an error
  726. return;
  727. }
  728. data->total_samples[idx] += data->frame_size;
  729. packet = av_packet_alloc();
  730. #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 40, 101)
  731. ret = avcodec_send_frame(context, data->aframe[idx]);
  732. if (ret == 0)
  733. ret = avcodec_receive_packet(context, packet);
  734. got_packet = (ret == 0);
  735. if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
  736. ret = 0;
  737. #else
  738. ret = avcodec_encode_audio2(context, packet, data->aframe[idx],
  739. &got_packet);
  740. #endif
  741. if (ret < 0) {
  742. blog(LOG_WARNING, "encode_audio: Error encoding audio: %s",
  743. av_err2str(ret));
  744. //FIXME: stop the encode with an error
  745. goto fail;
  746. }
  747. if (!got_packet)
  748. goto fail;
  749. packet->pts = rescale_ts(packet->pts, context,
  750. data->audio_infos[idx].stream->time_base);
  751. packet->dts = rescale_ts(packet->dts, context,
  752. data->audio_infos[idx].stream->time_base);
  753. packet->duration =
  754. (int)av_rescale_q(packet->duration, context->time_base,
  755. data->audio_infos[idx].stream->time_base);
  756. packet->stream_index = data->audio_infos[idx].stream->index;
  757. pthread_mutex_lock(&output->write_mutex);
  758. da_push_back(output->packets, &packet);
  759. pthread_mutex_unlock(&output->write_mutex);
  760. os_sem_post(output->write_sem);
  761. return;
  762. fail:
  763. av_packet_free(&packet);
  764. }
  765. /* Given a bitmask for the selected tracks and the mix index,
  766. * this returns the stream index which will be passed to the muxer. */
  767. static int get_track_order(int track_config, size_t mix_index)
  768. {
  769. int position = 0;
  770. for (size_t i = 0; i < mix_index; i++) {
  771. if (track_config & 1 << i)
  772. position++;
  773. }
  774. return position;
  775. }
  776. static void receive_audio(void *param, size_t mix_idx, struct audio_data *frame)
  777. {
  778. struct ffmpeg_output *output = param;
  779. struct ffmpeg_data *data = &output->ff_data;
  780. size_t frame_size_bytes;
  781. struct audio_data in = *frame;
  782. int track_order;
  783. // codec doesn't support audio or none configured
  784. if (!data->audio_infos)
  785. return;
  786. /* check that the track was selected */
  787. if ((data->audio_tracks & (1 << mix_idx)) == 0)
  788. return;
  789. /* get track order (first selected, etc ...) */
  790. track_order = get_track_order(data->audio_tracks, mix_idx);
  791. AVCodecContext *context = data->audio_infos[track_order].ctx;
  792. if (!data->start_timestamp && data->video)
  793. return;
  794. if (!output->audio_start_ts)
  795. output->audio_start_ts = in.timestamp;
  796. frame_size_bytes = (size_t)data->frame_size * data->audio_size;
  797. for (size_t i = 0; i < data->audio_planes; i++)
  798. circlebuf_push_back(&data->excess_frames[track_order][i],
  799. in.data[i], in.frames * data->audio_size);
  800. while (data->excess_frames[track_order][0].size >= frame_size_bytes) {
  801. for (size_t i = 0; i < data->audio_planes; i++)
  802. circlebuf_pop_front(
  803. &data->excess_frames[track_order][i],
  804. data->samples[track_order][i],
  805. frame_size_bytes);
  806. encode_audio(output, track_order, context, data->audio_size);
  807. }
  808. }
  809. static uint64_t get_packet_sys_dts(struct ffmpeg_output *output,
  810. AVPacket *packet)
  811. {
  812. struct ffmpeg_data *data = &output->ff_data;
  813. uint64_t pause_offset = obs_output_get_pause_offset(output->output);
  814. uint64_t start_ts;
  815. AVRational time_base;
  816. if (data->video && data->video->index == packet->stream_index) {
  817. time_base = data->video->time_base;
  818. start_ts = output->video_start_ts;
  819. } else {
  820. time_base = data->audio_infos[0].stream->time_base;
  821. start_ts = output->audio_start_ts;
  822. }
  823. return start_ts + pause_offset +
  824. (uint64_t)av_rescale_q(packet->dts, time_base,
  825. (AVRational){1, 1000000000});
  826. }
  827. static int process_packet(struct ffmpeg_output *output)
  828. {
  829. AVPacket *packet;
  830. bool new_packet = false;
  831. int ret;
  832. pthread_mutex_lock(&output->write_mutex);
  833. if (output->packets.num) {
  834. packet = output->packets.array[0];
  835. da_erase(output->packets, 0);
  836. new_packet = true;
  837. }
  838. pthread_mutex_unlock(&output->write_mutex);
  839. if (!new_packet)
  840. return 0;
  841. /*blog(LOG_DEBUG, "size = %d, flags = %lX, stream = %d, "
  842. "packets queued: %lu",
  843. packet.size, packet.flags,
  844. packet.stream_index, output->packets.num);*/
  845. if (stopping(output)) {
  846. uint64_t sys_ts = get_packet_sys_dts(output, packet);
  847. if (sys_ts >= output->stop_ts)
  848. return 0;
  849. }
  850. output->total_bytes += packet->size;
  851. ret = av_interleaved_write_frame(output->ff_data.output, packet);
  852. if (ret < 0) {
  853. av_packet_free(&packet);
  854. ffmpeg_log_error(LOG_WARNING, &output->ff_data,
  855. "process_packet: Error writing packet: %s",
  856. av_err2str(ret));
  857. return ret;
  858. }
  859. return 0;
  860. }
  861. static void *write_thread(void *data)
  862. {
  863. struct ffmpeg_output *output = data;
  864. while (os_sem_wait(output->write_sem) == 0) {
  865. /* check to see if shutting down */
  866. if (os_event_try(output->stop_event) == 0)
  867. break;
  868. int ret = process_packet(output);
  869. if (ret != 0) {
  870. int code = OBS_OUTPUT_ERROR;
  871. pthread_detach(output->write_thread);
  872. output->write_thread_active = false;
  873. if (ret == -ENOSPC)
  874. code = OBS_OUTPUT_NO_SPACE;
  875. obs_output_signal_stop(output->output, code);
  876. ffmpeg_deactivate(output);
  877. break;
  878. }
  879. }
  880. output->active = false;
  881. return NULL;
  882. }
  883. static inline const char *get_string_or_null(obs_data_t *settings,
  884. const char *name)
  885. {
  886. const char *value = obs_data_get_string(settings, name);
  887. if (!value || !strlen(value))
  888. return NULL;
  889. return value;
  890. }
  891. static int get_audio_mix_count(int audio_mix_mask)
  892. {
  893. int mix_count = 0;
  894. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  895. if ((audio_mix_mask & (1 << i)) != 0) {
  896. mix_count++;
  897. }
  898. }
  899. return mix_count;
  900. }
  901. static bool try_connect(struct ffmpeg_output *output)
  902. {
  903. video_t *video = obs_output_video(output->output);
  904. const struct video_output_info *voi = video_output_get_info(video);
  905. struct ffmpeg_cfg config;
  906. obs_data_t *settings;
  907. bool success;
  908. int ret;
  909. settings = obs_output_get_settings(output->output);
  910. obs_data_set_default_int(settings, "gop_size", 120);
  911. config.url = obs_data_get_string(settings, "url");
  912. config.format_name = get_string_or_null(settings, "format_name");
  913. config.format_mime_type =
  914. get_string_or_null(settings, "format_mime_type");
  915. config.muxer_settings = obs_data_get_string(settings, "muxer_settings");
  916. config.video_bitrate = (int)obs_data_get_int(settings, "video_bitrate");
  917. config.audio_bitrate = (int)obs_data_get_int(settings, "audio_bitrate");
  918. config.gop_size = (int)obs_data_get_int(settings, "gop_size");
  919. config.video_encoder = get_string_or_null(settings, "video_encoder");
  920. config.video_encoder_id =
  921. (int)obs_data_get_int(settings, "video_encoder_id");
  922. config.audio_encoder = get_string_or_null(settings, "audio_encoder");
  923. config.audio_encoder_id =
  924. (int)obs_data_get_int(settings, "audio_encoder_id");
  925. config.video_settings = obs_data_get_string(settings, "video_settings");
  926. config.audio_settings = obs_data_get_string(settings, "audio_settings");
  927. config.scale_width = (int)obs_data_get_int(settings, "scale_width");
  928. config.scale_height = (int)obs_data_get_int(settings, "scale_height");
  929. config.width = (int)obs_output_get_width(output->output);
  930. config.height = (int)obs_output_get_height(output->output);
  931. config.format =
  932. obs_to_ffmpeg_video_format(video_output_get_format(video));
  933. config.audio_tracks = (int)obs_output_get_mixers(output->output);
  934. config.audio_mix_count = get_audio_mix_count(config.audio_tracks);
  935. config.color_range = voi->range == VIDEO_RANGE_FULL ? AVCOL_RANGE_JPEG
  936. : AVCOL_RANGE_MPEG;
  937. config.colorspace = format_is_yuv(voi->format) ? AVCOL_SPC_BT709
  938. : AVCOL_SPC_RGB;
  939. switch (voi->colorspace) {
  940. case VIDEO_CS_601:
  941. config.color_primaries = AVCOL_PRI_SMPTE170M;
  942. config.color_trc = AVCOL_TRC_SMPTE170M;
  943. config.colorspace = AVCOL_SPC_SMPTE170M;
  944. break;
  945. case VIDEO_CS_DEFAULT:
  946. case VIDEO_CS_709:
  947. config.color_primaries = AVCOL_PRI_BT709;
  948. config.color_trc = AVCOL_TRC_BT709;
  949. config.colorspace = AVCOL_SPC_BT709;
  950. break;
  951. case VIDEO_CS_SRGB:
  952. config.color_primaries = AVCOL_PRI_BT709;
  953. config.color_trc = AVCOL_TRC_IEC61966_2_1;
  954. config.colorspace = AVCOL_SPC_BT709;
  955. break;
  956. case VIDEO_CS_2100_PQ:
  957. config.color_primaries = AVCOL_PRI_BT2020;
  958. config.color_trc = AVCOL_TRC_SMPTE2084;
  959. config.colorspace = AVCOL_SPC_BT2020_NCL;
  960. break;
  961. case VIDEO_CS_2100_HLG:
  962. config.color_primaries = AVCOL_PRI_BT2020;
  963. config.color_trc = AVCOL_TRC_ARIB_STD_B67;
  964. config.colorspace = AVCOL_SPC_BT2020_NCL;
  965. break;
  966. }
  967. if (config.format == AV_PIX_FMT_NONE) {
  968. blog(LOG_DEBUG, "invalid pixel format used for FFmpeg output");
  969. return false;
  970. }
  971. if (!config.scale_width)
  972. config.scale_width = config.width;
  973. if (!config.scale_height)
  974. config.scale_height = config.height;
  975. success = ffmpeg_data_init(&output->ff_data, &config);
  976. obs_data_release(settings);
  977. if (!success) {
  978. if (output->ff_data.last_error) {
  979. obs_output_set_last_error(output->output,
  980. output->ff_data.last_error);
  981. }
  982. ffmpeg_data_free(&output->ff_data);
  983. return false;
  984. }
  985. struct audio_convert_info aci = {.format =
  986. output->ff_data.audio_format};
  987. output->active = true;
  988. if (!obs_output_can_begin_data_capture(output->output, 0))
  989. return false;
  990. ret = pthread_create(&output->write_thread, NULL, write_thread, output);
  991. if (ret != 0) {
  992. ffmpeg_log_error(LOG_WARNING, &output->ff_data,
  993. "ffmpeg_output_start: failed to create write "
  994. "thread.");
  995. ffmpeg_output_full_stop(output);
  996. return false;
  997. }
  998. obs_output_set_video_conversion(output->output, NULL);
  999. obs_output_set_audio_conversion(output->output, &aci);
  1000. obs_output_begin_data_capture(output->output, 0);
  1001. output->write_thread_active = true;
  1002. return true;
  1003. }
  1004. static void *start_thread(void *data)
  1005. {
  1006. struct ffmpeg_output *output = data;
  1007. if (!try_connect(output))
  1008. obs_output_signal_stop(output->output,
  1009. OBS_OUTPUT_CONNECT_FAILED);
  1010. output->connecting = false;
  1011. return NULL;
  1012. }
  1013. static bool ffmpeg_output_start(void *data)
  1014. {
  1015. struct ffmpeg_output *output = data;
  1016. int ret;
  1017. if (output->connecting)
  1018. return false;
  1019. os_atomic_set_bool(&output->stopping, false);
  1020. output->audio_start_ts = 0;
  1021. output->video_start_ts = 0;
  1022. output->total_bytes = 0;
  1023. ret = pthread_create(&output->start_thread, NULL, start_thread, output);
  1024. return (output->connecting = (ret == 0));
  1025. }
  1026. static void ffmpeg_output_full_stop(void *data)
  1027. {
  1028. struct ffmpeg_output *output = data;
  1029. if (output->active) {
  1030. obs_output_end_data_capture(output->output);
  1031. ffmpeg_deactivate(output);
  1032. }
  1033. }
  1034. static void ffmpeg_output_stop(void *data, uint64_t ts)
  1035. {
  1036. struct ffmpeg_output *output = data;
  1037. if (output->active) {
  1038. if (ts > 0) {
  1039. output->stop_ts = ts;
  1040. os_atomic_set_bool(&output->stopping, true);
  1041. }
  1042. ffmpeg_output_full_stop(output);
  1043. }
  1044. }
  1045. static void ffmpeg_deactivate(struct ffmpeg_output *output)
  1046. {
  1047. if (output->write_thread_active) {
  1048. os_event_signal(output->stop_event);
  1049. os_sem_post(output->write_sem);
  1050. pthread_join(output->write_thread, NULL);
  1051. output->write_thread_active = false;
  1052. }
  1053. pthread_mutex_lock(&output->write_mutex);
  1054. for (size_t i = 0; i < output->packets.num; i++)
  1055. av_packet_free(output->packets.array + i);
  1056. da_free(output->packets);
  1057. pthread_mutex_unlock(&output->write_mutex);
  1058. ffmpeg_data_free(&output->ff_data);
  1059. }
  1060. static uint64_t ffmpeg_output_total_bytes(void *data)
  1061. {
  1062. struct ffmpeg_output *output = data;
  1063. return output->total_bytes;
  1064. }
  1065. struct obs_output_info ffmpeg_output = {
  1066. .id = "ffmpeg_output",
  1067. .flags = OBS_OUTPUT_AUDIO | OBS_OUTPUT_VIDEO | OBS_OUTPUT_MULTI_TRACK |
  1068. OBS_OUTPUT_CAN_PAUSE,
  1069. .get_name = ffmpeg_output_getname,
  1070. .create = ffmpeg_output_create,
  1071. .destroy = ffmpeg_output_destroy,
  1072. .start = ffmpeg_output_start,
  1073. .stop = ffmpeg_output_stop,
  1074. .raw_video = receive_video,
  1075. .raw_audio2 = receive_audio,
  1076. .get_total_bytes = ffmpeg_output_total_bytes,
  1077. };