obs-ffmpeg-source.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * Copyright (c) 2015 John R. Bradley <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <obs-module.h>
  17. #include <util/platform.h>
  18. #include <util/dstr.h>
  19. #include "obs-ffmpeg-compat.h"
  20. #include "obs-ffmpeg-formats.h"
  21. #include <media-playback/media.h>
  22. #define FF_LOG(level, format, ...) \
  23. blog(level, "[Media Source]: " format, ##__VA_ARGS__)
  24. #define FF_LOG_S(source, level, format, ...) \
  25. blog(level, "[Media Source '%s']: " format, \
  26. obs_source_get_name(source), ##__VA_ARGS__)
  27. #define FF_BLOG(level, format, ...) \
  28. FF_LOG_S(s->source, level, format, ##__VA_ARGS__)
  29. struct ffmpeg_source {
  30. mp_media_t media;
  31. bool media_valid;
  32. bool destroy_media;
  33. struct SwsContext *sws_ctx;
  34. int sws_width;
  35. int sws_height;
  36. enum AVPixelFormat sws_format;
  37. uint8_t *sws_data;
  38. int sws_linesize;
  39. enum video_range_type range;
  40. obs_source_t *source;
  41. obs_hotkey_id hotkey;
  42. char *input;
  43. char *input_format;
  44. int buffering_mb;
  45. int speed_percent;
  46. bool is_looping;
  47. bool is_local_file;
  48. bool is_hw_decoding;
  49. bool is_clear_on_media_end;
  50. bool restart_on_activate;
  51. bool close_when_inactive;
  52. bool seekable;
  53. enum obs_media_state state;
  54. obs_hotkey_pair_id play_pause_hotkey;
  55. obs_hotkey_id stop_hotkey;
  56. };
  57. static void set_media_state(void *data, enum obs_media_state state)
  58. {
  59. struct ffmpeg_source *s = data;
  60. s->state = state;
  61. }
  62. static bool is_local_file_modified(obs_properties_t *props,
  63. obs_property_t *prop, obs_data_t *settings)
  64. {
  65. UNUSED_PARAMETER(prop);
  66. bool enabled = obs_data_get_bool(settings, "is_local_file");
  67. obs_property_t *input = obs_properties_get(props, "input");
  68. obs_property_t *input_format =
  69. obs_properties_get(props, "input_format");
  70. obs_property_t *local_file = obs_properties_get(props, "local_file");
  71. obs_property_t *looping = obs_properties_get(props, "looping");
  72. obs_property_t *buffering = obs_properties_get(props, "buffering_mb");
  73. obs_property_t *close =
  74. obs_properties_get(props, "close_when_inactive");
  75. obs_property_t *seekable = obs_properties_get(props, "seekable");
  76. obs_property_t *speed = obs_properties_get(props, "speed_percent");
  77. obs_property_set_visible(input, !enabled);
  78. obs_property_set_visible(input_format, !enabled);
  79. obs_property_set_visible(buffering, !enabled);
  80. obs_property_set_visible(close, enabled);
  81. obs_property_set_visible(local_file, enabled);
  82. obs_property_set_visible(looping, enabled);
  83. obs_property_set_visible(speed, enabled);
  84. obs_property_set_visible(seekable, !enabled);
  85. return true;
  86. }
  87. static void ffmpeg_source_defaults(obs_data_t *settings)
  88. {
  89. obs_data_set_default_bool(settings, "is_local_file", true);
  90. obs_data_set_default_bool(settings, "looping", false);
  91. obs_data_set_default_bool(settings, "clear_on_media_end", true);
  92. obs_data_set_default_bool(settings, "restart_on_activate", true);
  93. obs_data_set_default_int(settings, "buffering_mb", 2);
  94. obs_data_set_default_int(settings, "speed_percent", 100);
  95. }
  96. static const char *media_filter =
  97. " (*.mp4 *.ts *.mov *.flv *.mkv *.avi *.mp3 *.ogg *.aac *.wav *.gif *.webm);;";
  98. static const char *video_filter =
  99. " (*.mp4 *.ts *.mov *.flv *.mkv *.avi *.gif *.webm);;";
  100. static const char *audio_filter = " (*.mp3 *.aac *.ogg *.wav);;";
  101. static obs_properties_t *ffmpeg_source_getproperties(void *data)
  102. {
  103. struct ffmpeg_source *s = data;
  104. struct dstr filter = {0};
  105. struct dstr path = {0};
  106. UNUSED_PARAMETER(data);
  107. obs_properties_t *props = obs_properties_create();
  108. obs_properties_set_flags(props, OBS_PROPERTIES_DEFER_UPDATE);
  109. obs_property_t *prop;
  110. // use this when obs allows non-readonly paths
  111. prop = obs_properties_add_bool(props, "is_local_file",
  112. obs_module_text("LocalFile"));
  113. obs_property_set_modified_callback(prop, is_local_file_modified);
  114. dstr_copy(&filter, obs_module_text("MediaFileFilter.AllMediaFiles"));
  115. dstr_cat(&filter, media_filter);
  116. dstr_cat(&filter, obs_module_text("MediaFileFilter.VideoFiles"));
  117. dstr_cat(&filter, video_filter);
  118. dstr_cat(&filter, obs_module_text("MediaFileFilter.AudioFiles"));
  119. dstr_cat(&filter, audio_filter);
  120. dstr_cat(&filter, obs_module_text("MediaFileFilter.AllFiles"));
  121. dstr_cat(&filter, " (*.*)");
  122. if (s && s->input && *s->input) {
  123. const char *slash;
  124. dstr_copy(&path, s->input);
  125. dstr_replace(&path, "\\", "/");
  126. slash = strrchr(path.array, '/');
  127. if (slash)
  128. dstr_resize(&path, slash - path.array + 1);
  129. }
  130. obs_properties_add_path(props, "local_file",
  131. obs_module_text("LocalFile"), OBS_PATH_FILE,
  132. filter.array, path.array);
  133. dstr_free(&filter);
  134. dstr_free(&path);
  135. prop = obs_properties_add_bool(props, "looping",
  136. obs_module_text("Looping"));
  137. obs_properties_add_bool(props, "restart_on_activate",
  138. obs_module_text("RestartWhenActivated"));
  139. prop = obs_properties_add_int_slider(props, "buffering_mb",
  140. obs_module_text("BufferingMB"), 1,
  141. 16, 1);
  142. obs_property_int_set_suffix(prop, " MB");
  143. obs_properties_add_text(props, "input", obs_module_text("Input"),
  144. OBS_TEXT_DEFAULT);
  145. obs_properties_add_text(props, "input_format",
  146. obs_module_text("InputFormat"),
  147. OBS_TEXT_DEFAULT);
  148. #ifndef __APPLE__
  149. obs_properties_add_bool(props, "hw_decode",
  150. obs_module_text("HardwareDecode"));
  151. #endif
  152. obs_properties_add_bool(props, "clear_on_media_end",
  153. obs_module_text("ClearOnMediaEnd"));
  154. prop = obs_properties_add_bool(
  155. props, "close_when_inactive",
  156. obs_module_text("CloseFileWhenInactive"));
  157. obs_property_set_long_description(
  158. prop, obs_module_text("CloseFileWhenInactive.ToolTip"));
  159. prop = obs_properties_add_int_slider(props, "speed_percent",
  160. obs_module_text("SpeedPercentage"),
  161. 1, 200, 1);
  162. obs_property_int_set_suffix(prop, "%");
  163. prop = obs_properties_add_list(props, "color_range",
  164. obs_module_text("ColorRange"),
  165. OBS_COMBO_TYPE_LIST,
  166. OBS_COMBO_FORMAT_INT);
  167. obs_property_list_add_int(prop, obs_module_text("ColorRange.Auto"),
  168. VIDEO_RANGE_DEFAULT);
  169. obs_property_list_add_int(prop, obs_module_text("ColorRange.Partial"),
  170. VIDEO_RANGE_PARTIAL);
  171. obs_property_list_add_int(prop, obs_module_text("ColorRange.Full"),
  172. VIDEO_RANGE_FULL);
  173. obs_properties_add_bool(props, "seekable", obs_module_text("Seekable"));
  174. return props;
  175. }
  176. static void dump_source_info(struct ffmpeg_source *s, const char *input,
  177. const char *input_format)
  178. {
  179. FF_BLOG(LOG_INFO,
  180. "settings:\n"
  181. "\tinput: %s\n"
  182. "\tinput_format: %s\n"
  183. "\tspeed: %d\n"
  184. "\tis_looping: %s\n"
  185. "\tis_hw_decoding: %s\n"
  186. "\tis_clear_on_media_end: %s\n"
  187. "\trestart_on_activate: %s\n"
  188. "\tclose_when_inactive: %s",
  189. input ? input : "(null)",
  190. input_format ? input_format : "(null)", s->speed_percent,
  191. s->is_looping ? "yes" : "no", s->is_hw_decoding ? "yes" : "no",
  192. s->is_clear_on_media_end ? "yes" : "no",
  193. s->restart_on_activate ? "yes" : "no",
  194. s->close_when_inactive ? "yes" : "no");
  195. }
  196. static void get_frame(void *opaque, struct obs_source_frame *f)
  197. {
  198. struct ffmpeg_source *s = opaque;
  199. obs_source_output_video(s->source, f);
  200. }
  201. static void preload_frame(void *opaque, struct obs_source_frame *f)
  202. {
  203. struct ffmpeg_source *s = opaque;
  204. if (s->close_when_inactive)
  205. return;
  206. if (s->is_clear_on_media_end || s->is_looping)
  207. obs_source_preload_video(s->source, f);
  208. }
  209. static void get_audio(void *opaque, struct obs_source_audio *a)
  210. {
  211. struct ffmpeg_source *s = opaque;
  212. obs_source_output_audio(s->source, a);
  213. }
  214. static void media_stopped(void *opaque)
  215. {
  216. struct ffmpeg_source *s = opaque;
  217. if (s->is_clear_on_media_end) {
  218. obs_source_output_video(s->source, NULL);
  219. if (s->close_when_inactive && s->media_valid)
  220. s->destroy_media = true;
  221. }
  222. set_media_state(s, OBS_MEDIA_STATE_ENDED);
  223. obs_source_media_ended(s->source);
  224. }
  225. static void ffmpeg_source_open(struct ffmpeg_source *s)
  226. {
  227. if (s->input && *s->input) {
  228. struct mp_media_info info = {
  229. .opaque = s,
  230. .v_cb = get_frame,
  231. .v_preload_cb = preload_frame,
  232. .a_cb = get_audio,
  233. .stop_cb = media_stopped,
  234. .path = s->input,
  235. .format = s->input_format,
  236. .buffering = s->buffering_mb * 1024 * 1024,
  237. .speed = s->speed_percent,
  238. .force_range = s->range,
  239. .hardware_decoding = s->is_hw_decoding,
  240. .is_local_file = s->is_local_file || s->seekable};
  241. s->media_valid = mp_media_init(&s->media, &info);
  242. }
  243. }
  244. static void ffmpeg_source_tick(void *data, float seconds)
  245. {
  246. UNUSED_PARAMETER(seconds);
  247. struct ffmpeg_source *s = data;
  248. if (s->destroy_media) {
  249. if (s->media_valid) {
  250. mp_media_free(&s->media);
  251. s->media_valid = false;
  252. }
  253. s->destroy_media = false;
  254. }
  255. }
  256. static void ffmpeg_source_start(struct ffmpeg_source *s)
  257. {
  258. if (!s->media_valid)
  259. ffmpeg_source_open(s);
  260. if (s->media_valid) {
  261. mp_media_play(&s->media, s->is_looping);
  262. if (s->is_local_file)
  263. obs_source_show_preloaded_video(s->source);
  264. set_media_state(s, OBS_MEDIA_STATE_PLAYING);
  265. obs_source_media_started(s->source);
  266. }
  267. }
  268. static void ffmpeg_source_update(void *data, obs_data_t *settings)
  269. {
  270. struct ffmpeg_source *s = data;
  271. bool is_local_file = obs_data_get_bool(settings, "is_local_file");
  272. char *input;
  273. char *input_format;
  274. bfree(s->input);
  275. bfree(s->input_format);
  276. if (is_local_file) {
  277. input = (char *)obs_data_get_string(settings, "local_file");
  278. input_format = NULL;
  279. s->is_looping = obs_data_get_bool(settings, "looping");
  280. s->close_when_inactive =
  281. obs_data_get_bool(settings, "close_when_inactive");
  282. } else {
  283. input = (char *)obs_data_get_string(settings, "input");
  284. input_format =
  285. (char *)obs_data_get_string(settings, "input_format");
  286. s->is_looping = false;
  287. s->close_when_inactive = true;
  288. }
  289. s->input = input ? bstrdup(input) : NULL;
  290. s->input_format = input_format ? bstrdup(input_format) : NULL;
  291. #ifndef __APPLE__
  292. s->is_hw_decoding = obs_data_get_bool(settings, "hw_decode");
  293. #endif
  294. s->is_clear_on_media_end =
  295. obs_data_get_bool(settings, "clear_on_media_end");
  296. s->restart_on_activate =
  297. obs_data_get_bool(settings, "restart_on_activate");
  298. s->range = (enum video_range_type)obs_data_get_int(settings,
  299. "color_range");
  300. s->buffering_mb = (int)obs_data_get_int(settings, "buffering_mb");
  301. s->speed_percent = (int)obs_data_get_int(settings, "speed_percent");
  302. s->is_local_file = is_local_file;
  303. s->seekable = obs_data_get_bool(settings, "seekable");
  304. if (s->speed_percent < 1 || s->speed_percent > 200)
  305. s->speed_percent = 100;
  306. if (s->media_valid) {
  307. mp_media_free(&s->media);
  308. s->media_valid = false;
  309. }
  310. bool active = obs_source_active(s->source);
  311. if (!s->close_when_inactive || active)
  312. ffmpeg_source_open(s);
  313. dump_source_info(s, input, input_format);
  314. if (!s->restart_on_activate || active)
  315. ffmpeg_source_start(s);
  316. }
  317. static const char *ffmpeg_source_getname(void *unused)
  318. {
  319. UNUSED_PARAMETER(unused);
  320. return obs_module_text("FFMpegSource");
  321. }
  322. static void restart_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
  323. bool pressed)
  324. {
  325. UNUSED_PARAMETER(id);
  326. UNUSED_PARAMETER(hotkey);
  327. UNUSED_PARAMETER(pressed);
  328. struct ffmpeg_source *s = data;
  329. if (obs_source_active(s->source))
  330. obs_source_media_restart(s->source);
  331. }
  332. static void restart_proc(void *data, calldata_t *cd)
  333. {
  334. restart_hotkey(data, 0, NULL, true);
  335. UNUSED_PARAMETER(cd);
  336. }
  337. static void get_duration(void *data, calldata_t *cd)
  338. {
  339. struct ffmpeg_source *s = data;
  340. int64_t dur = 0;
  341. if (s->media.fmt)
  342. dur = s->media.fmt->duration;
  343. calldata_set_int(cd, "duration", dur * 1000);
  344. }
  345. static void get_nb_frames(void *data, calldata_t *cd)
  346. {
  347. struct ffmpeg_source *s = data;
  348. int64_t frames = 0;
  349. if (!s->media.fmt) {
  350. calldata_set_int(cd, "num_frames", frames);
  351. return;
  352. }
  353. int video_stream_index = av_find_best_stream(
  354. s->media.fmt, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
  355. if (video_stream_index < 0) {
  356. FF_BLOG(LOG_WARNING, "Getting number of frames failed: No "
  357. "video stream in media file!");
  358. calldata_set_int(cd, "num_frames", frames);
  359. return;
  360. }
  361. AVStream *stream = s->media.fmt->streams[video_stream_index];
  362. if (stream->nb_frames > 0) {
  363. frames = stream->nb_frames;
  364. } else {
  365. FF_BLOG(LOG_DEBUG, "nb_frames not set, estimating using frame "
  366. "rate and duration");
  367. AVRational avg_frame_rate = stream->avg_frame_rate;
  368. frames = (int64_t)ceil((double)s->media.fmt->duration /
  369. (double)AV_TIME_BASE *
  370. (double)avg_frame_rate.num /
  371. (double)avg_frame_rate.den);
  372. }
  373. calldata_set_int(cd, "num_frames", frames);
  374. }
  375. static bool ffmpeg_source_play_hotkey(void *data, obs_hotkey_pair_id id,
  376. obs_hotkey_t *hotkey, bool pressed)
  377. {
  378. UNUSED_PARAMETER(id);
  379. UNUSED_PARAMETER(hotkey);
  380. struct ffmpeg_source *s = data;
  381. if (s->state == OBS_MEDIA_STATE_PLAYING || !pressed ||
  382. !obs_source_active(s->source))
  383. return false;
  384. obs_source_media_play_pause(s->source, false);
  385. return true;
  386. }
  387. static bool ffmpeg_source_pause_hotkey(void *data, obs_hotkey_pair_id id,
  388. obs_hotkey_t *hotkey, bool pressed)
  389. {
  390. UNUSED_PARAMETER(id);
  391. UNUSED_PARAMETER(hotkey);
  392. struct ffmpeg_source *s = data;
  393. if (s->state != OBS_MEDIA_STATE_PLAYING || !pressed ||
  394. !obs_source_active(s->source))
  395. return false;
  396. obs_source_media_play_pause(s->source, true);
  397. return true;
  398. }
  399. static void ffmpeg_source_stop_hotkey(void *data, obs_hotkey_id id,
  400. obs_hotkey_t *hotkey, bool pressed)
  401. {
  402. UNUSED_PARAMETER(id);
  403. UNUSED_PARAMETER(hotkey);
  404. struct ffmpeg_source *s = data;
  405. if (pressed && obs_source_active(s->source))
  406. obs_source_media_stop(s->source);
  407. }
  408. static void *ffmpeg_source_create(obs_data_t *settings, obs_source_t *source)
  409. {
  410. UNUSED_PARAMETER(settings);
  411. struct ffmpeg_source *s = bzalloc(sizeof(struct ffmpeg_source));
  412. s->source = source;
  413. s->hotkey = obs_hotkey_register_source(source, "MediaSource.Restart",
  414. obs_module_text("RestartMedia"),
  415. restart_hotkey, s);
  416. s->play_pause_hotkey = obs_hotkey_pair_register_source(
  417. s->source, "MediaSource.Play", obs_module_text("Play"),
  418. "MediaSource.Pause", obs_module_text("Pause"),
  419. ffmpeg_source_play_hotkey, ffmpeg_source_pause_hotkey, s, s);
  420. s->stop_hotkey = obs_hotkey_register_source(source, "MediaSource.Stop",
  421. obs_module_text("Stop"),
  422. ffmpeg_source_stop_hotkey,
  423. s);
  424. proc_handler_t *ph = obs_source_get_proc_handler(source);
  425. proc_handler_add(ph, "void restart()", restart_proc, s);
  426. proc_handler_add(ph, "void get_duration(out int duration)",
  427. get_duration, s);
  428. proc_handler_add(ph, "void get_nb_frames(out int num_frames)",
  429. get_nb_frames, s);
  430. ffmpeg_source_update(s, settings);
  431. return s;
  432. }
  433. static void ffmpeg_source_destroy(void *data)
  434. {
  435. struct ffmpeg_source *s = data;
  436. if (s->hotkey)
  437. obs_hotkey_unregister(s->hotkey);
  438. if (s->media_valid)
  439. mp_media_free(&s->media);
  440. if (s->sws_ctx != NULL)
  441. sws_freeContext(s->sws_ctx);
  442. bfree(s->sws_data);
  443. bfree(s->input);
  444. bfree(s->input_format);
  445. bfree(s);
  446. }
  447. static void ffmpeg_source_activate(void *data)
  448. {
  449. struct ffmpeg_source *s = data;
  450. if (s->restart_on_activate)
  451. obs_source_media_restart(s->source);
  452. }
  453. static void ffmpeg_source_deactivate(void *data)
  454. {
  455. struct ffmpeg_source *s = data;
  456. if (s->restart_on_activate) {
  457. if (s->media_valid) {
  458. mp_media_stop(&s->media);
  459. if (s->is_clear_on_media_end)
  460. obs_source_output_video(s->source, NULL);
  461. }
  462. }
  463. }
  464. static void ffmpeg_source_play_pause(void *data, bool pause)
  465. {
  466. struct ffmpeg_source *s = data;
  467. mp_media_play_pause(&s->media, pause);
  468. if (pause)
  469. set_media_state(s, OBS_MEDIA_STATE_PAUSED);
  470. else
  471. set_media_state(s, OBS_MEDIA_STATE_PLAYING);
  472. }
  473. static void ffmpeg_source_stop(void *data)
  474. {
  475. struct ffmpeg_source *s = data;
  476. if (s->media_valid) {
  477. mp_media_stop(&s->media);
  478. obs_source_output_video(s->source, NULL);
  479. set_media_state(s, OBS_MEDIA_STATE_STOPPED);
  480. }
  481. }
  482. static void ffmpeg_source_restart(void *data)
  483. {
  484. struct ffmpeg_source *s = data;
  485. if (obs_source_active(s->source))
  486. ffmpeg_source_start(s);
  487. set_media_state(s, OBS_MEDIA_STATE_PLAYING);
  488. }
  489. static int64_t ffmpeg_source_get_duration(void *data)
  490. {
  491. struct ffmpeg_source *s = data;
  492. int64_t dur = 0;
  493. if (s->media.fmt)
  494. dur = (float)s->media.fmt->duration / 1000.0f;
  495. return dur;
  496. }
  497. static int64_t ffmpeg_source_get_time(void *data)
  498. {
  499. struct ffmpeg_source *s = data;
  500. return mp_get_current_time(&s->media);
  501. }
  502. static void ffmpeg_source_set_time(void *data, int64_t ms)
  503. {
  504. struct ffmpeg_source *s = data;
  505. mp_media_seek_to(&s->media, ms);
  506. }
  507. static enum obs_media_state ffmpeg_source_get_state(void *data)
  508. {
  509. struct ffmpeg_source *s = data;
  510. return s->state;
  511. }
  512. struct obs_source_info ffmpeg_source = {
  513. .id = "ffmpeg_source",
  514. .type = OBS_SOURCE_TYPE_INPUT,
  515. .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO |
  516. OBS_SOURCE_DO_NOT_DUPLICATE |
  517. OBS_SOURCE_CONTROLLABLE_MEDIA,
  518. .get_name = ffmpeg_source_getname,
  519. .create = ffmpeg_source_create,
  520. .destroy = ffmpeg_source_destroy,
  521. .get_defaults = ffmpeg_source_defaults,
  522. .get_properties = ffmpeg_source_getproperties,
  523. .activate = ffmpeg_source_activate,
  524. .deactivate = ffmpeg_source_deactivate,
  525. .video_tick = ffmpeg_source_tick,
  526. .update = ffmpeg_source_update,
  527. .icon_type = OBS_ICON_TYPE_MEDIA,
  528. .media_play_pause = ffmpeg_source_play_pause,
  529. .media_restart = ffmpeg_source_restart,
  530. .media_stop = ffmpeg_source_stop,
  531. .media_get_duration = ffmpeg_source_get_duration,
  532. .media_get_time = ffmpeg_source_get_time,
  533. .media_set_time = ffmpeg_source_set_time,
  534. .media_get_state = ffmpeg_source_get_state,
  535. };