FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ffmpeg.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef FFMPEG_H
20 #define FFMPEG_H
21 
22 #include "config.h"
23 
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <signal.h>
27 
28 #if HAVE_PTHREADS
29 #include <pthread.h>
30 #endif
31 
32 #include "cmdutils.h"
33 
34 #include "libavformat/avformat.h"
35 #include "libavformat/avio.h"
36 
37 #include "libavcodec/avcodec.h"
38 
39 #include "libavfilter/avfilter.h"
40 
41 #include "libavutil/avutil.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/eval.h"
44 #include "libavutil/fifo.h"
45 #include "libavutil/pixfmt.h"
46 #include "libavutil/rational.h"
47 
49 
50 #define VSYNC_AUTO -1
51 #define VSYNC_PASSTHROUGH 0
52 #define VSYNC_CFR 1
53 #define VSYNC_VFR 2
54 #define VSYNC_VSCFR 0xfe
55 #define VSYNC_DROP 0xff
56 
57 #define MAX_STREAMS 1024 /* arbitrary sanity check value */
58 
59 enum HWAccelID {
63 };
64 
65 typedef struct HWAccel {
66  const char *name;
67  int (*init)(AVCodecContext *s);
68  enum HWAccelID id;
70 } HWAccel;
71 
72 /* select an input stream for an output stream */
73 typedef struct StreamMap {
74  int disabled; /* 1 is this mapping is disabled by a negative map */
79  char *linklabel; /* name of an output link, for mapping lavfi outputs */
80 } StreamMap;
81 
82 typedef struct {
83  int file_idx, stream_idx, channel_idx; // input
84  int ofile_idx, ostream_idx; // output
86 
87 typedef struct OptionsContext {
89 
90  /* input/output options */
91  int64_t start_time;
92  const char *format;
93 
106 
107  /* input options */
109  int rate_emu;
111 
120 
121  /* output options */
124  AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */
125  int nb_audio_channel_maps; /* number of (valid) -map_channel settings */
129  const char **attachments;
131 
133 
134  int64_t recording_time;
135  int64_t stop_time;
136  uint64_t limit_filesize;
137  float mux_preload;
139  int shortest;
140 
145 
146  /* indexed by output file stream index */
149 
197  int nb_pass;
203  int nb_apad;
205 
206 typedef struct InputFilter {
208  struct InputStream *ist;
211 } InputFilter;
212 
213 typedef struct OutputFilter {
215  struct OutputStream *ost;
218 
219  /* temporary storage until stream maps are processed */
221 } OutputFilter;
222 
223 typedef struct FilterGraph {
224  int index;
225  const char *graph_desc;
226 
229 
234 } FilterGraph;
235 
236 typedef struct InputStream {
239  int discard; /* true if stream data should be discarded */
240  int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
243  AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
244 
245  int64_t start; /* time when read started */
246  /* predicted dts of the next packet read for this stream or (when there are
247  * several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
248  int64_t next_dts;
249  int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
250 
251  int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
252  int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
254 
256 
257  double ts_scale;
261  AVRational framerate; /* framerate forced with -r */
264 
268 
273 
275  struct { /* previous decoded subtitle and related variables */
277  int ret;
279  } prev_sub;
280 
281  struct sub2video {
282  int64_t last_pts;
283  int64_t end_pts;
285  int w, h;
286  } sub2video;
287 
288  int dr1;
289 
290  /* decoded data from this stream goes into all those filters
291  * currently video and audio only */
294 
296 
297  /* hwaccel options */
300 
301  /* hwaccel context */
303  void *hwaccel_ctx;
309 } InputStream;
310 
311 typedef struct InputFile {
313  int eof_reached; /* true if eof reached */
314  int eagain; /* true if last read attempt returned EAGAIN */
315  int ist_index; /* index of first stream in input_streams */
317  int64_t ts_offset;
318  int64_t last_ts;
319  int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
320  int64_t recording_time;
321  int nb_streams; /* number of stream that ffmpeg is aware of; may be different
322  from ctx.nb_streams if new streams appear during av_read_frame() */
323  int nb_streams_warn; /* number of streams that the user was warned of */
324  int rate_emu;
326 
327 #if HAVE_PTHREADS
328  pthread_t thread; /* thread reading from this file */
329  int non_blocking; /* reading packets from the thread should not block */
330  int finished; /* the thread has exited */
331  int joined; /* the thread has been joined */
332  pthread_mutex_t fifo_lock; /* lock for access to fifo */
333  pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
334  AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
335 #endif
336 } InputFile;
337 
345 };
346 
347 extern const char *const forced_keyframes_const_names[];
348 
349 typedef enum {
352 } OSTFinished ;
353 
354 typedef struct OutputStream {
355  int file_index; /* file index */
356  int index; /* stream index in the output file */
357  int source_index; /* InputStream index */
358  AVStream *st; /* stream in the output file */
359  int encoding_needed; /* true if encoding needed for this stream */
361  /* input pts and corresponding output pts
362  for A/V sync */
363  struct InputStream *sync_ist; /* input stream to sync against */
364  int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
365  /* pts of the first frame encoded for this stream, used for limiting
366  * recording time */
367  int64_t first_pts;
368  /* dts of the last packet sent to the muxer */
369  int64_t last_mux_dts;
372  int64_t max_frames;
374 
375  /* video only */
379 
381 
382  /* forced key frames */
383  int64_t *forced_kf_pts;
389 
390  /* audio only */
391  int audio_channels_map[SWR_CH_MAX]; /* list of the channels id to pick from the source stream */
392  int audio_channels_mapped; /* number of channels in audio_channels_map */
393 
395  FILE *logfile;
396 
398  char *avfilter;
399  char *filters; ///< filtergraph associated to the -filter option
400  char *filters_script; ///< filtergraph script associated to the -filter_script option
401 
402  int64_t sws_flags;
406  char *apad;
407  OSTFinished finished; /* no more packets should be written for this stream */
408  int unavailable; /* true if the steram is unavailable (possibly temporarily) */
410  const char *attachment_filename;
413 
415 
417 } OutputStream;
418 
419 typedef struct OutputFile {
422  int ost_index; /* index of the first stream in output_streams */
423  int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
424  int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
425  uint64_t limit_filesize; /* filesize limit expressed in bytes */
426 
427  int shortest;
428 } OutputFile;
429 
430 extern InputStream **input_streams;
431 extern int nb_input_streams;
432 extern InputFile **input_files;
433 extern int nb_input_files;
434 
436 extern int nb_output_streams;
437 extern OutputFile **output_files;
438 extern int nb_output_files;
439 
440 extern FilterGraph **filtergraphs;
441 extern int nb_filtergraphs;
442 
443 extern char *vstats_filename;
444 
445 extern float audio_drift_threshold;
446 extern float dts_delta_threshold;
447 extern float dts_error_threshold;
448 
449 extern int audio_volume;
450 extern int audio_sync_method;
451 extern int video_sync_method;
452 extern int do_benchmark;
453 extern int do_benchmark_all;
454 extern int do_deinterlace;
455 extern int do_hex_dump;
456 extern int do_pkt_dump;
457 extern int copy_ts;
458 extern int copy_tb;
459 extern int debug_ts;
460 extern int exit_on_error;
461 extern int print_stats;
462 extern int qp_hist;
463 extern int stdin_interaction;
464 extern int frame_bits_per_raw_sample;
465 extern AVIOContext *progress_avio;
466 extern float max_error_rate;
467 
468 extern const AVIOInterruptCB int_cb;
469 
470 extern const OptionDef options[];
471 extern const HWAccel hwaccels[];
472 
473 
474 void term_init(void);
475 void term_exit(void);
476 
477 void reset_options(OptionsContext *o, int is_input);
478 void show_usage(void);
479 
480 void opt_output_file(void *optctx, const char *filename);
481 
483 
485 
486 enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodec *codec, enum AVPixelFormat target);
487 void choose_sample_fmt(AVStream *st, AVCodec *codec);
488 
493 
494 int ffmpeg_parse_options(int argc, char **argv);
495 
497 
498 #endif /* FFMPEG_H */