aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / avtools / avconv.h
blob0d24c71a749aa265af1f1500c9b394c73a3a204b
1 /*
2 * This file is part of Libav.
4 * Libav 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.
9 * Libav 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVCONV_H
20 #define AVCONV_H
22 #include "config.h"
24 #include <stdint.h>
25 #include <stdio.h>
27 #if HAVE_PTHREADS
28 #include <pthread.h>
29 #endif
31 #include "cmdutils.h"
33 #include "libavformat/avformat.h"
34 #include "libavformat/avio.h"
36 #include "libavcodec/avcodec.h"
38 #include "libavfilter/avfilter.h"
40 #include "libavutil/avutil.h"
41 #include "libavutil/dict.h"
42 #include "libavutil/fifo.h"
43 #include "libavutil/hwcontext.h"
44 #include "libavutil/pixfmt.h"
45 #include "libavutil/rational.h"
47 #define VSYNC_AUTO -1
48 #define VSYNC_PASSTHROUGH 0
49 #define VSYNC_CFR 1
50 #define VSYNC_VFR 2
52 enum HWAccelID {
53 HWACCEL_NONE = 0,
54 HWACCEL_AUTO,
55 HWACCEL_GENERIC,
56 HWACCEL_VDA,
57 HWACCEL_QSV,
60 typedef struct HWAccel {
61 const char *name;
62 int (*init)(AVCodecContext *s);
63 enum HWAccelID id;
64 enum AVPixelFormat pix_fmt;
65 } HWAccel;
67 typedef struct HWDevice {
68 char *name;
69 enum AVHWDeviceType type;
70 AVBufferRef *device_ref;
71 } HWDevice;
73 /* select an input stream for an output stream */
74 typedef struct StreamMap {
75 int disabled; /* 1 is this mapping is disabled by a negative map */
76 int file_index;
77 int stream_index;
78 int sync_file_index;
79 int sync_stream_index;
80 char *linklabel; /* name of an output link, for mapping lavfi outputs */
81 } StreamMap;
83 /* select an input file for an output file */
84 typedef struct MetadataMap {
85 int file; // file index
86 char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
87 int index; // stream/chapter/program number
88 } MetadataMap;
90 typedef struct OptionsContext {
91 OptionGroup *g;
93 /* input/output options */
94 int64_t start_time;
95 const char *format;
97 SpecifierOpt *codec_names;
98 int nb_codec_names;
99 SpecifierOpt *audio_channels;
100 int nb_audio_channels;
101 SpecifierOpt *audio_sample_rate;
102 int nb_audio_sample_rate;
103 SpecifierOpt *frame_rates;
104 int nb_frame_rates;
105 SpecifierOpt *frame_sizes;
106 int nb_frame_sizes;
107 SpecifierOpt *frame_pix_fmts;
108 int nb_frame_pix_fmts;
110 /* input options */
111 int64_t input_ts_offset;
112 int loop;
113 int rate_emu;
114 int accurate_seek;
116 SpecifierOpt *ts_scale;
117 int nb_ts_scale;
118 SpecifierOpt *dump_attachment;
119 int nb_dump_attachment;
120 SpecifierOpt *hwaccels;
121 int nb_hwaccels;
122 SpecifierOpt *hwaccel_devices;
123 int nb_hwaccel_devices;
124 SpecifierOpt *hwaccel_output_formats;
125 int nb_hwaccel_output_formats;
126 SpecifierOpt *autorotate;
127 int nb_autorotate;
129 /* output options */
130 StreamMap *stream_maps;
131 int nb_stream_maps;
132 /* first item specifies output metadata, second is input */
133 MetadataMap (*meta_data_maps)[2];
134 int nb_meta_data_maps;
135 int metadata_global_manual;
136 int metadata_streams_manual;
137 int metadata_chapters_manual;
138 const char **attachments;
139 int nb_attachments;
141 int chapters_input_file;
143 int64_t recording_time;
144 uint64_t limit_filesize;
145 float mux_preload;
146 float mux_max_delay;
147 int shortest;
149 int video_disable;
150 int audio_disable;
151 int subtitle_disable;
152 int data_disable;
154 /* indexed by output file stream index */
155 int *streamid_map;
156 int nb_streamid_map;
158 SpecifierOpt *metadata;
159 int nb_metadata;
160 SpecifierOpt *max_frames;
161 int nb_max_frames;
162 SpecifierOpt *bitstream_filters;
163 int nb_bitstream_filters;
164 SpecifierOpt *codec_tags;
165 int nb_codec_tags;
166 SpecifierOpt *sample_fmts;
167 int nb_sample_fmts;
168 SpecifierOpt *qscale;
169 int nb_qscale;
170 SpecifierOpt *bitrates;
171 int nb_bitrates;
172 SpecifierOpt *forced_key_frames;
173 int nb_forced_key_frames;
174 SpecifierOpt *force_fps;
175 int nb_force_fps;
176 SpecifierOpt *frame_aspect_ratios;
177 int nb_frame_aspect_ratios;
178 SpecifierOpt *rc_overrides;
179 int nb_rc_overrides;
180 SpecifierOpt *intra_matrices;
181 int nb_intra_matrices;
182 SpecifierOpt *inter_matrices;
183 int nb_inter_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 *filters;
193 int nb_filters;
194 SpecifierOpt *filter_scripts;
195 int nb_filter_scripts;
196 SpecifierOpt *pass;
197 int nb_pass;
198 SpecifierOpt *passlogfiles;
199 int nb_passlogfiles;
200 SpecifierOpt *max_muxing_queue_size;
201 int nb_max_muxing_queue_size;
202 } OptionsContext;
204 typedef struct InputFilter {
205 AVFilterContext *filter;
206 struct InputStream *ist;
207 struct FilterGraph *graph;
208 uint8_t *name;
210 AVFifoBuffer *frame_queue;
212 // parameters configured for this input
213 int format;
215 int width, height;
216 AVRational sample_aspect_ratio;
218 int sample_rate;
219 uint64_t channel_layout;
221 AVBufferRef *hw_frames_ctx;
223 int eof;
224 } InputFilter;
226 typedef struct OutputFilter {
227 AVFilterContext *filter;
228 struct OutputStream *ost;
229 struct FilterGraph *graph;
230 uint8_t *name;
232 /* temporary storage until stream maps are processed */
233 AVFilterInOut *out_tmp;
234 enum AVMediaType type;
236 /* desired output stream properties */
237 int width, height;
238 AVRational frame_rate;
239 int format;
240 int sample_rate;
241 uint64_t channel_layout;
243 // those are only set if no format is specified and the encoder gives us multiple options
244 int *formats;
245 uint64_t *channel_layouts;
246 int *sample_rates;
247 } OutputFilter;
249 typedef struct FilterGraph {
250 int index;
251 const char *graph_desc;
253 AVFilterGraph *graph;
255 InputFilter **inputs;
256 int nb_inputs;
257 OutputFilter **outputs;
258 int nb_outputs;
259 } FilterGraph;
261 typedef struct InputStream {
262 int file_index;
263 AVStream *st;
264 int discard; /* true if stream data should be discarded */
265 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
266 AVCodecContext *dec_ctx;
267 AVCodec *dec;
268 AVFrame *decoded_frame;
269 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
271 int64_t start; /* time when read started */
272 /* predicted dts of the next packet read for this stream or (when there are
273 * several frames in a packet) of the next frame in current packet */
274 int64_t next_dts;
275 /* dts of the last packet read for this stream */
276 int64_t last_dts;
277 int64_t min_pts; /* pts with the smallest value in a current stream */
278 int64_t max_pts; /* pts with the higher value in a current stream */
280 // when forcing constant input framerate through -r,
281 // this contains the pts that will be given to the next decoded frame
282 int64_t cfr_next_pts;
284 int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
285 PtsCorrectionContext pts_ctx;
286 double ts_scale;
287 AVDictionary *decoder_opts;
288 AVRational framerate; /* framerate forced with -r */
290 int autorotate;
292 /* decoded data from this stream goes into all those filters
293 * currently video and audio only */
294 InputFilter **filters;
295 int nb_filters;
297 /* hwaccel options */
298 enum HWAccelID hwaccel_id;
299 enum AVHWDeviceType hwaccel_device_type;
300 char *hwaccel_device;
301 enum AVPixelFormat hwaccel_output_format;
303 /* hwaccel context */
304 void *hwaccel_ctx;
305 void (*hwaccel_uninit)(AVCodecContext *s);
306 int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
307 int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
308 enum AVPixelFormat hwaccel_pix_fmt;
309 enum AVPixelFormat hwaccel_retrieved_pix_fmt;
310 AVBufferRef *hw_frames_ctx;
312 /* stats */
313 // combined size of all the packets read
314 uint64_t data_size;
315 /* number of packets successfully read for this stream */
316 uint64_t nb_packets;
317 // number of frames/samples retrieved from the decoder
318 uint64_t frames_decoded;
319 uint64_t samples_decoded;
320 } InputStream;
322 typedef struct InputFile {
323 AVFormatContext *ctx;
324 int eof_reached; /* true if eof reached */
325 int eagain; /* true if last read attempt returned EAGAIN */
326 int ist_index; /* index of first stream in ist_table */
327 int loop; /* set number of times input stream should be looped */
328 int64_t duration; /* actual duration of the longest stream in a file
329 at the moment when looping happens */
330 AVRational time_base; /* time base of the duration */
331 int64_t ts_offset;
332 int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
333 int64_t recording_time;
334 int nb_streams; /* number of stream that avconv is aware of; may be different
335 from ctx.nb_streams if new streams appear during av_read_frame() */
336 int rate_emu;
337 int accurate_seek;
339 #if HAVE_PTHREADS
340 pthread_t thread; /* thread reading from this file */
341 int finished; /* the thread has exited */
342 int joined; /* the thread has been joined */
343 pthread_mutex_t fifo_lock; /* lock for access to fifo */
344 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
345 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
346 #endif
347 } InputFile;
349 typedef struct OutputStream {
350 int file_index; /* file index */
351 int index; /* stream index in the output file */
352 int source_index; /* InputStream index */
353 AVStream *st; /* stream in the output file */
354 int encoding_needed; /* true if encoding needed for this stream */
355 int frame_number;
356 /* input pts and corresponding output pts
357 for A/V sync */
358 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
359 struct InputStream *sync_ist; /* input stream to sync against */
360 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
361 /* pts of the first frame encoded for this stream, used for limiting
362 * recording time */
363 int64_t first_pts;
364 /* dts of the last packet sent to the muxer */
365 int64_t last_mux_dts;
366 // the timebase of the packets sent to the muxer
367 AVRational mux_timebase;
369 int nb_bitstream_filters;
370 AVBSFContext **bsf_ctx;
372 AVCodecContext *enc_ctx;
373 AVCodec *enc;
374 int64_t max_frames;
375 AVFrame *filtered_frame;
377 void *hwaccel_ctx;
379 /* video only */
380 AVRational frame_rate;
381 int force_fps;
382 int top_field_first;
384 float frame_aspect_ratio;
386 /* forced key frames */
387 int64_t *forced_kf_pts;
388 int forced_kf_count;
389 int forced_kf_index;
390 char *forced_keyframes;
392 // the bitrate to send to the muxer for streamcopy
393 int bitrate_override;
395 char *logfile_prefix;
396 FILE *logfile;
398 OutputFilter *filter;
399 char *avfilter;
401 int64_t sws_flags;
402 AVDictionary *encoder_opts;
403 AVDictionary *resample_opts;
404 int finished; /* no more packets should be written for this stream */
405 int stream_copy;
407 // init_output_stream() has been called for this stream
408 // The encoder and the bistream filters have been initialized and the stream
409 // parameters are set in the AVStream.
410 int initialized;
412 const char *attachment_filename;
413 int copy_initial_nonkeyframes;
415 enum AVPixelFormat pix_fmts[2];
417 AVCodecParserContext *parser;
418 AVCodecContext *parser_avctx;
420 /* stats */
421 // combined size of all the packets written
422 uint64_t data_size;
423 // number of packets send to the muxer
424 uint64_t packets_written;
425 // number of frames/samples sent to the encoder
426 uint64_t frames_encoded;
427 uint64_t samples_encoded;
429 /* packet quality factor */
430 int quality;
432 int max_muxing_queue_size;
434 /* the packets are buffered here until the muxer is ready to be initialized */
435 AVFifoBuffer *muxing_queue;
436 } OutputStream;
438 typedef struct OutputFile {
439 AVFormatContext *ctx;
440 AVDictionary *opts;
441 int ost_index; /* index of the first stream in output_streams */
442 int64_t recording_time; /* desired length of the resulting file in microseconds */
443 int64_t start_time; /* start time in microseconds */
444 uint64_t limit_filesize;
446 int shortest;
448 int header_written;
449 } OutputFile;
451 extern InputStream **input_streams;
452 extern int nb_input_streams;
453 extern InputFile **input_files;
454 extern int nb_input_files;
456 extern OutputStream **output_streams;
457 extern int nb_output_streams;
458 extern OutputFile **output_files;
459 extern int nb_output_files;
461 extern FilterGraph **filtergraphs;
462 extern int nb_filtergraphs;
464 extern char *vstats_filename;
466 extern float audio_drift_threshold;
467 extern float dts_delta_threshold;
469 extern int audio_volume;
470 extern int audio_sync_method;
471 extern int video_sync_method;
472 extern int do_benchmark;
473 extern int do_deinterlace;
474 extern int do_hex_dump;
475 extern int do_pkt_dump;
476 extern int copy_ts;
477 extern int copy_tb;
478 extern int exit_on_error;
479 extern int print_stats;
480 extern int qp_hist;
482 extern const AVIOInterruptCB int_cb;
484 extern const OptionDef options[];
486 extern const HWAccel hwaccels[];
487 extern int hwaccel_lax_profile_check;
488 extern AVBufferRef *hw_device_ctx;
489 extern HWDevice *filter_hw_device;
491 void reset_options(OptionsContext *o);
492 void show_usage(void);
494 void opt_output_file(void *optctx, const char *filename);
496 void assert_avoptions(AVDictionary *m);
498 int guess_input_channel_layout(InputStream *ist);
500 int configure_filtergraph(FilterGraph *fg);
501 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
502 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
503 int filtergraph_is_simple(FilterGraph *fg);
504 int init_simple_filtergraph(InputStream *ist, OutputStream *ost);
505 int init_complex_filtergraph(FilterGraph *fg);
507 int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
509 int avconv_parse_options(int argc, char **argv);
511 int dxva2_init(AVCodecContext *s);
512 int vda_init(AVCodecContext *s);
513 int qsv_init(AVCodecContext *s);
514 int qsv_transcode_init(OutputStream *ost);
516 HWDevice *hw_device_get_by_name(const char *name);
517 int hw_device_init_from_string(const char *arg, HWDevice **dev);
518 void hw_device_free_all(void);
520 int hw_device_setup_for_decode(InputStream *ist);
521 int hw_device_setup_for_encode(OutputStream *ost);
523 int hwaccel_decode_init(AVCodecContext *avctx);
525 #endif /* AVCONV_H */