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 */