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"
39 #include "libavfilter/avfiltergraph.h"
41 #include "libavutil/avutil.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/fifo.h"
44 #include "libavutil/pixfmt.h"
45 #include "libavutil/rational.h"
48 #define VSYNC_PASSTHROUGH 0
52 /* select an input stream for an output stream */
53 typedef struct StreamMap {
54 int disabled; /** 1 is this mapping is disabled by a negative map */
58 int sync_stream_index;
59 char *linklabel; /** name of an output link, for mapping lavfi outputs */
63 * select an input file for an output file
65 typedef struct MetadataMap {
66 int file; ///< file index
67 char type; ///< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
68 int index; ///< stream/chapter/program number
71 typedef struct OptionsContext {
72 /* input/output options */
76 SpecifierOpt *codec_names;
78 SpecifierOpt *audio_channels;
79 int nb_audio_channels;
80 SpecifierOpt *audio_sample_rate;
81 int nb_audio_sample_rate;
82 SpecifierOpt *frame_rates;
84 SpecifierOpt *frame_sizes;
86 SpecifierOpt *frame_pix_fmts;
87 int nb_frame_pix_fmts;
90 int64_t input_ts_offset;
93 SpecifierOpt *ts_scale;
95 SpecifierOpt *dump_attachment;
96 int nb_dump_attachment;
99 StreamMap *stream_maps;
101 /* first item specifies output metadata, second is input */
102 MetadataMap (*meta_data_maps)[2];
103 int nb_meta_data_maps;
104 int metadata_global_manual;
105 int metadata_streams_manual;
106 int metadata_chapters_manual;
107 const char **attachments;
110 int chapters_input_file;
112 int64_t recording_time;
113 uint64_t limit_filesize;
120 int subtitle_disable;
123 /* indexed by output file stream index */
127 SpecifierOpt *metadata;
129 SpecifierOpt *max_frames;
131 SpecifierOpt *bitstream_filters;
132 int nb_bitstream_filters;
133 SpecifierOpt *codec_tags;
135 SpecifierOpt *sample_fmts;
137 SpecifierOpt *qscale;
139 SpecifierOpt *forced_key_frames;
140 int nb_forced_key_frames;
141 SpecifierOpt *force_fps;
143 SpecifierOpt *frame_aspect_ratios;
144 int nb_frame_aspect_ratios;
145 SpecifierOpt *rc_overrides;
147 SpecifierOpt *intra_matrices;
148 int nb_intra_matrices;
149 SpecifierOpt *inter_matrices;
150 int nb_inter_matrices;
151 SpecifierOpt *top_field_first;
152 int nb_top_field_first;
153 SpecifierOpt *metadata_map;
155 SpecifierOpt *presets;
157 SpecifierOpt *copy_initial_nonkeyframes;
158 int nb_copy_initial_nonkeyframes;
159 SpecifierOpt *filters;
163 typedef struct InputFilter {
164 AVFilterContext *filter;
165 struct InputStream *ist;
166 struct FilterGraph *graph;
170 typedef struct OutputFilter {
171 AVFilterContext *filter;
172 struct OutputStream *ost;
173 struct FilterGraph *graph;
176 /* temporary storage until stream maps are processed */
177 AVFilterInOut *out_tmp;
180 typedef struct FilterGraph {
182 const char *graph_desc;
184 AVFilterGraph *graph;
186 InputFilter **inputs;
188 OutputFilter **outputs;
192 typedef struct InputStream {
195 int discard; /* true if stream data should be discarded */
196 int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
198 AVFrame *decoded_frame;
200 int64_t start; /* time when read started */
201 /* predicted dts of the next packet read for this stream or (when there are
202 * several frames in a packet) of the next frame in current packet */
204 /* dts of the last packet read for this stream */
206 PtsCorrectionContext pts_ctx;
208 int is_start; /* is 1 at the start and after a discontinuity */
209 int showed_multi_packet_warning;
211 AVRational framerate; /* framerate forced with -r */
215 int resample_pix_fmt;
217 int resample_sample_fmt;
218 int resample_sample_rate;
219 int resample_channels;
220 uint64_t resample_channel_layout;
222 /* a pool of free buffers for decoded data */
223 FrameBuffer *buffer_pool;
225 /* decoded data from this stream goes into all those filters
226 * currently video and audio only */
227 InputFilter **filters;
231 typedef struct InputFile {
232 AVFormatContext *ctx;
233 int eof_reached; /* true if eof reached */
234 int eagain; /* true if last read attempt returned EAGAIN */
235 int ist_index; /* index of first stream in ist_table */
237 int nb_streams; /* number of stream that avconv is aware of; may be different
238 from ctx.nb_streams if new streams appear during av_read_frame() */
242 pthread_t thread; /* thread reading from this file */
243 int finished; /* the thread has exited */
244 int joined; /* the thread has been joined */
245 pthread_mutex_t fifo_lock; /* lock for access to fifo */
246 pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
247 AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
251 typedef struct OutputStream {
252 int file_index; /* file index */
253 int index; /* stream index in the output file */
254 int source_index; /* InputStream index */
255 AVStream *st; /* stream in the output file */
256 int encoding_needed; /* true if encoding needed for this stream */
258 /* input pts and corresponding output pts
260 // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
261 struct InputStream *sync_ist; /* input stream to sync against */
262 int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
263 /* pts of the first frame encoded for this stream, used for limiting
266 AVBitStreamFilterContext *bitstream_filters;
269 AVFrame *filtered_frame;
272 AVRational frame_rate;
276 float frame_aspect_ratio;
279 /* forced key frames */
280 int64_t *forced_kf_pts;
283 char *forced_keyframes;
287 OutputFilter *filter;
292 int finished; /* no more packets should be written for this stream */
294 const char *attachment_filename;
295 int copy_initial_nonkeyframes;
297 enum PixelFormat pix_fmts[2];
300 typedef struct OutputFile {
301 AVFormatContext *ctx;
303 int ost_index; /* index of the first stream in output_streams */
304 int64_t recording_time; /* desired length of the resulting file in microseconds */
305 int64_t start_time; /* start time in microseconds */
306 uint64_t limit_filesize;
311 extern InputStream **input_streams;
312 extern int nb_input_streams;
313 extern InputFile **input_files;
314 extern int nb_input_files;
316 extern OutputStream **output_streams;
317 extern int nb_output_streams;
318 extern OutputFile **output_files;
319 extern int nb_output_files;
321 extern FilterGraph **filtergraphs;
322 extern int nb_filtergraphs;
324 extern char *pass_logfilename_prefix;
325 extern char *vstats_filename;
327 extern float audio_drift_threshold;
328 extern float dts_delta_threshold;
330 extern int audio_volume;
331 extern int audio_sync_method;
332 extern int video_sync_method;
333 extern int do_benchmark;
334 extern int do_deinterlace;
335 extern int do_hex_dump;
336 extern int do_pkt_dump;
339 extern int exit_on_error;
340 extern int print_stats;
342 extern int same_quant;
344 extern const AVIOInterruptCB int_cb;
346 extern const OptionDef options[];
348 void reset_options(OptionsContext *o);
349 void show_usage(void);
351 int opt_cpuflags(const char *opt, const char *arg);
353 void opt_output_file(void *optctx, const char *filename);
355 void assert_avoptions(AVDictionary *m);
357 int guess_input_channel_layout(InputStream *ist);
359 int configure_filtergraph(FilterGraph *fg);
360 int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
361 int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
362 FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
364 #endif /* AVCONV_H */