ffmpeg.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef FFTOOLS_FFMPEG_H
  19. #define FFTOOLS_FFMPEG_H
  20. #include "config.h"
  21. #include <stdatomic.h>
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <signal.h>
  25. #include "cmdutils.h"
  26. #include "ffmpeg_sched.h"
  27. #include "sync_queue.h"
  28. #include "libavformat/avformat.h"
  29. #include "libavformat/avio.h"
  30. #include "libavcodec/avcodec.h"
  31. #include "libavcodec/bsf.h"
  32. #include "libavfilter/avfilter.h"
  33. #include "libavutil/avutil.h"
  34. #include "libavutil/dict.h"
  35. #include "libavutil/eval.h"
  36. #include "libavutil/fifo.h"
  37. #include "libavutil/hwcontext.h"
  38. #include "libavutil/pixfmt.h"
  39. #include "libavutil/rational.h"
  40. #include "libavutil/thread.h"
  41. #include "libavutil/threadmessage.h"
  42. #include "libswresample/swresample.h"
  43. // deprecated features
  44. #define FFMPEG_OPT_QPHIST 1
  45. #define FFMPEG_OPT_ADRIFT_THRESHOLD 1
  46. #define FFMPEG_OPT_ENC_TIME_BASE_NUM 1
  47. #define FFMPEG_OPT_TOP 1
  48. #define FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP 1
  49. #define FFMPEG_OPT_VSYNC_DROP 1
  50. #define FFMPEG_OPT_VSYNC 1
  51. #define FFMPEG_OPT_FILTER_SCRIPT 1
  52. #define FFMPEG_ERROR_RATE_EXCEEDED FFERRTAG('E', 'R', 'E', 'D')
  53. enum VideoSyncMethod {
  54. VSYNC_AUTO = -1,
  55. VSYNC_PASSTHROUGH,
  56. VSYNC_CFR,
  57. VSYNC_VFR,
  58. VSYNC_VSCFR,
  59. #if FFMPEG_OPT_VSYNC_DROP
  60. VSYNC_DROP,
  61. #endif
  62. };
  63. enum EncTimeBase {
  64. ENC_TIME_BASE_DEMUX = -1,
  65. ENC_TIME_BASE_FILTER = -2,
  66. };
  67. enum HWAccelID {
  68. HWACCEL_NONE = 0,
  69. HWACCEL_AUTO,
  70. HWACCEL_GENERIC,
  71. };
  72. enum FrameOpaque {
  73. FRAME_OPAQUE_SUB_HEARTBEAT = 1,
  74. FRAME_OPAQUE_EOF,
  75. FRAME_OPAQUE_SEND_COMMAND,
  76. };
  77. enum PacketOpaque {
  78. PKT_OPAQUE_SUB_HEARTBEAT = 1,
  79. PKT_OPAQUE_FIX_SUB_DURATION,
  80. };
  81. enum LatencyProbe {
  82. LATENCY_PROBE_DEMUX,
  83. LATENCY_PROBE_DEC_PRE,
  84. LATENCY_PROBE_DEC_POST,
  85. LATENCY_PROBE_FILTER_PRE,
  86. LATENCY_PROBE_FILTER_POST,
  87. LATENCY_PROBE_ENC_PRE,
  88. LATENCY_PROBE_ENC_POST,
  89. LATENCY_PROBE_NB,
  90. };
  91. typedef struct HWDevice {
  92. const char *name;
  93. enum AVHWDeviceType type;
  94. AVBufferRef *device_ref;
  95. } HWDevice;
  96. enum ViewSpecifierType {
  97. // no specifier given
  98. VIEW_SPECIFIER_TYPE_NONE = 0,
  99. // val is view index
  100. VIEW_SPECIFIER_TYPE_IDX,
  101. // val is view ID
  102. VIEW_SPECIFIER_TYPE_ID,
  103. // specify view by its position, val is AV_STEREO3D_VIEW_LEFT/RIGHT
  104. VIEW_SPECIFIER_TYPE_POS,
  105. // use all views, val is ignored
  106. VIEW_SPECIFIER_TYPE_ALL,
  107. };
  108. typedef struct ViewSpecifier {
  109. enum ViewSpecifierType type;
  110. unsigned val;
  111. } ViewSpecifier;
  112. /* select an input stream for an output stream */
  113. typedef struct StreamMap {
  114. int disabled; /* 1 is this mapping is disabled by a negative map */
  115. int file_index;
  116. int stream_index;
  117. char *linklabel; /* name of an output link, for mapping lavfi outputs */
  118. ViewSpecifier vs;
  119. } StreamMap;
  120. typedef struct OptionsContext {
  121. OptionGroup *g;
  122. /* input/output options */
  123. int64_t start_time;
  124. int64_t start_time_eof;
  125. int seek_timestamp;
  126. const char *format;
  127. SpecifierOptList codec_names;
  128. SpecifierOptList audio_ch_layouts;
  129. SpecifierOptList audio_channels;
  130. SpecifierOptList audio_sample_rate;
  131. SpecifierOptList frame_rates;
  132. SpecifierOptList max_frame_rates;
  133. SpecifierOptList frame_sizes;
  134. SpecifierOptList frame_pix_fmts;
  135. /* input options */
  136. int64_t input_ts_offset;
  137. int loop;
  138. int rate_emu;
  139. float readrate;
  140. double readrate_initial_burst;
  141. int accurate_seek;
  142. int thread_queue_size;
  143. int input_sync_ref;
  144. int find_stream_info;
  145. SpecifierOptList ts_scale;
  146. SpecifierOptList dump_attachment;
  147. SpecifierOptList hwaccels;
  148. SpecifierOptList hwaccel_devices;
  149. SpecifierOptList hwaccel_output_formats;
  150. SpecifierOptList autorotate;
  151. SpecifierOptList apply_cropping;
  152. /* output options */
  153. StreamMap *stream_maps;
  154. int nb_stream_maps;
  155. const char **attachments;
  156. int nb_attachments;
  157. int chapters_input_file;
  158. int64_t recording_time;
  159. int64_t stop_time;
  160. int64_t limit_filesize;
  161. float mux_preload;
  162. float mux_max_delay;
  163. float shortest_buf_duration;
  164. int shortest;
  165. int bitexact;
  166. int video_disable;
  167. int audio_disable;
  168. int subtitle_disable;
  169. int data_disable;
  170. // keys are stream indices
  171. AVDictionary *streamid;
  172. SpecifierOptList metadata;
  173. SpecifierOptList max_frames;
  174. SpecifierOptList bitstream_filters;
  175. SpecifierOptList codec_tags;
  176. SpecifierOptList sample_fmts;
  177. SpecifierOptList qscale;
  178. SpecifierOptList forced_key_frames;
  179. SpecifierOptList fps_mode;
  180. SpecifierOptList force_fps;
  181. SpecifierOptList frame_aspect_ratios;
  182. SpecifierOptList display_rotations;
  183. SpecifierOptList display_hflips;
  184. SpecifierOptList display_vflips;
  185. SpecifierOptList rc_overrides;
  186. SpecifierOptList intra_matrices;
  187. SpecifierOptList inter_matrices;
  188. SpecifierOptList chroma_intra_matrices;
  189. #if FFMPEG_OPT_TOP
  190. SpecifierOptList top_field_first;
  191. #endif
  192. SpecifierOptList metadata_map;
  193. SpecifierOptList presets;
  194. SpecifierOptList copy_initial_nonkeyframes;
  195. SpecifierOptList copy_prior_start;
  196. SpecifierOptList filters;
  197. #if FFMPEG_OPT_FILTER_SCRIPT
  198. SpecifierOptList filter_scripts;
  199. #endif
  200. SpecifierOptList reinit_filters;
  201. SpecifierOptList fix_sub_duration;
  202. SpecifierOptList fix_sub_duration_heartbeat;
  203. SpecifierOptList canvas_sizes;
  204. SpecifierOptList pass;
  205. SpecifierOptList passlogfiles;
  206. SpecifierOptList max_muxing_queue_size;
  207. SpecifierOptList muxing_queue_data_threshold;
  208. SpecifierOptList guess_layout_max;
  209. SpecifierOptList apad;
  210. SpecifierOptList discard;
  211. SpecifierOptList disposition;
  212. SpecifierOptList program;
  213. SpecifierOptList stream_groups;
  214. SpecifierOptList time_bases;
  215. SpecifierOptList enc_time_bases;
  216. SpecifierOptList autoscale;
  217. SpecifierOptList bits_per_raw_sample;
  218. SpecifierOptList enc_stats_pre;
  219. SpecifierOptList enc_stats_post;
  220. SpecifierOptList mux_stats;
  221. SpecifierOptList enc_stats_pre_fmt;
  222. SpecifierOptList enc_stats_post_fmt;
  223. SpecifierOptList mux_stats_fmt;
  224. } OptionsContext;
  225. enum IFilterFlags {
  226. IFILTER_FLAG_AUTOROTATE = (1 << 0),
  227. IFILTER_FLAG_REINIT = (1 << 1),
  228. IFILTER_FLAG_CFR = (1 << 2),
  229. IFILTER_FLAG_CROP = (1 << 3),
  230. };
  231. typedef struct InputFilterOptions {
  232. int64_t trim_start_us;
  233. int64_t trim_end_us;
  234. uint8_t *name;
  235. /* When IFILTER_FLAG_CFR is set, the stream is guaranteed to be CFR with
  236. * this framerate.
  237. *
  238. * Otherwise, this is an estimate that should not be relied upon to be
  239. * accurate */
  240. AVRational framerate;
  241. unsigned crop_top;
  242. unsigned crop_bottom;
  243. unsigned crop_left;
  244. unsigned crop_right;
  245. int sub2video_width;
  246. int sub2video_height;
  247. // a combination of IFILTER_FLAG_*
  248. unsigned flags;
  249. AVFrame *fallback;
  250. } InputFilterOptions;
  251. enum OFilterFlags {
  252. OFILTER_FLAG_DISABLE_CONVERT = (1 << 0),
  253. // produce 24-bit audio
  254. OFILTER_FLAG_AUDIO_24BIT = (1 << 1),
  255. OFILTER_FLAG_AUTOSCALE = (1 << 2),
  256. };
  257. typedef struct OutputFilterOptions {
  258. // Caller-provided name for this output
  259. char *name;
  260. // Codec used for encoding, may be NULL
  261. const AVCodec *enc;
  262. int64_t trim_start_us;
  263. int64_t trim_duration_us;
  264. int64_t ts_offset;
  265. /* Desired output timebase.
  266. * Numerator can be one of EncTimeBase values, or 0 when no preference.
  267. */
  268. AVRational output_tb;
  269. AVDictionary *sws_opts;
  270. AVDictionary *swr_opts;
  271. const char *nb_threads;
  272. // A combination of OFilterFlags.
  273. unsigned flags;
  274. int format;
  275. int width;
  276. int height;
  277. enum AVColorSpace color_space;
  278. enum AVColorRange color_range;
  279. enum VideoSyncMethod vsync_method;
  280. AVRational frame_rate;
  281. AVRational max_frame_rate;
  282. int sample_rate;
  283. AVChannelLayout ch_layout;
  284. const int *formats;
  285. const int *sample_rates;
  286. const AVChannelLayout *ch_layouts;
  287. const AVRational *frame_rates;
  288. const enum AVColorSpace *color_spaces;
  289. const enum AVColorRange *color_ranges;
  290. // for simple filtergraphs only, view specifier passed
  291. // along to the decoder
  292. const ViewSpecifier *vs;
  293. } OutputFilterOptions;
  294. typedef struct InputFilter {
  295. struct FilterGraph *graph;
  296. uint8_t *name;
  297. } InputFilter;
  298. typedef struct OutputFilter {
  299. const AVClass *class;
  300. struct FilterGraph *graph;
  301. uint8_t *name;
  302. /* for filters that are not yet bound to an output stream,
  303. * this stores the output linklabel, if any */
  304. int bound;
  305. uint8_t *linklabel;
  306. char *apad;
  307. enum AVMediaType type;
  308. atomic_uint_least64_t nb_frames_dup;
  309. atomic_uint_least64_t nb_frames_drop;
  310. } OutputFilter;
  311. typedef struct FilterGraph {
  312. const AVClass *class;
  313. int index;
  314. InputFilter **inputs;
  315. int nb_inputs;
  316. OutputFilter **outputs;
  317. int nb_outputs;
  318. } FilterGraph;
  319. enum DecoderFlags {
  320. DECODER_FLAG_FIX_SUB_DURATION = (1 << 0),
  321. // input timestamps are unreliable (guessed by demuxer)
  322. DECODER_FLAG_TS_UNRELIABLE = (1 << 1),
  323. // decoder should override timestamps by fixed framerate
  324. // from DecoderOpts.framerate
  325. DECODER_FLAG_FRAMERATE_FORCED = (1 << 2),
  326. #if FFMPEG_OPT_TOP
  327. DECODER_FLAG_TOP_FIELD_FIRST = (1 << 3),
  328. #endif
  329. DECODER_FLAG_SEND_END_TS = (1 << 4),
  330. // force bitexact decoding
  331. DECODER_FLAG_BITEXACT = (1 << 5),
  332. };
  333. typedef struct DecoderOpts {
  334. int flags;
  335. char *name;
  336. void *log_parent;
  337. const AVCodec *codec;
  338. const AVCodecParameters *par;
  339. /* hwaccel options */
  340. enum HWAccelID hwaccel_id;
  341. enum AVHWDeviceType hwaccel_device_type;
  342. char *hwaccel_device;
  343. enum AVPixelFormat hwaccel_output_format;
  344. AVRational time_base;
  345. // Either forced (when DECODER_FLAG_FRAMERATE_FORCED is set) or
  346. // estimated (otherwise) video framerate.
  347. AVRational framerate;
  348. } DecoderOpts;
  349. typedef struct Decoder {
  350. const AVClass *class;
  351. enum AVMediaType type;
  352. const uint8_t *subtitle_header;
  353. int subtitle_header_size;
  354. // number of frames/samples retrieved from the decoder
  355. uint64_t frames_decoded;
  356. uint64_t samples_decoded;
  357. uint64_t decode_errors;
  358. } Decoder;
  359. typedef struct InputStream {
  360. const AVClass *class;
  361. /* parent source */
  362. struct InputFile *file;
  363. int index;
  364. AVStream *st;
  365. int user_set_discard;
  366. /**
  367. * Codec parameters - to be used by the decoding/streamcopy code.
  368. * st->codecpar should not be accessed, because it may be modified
  369. * concurrently by the demuxing thread.
  370. */
  371. AVCodecParameters *par;
  372. Decoder *decoder;
  373. const AVCodec *dec;
  374. /* framerate forced with -r */
  375. AVRational framerate;
  376. #if FFMPEG_OPT_TOP
  377. int top_field_first;
  378. #endif
  379. int fix_sub_duration;
  380. /* decoded data from this stream goes into all those filters
  381. * currently video and audio only */
  382. InputFilter **filters;
  383. int nb_filters;
  384. } InputStream;
  385. typedef struct InputFile {
  386. const AVClass *class;
  387. int index;
  388. AVFormatContext *ctx;
  389. int64_t input_ts_offset;
  390. int input_sync_ref;
  391. /**
  392. * Effective format start time based on enabled streams.
  393. */
  394. int64_t start_time_effective;
  395. int64_t ts_offset;
  396. /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
  397. int64_t start_time;
  398. /* streams that ffmpeg is aware of;
  399. * there may be extra streams in ctx that are not mapped to an InputStream
  400. * if new streams appear dynamically during demuxing */
  401. InputStream **streams;
  402. int nb_streams;
  403. } InputFile;
  404. enum forced_keyframes_const {
  405. FKF_N,
  406. FKF_N_FORCED,
  407. FKF_PREV_FORCED_N,
  408. FKF_PREV_FORCED_T,
  409. FKF_T,
  410. FKF_NB
  411. };
  412. #define ABORT_ON_FLAG_EMPTY_OUTPUT (1 << 0)
  413. #define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM (1 << 1)
  414. enum EncStatsType {
  415. ENC_STATS_LITERAL = 0,
  416. ENC_STATS_FILE_IDX,
  417. ENC_STATS_STREAM_IDX,
  418. ENC_STATS_FRAME_NUM,
  419. ENC_STATS_FRAME_NUM_IN,
  420. ENC_STATS_TIMEBASE,
  421. ENC_STATS_TIMEBASE_IN,
  422. ENC_STATS_PTS,
  423. ENC_STATS_PTS_TIME,
  424. ENC_STATS_PTS_IN,
  425. ENC_STATS_PTS_TIME_IN,
  426. ENC_STATS_DTS,
  427. ENC_STATS_DTS_TIME,
  428. ENC_STATS_SAMPLE_NUM,
  429. ENC_STATS_NB_SAMPLES,
  430. ENC_STATS_PKT_SIZE,
  431. ENC_STATS_BITRATE,
  432. ENC_STATS_AVG_BITRATE,
  433. ENC_STATS_KEYFRAME,
  434. };
  435. typedef struct EncStatsComponent {
  436. enum EncStatsType type;
  437. uint8_t *str;
  438. size_t str_len;
  439. } EncStatsComponent;
  440. typedef struct EncStats {
  441. EncStatsComponent *components;
  442. int nb_components;
  443. AVIOContext *io;
  444. pthread_mutex_t lock;
  445. int lock_initialized;
  446. } EncStats;
  447. enum {
  448. KF_FORCE_SOURCE = 1,
  449. #if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP
  450. KF_FORCE_SOURCE_NO_DROP = 2,
  451. #endif
  452. };
  453. typedef struct KeyframeForceCtx {
  454. int type;
  455. int64_t ref_pts;
  456. // timestamps of the forced keyframes, in AV_TIME_BASE_Q
  457. int64_t *pts;
  458. int nb_pts;
  459. int index;
  460. AVExpr *pexpr;
  461. double expr_const_values[FKF_NB];
  462. int dropped_keyframe;
  463. } KeyframeForceCtx;
  464. typedef struct Encoder {
  465. const AVClass *class;
  466. AVCodecContext *enc_ctx;
  467. // number of frames/samples sent to the encoder
  468. uint64_t frames_encoded;
  469. uint64_t samples_encoded;
  470. } Encoder;
  471. enum CroppingType {
  472. CROP_DISABLED = 0,
  473. CROP_ALL,
  474. CROP_CODEC,
  475. CROP_CONTAINER,
  476. };
  477. typedef struct OutputStream {
  478. const AVClass *class;
  479. enum AVMediaType type;
  480. /* parent muxer */
  481. struct OutputFile *file;
  482. int index; /* stream index in the output file */
  483. /* input stream that is the source for this output stream;
  484. * may be NULL for streams with no well-defined source, e.g.
  485. * attachments or outputs from complex filtergraphs */
  486. InputStream *ist;
  487. AVStream *st; /* stream in the output file */
  488. Encoder *enc;
  489. /* video only */
  490. #if FFMPEG_OPT_TOP
  491. int top_field_first;
  492. #endif
  493. int bitexact;
  494. int bits_per_raw_sample;
  495. AVRational frame_aspect_ratio;
  496. KeyframeForceCtx kf;
  497. const char *logfile_prefix;
  498. FILE *logfile;
  499. // simple filtergraph feeding this stream, if any
  500. FilterGraph *fg_simple;
  501. OutputFilter *filter;
  502. char *attachment_filename;
  503. /* stats */
  504. // number of packets send to the muxer
  505. atomic_uint_least64_t packets_written;
  506. /* packet quality factor */
  507. atomic_int quality;
  508. EncStats enc_stats_pre;
  509. EncStats enc_stats_post;
  510. /*
  511. * bool on whether this stream should be utilized for splitting
  512. * subtitles utilizing fix_sub_duration at random access points.
  513. */
  514. unsigned int fix_sub_duration_heartbeat;
  515. } OutputStream;
  516. typedef struct OutputFile {
  517. const AVClass *class;
  518. int index;
  519. const char *url;
  520. OutputStream **streams;
  521. int nb_streams;
  522. int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
  523. int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
  524. int bitexact;
  525. } OutputFile;
  526. // optionally attached as opaque_ref to decoded AVFrames
  527. typedef struct FrameData {
  528. // demuxer-estimated dts in AV_TIME_BASE_Q,
  529. // to be used when real dts is missing
  530. int64_t dts_est;
  531. // properties that come from the decoder
  532. struct {
  533. uint64_t frame_num;
  534. int64_t pts;
  535. AVRational tb;
  536. } dec;
  537. AVRational frame_rate_filter;
  538. int bits_per_raw_sample;
  539. int64_t wallclock[LATENCY_PROBE_NB];
  540. AVCodecParameters *par_enc;
  541. } FrameData;
  542. extern InputFile **input_files;
  543. extern int nb_input_files;
  544. extern OutputFile **output_files;
  545. extern int nb_output_files;
  546. // complex filtergraphs
  547. extern FilterGraph **filtergraphs;
  548. extern int nb_filtergraphs;
  549. // standalone decoders (not tied to demuxed streams)
  550. extern Decoder **decoders;
  551. extern int nb_decoders;
  552. extern char *vstats_filename;
  553. extern float dts_delta_threshold;
  554. extern float dts_error_threshold;
  555. extern enum VideoSyncMethod video_sync_method;
  556. extern float frame_drop_threshold;
  557. extern int do_benchmark;
  558. extern int do_benchmark_all;
  559. extern int do_hex_dump;
  560. extern int do_pkt_dump;
  561. extern int copy_ts;
  562. extern int start_at_zero;
  563. extern int copy_tb;
  564. extern int debug_ts;
  565. extern int exit_on_error;
  566. extern int abort_on_flags;
  567. extern int print_stats;
  568. extern int64_t stats_period;
  569. extern int stdin_interaction;
  570. extern AVIOContext *progress_avio;
  571. extern float max_error_rate;
  572. extern char *filter_nbthreads;
  573. extern int filter_complex_nbthreads;
  574. extern int vstats_version;
  575. extern int auto_conversion_filters;
  576. extern const AVIOInterruptCB int_cb;
  577. extern const OptionDef options[];
  578. extern HWDevice *filter_hw_device;
  579. extern atomic_uint nb_output_dumped;
  580. extern int ignore_unknown_streams;
  581. extern int copy_unknown_streams;
  582. extern int recast_media;
  583. extern FILE *vstats_file;
  584. void term_init(void);
  585. void term_exit(void);
  586. void show_usage(void);
  587. int check_avoptions_used(const AVDictionary *opts, const AVDictionary *opts_used,
  588. void *logctx, int decode);
  589. int assert_file_overwrite(const char *filename);
  590. int find_codec(void *logctx, const char *name,
  591. enum AVMediaType type, int encoder, const AVCodec **codec);
  592. int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
  593. int filtergraph_is_simple(const FilterGraph *fg);
  594. int fg_create_simple(FilterGraph **pfg,
  595. InputStream *ist,
  596. char *graph_desc,
  597. Scheduler *sch, unsigned sched_idx_enc,
  598. const OutputFilterOptions *opts);
  599. int fg_finalise_bindings(void);
  600. /**
  601. * Get our axiliary frame data attached to the frame, allocating it
  602. * if needed.
  603. */
  604. FrameData *frame_data(AVFrame *frame);
  605. const FrameData *frame_data_c(AVFrame *frame);
  606. FrameData *packet_data (AVPacket *pkt);
  607. const FrameData *packet_data_c(AVPacket *pkt);
  608. int ofilter_bind_enc(OutputFilter *ofilter,
  609. unsigned sched_idx_enc,
  610. const OutputFilterOptions *opts);
  611. /**
  612. * Create a new filtergraph in the global filtergraph list.
  613. *
  614. * @param graph_desc Graph description; an av_malloc()ed string, filtergraph
  615. * takes ownership of it.
  616. */
  617. int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch);
  618. void fg_free(FilterGraph **pfg);
  619. void fg_send_command(FilterGraph *fg, double time, const char *target,
  620. const char *command, const char *arg, int all_filters);
  621. int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch);
  622. void enc_stats_write(OutputStream *ost, EncStats *es,
  623. const AVFrame *frame, const AVPacket *pkt,
  624. uint64_t frame_num);
  625. HWDevice *hw_device_get_by_name(const char *name);
  626. HWDevice *hw_device_get_by_type(enum AVHWDeviceType type);
  627. int hw_device_init_from_string(const char *arg, HWDevice **dev);
  628. int hw_device_init_from_type(enum AVHWDeviceType type,
  629. const char *device,
  630. HWDevice **dev_out);
  631. void hw_device_free_all(void);
  632. /**
  633. * Get a hardware device to be used with this filtergraph.
  634. * The returned reference is owned by the callee, the caller
  635. * must ref it explicitly for long-term use.
  636. */
  637. AVBufferRef *hw_device_for_filter(void);
  638. /**
  639. * Create a standalone decoder.
  640. */
  641. int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch);
  642. /**
  643. * @param dec_opts Dictionary filled with decoder options. Its ownership
  644. * is transferred to the decoder.
  645. * @param param_out If non-NULL, media properties after opening the decoder
  646. * are written here.
  647. *
  648. * @retval ">=0" non-negative scheduler index on success
  649. * @retval "<0" an error code on failure
  650. */
  651. int dec_init(Decoder **pdec, Scheduler *sch,
  652. AVDictionary **dec_opts, const DecoderOpts *o,
  653. AVFrame *param_out);
  654. void dec_free(Decoder **pdec);
  655. /*
  656. * Called by filters to connect decoder's output to given filtergraph input.
  657. *
  658. * @param opts filtergraph input options, to be filled by this function
  659. */
  660. int dec_filter_add(Decoder *dec, InputFilter *ifilter, InputFilterOptions *opts,
  661. const ViewSpecifier *vs, SchedulerNode *src);
  662. /*
  663. * For multiview video, request output of the view(s) determined by vs.
  664. * May be called multiple times.
  665. *
  666. * If this function is never called, only the base view is output. If it is
  667. * called at least once, only the views requested are output.
  668. *
  669. * @param src scheduler node from which the frames corresponding vs
  670. * will originate
  671. */
  672. int dec_request_view(Decoder *dec, const ViewSpecifier *vs,
  673. SchedulerNode *src);
  674. int enc_alloc(Encoder **penc, const AVCodec *codec,
  675. Scheduler *sch, unsigned sch_idx, void *log_parent);
  676. void enc_free(Encoder **penc);
  677. int enc_open(void *opaque, const AVFrame *frame);
  678. int enc_loopback(Encoder *enc);
  679. /*
  680. * Initialize muxing state for the given stream, should be called
  681. * after the codec/streamcopy setup has been done.
  682. *
  683. * Open the muxer once all the streams have been initialized.
  684. */
  685. int of_stream_init(OutputFile *of, OutputStream *ost,
  686. const AVCodecContext *enc_ctx);
  687. int of_write_trailer(OutputFile *of);
  688. int of_open(const OptionsContext *o, const char *filename, Scheduler *sch);
  689. void of_free(OutputFile **pof);
  690. void of_enc_stats_close(void);
  691. int64_t of_filesize(OutputFile *of);
  692. int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch);
  693. void ifile_close(InputFile **f);
  694. int ist_use(InputStream *ist, int decoding_needed,
  695. const ViewSpecifier *vs, SchedulerNode *src);
  696. int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
  697. const ViewSpecifier *vs, InputFilterOptions *opts,
  698. SchedulerNode *src);
  699. /**
  700. * Find an unused input stream of given type.
  701. */
  702. InputStream *ist_find_unused(enum AVMediaType type);
  703. /* iterate over all input streams in all input files;
  704. * pass NULL to start iteration */
  705. InputStream *ist_iter(InputStream *prev);
  706. /* iterate over all output streams in all output files;
  707. * pass NULL to start iteration */
  708. OutputStream *ost_iter(OutputStream *prev);
  709. void update_benchmark(const char *fmt, ...);
  710. const char *opt_match_per_type_str(const SpecifierOptList *sol,
  711. char mediatype);
  712. void opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol,
  713. AVFormatContext *fc, AVStream *st, const char **out);
  714. void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol,
  715. AVFormatContext *fc, AVStream *st, int *out);
  716. void opt_match_per_stream_int64(void *logctx, const SpecifierOptList *sol,
  717. AVFormatContext *fc, AVStream *st, int64_t *out);
  718. void opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol,
  719. AVFormatContext *fc, AVStream *st, double *out);
  720. int view_specifier_parse(const char **pspec, ViewSpecifier *vs);
  721. int muxer_thread(void *arg);
  722. int encoder_thread(void *arg);
  723. #endif /* FFTOOLS_FFMPEG_H */