avconv.h
Go to the documentation of this file.
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"
40 
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"
46 
47 #define VSYNC_AUTO -1
48 #define VSYNC_PASSTHROUGH 0
49 #define VSYNC_CFR 1
50 #define VSYNC_VFR 2
51 
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 */
59  char *linklabel; /* name of an output link, for mapping lavfi outputs */
60 } StreamMap;
61 
62 /* select an input file for an output file */
63 typedef struct MetadataMap {
64  int file; // file index
65  char type; // type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
66  int index; // stream/chapter/program number
67 } MetadataMap;
68 
69 typedef struct OptionsContext {
71 
72  /* input/output options */
73  int64_t start_time;
74  const char *format;
75 
88 
89  /* input options */
90  int64_t input_ts_offset;
91  int rate_emu;
92 
97 
98  /* output options */
101  /* first item specifies output metadata, second is input */
107  const char **attachments;
109 
111 
112  int64_t recording_time;
113  uint64_t limit_filesize;
114  float mux_preload;
116  int shortest;
117 
122 
123  /* indexed by output file stream index */
126 
162  int nb_pass;
166 
167 typedef struct InputFilter {
169  struct InputStream *ist;
172 } InputFilter;
173 
174 typedef struct OutputFilter {
176  struct OutputStream *ost;
179 
180  /* temporary storage until stream maps are processed */
182 } OutputFilter;
183 
184 typedef struct FilterGraph {
185  int index;
186  const char *graph_desc;
187 
189 
194 } FilterGraph;
195 
196 typedef struct InputStream {
199  int discard; /* true if stream data should be discarded */
200  int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
203 
204  int64_t start; /* time when read started */
205  /* predicted dts of the next packet read for this stream or (when there are
206  * several frames in a packet) of the next frame in current packet */
207  int64_t next_dts;
208  /* dts of the last packet read for this stream */
209  int64_t last_dts;
211  double ts_scale;
212  int is_start; /* is 1 at the start and after a discontinuity */
215  AVRational framerate; /* framerate forced with -r */
216 
220 
225 
226  /* a pool of free buffers for decoded data */
228 
229  /* decoded data from this stream goes into all those filters
230  * currently video and audio only */
233 } InputStream;
234 
235 typedef struct InputFile {
237  int eof_reached; /* true if eof reached */
238  int eagain; /* true if last read attempt returned EAGAIN */
239  int ist_index; /* index of first stream in ist_table */
240  int64_t ts_offset;
241  int nb_streams; /* number of stream that avconv is aware of; may be different
242  from ctx.nb_streams if new streams appear during av_read_frame() */
243  int rate_emu;
244 
245 #if HAVE_PTHREADS
246  pthread_t thread; /* thread reading from this file */
247  int finished; /* the thread has exited */
248  int joined; /* the thread has been joined */
249  pthread_mutex_t fifo_lock; /* lock for access to fifo */
250  pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
251  AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
252 #endif
253 } InputFile;
254 
255 typedef struct OutputStream {
256  int file_index; /* file index */
257  int index; /* stream index in the output file */
258  int source_index; /* InputStream index */
259  AVStream *st; /* stream in the output file */
260  int encoding_needed; /* true if encoding needed for this stream */
262  /* input pts and corresponding output pts
263  for A/V sync */
264  // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
265  struct InputStream *sync_ist; /* input stream to sync against */
266  int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
267  /* pts of the first frame encoded for this stream, used for limiting
268  * recording time */
269  int64_t first_pts;
270  /* dts of the last packet sent to the muxer */
271  int64_t last_mux_dts;
274  int64_t max_frames;
276 
277  /* video only */
281 
283 
284  /* forced key frames */
285  int64_t *forced_kf_pts;
289 
291  FILE *logfile;
292 
294  char *avfilter;
295 
296  int64_t sws_flags;
298  int finished; /* no more packets should be written for this stream */
300  const char *attachment_filename;
302 
304 } OutputStream;
305 
306 typedef struct OutputFile {
309  int ost_index; /* index of the first stream in output_streams */
310  int64_t recording_time; /* desired length of the resulting file in microseconds */
311  int64_t start_time; /* start time in microseconds */
312  uint64_t limit_filesize;
313 
314  int shortest;
315 } OutputFile;
316 
317 extern InputStream **input_streams;
318 extern int nb_input_streams;
319 extern InputFile **input_files;
320 extern int nb_input_files;
321 
323 extern int nb_output_streams;
324 extern OutputFile **output_files;
325 extern int nb_output_files;
326 
327 extern FilterGraph **filtergraphs;
328 extern int nb_filtergraphs;
329 
330 extern char *vstats_filename;
331 
332 extern float audio_drift_threshold;
333 extern float dts_delta_threshold;
334 
335 extern int audio_volume;
336 extern int audio_sync_method;
337 extern int video_sync_method;
338 extern int do_benchmark;
339 extern int do_deinterlace;
340 extern int do_hex_dump;
341 extern int do_pkt_dump;
342 extern int copy_ts;
343 extern int copy_tb;
344 extern int exit_on_error;
345 extern int print_stats;
346 extern int qp_hist;
347 
348 extern const AVIOInterruptCB int_cb;
349 
350 extern const OptionDef options[];
351 
353 void show_usage(void);
354 
355 int opt_cpuflags(void *optctx, const char *opt, const char *arg);
356 
357 void opt_output_file(void *optctx, const char *filename);
358 
360 
362 
367 
368 int avconv_parse_options(int argc, char **argv);
369 
370 #endif /* AVCONV_H */
struct OutputFilter OutputFilter
SpecifierOpt * passlogfiles
Definition: avconv.h:163
int nb_dump_attachment
Definition: avconv.h:96
int nb_metadata
Definition: avconv.h:128
int nb_streamid_map
Definition: avconv.h:125
int frame_number
Definition: avconv.h:261
float mux_preload
Definition: avconv.h:114
int64_t recording_time
Definition: avconv.h:310
Buffered I/O operations.
uint8_t * name
Definition: avconv.h:178
int nb_outputs
Definition: avconv.h:193
int resample_channels
Definition: avconv.h:223
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
int stream_copy
Definition: avconv.h:299
AVRational frame_rate
Definition: avconv.h:278
int64_t * forced_kf_pts
Definition: avconv.h:285
int data_disable
Definition: avconv.h:121
float mux_max_delay
Definition: avconv.h:115
int nb_forced_key_frames
Definition: avconv.h:140
int * streamid_map
Definition: avconv.h:124
int nb_stream_maps
Definition: avconv.h:100
SpecifierOpt * copy_initial_nonkeyframes
Definition: avconv.h:157
AVStream * st
Definition: avconv.h:259
AVRational framerate
Definition: avconv.h:215
PtsCorrectionContext pts_ctx
Definition: avconv.h:210
SpecifierOpt * ts_scale
Definition: avconv.h:93
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)
AVFilterInOut * out_tmp
Definition: avconv.h:181
int decoding_needed
Definition: avconv.h:200
int guess_input_channel_layout(InputStream *ist)
Definition: avconv.c:1086
int nb_frame_pix_fmts
Definition: avconv.h:87
SpecifierOpt * sample_fmts
Definition: avconv.h:135
int eagain
Definition: avconv.h:238
AVBitStreamFilterContext * bitstream_filters
Definition: avconv.h:272
external API header
FilterGraph * init_simple_filtergraph(InputStream *ist, OutputStream *ost)
int copy_ts
Definition: avconv_opt.c:69
int print_stats
Definition: avconv_opt.c:72
int nb_filtergraphs
Definition: avconv.c:113
AVCodec.
Definition: avcodec.h:2960
SpecifierOpt * filters
Definition: avconv.h:159
int64_t start_time
Definition: avconv.h:311
int index
Definition: avconv.h:185
SpecifierOpt * qscale
Definition: avconv.h:137
FilterGraph ** filtergraphs
Definition: avconv.c:112
int64_t last_dts
Definition: avconv.h:209
int video_sync_method
Definition: avconv_opt.c:64
SpecifierOpt * frame_pix_fmts
Definition: avconv.h:86
struct FilterGraph * graph
Definition: avconv.h:170
float dts_delta_threshold
Definition: avconv_opt.c:60
SpecifierOpt * intra_matrices
Definition: avconv.h:147
int encoding_needed
Definition: avconv.h:260
Format I/O context.
Definition: avformat.h:828
struct InputStream * ist
Definition: avconv.h:169
AVFilterGraph * graph
Definition: avconv.h:188
Public dictionary API.
char * logfile_prefix
Definition: avconv.h:290
int copy_initial_nonkeyframes
Definition: avconv.h:301
uint8_t
float audio_drift_threshold
Definition: avconv_opt.c:59
int is_start
Definition: avconv.h:212
FILE * logfile
Definition: avconv.h:291
AVDictionary * opts
Definition: avconv.h:308
AVDictionary * opts
Definition: avconv.h:297
struct InputFilter InputFilter
CRITICAL_SECTION pthread_mutex_t
Definition: w32pthreads.h:54
void assert_avoptions(AVDictionary *m)
Definition: avconv.c:224
int nb_max_frames
Definition: avconv.h:130
int shortest
Definition: avconv.h:314
int nb_meta_data_maps
Definition: avconv.h:103
struct OutputFile OutputFile
InputFile ** input_files
Definition: avconv.c:104
int nb_streams
Definition: avconv.h:241
int sync_file_index
Definition: avconv.h:57
AVFilterContext * filter
Definition: avconv.h:175
SpecifierOpt * bitstream_filters
Definition: avconv.h:131
int resample_sample_rate
Definition: avconv.h:222
OutputFile ** output_files
Definition: avconv.c:109
AVCodec * dec
Definition: avconv.h:201
int file_index
Definition: avconv.h:197
int resample_pix_fmt
Definition: avconv.h:219
int resample_height
Definition: avconv.h:217
int64_t next_dts
Definition: avconv.h:207
int configure_filtergraph(FilterGraph *fg)
Callback for checking whether to abort blocking functions.
Definition: avio.h:51
int nb_top_field_first
Definition: avconv.h:152
int rate_emu
Definition: avconv.h:243
int do_deinterlace
Definition: avconv_opt.c:65
void opt_output_file(void *optctx, const char *filename)
struct InputFile InputFile
AVFilterContext * filter
Definition: avconv.h:168
int nb_filters
Definition: avconv.h:160
int64_t start_time
Definition: avconv.h:73
int64_t start
Definition: avconv.h:204
int64_t last_mux_dts
Definition: avconv.h:271
int64_t sws_flags
Definition: avconv.h:296
int finished
Definition: avconv.h:298
SpecifierOpt * codec_tags
Definition: avconv.h:133
SpecifierOpt * rc_overrides
Definition: avconv.h:145
int video_disable
Definition: avconv.h:118
int force_fps
Definition: avconv.h:279
char type
Definition: avconv.h:65
int nb_codec_names
Definition: avconv.h:77
StreamMap * stream_maps
Definition: avconv.h:99
uint64_t limit_filesize
Definition: avconv.h:113
const char * format
Definition: avconv.h:74
int nb_passlogfiles
Definition: avconv.h:164
int nb_force_fps
Definition: avconv.h:142
OutputFilter * filter
Definition: avconv.h:293
int nb_sample_fmts
Definition: avconv.h:136
AVDictionary * opts
Definition: avconv.h:214
int file_index
Definition: avconv.h:55
MetadataMap(* meta_data_maps)[2]
Definition: avconv.h:102
int nb_attachments
Definition: avconv.h:108
int copy_tb
Definition: avconv_opt.c:70
char * linklabel
Definition: avconv.h:59
int nb_ts_scale
Definition: avconv.h:94
SpecifierOpt * audio_channels
Definition: avconv.h:78
int nb_audio_sample_rate
Definition: avconv.h:81
int metadata_chapters_manual
Definition: avconv.h:106
struct OutputStream * ost
Definition: avconv.h:176
SpecifierOpt * pass
Definition: avconv.h:161
SpecifierOpt * audio_sample_rate
Definition: avconv.h:80
struct OutputStream OutputStream
FrameBuffer * buffer_pool
Definition: avconv.h:227
SpecifierOpt * dump_attachment
Definition: avconv.h:95
int nb_codec_tags
Definition: avconv.h:134
SpecifierOpt * metadata_map
Definition: avconv.h:153
int64_t max_frames
Definition: avconv.h:274
SpecifierOpt * frame_aspect_ratios
Definition: avconv.h:143
SpecifierOpt * frame_sizes
Definition: avconv.h:84
int do_benchmark
Definition: avconv_opt.c:66
int nb_output_files
Definition: avconv.c:110
OutputStream ** output_streams
Definition: avconv.c:107
Stream structure.
Definition: avformat.h:622
A linked-list of the inputs/outputs of the filter chain.
Definition: avfiltergraph.h:98
int audio_sync_method
Definition: avconv_opt.c:63
InputFilter ** filters
Definition: avconv.h:231
SpecifierOpt * frame_rates
Definition: avconv.h:82
int nb_presets
Definition: avconv.h:156
int ost_index
Definition: avconv.h:309
struct InputStream * sync_ist
Definition: avconv.h:265
int exit_on_error
Definition: avconv_opt.c:71
external API header
double ts_scale
Definition: avconv.h:211
int64_t recording_time
Definition: avconv.h:112
const AVIOInterruptCB int_cb
Definition: avconv.c:145
int chapters_input_file
Definition: avconv.h:110
int ist_index
Definition: avconv.h:239
const char * graph_desc
Definition: avconv.h:186
void reset_options(OptionsContext *o)
int rate_emu
Definition: avconv.h:91
int metadata_streams_manual
Definition: avconv.h:105
const char * attachment_filename
Definition: avconv.h:300
a very simple circular buffer FIFO implementation
int audio_disable
Definition: avconv.h:119
int64_t input_ts_offset
Definition: avconv.h:90
AVFrame * decoded_frame
Definition: avconv.h:202
int nb_bitstream_filters
Definition: avconv.h:132
int avconv_parse_options(int argc, char **argv)
Definition: avconv_opt.c:1900
SpecifierOpt * top_field_first
Definition: avconv.h:151
AVStream * st
Definition: avconv.h:198
int nb_input_files
Definition: avconv.c:105
int index
Definition: avconv.h:66
rational number numerator/denominator
Definition: rational.h:43
struct InputStream InputStream
int file_index
Definition: avconv.h:256
int metadata_global_manual
Definition: avconv.h:104
int64_t sync_opts
Definition: avconv.h:266
SpecifierOpt * force_fps
Definition: avconv.h:141
int nb_inter_matrices
Definition: avconv.h:150
int shortest
Definition: avconv.h:116
int showed_multi_packet_warning
Definition: avconv.h:213
int64_t ts_offset
Definition: avconv.h:240
int nb_qscale
Definition: avconv.h:138
AVFrame * filtered_frame
Definition: avconv.h:275
int nb_audio_channels
Definition: avconv.h:79
int source_index
Definition: avconv.h:258
SpecifierOpt * metadata
Definition: avconv.h:127
int nb_filters
Definition: avconv.h:232
struct StreamMap StreamMap
int qp_hist
Definition: avconv_opt.c:73
int forced_kf_count
Definition: avconv.h:286
int resample_sample_fmt
Definition: avconv.h:221
int nb_intra_matrices
Definition: avconv.h:148
char * forced_keyframes
Definition: avconv.h:288
int nb_frame_rates
Definition: avconv.h:83
const OptionDef options[]
Definition: avserver.c:4665
int resample_width
Definition: avconv.h:218
Main libavformat public API header.
int file
Definition: avconv.h:64
struct FilterGraph * graph
Definition: avconv.h:177
uint64_t limit_filesize
Definition: avconv.h:312
SpecifierOpt * presets
Definition: avconv.h:155
int nb_frame_sizes
Definition: avconv.h:85
rational numbers
OptionGroup * g
Definition: avconv.h:70
SpecifierOpt * inter_matrices
Definition: avconv.h:149
int do_pkt_dump
Definition: avconv_opt.c:68
struct FilterGraph FilterGraph
struct MetadataMap MetadataMap
SpecifierOpt * forced_key_frames
Definition: avconv.h:139
const char ** attachments
Definition: avconv.h:107
char * vstats_filename
Definition: avconv_opt.c:57
void show_usage(void)
Definition: avconv_opt.c:1850
AVFormatContext * ctx
Definition: avconv.h:236
int stream_index
Definition: avconv.h:56
AVCodec * enc
Definition: avconv.h:273
int eof_reached
Definition: avconv.h:237
int nb_metadata_map
Definition: avconv.h:154
int forced_kf_index
Definition: avconv.h:287
int nb_rc_overrides
Definition: avconv.h:146
InputStream ** input_streams
Definition: avconv.c:102
pixel format definitions
char * avfilter
Definition: avconv.h:294
uint8_t * name
Definition: avconv.h:171
int audio_volume
Definition: avconv_opt.c:62
int top_field_first
Definition: avconv.h:280
OutputFilter ** outputs
Definition: avconv.h:192
SpecifierOpt * max_frames
Definition: avconv.h:129
int nb_copy_initial_nonkeyframes
Definition: avconv.h:158
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
int disabled
Definition: avconv.h:54
int nb_input_streams
Definition: avconv.c:103
AVFormatContext * ctx
Definition: avconv.h:307
SpecifierOpt * codec_names
Definition: avconv.h:76
An instance of a filter.
Definition: avfilter.h:418
int do_hex_dump
Definition: avconv_opt.c:67
InputFilter ** inputs
Definition: avconv.h:190
float frame_aspect_ratio
Definition: avconv.h:282
int sync_stream_index
Definition: avconv.h:58
struct OptionsContext OptionsContext
int discard
Definition: avconv.h:199
enum AVPixelFormat pix_fmts[2]
Definition: avconv.h:303
int64_t first_pts
Definition: avconv.h:269
int nb_inputs
Definition: avconv.h:191
int index
Definition: avconv.h:257
int opt_cpuflags(void *optctx, const char *opt, const char *arg)
Definition: avconv_opt.c:1723
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
uint64_t resample_channel_layout
Definition: avconv.h:224
int nb_output_streams
Definition: avconv.c:108
int nb_frame_aspect_ratios
Definition: avconv.h:144
int subtitle_disable
Definition: avconv.h:120