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
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/pixfmt.h"
44 #include "libavutil/rational.h"
47 #define VSYNC_PASSTHROUGH 0
59 typedef struct HWAccel {
61 int (*init)(AVCodecContext *s);
63 enum AVPixelFormat pix_fmt;
66 /* select an input stream for an output stream */
67 typedef struct StreamMap {
68 int disabled; /* 1 is this mapping is disabled by a negative map */
72 int sync_stream_index;
73 char *linklabel; /* name of an output link, for mapping lavfi outputs */
76 /* select an input file for an output file */
77 typedef struct MetadataMap {
78 int file; // file index
79 char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
80 int index; // stream/chapter/program number
83 typedef struct OptionsContext {
86 /* input/output options */
90 SpecifierOpt *codec_names;
92 SpecifierOpt *audio_channels;
93 int nb_audio_channels;
94 SpecifierOpt *audio_sample_rate;
95 int nb_audio_sample_rate;
96 SpecifierOpt *frame_rates;
98 SpecifierOpt *frame_sizes;
100 SpecifierOpt *frame_pix_fmts;
101 int nb_frame_pix_fmts;
104 int64_t input_ts_offset;
108 SpecifierOpt *ts_scale;
110 SpecifierOpt *dump_attachment;
111 int nb_dump_attachment;
112 SpecifierOpt *hwaccels;
114 SpecifierOpt *hwaccel_devices;
115 int nb_hwaccel_devices;
116 SpecifierOpt *autorotate;
120 StreamMap *stream_maps;
122 /* first item specifies output metadata, second is input */
123 MetadataMap (*meta_data_maps)[2];
124 int nb_meta_data_maps;
125 int metadata_global_manual;
126 int metadata_streams_manual;
127 int metadata_chapters_manual;
128 const char **attachments;
131 int chapters_input_file;
133 int64_t recording_time;
134 uint64_t limit_filesize;
141 int subtitle_disable;
144 /* indexed by output file stream index */
148 SpecifierOpt *metadata;
150 SpecifierOpt *max_frames;
152 SpecifierOpt *bitstream_filters;
153 int nb_bitstream_filters;
154 SpecifierOpt *codec_tags;
156 SpecifierOpt *sample_fmts;
158 SpecifierOpt *qscale;
160 SpecifierOpt *forced_key_frames;
161 int nb_forced_key_frames;
162 SpecifierOpt *force_fps;
164 SpecifierOpt *frame_aspect_ratios;
165 int nb_frame_aspect_ratios;
166 SpecifierOpt *rc_overrides;
168 SpecifierOpt *intra_matrices;
169 int nb_intra_matrices;
170 SpecifierOpt *inter_matrices;
171 int nb_inter_matrices;
172 SpecifierOpt *top_field_first;
173 int nb_top_field_first;
174 SpecifierOpt *metadata_map;
176 SpecifierOpt *presets;
178 SpecifierOpt *copy_initial_nonkeyframes;
179 int nb_copy_initial_nonkeyframes;
180 SpecifierOpt *filters;
182 SpecifierOpt *filter_scripts;
183 int nb_filter_scripts;
186 SpecifierOpt *passlogfiles;
190 typedef struct InputFilter {
191 AVFilterContext *filter;
192 struct InputStream *ist;
193 struct FilterGraph *graph;
197 typedef struct OutputFilter {
198 AVFilterContext *filter;
199 struct OutputStream *ost;
200 struct FilterGraph *graph;
203 /* temporary storage until stream maps are processed */
204 AVFilterInOut *out_tmp;
207 typedef struct FilterGraph {
209 const char *graph_desc;
211 AVFilterGraph *graph;
213 InputFilter **inputs;
215 OutputFilter **outputs;
219 typedef struct InputStream {
222 int discard; /* true if stream data should be discarded */
223 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
224 AVCodecContext *dec_ctx;
226 AVFrame *decoded_frame;
227 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
229 int64_t start; /* time when read started */
230 /* predicted dts of the next packet read for this stream or (when there are
231 * several frames in a packet) of the next frame in current packet */
233 /* dts of the last packet read for this stream */
235 PtsCorrectionContext pts_ctx;
237 int showed_multi_packet_warning;
238 AVDictionary *decoder_opts;
239 AVRational framerate; /* framerate forced with -r */
244 int resample_pix_fmt;
246 int resample_sample_fmt;
247 int resample_sample_rate;
248 int resample_channels;
249 uint64_t resample_channel_layout;
251 /* decoded data from this stream goes into all those filters
252 * currently video and audio only */
253 InputFilter **filters;
256 /* hwaccel options */
257 enum HWAccelID hwaccel_id;
258 char *hwaccel_device;
260 /* hwaccel context */
261 enum HWAccelID active_hwaccel_id;
263 void (*hwaccel_uninit)(AVCodecContext *s);
264 int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
265 int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
266 enum AVPixelFormat hwaccel_pix_fmt;
267 enum AVPixelFormat hwaccel_retrieved_pix_fmt;
270 // combined size of all the packets read
272 /* number of packets successfully read for this stream */
274 // number of frames/samples retrieved from the decoder
275 uint64_t frames_decoded;
276 uint64_t samples_decoded;
279 typedef struct InputFile {
280 AVFormatContext *ctx;
281 int eof_reached; /* true if eof reached */
282 int eagain; /* true if last read attempt returned EAGAIN */
283 int ist_index; /* index of first stream in ist_table */
285 int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
286 int64_t recording_time;
287 int nb_streams; /* number of stream that avconv is aware of; may be different
288 from ctx.nb_streams if new streams appear during av_read_frame() */
293 pthread_t thread; /* thread reading from this file */
294 int finished; /* the thread has exited */
295 int joined; /* the thread has been joined */
296 pthread_mutex_t fifo_lock; /* lock for access to fifo */
297 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
298 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
302 typedef struct OutputStream {
303 int file_index; /* file index */
304 int index; /* stream index in the output file */
305 int source_index; /* InputStream index */
306 AVStream *st; /* stream in the output file */
307 int encoding_needed; /* true if encoding needed for this stream */
309 /* input pts and corresponding output pts
311 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
312 struct InputStream *sync_ist; /* input stream to sync against */
313 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
314 /* pts of the first frame encoded for this stream, used for limiting
317 /* dts of the last packet sent to the muxer */
318 int64_t last_mux_dts;
319 AVBitStreamFilterContext *bitstream_filters;
320 AVCodecContext *enc_ctx;
323 AVFrame *filtered_frame;
326 AVRational frame_rate;
330 float frame_aspect_ratio;
332 /* forced key frames */
333 int64_t *forced_kf_pts;
336 char *forced_keyframes;
338 char *logfile_prefix;
341 OutputFilter *filter;
345 AVDictionary *encoder_opts;
346 AVDictionary *resample_opts;
347 int finished; /* no more packets should be written for this stream */
349 const char *attachment_filename;
350 int copy_initial_nonkeyframes;
352 enum AVPixelFormat pix_fmts[2];
354 AVCodecParserContext *parser;
357 // combined size of all the packets written
359 // number of packets send to the muxer
360 uint64_t packets_written;
361 // number of frames/samples sent to the encoder
362 uint64_t frames_encoded;
363 uint64_t samples_encoded;
366 typedef struct OutputFile {
367 AVFormatContext *ctx;
369 int ost_index; /* index of the first stream in output_streams */
370 int64_t recording_time; /* desired length of the resulting file in microseconds */
371 int64_t start_time; /* start time in microseconds */
372 uint64_t limit_filesize;
377 extern InputStream **input_streams;
378 extern int nb_input_streams;
379 extern InputFile **input_files;
380 extern int nb_input_files;
382 extern OutputStream **output_streams;
383 extern int nb_output_streams;
384 extern OutputFile **output_files;
385 extern int nb_output_files;
387 extern FilterGraph **filtergraphs;
388 extern int nb_filtergraphs;
390 extern char *vstats_filename;
392 extern float audio_drift_threshold;
393 extern float dts_delta_threshold;
395 extern int audio_volume;
396 extern int audio_sync_method;
397 extern int video_sync_method;
398 extern int do_benchmark;
399 extern int do_deinterlace;
400 extern int do_hex_dump;
401 extern int do_pkt_dump;
404 extern int exit_on_error;
405 extern int print_stats;
408 extern const AVIOInterruptCB int_cb;
410 extern const OptionDef options[];
412 extern const HWAccel hwaccels[];
414 void reset_options(OptionsContext *o);
415 void show_usage(void);
417 void opt_output_file(void *optctx, const char *filename);
419 void assert_avoptions(AVDictionary *m);
421 int guess_input_channel_layout(InputStream *ist);
423 int configure_filtergraph(FilterGraph *fg);
424 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
425 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
426 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
428 int avconv_parse_options(int argc, char **argv);
430 int vdpau_init(AVCodecContext *s);
431 int dxva2_init(AVCodecContext *s);
432 int vda_init(AVCodecContext *s);
434 #endif /* AVCONV_H */