obs-ffmpeg-output.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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.h>
  15. #include <util/circlebuf.h>
  16. #include <util/threading.h>
  17. #include <libavutil/opt.h>
  18. #include <libavformat/avformat.h>
  19. #include <libswscale/swscale.h>
  20. /* NOTE: much of this stuff is test stuff that was more or less copied from
  21. * the muxing.c ffmpeg example */
  22. struct ffmpeg_data {
  23. AVStream *video;
  24. AVStream *audio;
  25. AVCodec *acodec;
  26. AVCodec *vcodec;
  27. AVFormatContext *output;
  28. struct SwsContext *swscale;
  29. AVPicture dst_picture;
  30. AVFrame *vframe;
  31. int frame_size;
  32. int total_frames;
  33. uint64_t start_timestamp;
  34. uint32_t audio_samplerate;
  35. enum audio_format audio_format;
  36. size_t audio_planes;
  37. size_t audio_size;
  38. struct circlebuf excess_frames[MAX_AV_PLANES];
  39. uint8_t *samples[MAX_AV_PLANES];
  40. AVFrame *aframe;
  41. int total_samples;
  42. pthread_mutex_t write_mutex;
  43. const char *filename_test;
  44. bool initialized;
  45. };
  46. struct ffmpeg_output {
  47. obs_output_t output;
  48. volatile bool active;
  49. struct ffmpeg_data ff_data;
  50. };
  51. /* ------------------------------------------------------------------------- */
  52. static inline enum AVPixelFormat obs_to_ffmpeg_video_format(
  53. enum video_format format)
  54. {
  55. switch (format) {
  56. case VIDEO_FORMAT_NONE: return AV_PIX_FMT_NONE;
  57. case VIDEO_FORMAT_I420: return AV_PIX_FMT_YUV420P;
  58. case VIDEO_FORMAT_NV12: return AV_PIX_FMT_NV12;
  59. case VIDEO_FORMAT_YVYU: return AV_PIX_FMT_NONE;
  60. case VIDEO_FORMAT_YUY2: return AV_PIX_FMT_YUYV422;
  61. case VIDEO_FORMAT_UYVY: return AV_PIX_FMT_UYVY422;
  62. case VIDEO_FORMAT_RGBA: return AV_PIX_FMT_RGBA;
  63. case VIDEO_FORMAT_BGRA: return AV_PIX_FMT_BGRA;
  64. case VIDEO_FORMAT_BGRX: return AV_PIX_FMT_BGRA;
  65. }
  66. return AV_PIX_FMT_NONE;
  67. }
  68. static inline enum audio_format convert_ffmpeg_sample_format(
  69. enum AVSampleFormat format)
  70. {
  71. switch ((uint32_t)format) {
  72. case AV_SAMPLE_FMT_U8: return AUDIO_FORMAT_U8BIT;
  73. case AV_SAMPLE_FMT_S16: return AUDIO_FORMAT_16BIT;
  74. case AV_SAMPLE_FMT_S32: return AUDIO_FORMAT_32BIT;
  75. case AV_SAMPLE_FMT_FLT: return AUDIO_FORMAT_FLOAT;
  76. case AV_SAMPLE_FMT_U8P: return AUDIO_FORMAT_U8BIT_PLANAR;
  77. case AV_SAMPLE_FMT_S16P: return AUDIO_FORMAT_16BIT_PLANAR;
  78. case AV_SAMPLE_FMT_S32P: return AUDIO_FORMAT_32BIT_PLANAR;
  79. case AV_SAMPLE_FMT_FLTP: return AUDIO_FORMAT_FLOAT_PLANAR;
  80. }
  81. /* shouldn't get here */
  82. return AUDIO_FORMAT_16BIT;
  83. }
  84. static bool new_stream(struct ffmpeg_data *data, AVStream **stream,
  85. AVCodec **codec, enum AVCodecID id)
  86. {
  87. *codec = avcodec_find_encoder(id);
  88. if (!*codec) {
  89. blog(LOG_WARNING, "Couldn't find encoder '%s'",
  90. avcodec_get_name(id));
  91. return false;
  92. }
  93. *stream = avformat_new_stream(data->output, *codec);
  94. if (!*stream) {
  95. blog(LOG_WARNING, "Couldn't create stream for encoder '%s'",
  96. avcodec_get_name(id));
  97. return false;
  98. }
  99. (*stream)->id = data->output->nb_streams-1;
  100. return true;
  101. }
  102. static bool open_video_codec(struct ffmpeg_data *data)
  103. {
  104. AVCodecContext *context = data->video->codec;
  105. int ret;
  106. if (data->vcodec->id == AV_CODEC_ID_H264)
  107. av_opt_set(context->priv_data, "preset", "veryfast", 0);
  108. ret = avcodec_open2(context, data->vcodec, NULL);
  109. if (ret < 0) {
  110. blog(LOG_WARNING, "Failed to open video codec: %s",
  111. av_err2str(ret));
  112. return false;
  113. }
  114. data->vframe = av_frame_alloc();
  115. if (!data->vframe) {
  116. blog(LOG_WARNING, "Failed to allocate video frame");
  117. return false;
  118. }
  119. data->vframe->format = context->pix_fmt;
  120. data->vframe->width = context->width;
  121. data->vframe->height = context->height;
  122. ret = avpicture_alloc(&data->dst_picture, context->pix_fmt,
  123. context->width, context->height);
  124. if (ret < 0) {
  125. blog(LOG_WARNING, "Failed to allocate dst_picture: %s",
  126. av_err2str(ret));
  127. return false;
  128. }
  129. *((AVPicture*)data->vframe) = data->dst_picture;
  130. return true;
  131. }
  132. static bool init_swscale(struct ffmpeg_data *data, AVCodecContext *context)
  133. {
  134. data->swscale = sws_getContext(
  135. context->width, context->height, AV_PIX_FMT_YUV420P,
  136. context->width, context->height, context->pix_fmt,
  137. SWS_BICUBIC, NULL, NULL, NULL);
  138. if (!data->swscale) {
  139. blog(LOG_WARNING, "Could not initialize swscale");
  140. return false;
  141. }
  142. return true;
  143. }
  144. static bool create_video_stream(struct ffmpeg_data *data)
  145. {
  146. AVCodecContext *context;
  147. struct obs_video_info ovi;
  148. if (!obs_get_video_info(&ovi)) {
  149. blog(LOG_WARNING, "No active video");
  150. return false;
  151. }
  152. if (!new_stream(data, &data->video, &data->vcodec,
  153. data->output->oformat->video_codec))
  154. return false;
  155. context = data->video->codec;
  156. context->codec_id = data->output->oformat->video_codec;
  157. context->bit_rate = 6000000;
  158. context->width = ovi.output_width;
  159. context->height = ovi.output_height;
  160. context->time_base.num = ovi.fps_den;
  161. context->time_base.den = ovi.fps_num;
  162. context->gop_size = 12;
  163. context->pix_fmt = AV_PIX_FMT_YUV420P;
  164. if (data->output->oformat->flags & AVFMT_GLOBALHEADER)
  165. context->flags |= CODEC_FLAG_GLOBAL_HEADER;
  166. if (!open_video_codec(data))
  167. return false;
  168. if (context->pix_fmt != AV_PIX_FMT_YUV420P)
  169. if (!init_swscale(data, context))
  170. return false;
  171. return true;
  172. }
  173. static bool open_audio_codec(struct ffmpeg_data *data)
  174. {
  175. AVCodecContext *context = data->audio->codec;
  176. int ret;
  177. data->aframe = av_frame_alloc();
  178. if (!data->aframe) {
  179. blog(LOG_WARNING, "Failed to allocate audio frame");
  180. return false;
  181. }
  182. context->strict_std_compliance = -2;
  183. ret = avcodec_open2(context, data->acodec, NULL);
  184. if (ret < 0) {
  185. blog(LOG_WARNING, "Failed to open audio codec: %s",
  186. av_err2str(ret));
  187. return false;
  188. }
  189. data->frame_size = context->frame_size ? context->frame_size : 1024;
  190. ret = av_samples_alloc(data->samples, NULL, context->channels,
  191. data->frame_size, context->sample_fmt, 0);
  192. if (ret < 0) {
  193. blog(LOG_WARNING, "Failed to create audio buffer: %s",
  194. av_err2str(ret));
  195. return false;
  196. }
  197. return true;
  198. }
  199. static bool create_audio_stream(struct ffmpeg_data *data)
  200. {
  201. AVCodecContext *context;
  202. struct audio_output_info aoi;
  203. if (!obs_get_audio_info(&aoi)) {
  204. blog(LOG_WARNING, "No active audio");
  205. return false;
  206. }
  207. if (!new_stream(data, &data->audio, &data->acodec,
  208. data->output->oformat->audio_codec))
  209. return false;
  210. context = data->audio->codec;
  211. context->bit_rate = 128000;
  212. context->channels = get_audio_channels(aoi.speakers);
  213. context->sample_rate = aoi.samples_per_sec;
  214. context->sample_fmt = data->acodec->sample_fmts ?
  215. data->acodec->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
  216. data->audio_samplerate = aoi.samples_per_sec;
  217. data->audio_format = convert_ffmpeg_sample_format(context->sample_fmt);
  218. data->audio_planes = get_audio_planes(data->audio_format, aoi.speakers);
  219. data->audio_size = get_audio_size(data->audio_format, aoi.speakers, 1);
  220. if (data->output->oformat->flags & AVFMT_GLOBALHEADER)
  221. context->flags |= CODEC_FLAG_GLOBAL_HEADER;
  222. return open_audio_codec(data);
  223. }
  224. static inline bool init_streams(struct ffmpeg_data *data)
  225. {
  226. AVOutputFormat *format = data->output->oformat;
  227. if (format->video_codec != AV_CODEC_ID_NONE)
  228. if (!create_video_stream(data))
  229. return false;
  230. if (format->audio_codec != AV_CODEC_ID_NONE)
  231. if (!create_audio_stream(data))
  232. return false;
  233. return true;
  234. }
  235. static inline bool open_output_file(struct ffmpeg_data *data)
  236. {
  237. AVOutputFormat *format = data->output->oformat;
  238. int ret;
  239. if ((format->flags & AVFMT_NOFILE) == 0) {
  240. ret = avio_open(&data->output->pb, data->filename_test,
  241. AVIO_FLAG_WRITE);
  242. if (ret < 0) {
  243. blog(LOG_WARNING, "Couldn't open file '%s', %s",
  244. data->filename_test, av_err2str(ret));
  245. return false;
  246. }
  247. }
  248. ret = avformat_write_header(data->output, NULL);
  249. if (ret < 0) {
  250. blog(LOG_WARNING, "Error opening file '%s': %s",
  251. data->filename_test, av_err2str(ret));
  252. return false;
  253. }
  254. return true;
  255. }
  256. static void close_video(struct ffmpeg_data *data)
  257. {
  258. avcodec_close(data->video->codec);
  259. avpicture_free(&data->dst_picture);
  260. av_frame_free(&data->vframe);
  261. }
  262. static void close_audio(struct ffmpeg_data *data)
  263. {
  264. for (size_t i = 0; i < MAX_AV_PLANES; i++)
  265. circlebuf_free(&data->excess_frames[i]);
  266. av_freep(&data->samples[0]);
  267. avcodec_close(data->audio->codec);
  268. av_frame_free(&data->aframe);
  269. }
  270. static void ffmpeg_data_free(struct ffmpeg_data *data)
  271. {
  272. pthread_mutex_lock(&data->write_mutex);
  273. if (data->initialized)
  274. av_write_trailer(data->output);
  275. if (data->video)
  276. close_video(data);
  277. if (data->audio)
  278. close_audio(data);
  279. if ((data->output->oformat->flags & AVFMT_NOFILE) == 0)
  280. avio_close(data->output->pb);
  281. avformat_free_context(data->output);
  282. pthread_mutex_unlock(&data->write_mutex);
  283. pthread_mutex_destroy(&data->write_mutex);
  284. memset(data, 0, sizeof(struct ffmpeg_data));
  285. }
  286. static bool ffmpeg_data_init(struct ffmpeg_data *data, const char *filename)
  287. {
  288. memset(data, 0, sizeof(struct ffmpeg_data));
  289. pthread_mutex_init_value(&data->write_mutex);
  290. data->filename_test = filename;
  291. if (!filename || !*filename)
  292. return false;
  293. if (pthread_mutex_init(&data->write_mutex, NULL) != 0)
  294. return false;
  295. av_register_all();
  296. /* TODO: settings */
  297. avformat_alloc_output_context2(&data->output, NULL, NULL,
  298. data->filename_test);
  299. if (!data->output) {
  300. blog(LOG_WARNING, "Couldn't create avformat context");
  301. goto fail;
  302. }
  303. if (!init_streams(data))
  304. goto fail;
  305. if (!open_output_file(data))
  306. goto fail;
  307. data->initialized = true;
  308. return true;
  309. fail:
  310. blog(LOG_WARNING, "ffmpeg_data_init failed");
  311. ffmpeg_data_free(data);
  312. return false;
  313. }
  314. /* ------------------------------------------------------------------------- */
  315. static const char *ffmpeg_output_getname(const char *locale)
  316. {
  317. UNUSED_PARAMETER(locale);
  318. return "FFmpeg file output";
  319. }
  320. static void ffmpeg_log_callback(void *param, int level, const char *format,
  321. va_list args)
  322. {
  323. blogva(LOG_DEBUG, format, args);
  324. UNUSED_PARAMETER(param);
  325. }
  326. static void *ffmpeg_output_create(obs_data_t settings, obs_output_t output)
  327. {
  328. struct ffmpeg_output *data = bzalloc(sizeof(struct ffmpeg_output));
  329. data->output = output;
  330. av_log_set_callback(ffmpeg_log_callback);
  331. UNUSED_PARAMETER(settings);
  332. return data;
  333. }
  334. static void ffmpeg_output_destroy(void *data)
  335. {
  336. struct ffmpeg_output *output = data;
  337. if (output) {
  338. if (output->active)
  339. ffmpeg_data_free(&output->ff_data);
  340. bfree(data);
  341. }
  342. }
  343. static inline int64_t rescale_ts(int64_t val, AVCodecContext *context,
  344. AVStream *stream)
  345. {
  346. return av_rescale_q_rnd(val, context->time_base,
  347. stream->time_base,
  348. AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
  349. }
  350. #define YUV420_PLANES 3
  351. static inline void copy_data(AVPicture *pic, const struct video_data *frame,
  352. int height)
  353. {
  354. for (int plane = 0; plane < YUV420_PLANES; plane++) {
  355. int frame_rowsize = (int)frame->linesize[plane];
  356. int pic_rowsize = pic->linesize[plane];
  357. int bytes = frame_rowsize < pic_rowsize ?
  358. frame_rowsize : pic_rowsize;
  359. int plane_height = plane == 0 ? height : height/2;
  360. for (int y = 0; y < plane_height; y++) {
  361. int pos_frame = y * frame_rowsize;
  362. int pos_pic = y * pic_rowsize;
  363. memcpy(pic->data[plane] + pos_pic,
  364. frame->data[plane] + pos_frame,
  365. bytes);
  366. }
  367. }
  368. }
  369. static void receive_video(void *param, const struct video_data *frame)
  370. {
  371. struct ffmpeg_output *output = param;
  372. struct ffmpeg_data *data = &output->ff_data;
  373. AVCodecContext *context = data->video->codec;
  374. AVPacket packet = {0};
  375. int ret, got_packet;
  376. av_init_packet(&packet);
  377. if (!data->start_timestamp)
  378. data->start_timestamp = frame->timestamp;
  379. if (context->pix_fmt != AV_PIX_FMT_YUV420P)
  380. sws_scale(data->swscale, frame->data,
  381. (const int*)frame->linesize,
  382. 0, context->height, data->dst_picture.data,
  383. data->dst_picture.linesize);
  384. else
  385. copy_data(&data->dst_picture, frame, context->height);
  386. if (data->output->flags & AVFMT_RAWPICTURE) {
  387. packet.flags |= AV_PKT_FLAG_KEY;
  388. packet.stream_index = data->video->index;
  389. packet.data = data->dst_picture.data[0];
  390. packet.size = sizeof(AVPicture);
  391. pthread_mutex_lock(&data->write_mutex);
  392. ret = av_interleaved_write_frame(data->output, &packet);
  393. pthread_mutex_unlock(&data->write_mutex);
  394. } else {
  395. data->vframe->pts = data->total_frames;
  396. ret = avcodec_encode_video2(context, &packet, data->vframe,
  397. &got_packet);
  398. if (ret < 0) {
  399. blog(LOG_WARNING, "receive_video: Error encoding "
  400. "video: %s", av_err2str(ret));
  401. return;
  402. }
  403. if (!ret && got_packet && packet.size) {
  404. packet.pts = rescale_ts(packet.pts, context,
  405. data->video);
  406. packet.dts = rescale_ts(packet.dts, context,
  407. data->video);
  408. packet.duration = (int)av_rescale_q(packet.duration,
  409. context->time_base,
  410. data->video->time_base);
  411. pthread_mutex_lock(&data->write_mutex);
  412. ret = av_interleaved_write_frame(data->output,
  413. &packet);
  414. pthread_mutex_unlock(&data->write_mutex);
  415. } else {
  416. ret = 0;
  417. }
  418. }
  419. if (ret != 0) {
  420. blog(LOG_WARNING, "receive_video: Error writing video: %s",
  421. av_err2str(ret));
  422. }
  423. data->total_frames++;
  424. }
  425. static inline void encode_audio(struct ffmpeg_data *output,
  426. struct AVCodecContext *context, size_t block_size)
  427. {
  428. AVPacket packet = {0};
  429. int ret, got_packet;
  430. size_t total_size = output->frame_size * block_size * context->channels;
  431. output->aframe->nb_samples = output->frame_size;
  432. output->aframe->pts = av_rescale_q(output->total_samples,
  433. (AVRational){1, context->sample_rate},
  434. context->time_base);
  435. ret = avcodec_fill_audio_frame(output->aframe, context->channels,
  436. context->sample_fmt, output->samples[0],
  437. (int)total_size, 1);
  438. if (ret < 0) {
  439. blog(LOG_WARNING, "receive_audio: avcodec_fill_audio_frame "
  440. "failed: %s", av_err2str(ret));
  441. return;
  442. }
  443. output->total_samples += output->frame_size;
  444. ret = avcodec_encode_audio2(context, &packet, output->aframe,
  445. &got_packet);
  446. if (ret < 0) {
  447. blog(LOG_WARNING, "receive_audio: Error encoding audio: %s",
  448. av_err2str(ret));
  449. return;
  450. }
  451. if (!got_packet)
  452. return;
  453. packet.pts = rescale_ts(packet.pts, context, output->audio);
  454. packet.dts = rescale_ts(packet.dts, context, output->audio);
  455. packet.duration = (int)av_rescale_q(packet.duration, context->time_base,
  456. output->audio->time_base);
  457. packet.stream_index = output->audio->index;
  458. pthread_mutex_lock(&output->write_mutex);
  459. ret = av_interleaved_write_frame(output->output, &packet);
  460. if (ret != 0)
  461. blog(LOG_WARNING, "receive_audio: Error writing audio: %s",
  462. av_err2str(ret));
  463. pthread_mutex_unlock(&output->write_mutex);
  464. }
  465. static bool prepare_audio(struct ffmpeg_data *data,
  466. const struct audio_data *frame, struct audio_data *output)
  467. {
  468. *output = *frame;
  469. if (frame->timestamp < data->start_timestamp) {
  470. uint64_t duration = (uint64_t)frame->frames * 1000000000 /
  471. (uint64_t)data->audio_samplerate;
  472. uint64_t end_ts = (frame->timestamp + duration);
  473. uint64_t cutoff;
  474. if (end_ts <= data->start_timestamp)
  475. return false;
  476. cutoff = data->start_timestamp - frame->timestamp;
  477. cutoff = cutoff * (uint64_t)data->audio_samplerate /
  478. 1000000000;
  479. for (size_t i = 0; i < data->audio_planes; i++)
  480. output->data[i] += data->audio_size * (uint32_t)cutoff;
  481. output->frames -= (uint32_t)cutoff;
  482. }
  483. return true;
  484. }
  485. static void receive_audio(void *param, const struct audio_data *frame)
  486. {
  487. struct ffmpeg_output *output = param;
  488. struct ffmpeg_data *data = &output->ff_data;
  489. size_t frame_size_bytes;
  490. struct audio_data in;
  491. AVCodecContext *context = data->audio->codec;
  492. if (!data->start_timestamp)
  493. return;
  494. if (!prepare_audio(data, frame, &in))
  495. return;
  496. frame_size_bytes = (size_t)data->frame_size * data->audio_size;
  497. for (size_t i = 0; i < data->audio_planes; i++)
  498. circlebuf_push_back(&data->excess_frames[i], in.data[i],
  499. in.frames * data->audio_size);
  500. while (data->excess_frames[0].size >= frame_size_bytes) {
  501. for (size_t i = 0; i < data->audio_planes; i++)
  502. circlebuf_pop_front(&data->excess_frames[i],
  503. data->samples[i], frame_size_bytes);
  504. encode_audio(data, context, data->audio_size);
  505. }
  506. }
  507. static bool ffmpeg_output_start(void *data)
  508. {
  509. struct ffmpeg_output *output = data;
  510. video_t video = obs_video();
  511. audio_t audio = obs_audio();
  512. if (!video || !audio) {
  513. blog(LOG_WARNING, "ffmpeg_output_start: audio and video must "
  514. "both be active (as of this writing)");
  515. return false;
  516. }
  517. const char *filename_test;
  518. obs_data_t settings = obs_output_get_settings(output->output);
  519. filename_test = obs_data_getstring(settings, "filename");
  520. obs_data_release(settings);
  521. if (!filename_test || !*filename_test)
  522. return false;
  523. if (!ffmpeg_data_init(&output->ff_data, filename_test))
  524. return false;
  525. struct audio_convert_info aci = {
  526. .format = output->ff_data.audio_format
  527. };
  528. struct video_scale_info vsi = {
  529. .format = VIDEO_FORMAT_I420
  530. };
  531. video_output_connect(video, &vsi, receive_video, output);
  532. audio_output_connect(audio, &aci, receive_audio, output);
  533. output->active = true;
  534. return true;
  535. }
  536. static void ffmpeg_output_stop(void *data)
  537. {
  538. struct ffmpeg_output *output = data;
  539. if (output->active) {
  540. output->active = false;
  541. video_output_disconnect(obs_video(), receive_video, data);
  542. audio_output_disconnect(obs_audio(), receive_audio, data);
  543. ffmpeg_data_free(&output->ff_data);
  544. }
  545. }
  546. static bool ffmpeg_output_active(void *data)
  547. {
  548. struct ffmpeg_output *output = data;
  549. return output->active;
  550. }
  551. struct obs_output_info ffmpeg_output = {
  552. .id = "ffmpeg_output",
  553. .getname = ffmpeg_output_getname,
  554. .create = ffmpeg_output_create,
  555. .destroy = ffmpeg_output_destroy,
  556. .start = ffmpeg_output_start,
  557. .stop = ffmpeg_output_stop,
  558. .active = ffmpeg_output_active
  559. };