Libav
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"
39 
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"
45 
46 #define VSYNC_AUTO -1
47 #define VSYNC_PASSTHROUGH 0
48 #define VSYNC_CFR 1
49 #define VSYNC_VFR 2
50 
51 enum HWAccelID {
55 };
56 
57 typedef struct HWAccel {
58  const char *name;
59  int (*init)(AVCodecContext *s);
60  enum HWAccelID id;
62 } HWAccel;
63 
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 */
71  char *linklabel; /* name of an output link, for mapping lavfi outputs */
72 } StreamMap;
73 
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
79 } MetadataMap;
80 
81 typedef struct OptionsContext {
83 
84  /* input/output options */
85  int64_t start_time;
86  const char *format;
87 
100 
101  /* input options */
103  int rate_emu;
105 
114 
115  /* output options */
118  /* first item specifies output metadata, second is input */
124  const char **attachments;
126 
128 
129  int64_t recording_time;
130  uint64_t limit_filesize;
131  float mux_preload;
133  int shortest;
134 
139 
140  /* indexed by output file stream index */
143 
181  int nb_pass;
185 
186 typedef struct InputFilter {
188  struct InputStream *ist;
191 } InputFilter;
192 
193 typedef struct OutputFilter {
195  struct OutputStream *ost;
198 
199  /* temporary storage until stream maps are processed */
201 } OutputFilter;
202 
203 typedef struct FilterGraph {
204  int index;
205  const char *graph_desc;
206 
208 
213 } FilterGraph;
214 
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' */
222  AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
223 
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 */
227  int64_t next_dts;
228  /* dts of the last packet read for this stream */
229  int64_t last_dts;
231  double ts_scale;
232  int is_start; /* is 1 at the start and after a discontinuity */
235  AVRational framerate; /* framerate forced with -r */
236 
240 
245 
246  /* decoded data from this stream goes into all those filters
247  * currently video and audio only */
250 
251  /* hwaccel options */
254 
255  /* hwaccel context */
257  void *hwaccel_ctx;
263 } InputStream;
264 
265 typedef struct InputFile {
267  int eof_reached; /* true if eof reached */
268  int eagain; /* true if last read attempt returned EAGAIN */
269  int ist_index; /* index of first stream in ist_table */
270  int64_t ts_offset;
271  int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
272  int64_t recording_time;
273  int nb_streams; /* number of stream that avconv is aware of; may be different
274  from ctx.nb_streams if new streams appear during av_read_frame() */
275  int rate_emu;
277 
278 #if HAVE_PTHREADS
279  pthread_t thread; /* thread reading from this file */
280  int finished; /* the thread has exited */
281  int joined; /* the thread has been joined */
282  pthread_mutex_t fifo_lock; /* lock for access to fifo */
283  pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
284  AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
285 #endif
286 } InputFile;
287 
288 typedef struct OutputStream {
289  int file_index; /* file index */
290  int index; /* stream index in the output file */
291  int source_index; /* InputStream index */
292  AVStream *st; /* stream in the output file */
293  int encoding_needed; /* true if encoding needed for this stream */
295  /* input pts and corresponding output pts
296  for A/V sync */
297  // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
298  struct InputStream *sync_ist; /* input stream to sync against */
299  int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
300  /* pts of the first frame encoded for this stream, used for limiting
301  * recording time */
302  int64_t first_pts;
303  /* dts of the last packet sent to the muxer */
304  int64_t last_mux_dts;
307  int64_t max_frames;
309 
310  /* video only */
314 
316 
317  /* forced key frames */
318  int64_t *forced_kf_pts;
322 
324  FILE *logfile;
325 
327  char *avfilter;
328 
329  int64_t sws_flags;
332  int finished; /* no more packets should be written for this stream */
334  const char *attachment_filename;
336 
338 
340 } OutputStream;
341 
342 typedef struct OutputFile {
345  int ost_index; /* index of the first stream in output_streams */
346  int64_t recording_time; /* desired length of the resulting file in microseconds */
347  int64_t start_time; /* start time in microseconds */
348  uint64_t limit_filesize;
349 
350  int shortest;
351 } OutputFile;
352 
353 extern InputStream **input_streams;
354 extern int nb_input_streams;
355 extern InputFile **input_files;
356 extern int nb_input_files;
357 
359 extern int nb_output_streams;
360 extern OutputFile **output_files;
361 extern int nb_output_files;
362 
363 extern FilterGraph **filtergraphs;
364 extern int nb_filtergraphs;
365 
366 extern char *vstats_filename;
367 
368 extern float audio_drift_threshold;
369 extern float dts_delta_threshold;
370 
371 extern int audio_volume;
372 extern int audio_sync_method;
373 extern int video_sync_method;
374 extern int do_benchmark;
375 extern int do_deinterlace;
376 extern int do_hex_dump;
377 extern int do_pkt_dump;
378 extern int copy_ts;
379 extern int copy_tb;
380 extern int exit_on_error;
381 extern int print_stats;
382 extern int qp_hist;
383 
384 extern const AVIOInterruptCB int_cb;
385 
386 extern const OptionDef options[];
387 
388 extern const HWAccel hwaccels[];
389 
391 void show_usage(void);
392 
393 void opt_output_file(void *optctx, const char *filename);
394 
396 
398 
403 
404 int avconv_parse_options(int argc, char **argv);
405 
406 int vdpau_init(AVCodecContext *s);
407 
408 #endif /* AVCONV_H */