intrax8: Remove mpegvideo dependency
[libav.git] / avconv.h
CommitLineData
f5e66827
AK
1/*
2 * This file is part of Libav.
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef AVCONV_H
20#define AVCONV_H
21
22#include "config.h"
23
24#include <stdint.h>
25#include <stdio.h>
26
27#if HAVE_PTHREADS
28#include <pthread.h>
29#endif
30
31#include "cmdutils.h"
32
33#include "libavformat/avformat.h"
34#include "libavformat/avio.h"
35
36#include "libavcodec/avcodec.h"
37
38#include "libavfilter/avfilter.h"
f5e66827
AK
39
40#include "libavutil/avutil.h"
41#include "libavutil/dict.h"
42#include "libavutil/fifo.h"
43#include "libavutil/pixfmt.h"
44#include "libavutil/rational.h"
45
46#define VSYNC_AUTO -1
47#define VSYNC_PASSTHROUGH 0
48#define VSYNC_CFR 1
49#define VSYNC_VFR 2
50
07fd0a22
AK
51enum HWAccelID {
52 HWACCEL_NONE = 0,
53 HWACCEL_AUTO,
7671dd7c 54 HWACCEL_VDPAU,
35177ba7 55 HWACCEL_DXVA2,
1839fafa 56 HWACCEL_VDA,
fb472e1a 57 HWACCEL_QSV,
07fd0a22
AK
58};
59
60typedef struct HWAccel {
61 const char *name;
62 int (*init)(AVCodecContext *s);
63 enum HWAccelID id;
64 enum AVPixelFormat pix_fmt;
65} HWAccel;
66
f5e66827
AK
67/* select an input stream for an output stream */
68typedef struct StreamMap {
c1ef30a6 69 int disabled; /* 1 is this mapping is disabled by a negative map */
f5e66827
AK
70 int file_index;
71 int stream_index;
72 int sync_file_index;
73 int sync_stream_index;
c1ef30a6 74 char *linklabel; /* name of an output link, for mapping lavfi outputs */
f5e66827
AK
75} StreamMap;
76
c1ef30a6 77/* select an input file for an output file */
f5e66827 78typedef struct MetadataMap {
c1ef30a6
DB
79 int file; // file index
80 char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
81 int index; // stream/chapter/program number
f5e66827
AK
82} MetadataMap;
83
84typedef struct OptionsContext {
77bd1bc7
AK
85 OptionGroup *g;
86
f5e66827
AK
87 /* input/output options */
88 int64_t start_time;
89 const char *format;
90
91 SpecifierOpt *codec_names;
92 int nb_codec_names;
93 SpecifierOpt *audio_channels;
94 int nb_audio_channels;
95 SpecifierOpt *audio_sample_rate;
96 int nb_audio_sample_rate;
97 SpecifierOpt *frame_rates;
98 int nb_frame_rates;
99 SpecifierOpt *frame_sizes;
100 int nb_frame_sizes;
101 SpecifierOpt *frame_pix_fmts;
102 int nb_frame_pix_fmts;
103
104 /* input options */
105 int64_t input_ts_offset;
16b0c929 106 int loop;
f5e66827 107 int rate_emu;
811bd078 108 int accurate_seek;
f5e66827
AK
109
110 SpecifierOpt *ts_scale;
111 int nb_ts_scale;
112 SpecifierOpt *dump_attachment;
113 int nb_dump_attachment;
07fd0a22
AK
114 SpecifierOpt *hwaccels;
115 int nb_hwaccels;
116 SpecifierOpt *hwaccel_devices;
117 int nb_hwaccel_devices;
16302246
MS
118 SpecifierOpt *autorotate;
119 int nb_autorotate;
f5e66827
AK
120
121 /* output options */
122 StreamMap *stream_maps;
123 int nb_stream_maps;
124 /* first item specifies output metadata, second is input */
125 MetadataMap (*meta_data_maps)[2];
126 int nb_meta_data_maps;
127 int metadata_global_manual;
128 int metadata_streams_manual;
129 int metadata_chapters_manual;
130 const char **attachments;
131 int nb_attachments;
132
133 int chapters_input_file;
134
135 int64_t recording_time;
136 uint64_t limit_filesize;
137 float mux_preload;
138 float mux_max_delay;
3c0df905 139 int shortest;
f5e66827
AK
140
141 int video_disable;
142 int audio_disable;
143 int subtitle_disable;
144 int data_disable;
145
146 /* indexed by output file stream index */
147 int *streamid_map;
148 int nb_streamid_map;
149
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 *force_fps;
165 int nb_force_fps;
166 SpecifierOpt *frame_aspect_ratios;
167 int nb_frame_aspect_ratios;
168 SpecifierOpt *rc_overrides;
169 int nb_rc_overrides;
170 SpecifierOpt *intra_matrices;
171 int nb_intra_matrices;
172 SpecifierOpt *inter_matrices;
173 int nb_inter_matrices;
174 SpecifierOpt *top_field_first;
175 int nb_top_field_first;
176 SpecifierOpt *metadata_map;
177 int nb_metadata_map;
178 SpecifierOpt *presets;
179 int nb_presets;
180 SpecifierOpt *copy_initial_nonkeyframes;
181 int nb_copy_initial_nonkeyframes;
182 SpecifierOpt *filters;
183 int nb_filters;
a4208b9b
AK
184 SpecifierOpt *filter_scripts;
185 int nb_filter_scripts;
038c0b1e
AK
186 SpecifierOpt *pass;
187 int nb_pass;
bbcedade
AK
188 SpecifierOpt *passlogfiles;
189 int nb_passlogfiles;
f5e66827
AK
190} OptionsContext;
191
192typedef struct InputFilter {
193 AVFilterContext *filter;
194 struct InputStream *ist;
195 struct FilterGraph *graph;
196 uint8_t *name;
197} InputFilter;
198
199typedef struct OutputFilter {
200 AVFilterContext *filter;
201 struct OutputStream *ost;
202 struct FilterGraph *graph;
203 uint8_t *name;
204
205 /* temporary storage until stream maps are processed */
206 AVFilterInOut *out_tmp;
6d592fbd 207 enum AVMediaType type;
f5e66827
AK
208} OutputFilter;
209
210typedef struct FilterGraph {
211 int index;
212 const char *graph_desc;
213
214 AVFilterGraph *graph;
215
216 InputFilter **inputs;
217 int nb_inputs;
218 OutputFilter **outputs;
219 int nb_outputs;
220} FilterGraph;
221
222typedef struct InputStream {
223 int file_index;
224 AVStream *st;
225 int discard; /* true if stream data should be discarded */
226 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
41776ba9 227 AVCodecContext *dec_ctx;
f5e66827
AK
228 AVCodec *dec;
229 AVFrame *decoded_frame;
9b2dc295 230 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
f5e66827
AK
231
232 int64_t start; /* time when read started */
233 /* predicted dts of the next packet read for this stream or (when there are
234 * several frames in a packet) of the next frame in current packet */
235 int64_t next_dts;
236 /* dts of the last packet read for this stream */
237 int64_t last_dts;
16b0c929
AH
238 int64_t min_pts; /* pts with the smallest value in a current stream */
239 int64_t max_pts; /* pts with the higher value in a current stream */
240 int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
f5e66827
AK
241 PtsCorrectionContext pts_ctx;
242 double ts_scale;
f3a6ad22 243 AVDictionary *decoder_opts;
f5e66827
AK
244 AVRational framerate; /* framerate forced with -r */
245
16302246 246 int autorotate;
f5e66827
AK
247 int resample_height;
248 int resample_width;
249 int resample_pix_fmt;
250
251 int resample_sample_fmt;
252 int resample_sample_rate;
253 int resample_channels;
254 uint64_t resample_channel_layout;
255
f5e66827
AK
256 /* decoded data from this stream goes into all those filters
257 * currently video and audio only */
258 InputFilter **filters;
259 int nb_filters;
07fd0a22
AK
260
261 /* hwaccel options */
262 enum HWAccelID hwaccel_id;
263 char *hwaccel_device;
264
265 /* hwaccel context */
266 enum HWAccelID active_hwaccel_id;
267 void *hwaccel_ctx;
268 void (*hwaccel_uninit)(AVCodecContext *s);
269 int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
270 int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
271 enum AVPixelFormat hwaccel_pix_fmt;
272 enum AVPixelFormat hwaccel_retrieved_pix_fmt;
47543450
AK
273
274 /* stats */
275 // combined size of all the packets read
276 uint64_t data_size;
277 /* number of packets successfully read for this stream */
278 uint64_t nb_packets;
279 // number of frames/samples retrieved from the decoder
280 uint64_t frames_decoded;
281 uint64_t samples_decoded;
f5e66827
AK
282} InputStream;
283
284typedef struct InputFile {
285 AVFormatContext *ctx;
286 int eof_reached; /* true if eof reached */
0b26ef42 287 int eagain; /* true if last read attempt returned EAGAIN */
f5e66827 288 int ist_index; /* index of first stream in ist_table */
16b0c929
AH
289 int loop; /* set number of times input stream should be looped */
290 int64_t duration; /* actual duration of the longest stream in a file
291 at the moment when looping happens */
292 AVRational time_base; /* time base of the duration */
f5e66827 293 int64_t ts_offset;
811bd078 294 int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
488a0fa6 295 int64_t recording_time;
f5e66827
AK
296 int nb_streams; /* number of stream that avconv is aware of; may be different
297 from ctx.nb_streams if new streams appear during av_read_frame() */
298 int rate_emu;
811bd078 299 int accurate_seek;
f5e66827
AK
300
301#if HAVE_PTHREADS
302 pthread_t thread; /* thread reading from this file */
303 int finished; /* the thread has exited */
304 int joined; /* the thread has been joined */
305 pthread_mutex_t fifo_lock; /* lock for access to fifo */
306 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
307 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
308#endif
309} InputFile;
310
311typedef struct OutputStream {
312 int file_index; /* file index */
313 int index; /* stream index in the output file */
314 int source_index; /* InputStream index */
315 AVStream *st; /* stream in the output file */
316 int encoding_needed; /* true if encoding needed for this stream */
317 int frame_number;
318 /* input pts and corresponding output pts
319 for A/V sync */
320 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
321 struct InputStream *sync_ist; /* input stream to sync against */
322 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
323 /* pts of the first frame encoded for this stream, used for limiting
324 * recording time */
325 int64_t first_pts;
76d23f40
AK
326 /* dts of the last packet sent to the muxer */
327 int64_t last_mux_dts;
4426540f
AK
328
329 int nb_bitstream_filters;
330 const AVBitStreamFilter **bitstream_filters;
331 AVBSFContext **bsf_ctx;
332
38313626 333 AVCodecContext *enc_ctx;
f5e66827
AK
334 AVCodec *enc;
335 int64_t max_frames;
336 AVFrame *filtered_frame;
337
fb472e1a
AK
338 void *hwaccel_ctx;
339
f5e66827
AK
340 /* video only */
341 AVRational frame_rate;
342 int force_fps;
343 int top_field_first;
344
345 float frame_aspect_ratio;
f5e66827
AK
346
347 /* forced key frames */
348 int64_t *forced_kf_pts;
349 int forced_kf_count;
350 int forced_kf_index;
351 char *forced_keyframes;
352
bbcedade 353 char *logfile_prefix;
f5e66827
AK
354 FILE *logfile;
355
356 OutputFilter *filter;
357 char *avfilter;
358
359 int64_t sws_flags;
9580818c 360 AVDictionary *encoder_opts;
5c7db097 361 AVDictionary *resample_opts;
57d24225 362 int finished; /* no more packets should be written for this stream */
f5e66827
AK
363 int stream_copy;
364 const char *attachment_filename;
365 int copy_initial_nonkeyframes;
366
716d413c 367 enum AVPixelFormat pix_fmts[2];
c872d310
AK
368
369 AVCodecParserContext *parser;
baeb59d8
AK
370
371 /* stats */
372 // combined size of all the packets written
373 uint64_t data_size;
47543450
AK
374 // number of packets send to the muxer
375 uint64_t packets_written;
376 // number of frames/samples sent to the encoder
377 uint64_t frames_encoded;
378 uint64_t samples_encoded;
5d3addb9
VG
379
380 /* packet quality factor */
381 int quality;
f5e66827
AK
382} OutputStream;
383
384typedef struct OutputFile {
385 AVFormatContext *ctx;
386 AVDictionary *opts;
387 int ost_index; /* index of the first stream in output_streams */
388 int64_t recording_time; /* desired length of the resulting file in microseconds */
389 int64_t start_time; /* start time in microseconds */
390 uint64_t limit_filesize;
3c0df905
AK
391
392 int shortest;
f5e66827
AK
393} OutputFile;
394
395extern InputStream **input_streams;
396extern int nb_input_streams;
397extern InputFile **input_files;
398extern int nb_input_files;
399
400extern OutputStream **output_streams;
401extern int nb_output_streams;
402extern OutputFile **output_files;
403extern int nb_output_files;
404
405extern FilterGraph **filtergraphs;
406extern int nb_filtergraphs;
407
f5e66827
AK
408extern char *vstats_filename;
409
410extern float audio_drift_threshold;
411extern float dts_delta_threshold;
412
413extern int audio_volume;
414extern int audio_sync_method;
415extern int video_sync_method;
416extern int do_benchmark;
417extern int do_deinterlace;
418extern int do_hex_dump;
419extern int do_pkt_dump;
420extern int copy_ts;
421extern int copy_tb;
f5e66827
AK
422extern int exit_on_error;
423extern int print_stats;
424extern int qp_hist;
f5e66827
AK
425
426extern const AVIOInterruptCB int_cb;
427
428extern const OptionDef options[];
429
07fd0a22
AK
430extern const HWAccel hwaccels[];
431
f5e66827
AK
432void reset_options(OptionsContext *o);
433void show_usage(void);
434
f5e66827
AK
435void opt_output_file(void *optctx, const char *filename);
436
437void assert_avoptions(AVDictionary *m);
438
439int guess_input_channel_layout(InputStream *ist);
440
441int configure_filtergraph(FilterGraph *fg);
442int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
fe2147e9
AK
443int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
444FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
6d592fbd 445int init_complex_filtergraph(FilterGraph *fg);
f5e66827 446
77bd1bc7
AK
447int avconv_parse_options(int argc, char **argv);
448
7671dd7c 449int vdpau_init(AVCodecContext *s);
35177ba7 450int dxva2_init(AVCodecContext *s);
1839fafa 451int vda_init(AVCodecContext *s);
fb472e1a
AK
452int qsv_init(AVCodecContext *s);
453int qsv_transcode_init(OutputStream *ost);
7671dd7c 454
f5e66827 455#endif /* AVCONV_H */