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
57 typedef struct HWAccel {
59 int (*init)(AVCodecContext *s);
61 enum AVPixelFormat pix_fmt;
64 /* select an input stream for an output stream */
65 typedef struct StreamMap {
66 int disabled; /* 1 is this mapping is disabled by a negative map */
70 int sync_stream_index;
71 char *linklabel; /* name of an output link, for mapping lavfi outputs */
74 /* select an input file for an output file */
75 typedef struct MetadataMap {
76 int file; // file index
77 char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
78 int index; // stream/chapter/program number
81 typedef struct OptionsContext {
84 /* input/output options */
88 SpecifierOpt *codec_names;
90 SpecifierOpt *audio_channels;
91 int nb_audio_channels;
92 SpecifierOpt *audio_sample_rate;
93 int nb_audio_sample_rate;
94 SpecifierOpt *frame_rates;
96 SpecifierOpt *frame_sizes;
98 SpecifierOpt *frame_pix_fmts;
99 int nb_frame_pix_fmts;
102 int64_t input_ts_offset;
106 SpecifierOpt *ts_scale;
108 SpecifierOpt *dump_attachment;
109 int nb_dump_attachment;
110 SpecifierOpt *hwaccels;
112 SpecifierOpt *hwaccel_devices;
113 int nb_hwaccel_devices;
116 StreamMap *stream_maps;
118 /* first item specifies output metadata, second is input */
119 MetadataMap (*meta_data_maps)[2];
120 int nb_meta_data_maps;
121 int metadata_global_manual;
122 int metadata_streams_manual;
123 int metadata_chapters_manual;
124 const char **attachments;
127 int chapters_input_file;
129 int64_t recording_time;
130 uint64_t limit_filesize;
137 int subtitle_disable;
140 /* indexed by output file stream index */
144 SpecifierOpt *metadata;
146 SpecifierOpt *max_frames;
148 SpecifierOpt *bitstream_filters;
149 int nb_bitstream_filters;
150 SpecifierOpt *codec_tags;
152 SpecifierOpt *sample_fmts;
154 SpecifierOpt *qscale;
156 SpecifierOpt *forced_key_frames;
157 int nb_forced_key_frames;
158 SpecifierOpt *force_fps;
160 SpecifierOpt *frame_aspect_ratios;
161 int nb_frame_aspect_ratios;
162 SpecifierOpt *rc_overrides;
164 SpecifierOpt *intra_matrices;
165 int nb_intra_matrices;
166 SpecifierOpt *inter_matrices;
167 int nb_inter_matrices;
168 SpecifierOpt *top_field_first;
169 int nb_top_field_first;
170 SpecifierOpt *metadata_map;
172 SpecifierOpt *presets;
174 SpecifierOpt *copy_initial_nonkeyframes;
175 int nb_copy_initial_nonkeyframes;
176 SpecifierOpt *filters;
178 SpecifierOpt *filter_scripts;
179 int nb_filter_scripts;
182 SpecifierOpt *passlogfiles;
186 typedef struct InputFilter {
187 AVFilterContext *filter;
188 struct InputStream *ist;
189 struct FilterGraph *graph;
193 typedef struct OutputFilter {
194 AVFilterContext *filter;
195 struct OutputStream *ost;
196 struct FilterGraph *graph;
199 /* temporary storage until stream maps are processed */
200 AVFilterInOut *out_tmp;
203 typedef struct FilterGraph {
205 const char *graph_desc;
207 AVFilterGraph *graph;
209 InputFilter **inputs;
211 OutputFilter **outputs;
215 typedef struct InputStream {
218 int discard; /* true if stream data should be discarded */
219 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
221 AVFrame *decoded_frame;
222 AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
224 int64_t start; /* time when read started */
225 /* predicted dts of the next packet read for this stream or (when there are
226 * several frames in a packet) of the next frame in current packet */
228 /* dts of the last packet read for this stream */
230 PtsCorrectionContext pts_ctx;
232 int showed_multi_packet_warning;
234 AVRational framerate; /* framerate forced with -r */
238 int resample_pix_fmt;
240 int resample_sample_fmt;
241 int resample_sample_rate;
242 int resample_channels;
243 uint64_t resample_channel_layout;
245 /* decoded data from this stream goes into all those filters
246 * currently video and audio only */
247 InputFilter **filters;
250 /* hwaccel options */
251 enum HWAccelID hwaccel_id;
252 char *hwaccel_device;
254 /* hwaccel context */
255 enum HWAccelID active_hwaccel_id;
257 void (*hwaccel_uninit)(AVCodecContext *s);
258 int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags);
259 int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame);
260 enum AVPixelFormat hwaccel_pix_fmt;
261 enum AVPixelFormat hwaccel_retrieved_pix_fmt;
264 // combined size of all the packets read
266 /* number of packets successfully read for this stream */
268 // number of frames/samples retrieved from the decoder
269 uint64_t frames_decoded;
270 uint64_t samples_decoded;
273 typedef struct InputFile {
274 AVFormatContext *ctx;
275 int eof_reached; /* true if eof reached */
276 int eagain; /* true if last read attempt returned EAGAIN */
277 int ist_index; /* index of first stream in ist_table */
279 int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
280 int64_t recording_time;
281 int nb_streams; /* number of stream that avconv is aware of; may be different
282 from ctx.nb_streams if new streams appear during av_read_frame() */
287 pthread_t thread; /* thread reading from this file */
288 int finished; /* the thread has exited */
289 int joined; /* the thread has been joined */
290 pthread_mutex_t fifo_lock; /* lock for access to fifo */
291 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
292 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
296 typedef struct OutputStream {
297 int file_index; /* file index */
298 int index; /* stream index in the output file */
299 int source_index; /* InputStream index */
300 AVStream *st; /* stream in the output file */
301 int encoding_needed; /* true if encoding needed for this stream */
303 /* input pts and corresponding output pts
305 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
306 struct InputStream *sync_ist; /* input stream to sync against */
307 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
308 /* pts of the first frame encoded for this stream, used for limiting
311 /* dts of the last packet sent to the muxer */
312 int64_t last_mux_dts;
313 AVBitStreamFilterContext *bitstream_filters;
316 AVFrame *filtered_frame;
319 AVRational frame_rate;
323 float frame_aspect_ratio;
325 /* forced key frames */
326 int64_t *forced_kf_pts;
329 char *forced_keyframes;
331 char *logfile_prefix;
334 OutputFilter *filter;
339 AVDictionary *resample_opts;
340 int finished; /* no more packets should be written for this stream */
342 const char *attachment_filename;
343 int copy_initial_nonkeyframes;
345 enum AVPixelFormat pix_fmts[2];
347 AVCodecParserContext *parser;
350 // combined size of all the packets written
352 // number of packets send to the muxer
353 uint64_t packets_written;
354 // number of frames/samples sent to the encoder
355 uint64_t frames_encoded;
356 uint64_t samples_encoded;
359 typedef struct OutputFile {
360 AVFormatContext *ctx;
362 int ost_index; /* index of the first stream in output_streams */
363 int64_t recording_time; /* desired length of the resulting file in microseconds */
364 int64_t start_time; /* start time in microseconds */
365 uint64_t limit_filesize;
370 extern InputStream **input_streams;
371 extern int nb_input_streams;
372 extern InputFile **input_files;
373 extern int nb_input_files;
375 extern OutputStream **output_streams;
376 extern int nb_output_streams;
377 extern OutputFile **output_files;
378 extern int nb_output_files;
380 extern FilterGraph **filtergraphs;
381 extern int nb_filtergraphs;
383 extern char *vstats_filename;
385 extern float audio_drift_threshold;
386 extern float dts_delta_threshold;
388 extern int audio_volume;
389 extern int audio_sync_method;
390 extern int video_sync_method;
391 extern int do_benchmark;
392 extern int do_deinterlace;
393 extern int do_hex_dump;
394 extern int do_pkt_dump;
397 extern int exit_on_error;
398 extern int print_stats;
401 extern const AVIOInterruptCB int_cb;
403 extern const OptionDef options[];
405 extern const HWAccel hwaccels[];
407 void reset_options(OptionsContext *o);
408 void show_usage(void);
410 void opt_output_file(void *optctx, const char *filename);
412 void assert_avoptions(AVDictionary *m);
414 int guess_input_channel_layout(InputStream *ist);
416 int configure_filtergraph(FilterGraph *fg);
417 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
418 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
419 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
421 int avconv_parse_options(int argc, char **argv);
423 int vdpau_init(AVCodecContext *s);
425 #endif /* AVCONV_H */