ffmpeg.h 24 KB

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