ffmpeg.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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 "sync_queue.h"
  27. #include "libavformat/avformat.h"
  28. #include "libavformat/avio.h"
  29. #include "libavcodec/avcodec.h"
  30. #include "libavcodec/bsf.h"
  31. #include "libavfilter/avfilter.h"
  32. #include "libavutil/avutil.h"
  33. #include "libavutil/dict.h"
  34. #include "libavutil/eval.h"
  35. #include "libavutil/fifo.h"
  36. #include "libavutil/hwcontext.h"
  37. #include "libavutil/pixfmt.h"
  38. #include "libavutil/rational.h"
  39. #include "libavutil/thread.h"
  40. #include "libavutil/threadmessage.h"
  41. #include "libswresample/swresample.h"
  42. // deprecated features
  43. #define FFMPEG_OPT_PSNR 1
  44. #define FFMPEG_OPT_MAP_CHANNEL 1
  45. #define FFMPEG_OPT_MAP_SYNC 1
  46. enum VideoSyncMethod {
  47. VSYNC_AUTO = -1,
  48. VSYNC_PASSTHROUGH,
  49. VSYNC_CFR,
  50. VSYNC_VFR,
  51. VSYNC_VSCFR,
  52. VSYNC_DROP,
  53. };
  54. #define MAX_STREAMS 1024 /* arbitrary sanity check value */
  55. enum HWAccelID {
  56. HWACCEL_NONE = 0,
  57. HWACCEL_AUTO,
  58. HWACCEL_GENERIC,
  59. };
  60. typedef struct HWDevice {
  61. const char *name;
  62. enum AVHWDeviceType type;
  63. AVBufferRef *device_ref;
  64. } HWDevice;
  65. /* select an input stream for an output stream */
  66. typedef struct StreamMap {
  67. int disabled; /* 1 is this mapping is disabled by a negative map */
  68. int file_index;
  69. int stream_index;
  70. char *linklabel; /* name of an output link, for mapping lavfi outputs */
  71. } StreamMap;
  72. #if FFMPEG_OPT_MAP_CHANNEL
  73. typedef struct {
  74. int file_idx, stream_idx, channel_idx; // input
  75. int ofile_idx, ostream_idx; // output
  76. } AudioChannelMap;
  77. #endif
  78. typedef struct OptionsContext {
  79. OptionGroup *g;
  80. /* input/output options */
  81. int64_t start_time;
  82. int64_t start_time_eof;
  83. int seek_timestamp;
  84. const char *format;
  85. SpecifierOpt *codec_names;
  86. int nb_codec_names;
  87. SpecifierOpt *audio_ch_layouts;
  88. int nb_audio_ch_layouts;
  89. SpecifierOpt *audio_channels;
  90. int nb_audio_channels;
  91. SpecifierOpt *audio_sample_rate;
  92. int nb_audio_sample_rate;
  93. SpecifierOpt *frame_rates;
  94. int nb_frame_rates;
  95. SpecifierOpt *max_frame_rates;
  96. int nb_max_frame_rates;
  97. SpecifierOpt *frame_sizes;
  98. int nb_frame_sizes;
  99. SpecifierOpt *frame_pix_fmts;
  100. int nb_frame_pix_fmts;
  101. /* input options */
  102. int64_t input_ts_offset;
  103. int loop;
  104. int rate_emu;
  105. float readrate;
  106. int accurate_seek;
  107. int thread_queue_size;
  108. int input_sync_ref;
  109. int find_stream_info;
  110. SpecifierOpt *ts_scale;
  111. int nb_ts_scale;
  112. SpecifierOpt *dump_attachment;
  113. int nb_dump_attachment;
  114. SpecifierOpt *hwaccels;
  115. int nb_hwaccels;
  116. SpecifierOpt *hwaccel_devices;
  117. int nb_hwaccel_devices;
  118. SpecifierOpt *hwaccel_output_formats;
  119. int nb_hwaccel_output_formats;
  120. SpecifierOpt *autorotate;
  121. int nb_autorotate;
  122. /* output options */
  123. StreamMap *stream_maps;
  124. int nb_stream_maps;
  125. #if FFMPEG_OPT_MAP_CHANNEL
  126. AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */
  127. int nb_audio_channel_maps; /* number of (valid) -map_channel settings */
  128. #endif
  129. int metadata_global_manual;
  130. int metadata_streams_manual;
  131. int metadata_chapters_manual;
  132. const char **attachments;
  133. int nb_attachments;
  134. int chapters_input_file;
  135. int64_t recording_time;
  136. int64_t stop_time;
  137. int64_t limit_filesize;
  138. float mux_preload;
  139. float mux_max_delay;
  140. float shortest_buf_duration;
  141. int shortest;
  142. int bitexact;
  143. int video_disable;
  144. int audio_disable;
  145. int subtitle_disable;
  146. int data_disable;
  147. /* indexed by output file stream index */
  148. int *streamid_map;
  149. int nb_streamid_map;
  150. SpecifierOpt *metadata;
  151. int nb_metadata;
  152. SpecifierOpt *max_frames;
  153. int nb_max_frames;
  154. SpecifierOpt *bitstream_filters;
  155. int nb_bitstream_filters;
  156. SpecifierOpt *codec_tags;
  157. int nb_codec_tags;
  158. SpecifierOpt *sample_fmts;
  159. int nb_sample_fmts;
  160. SpecifierOpt *qscale;
  161. int nb_qscale;
  162. SpecifierOpt *forced_key_frames;
  163. int nb_forced_key_frames;
  164. SpecifierOpt *fps_mode;
  165. int nb_fps_mode;
  166. SpecifierOpt *force_fps;
  167. int nb_force_fps;
  168. SpecifierOpt *frame_aspect_ratios;
  169. int nb_frame_aspect_ratios;
  170. SpecifierOpt *display_rotations;
  171. int nb_display_rotations;
  172. SpecifierOpt *display_hflips;
  173. int nb_display_hflips;
  174. SpecifierOpt *display_vflips;
  175. int nb_display_vflips;
  176. SpecifierOpt *rc_overrides;
  177. int nb_rc_overrides;
  178. SpecifierOpt *intra_matrices;
  179. int nb_intra_matrices;
  180. SpecifierOpt *inter_matrices;
  181. int nb_inter_matrices;
  182. SpecifierOpt *chroma_intra_matrices;
  183. int nb_chroma_intra_matrices;
  184. SpecifierOpt *top_field_first;
  185. int nb_top_field_first;
  186. SpecifierOpt *metadata_map;
  187. int nb_metadata_map;
  188. SpecifierOpt *presets;
  189. int nb_presets;
  190. SpecifierOpt *copy_initial_nonkeyframes;
  191. int nb_copy_initial_nonkeyframes;
  192. SpecifierOpt *copy_prior_start;
  193. int nb_copy_prior_start;
  194. SpecifierOpt *filters;
  195. int nb_filters;
  196. SpecifierOpt *filter_scripts;
  197. int nb_filter_scripts;
  198. SpecifierOpt *reinit_filters;
  199. int nb_reinit_filters;
  200. SpecifierOpt *fix_sub_duration;
  201. int nb_fix_sub_duration;
  202. SpecifierOpt *canvas_sizes;
  203. int nb_canvas_sizes;
  204. SpecifierOpt *pass;
  205. int nb_pass;
  206. SpecifierOpt *passlogfiles;
  207. int nb_passlogfiles;
  208. SpecifierOpt *max_muxing_queue_size;
  209. int nb_max_muxing_queue_size;
  210. SpecifierOpt *muxing_queue_data_threshold;
  211. int nb_muxing_queue_data_threshold;
  212. SpecifierOpt *guess_layout_max;
  213. int nb_guess_layout_max;
  214. SpecifierOpt *apad;
  215. int nb_apad;
  216. SpecifierOpt *discard;
  217. int nb_discard;
  218. SpecifierOpt *disposition;
  219. int nb_disposition;
  220. SpecifierOpt *program;
  221. int nb_program;
  222. SpecifierOpt *time_bases;
  223. int nb_time_bases;
  224. SpecifierOpt *enc_time_bases;
  225. int nb_enc_time_bases;
  226. SpecifierOpt *autoscale;
  227. int nb_autoscale;
  228. SpecifierOpt *bits_per_raw_sample;
  229. int nb_bits_per_raw_sample;
  230. } OptionsContext;
  231. typedef struct InputFilter {
  232. AVFilterContext *filter;
  233. struct InputStream *ist;
  234. struct FilterGraph *graph;
  235. uint8_t *name;
  236. enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video
  237. AVFifo *frame_queue;
  238. // parameters configured for this input
  239. int format;
  240. int width, height;
  241. AVRational sample_aspect_ratio;
  242. int sample_rate;
  243. AVChannelLayout ch_layout;
  244. AVBufferRef *hw_frames_ctx;
  245. int32_t *displaymatrix;
  246. int eof;
  247. } InputFilter;
  248. typedef struct OutputFilter {
  249. AVFilterContext *filter;
  250. struct OutputStream *ost;
  251. struct FilterGraph *graph;
  252. uint8_t *name;
  253. /* temporary storage until stream maps are processed */
  254. AVFilterInOut *out_tmp;
  255. enum AVMediaType type;
  256. /* desired output stream properties */
  257. int width, height;
  258. AVRational frame_rate;
  259. int format;
  260. int sample_rate;
  261. AVChannelLayout ch_layout;
  262. // those are only set if no format is specified and the encoder gives us multiple options
  263. // They point directly to the relevant lists of the encoder.
  264. const int *formats;
  265. const AVChannelLayout *ch_layouts;
  266. const int *sample_rates;
  267. } OutputFilter;
  268. typedef struct FilterGraph {
  269. int index;
  270. const char *graph_desc;
  271. AVFilterGraph *graph;
  272. int reconfiguration;
  273. // true when the filtergraph contains only meta filters
  274. // that do not modify the frame data
  275. int is_meta;
  276. InputFilter **inputs;
  277. int nb_inputs;
  278. OutputFilter **outputs;
  279. int nb_outputs;
  280. } FilterGraph;
  281. typedef struct InputStream {
  282. int file_index;
  283. AVStream *st;
  284. int discard; /* true if stream data should be discarded */
  285. int user_set_discard;
  286. int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
  287. #define DECODING_FOR_OST 1
  288. #define DECODING_FOR_FILTER 2
  289. int processing_needed; /* non zero if the packets must be processed */
  290. /**
  291. * Codec parameters - to be used by the decoding/streamcopy code.
  292. * st->codecpar should not be accessed, because it may be modified
  293. * concurrently by the demuxing thread.
  294. */
  295. AVCodecParameters *par;
  296. AVCodecContext *dec_ctx;
  297. const AVCodec *dec;
  298. AVFrame *decoded_frame;
  299. AVPacket *pkt;
  300. AVRational framerate_guessed;
  301. int64_t prev_pkt_pts;
  302. int64_t start; /* time when read started */
  303. /* predicted dts of the next packet read for this stream or (when there are
  304. * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
  305. int64_t next_dts;
  306. int64_t first_dts; ///< dts of the first packet read for this stream (in AV_TIME_BASE units)
  307. int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
  308. int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
  309. int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
  310. int wrap_correction_done;
  311. // the value of AVCodecParserContext.repeat_pict from the AVStream parser
  312. // for the last packet returned from ifile_get_packet()
  313. // -1 if unknown
  314. // FIXME: this is a hack, the avstream parser should not be used
  315. int last_pkt_repeat_pict;
  316. int64_t filter_in_rescale_delta_last;
  317. int64_t min_pts; /* pts with the smallest value in a current stream */
  318. int64_t max_pts; /* pts with the higher value in a current stream */
  319. // when forcing constant input framerate through -r,
  320. // this contains the pts that will be given to the next decoded frame
  321. int64_t cfr_next_pts;
  322. int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
  323. double ts_scale;
  324. int saw_first_ts;
  325. AVDictionary *decoder_opts;
  326. AVRational framerate; /* framerate forced with -r */
  327. int top_field_first;
  328. int guess_layout_max;
  329. int autorotate;
  330. int fix_sub_duration;
  331. struct { /* previous decoded subtitle and related variables */
  332. int got_output;
  333. int ret;
  334. AVSubtitle subtitle;
  335. } prev_sub;
  336. struct sub2video {
  337. int64_t last_pts;
  338. int64_t end_pts;
  339. AVFifo *sub_queue; ///< queue of AVSubtitle* before filter init
  340. AVFrame *frame;
  341. int w, h;
  342. unsigned int initialize; ///< marks if sub2video_update should force an initialization
  343. } sub2video;
  344. /* decoded data from this stream goes into all those filters
  345. * currently video and audio only */
  346. InputFilter **filters;
  347. int nb_filters;
  348. int reinit_filters;
  349. /* hwaccel options */
  350. enum HWAccelID hwaccel_id;
  351. enum AVHWDeviceType hwaccel_device_type;
  352. char *hwaccel_device;
  353. enum AVPixelFormat hwaccel_output_format;
  354. int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
  355. enum AVPixelFormat hwaccel_pix_fmt;
  356. /* stats */
  357. // combined size of all the packets read
  358. uint64_t data_size;
  359. /* number of packets successfully read for this stream */
  360. uint64_t nb_packets;
  361. // number of frames/samples retrieved from the decoder
  362. uint64_t frames_decoded;
  363. uint64_t samples_decoded;
  364. int64_t *dts_buffer;
  365. int nb_dts_buffer;
  366. int got_output;
  367. } InputStream;
  368. typedef struct LastFrameDuration {
  369. int stream_idx;
  370. int64_t duration;
  371. } LastFrameDuration;
  372. typedef struct InputFile {
  373. int index;
  374. AVFormatContext *ctx;
  375. int eof_reached; /* true if eof reached */
  376. int eagain; /* true if last read attempt returned EAGAIN */
  377. int ist_index; /* index of first stream in input_streams */
  378. int loop; /* set number of times input stream should be looped */
  379. int64_t duration; /* actual duration of the longest stream in a file
  380. at the moment when looping happens */
  381. AVRational time_base; /* time base of the duration */
  382. int64_t input_ts_offset;
  383. int input_sync_ref;
  384. int64_t ts_offset;
  385. /**
  386. * Extra timestamp offset added by discontinuity handling.
  387. */
  388. int64_t ts_offset_discont;
  389. int64_t last_ts;
  390. int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
  391. int64_t recording_time;
  392. int nb_streams; /* number of stream that ffmpeg is aware of; may be different
  393. from ctx.nb_streams if new streams appear during av_read_frame() */
  394. int nb_streams_warn; /* number of streams that the user was warned of */
  395. int rate_emu;
  396. float readrate;
  397. int accurate_seek;
  398. AVThreadMessageQueue *in_thread_queue;
  399. pthread_t thread; /* thread reading from this file */
  400. int non_blocking; /* reading packets from the thread should not block */
  401. int thread_queue_size; /* maximum number of queued packets */
  402. /* when looping the input file, this queue is used by decoders to report
  403. * the last frame duration back to the demuxer thread */
  404. AVThreadMessageQueue *audio_duration_queue;
  405. int audio_duration_queue_size;
  406. } InputFile;
  407. enum forced_keyframes_const {
  408. FKF_N,
  409. FKF_N_FORCED,
  410. FKF_PREV_FORCED_N,
  411. FKF_PREV_FORCED_T,
  412. FKF_T,
  413. FKF_NB
  414. };
  415. #define ABORT_ON_FLAG_EMPTY_OUTPUT (1 << 0)
  416. #define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM (1 << 1)
  417. extern const char *const forced_keyframes_const_names[];
  418. typedef enum {
  419. ENCODER_FINISHED = 1,
  420. MUXER_FINISHED = 2,
  421. } OSTFinished ;
  422. typedef struct OutputStream {
  423. int file_index; /* file index */
  424. int index; /* stream index in the output file */
  425. int source_index; /* InputStream index */
  426. AVStream *st; /* stream in the output file */
  427. /* number of frames emitted by the video-encoding sync code */
  428. int64_t vsync_frame_number;
  429. /* predicted pts of the next frame to be encoded
  430. * audio/video encoding only */
  431. int64_t next_pts;
  432. /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */
  433. int64_t last_mux_dts;
  434. /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
  435. int64_t last_filter_pts;
  436. // timestamp from which the streamcopied streams should start,
  437. // in AV_TIME_BASE_Q;
  438. // everything before it should be discarded
  439. int64_t ts_copy_start;
  440. // the timebase of the packets sent to the muxer
  441. AVRational mux_timebase;
  442. AVRational enc_timebase;
  443. AVCodecContext *enc_ctx;
  444. int64_t max_frames;
  445. AVFrame *filtered_frame;
  446. AVFrame *last_frame;
  447. AVFrame *sq_frame;
  448. AVPacket *pkt;
  449. int64_t last_dropped;
  450. int64_t last_nb0_frames[3];
  451. /* video only */
  452. AVRational frame_rate;
  453. AVRational max_frame_rate;
  454. enum VideoSyncMethod vsync_method;
  455. int is_cfr;
  456. int force_fps;
  457. int top_field_first;
  458. int rotate_overridden;
  459. int autoscale;
  460. int bitexact;
  461. int bits_per_raw_sample;
  462. double rotate_override_value;
  463. AVRational frame_aspect_ratio;
  464. /* forced key frames */
  465. int64_t forced_kf_ref_pts;
  466. int64_t *forced_kf_pts;
  467. int forced_kf_count;
  468. int forced_kf_index;
  469. char *forced_keyframes;
  470. AVExpr *forced_keyframes_pexpr;
  471. double forced_keyframes_expr_const_values[FKF_NB];
  472. int dropped_keyframe;
  473. /* audio only */
  474. #if FFMPEG_OPT_MAP_CHANNEL
  475. int *audio_channels_map; /* list of the channels id to pick from the source stream */
  476. int audio_channels_mapped; /* number of channels in audio_channels_map */
  477. #endif
  478. char *logfile_prefix;
  479. FILE *logfile;
  480. OutputFilter *filter;
  481. char *avfilter;
  482. char *filters; ///< filtergraph associated to the -filter option
  483. char *filters_script; ///< filtergraph script associated to the -filter_script option
  484. AVDictionary *encoder_opts;
  485. AVDictionary *sws_dict;
  486. AVDictionary *swr_opts;
  487. char *apad;
  488. OSTFinished finished; /* no more packets should be written for this stream */
  489. int unavailable; /* true if the steram is unavailable (possibly temporarily) */
  490. // init_output_stream() has been called for this stream
  491. // The encoder and the bitstream filters have been initialized and the stream
  492. // parameters are set in the AVStream.
  493. int initialized;
  494. int inputs_done;
  495. const char *attachment_filename;
  496. int streamcopy_started;
  497. int copy_initial_nonkeyframes;
  498. int copy_prior_start;
  499. char *disposition;
  500. int keep_pix_fmt;
  501. /* stats */
  502. // combined size of all the packets sent to the muxer
  503. uint64_t data_size_mux;
  504. // combined size of all the packets received from the encoder
  505. uint64_t data_size_enc;
  506. // number of packets send to the muxer
  507. atomic_uint_least64_t packets_written;
  508. // number of frames/samples sent to the encoder
  509. uint64_t frames_encoded;
  510. uint64_t samples_encoded;
  511. // number of packets received from the encoder
  512. uint64_t packets_encoded;
  513. /* packet quality factor */
  514. int quality;
  515. /* packet picture type */
  516. int pict_type;
  517. /* frame encode sum of squared error values */
  518. int64_t error[4];
  519. int sq_idx_encode;
  520. int sq_idx_mux;
  521. } OutputStream;
  522. typedef struct OutputFile {
  523. int index;
  524. const AVOutputFormat *format;
  525. const char *url;
  526. OutputStream **streams;
  527. int nb_streams;
  528. SyncQueue *sq_encode;
  529. int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
  530. int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
  531. int shortest;
  532. int bitexact;
  533. } OutputFile;
  534. extern InputStream **input_streams;
  535. extern int nb_input_streams;
  536. extern InputFile **input_files;
  537. extern int nb_input_files;
  538. extern OutputFile **output_files;
  539. extern int nb_output_files;
  540. extern FilterGraph **filtergraphs;
  541. extern int nb_filtergraphs;
  542. extern char *vstats_filename;
  543. extern char *sdp_filename;
  544. extern float audio_drift_threshold;
  545. extern float dts_delta_threshold;
  546. extern float dts_error_threshold;
  547. extern enum VideoSyncMethod video_sync_method;
  548. extern float frame_drop_threshold;
  549. extern int do_benchmark;
  550. extern int do_benchmark_all;
  551. extern int do_hex_dump;
  552. extern int do_pkt_dump;
  553. extern int copy_ts;
  554. extern int start_at_zero;
  555. extern int copy_tb;
  556. extern int debug_ts;
  557. extern int exit_on_error;
  558. extern int abort_on_flags;
  559. extern int print_stats;
  560. extern int64_t stats_period;
  561. extern int qp_hist;
  562. extern int stdin_interaction;
  563. extern AVIOContext *progress_avio;
  564. extern float max_error_rate;
  565. extern char *filter_nbthreads;
  566. extern int filter_complex_nbthreads;
  567. extern int vstats_version;
  568. extern int auto_conversion_filters;
  569. extern const AVIOInterruptCB int_cb;
  570. extern const OptionDef options[];
  571. extern HWDevice *filter_hw_device;
  572. extern unsigned nb_output_dumped;
  573. extern int main_return_code;
  574. extern int input_stream_potentially_available;
  575. extern int ignore_unknown_streams;
  576. extern int copy_unknown_streams;
  577. #if FFMPEG_OPT_PSNR
  578. extern int do_psnr;
  579. #endif
  580. void term_init(void);
  581. void term_exit(void);
  582. void show_usage(void);
  583. void remove_avoptions(AVDictionary **a, AVDictionary *b);
  584. void assert_avoptions(AVDictionary *m);
  585. void assert_file_overwrite(const char *filename);
  586. char *read_file(const char *filename);
  587. AVDictionary *strip_specifiers(AVDictionary *dict);
  588. const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder);
  589. int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
  590. int configure_filtergraph(FilterGraph *fg);
  591. void check_filter_outputs(void);
  592. int filtergraph_is_simple(FilterGraph *fg);
  593. int init_simple_filtergraph(InputStream *ist, OutputStream *ost);
  594. int init_complex_filtergraph(FilterGraph *fg);
  595. void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub);
  596. int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
  597. int ffmpeg_parse_options(int argc, char **argv);
  598. HWDevice *hw_device_get_by_name(const char *name);
  599. int hw_device_init_from_string(const char *arg, HWDevice **dev);
  600. void hw_device_free_all(void);
  601. int hw_device_setup_for_decode(InputStream *ist);
  602. int hw_device_setup_for_encode(OutputStream *ost);
  603. int hw_device_setup_for_filter(FilterGraph *fg);
  604. int hwaccel_decode_init(AVCodecContext *avctx);
  605. /*
  606. * Initialize muxing state for the given stream, should be called
  607. * after the codec/streamcopy setup has been done.
  608. *
  609. * Open the muxer once all the streams have been initialized.
  610. */
  611. int of_stream_init(OutputFile *of, OutputStream *ost);
  612. int of_write_trailer(OutputFile *of);
  613. int of_open(OptionsContext *o, const char *filename);
  614. void of_close(OutputFile **pof);
  615. /*
  616. * Send a single packet to the output, applying any bitstream filters
  617. * associated with the output stream. This may result in any number
  618. * of packets actually being written, depending on what bitstream
  619. * filters are applied. The supplied packet is consumed and will be
  620. * blank (as if newly-allocated) when this function returns.
  621. *
  622. * If eof is set, instead indicate EOF to all bitstream filters and
  623. * therefore flush any delayed packets to the output. A blank packet
  624. * must be supplied in this case.
  625. */
  626. void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof);
  627. int64_t of_filesize(OutputFile *of);
  628. AVChapter * const *
  629. of_get_chapters(OutputFile *of, unsigned int *nb_chapters);
  630. /**
  631. * Get next input packet from the demuxer.
  632. *
  633. * @param pkt the packet is written here when this function returns 0
  634. * @return
  635. * - 0 when a packet has been read successfully
  636. * - 1 when stream end was reached, but the stream is looped;
  637. * caller should flush decoders and read from this demuxer again
  638. * - a negative error code on failure
  639. */
  640. int ifile_get_packet(InputFile *f, AVPacket **pkt);
  641. int init_input_threads(void);
  642. void free_input_threads(void);
  643. #define SPECIFIER_OPT_FMT_str "%s"
  644. #define SPECIFIER_OPT_FMT_i "%i"
  645. #define SPECIFIER_OPT_FMT_i64 "%"PRId64
  646. #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
  647. #define SPECIFIER_OPT_FMT_f "%f"
  648. #define SPECIFIER_OPT_FMT_dbl "%lf"
  649. #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
  650. {\
  651. char namestr[128] = "";\
  652. const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
  653. for (i = 0; opt_name_##name[i]; i++)\
  654. av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\
  655. av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
  656. namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
  657. }
  658. #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
  659. {\
  660. int i, ret, matches = 0;\
  661. SpecifierOpt *so;\
  662. for (i = 0; i < o->nb_ ## name; i++) {\
  663. char *spec = o->name[i].specifier;\
  664. if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
  665. outvar = o->name[i].u.type;\
  666. so = &o->name[i];\
  667. matches++;\
  668. } else if (ret < 0)\
  669. exit_program(1);\
  670. }\
  671. if (matches > 1)\
  672. WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
  673. }
  674. #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
  675. {\
  676. int i;\
  677. for (i = 0; i < o->nb_ ## name; i++) {\
  678. char *spec = o->name[i].specifier;\
  679. if (!strcmp(spec, mediatype))\
  680. outvar = o->name[i].u.type;\
  681. }\
  682. }
  683. extern const char * const opt_name_codec_names[];
  684. extern const char * const opt_name_codec_tags[];
  685. extern const char * const opt_name_frame_rates[];
  686. extern const char * const opt_name_top_field_first[];
  687. #endif /* FFTOOLS_FFMPEG_H */