You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

365 lines
11KB

  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. #ifndef AVCONV_H
  19. #define AVCONV_H
  20. #include "config.h"
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #if HAVE_PTHREADS
  24. #include <pthread.h>
  25. #endif
  26. #include "cmdutils.h"
  27. #include "libavformat/avformat.h"
  28. #include "libavformat/avio.h"
  29. #include "libavcodec/avcodec.h"
  30. #include "libavfilter/avfilter.h"
  31. #include "libavfilter/avfiltergraph.h"
  32. #include "libavutil/avutil.h"
  33. #include "libavutil/dict.h"
  34. #include "libavutil/fifo.h"
  35. #include "libavutil/pixfmt.h"
  36. #include "libavutil/rational.h"
  37. #define VSYNC_AUTO -1
  38. #define VSYNC_PASSTHROUGH 0
  39. #define VSYNC_CFR 1
  40. #define VSYNC_VFR 2
  41. /* select an input stream for an output stream */
  42. typedef struct StreamMap {
  43. int disabled; /** 1 is this mapping is disabled by a negative map */
  44. int file_index;
  45. int stream_index;
  46. int sync_file_index;
  47. int sync_stream_index;
  48. char *linklabel; /** name of an output link, for mapping lavfi outputs */
  49. } StreamMap;
  50. /**
  51. * select an input file for an output file
  52. */
  53. typedef struct MetadataMap {
  54. int file; ///< file index
  55. char type; ///< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram
  56. int index; ///< stream/chapter/program number
  57. } MetadataMap;
  58. typedef struct OptionsContext {
  59. /* input/output options */
  60. int64_t start_time;
  61. const char *format;
  62. SpecifierOpt *codec_names;
  63. int nb_codec_names;
  64. SpecifierOpt *audio_channels;
  65. int nb_audio_channels;
  66. SpecifierOpt *audio_sample_rate;
  67. int nb_audio_sample_rate;
  68. SpecifierOpt *frame_rates;
  69. int nb_frame_rates;
  70. SpecifierOpt *frame_sizes;
  71. int nb_frame_sizes;
  72. SpecifierOpt *frame_pix_fmts;
  73. int nb_frame_pix_fmts;
  74. /* input options */
  75. int64_t input_ts_offset;
  76. int rate_emu;
  77. SpecifierOpt *ts_scale;
  78. int nb_ts_scale;
  79. SpecifierOpt *dump_attachment;
  80. int nb_dump_attachment;
  81. /* output options */
  82. StreamMap *stream_maps;
  83. int nb_stream_maps;
  84. /* first item specifies output metadata, second is input */
  85. MetadataMap (*meta_data_maps)[2];
  86. int nb_meta_data_maps;
  87. int metadata_global_manual;
  88. int metadata_streams_manual;
  89. int metadata_chapters_manual;
  90. const char **attachments;
  91. int nb_attachments;
  92. int chapters_input_file;
  93. int64_t recording_time;
  94. uint64_t limit_filesize;
  95. float mux_preload;
  96. float mux_max_delay;
  97. int shortest;
  98. int video_disable;
  99. int audio_disable;
  100. int subtitle_disable;
  101. int data_disable;
  102. /* indexed by output file stream index */
  103. int *streamid_map;
  104. int nb_streamid_map;
  105. SpecifierOpt *metadata;
  106. int nb_metadata;
  107. SpecifierOpt *max_frames;
  108. int nb_max_frames;
  109. SpecifierOpt *bitstream_filters;
  110. int nb_bitstream_filters;
  111. SpecifierOpt *codec_tags;
  112. int nb_codec_tags;
  113. SpecifierOpt *sample_fmts;
  114. int nb_sample_fmts;
  115. SpecifierOpt *qscale;
  116. int nb_qscale;
  117. SpecifierOpt *forced_key_frames;
  118. int nb_forced_key_frames;
  119. SpecifierOpt *force_fps;
  120. int nb_force_fps;
  121. SpecifierOpt *frame_aspect_ratios;
  122. int nb_frame_aspect_ratios;
  123. SpecifierOpt *rc_overrides;
  124. int nb_rc_overrides;
  125. SpecifierOpt *intra_matrices;
  126. int nb_intra_matrices;
  127. SpecifierOpt *inter_matrices;
  128. int nb_inter_matrices;
  129. SpecifierOpt *top_field_first;
  130. int nb_top_field_first;
  131. SpecifierOpt *metadata_map;
  132. int nb_metadata_map;
  133. SpecifierOpt *presets;
  134. int nb_presets;
  135. SpecifierOpt *copy_initial_nonkeyframes;
  136. int nb_copy_initial_nonkeyframes;
  137. SpecifierOpt *filters;
  138. int nb_filters;
  139. } OptionsContext;
  140. typedef struct InputFilter {
  141. AVFilterContext *filter;
  142. struct InputStream *ist;
  143. struct FilterGraph *graph;
  144. uint8_t *name;
  145. } InputFilter;
  146. typedef struct OutputFilter {
  147. AVFilterContext *filter;
  148. struct OutputStream *ost;
  149. struct FilterGraph *graph;
  150. uint8_t *name;
  151. /* temporary storage until stream maps are processed */
  152. AVFilterInOut *out_tmp;
  153. } OutputFilter;
  154. typedef struct FilterGraph {
  155. int index;
  156. const char *graph_desc;
  157. AVFilterGraph *graph;
  158. InputFilter **inputs;
  159. int nb_inputs;
  160. OutputFilter **outputs;
  161. int nb_outputs;
  162. } FilterGraph;
  163. typedef struct InputStream {
  164. int file_index;
  165. AVStream *st;
  166. int discard; /* true if stream data should be discarded */
  167. int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
  168. AVCodec *dec;
  169. AVFrame *decoded_frame;
  170. int64_t start; /* time when read started */
  171. /* predicted dts of the next packet read for this stream or (when there are
  172. * several frames in a packet) of the next frame in current packet */
  173. int64_t next_dts;
  174. /* dts of the last packet read for this stream */
  175. int64_t last_dts;
  176. PtsCorrectionContext pts_ctx;
  177. double ts_scale;
  178. int is_start; /* is 1 at the start and after a discontinuity */
  179. int showed_multi_packet_warning;
  180. AVDictionary *opts;
  181. AVRational framerate; /* framerate forced with -r */
  182. int resample_height;
  183. int resample_width;
  184. int resample_pix_fmt;
  185. int resample_sample_fmt;
  186. int resample_sample_rate;
  187. int resample_channels;
  188. uint64_t resample_channel_layout;
  189. /* a pool of free buffers for decoded data */
  190. FrameBuffer *buffer_pool;
  191. /* decoded data from this stream goes into all those filters
  192. * currently video and audio only */
  193. InputFilter **filters;
  194. int nb_filters;
  195. } InputStream;
  196. typedef struct InputFile {
  197. AVFormatContext *ctx;
  198. int eof_reached; /* true if eof reached */
  199. int eagain; /* true if last read attempt returned EAGAIN */
  200. int ist_index; /* index of first stream in ist_table */
  201. int64_t ts_offset;
  202. int nb_streams; /* number of stream that avconv is aware of; may be different
  203. from ctx.nb_streams if new streams appear during av_read_frame() */
  204. int rate_emu;
  205. #if HAVE_PTHREADS
  206. pthread_t thread; /* thread reading from this file */
  207. int finished; /* the thread has exited */
  208. int joined; /* the thread has been joined */
  209. pthread_mutex_t fifo_lock; /* lock for access to fifo */
  210. pthread_cond_t fifo_cond; /* the main thread will signal on this cond after reading from fifo */
  211. AVFifoBuffer *fifo; /* demuxed packets are stored here; freed by the main thread */
  212. #endif
  213. } InputFile;
  214. typedef struct OutputStream {
  215. int file_index; /* file index */
  216. int index; /* stream index in the output file */
  217. int source_index; /* InputStream index */
  218. AVStream *st; /* stream in the output file */
  219. int encoding_needed; /* true if encoding needed for this stream */
  220. int frame_number;
  221. /* input pts and corresponding output pts
  222. for A/V sync */
  223. // double sync_ipts; /* dts from the AVPacket of the demuxer in second units */
  224. struct InputStream *sync_ist; /* input stream to sync against */
  225. int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
  226. /* pts of the first frame encoded for this stream, used for limiting
  227. * recording time */
  228. int64_t first_pts;
  229. AVBitStreamFilterContext *bitstream_filters;
  230. AVCodec *enc;
  231. int64_t max_frames;
  232. AVFrame *filtered_frame;
  233. /* video only */
  234. AVRational frame_rate;
  235. int force_fps;
  236. int top_field_first;
  237. float frame_aspect_ratio;
  238. float last_quality;
  239. /* forced key frames */
  240. int64_t *forced_kf_pts;
  241. int forced_kf_count;
  242. int forced_kf_index;
  243. char *forced_keyframes;
  244. FILE *logfile;
  245. OutputFilter *filter;
  246. char *avfilter;
  247. int64_t sws_flags;
  248. AVDictionary *opts;
  249. int finished; /* no more packets should be written for this stream */
  250. int stream_copy;
  251. const char *attachment_filename;
  252. int copy_initial_nonkeyframes;
  253. enum PixelFormat pix_fmts[2];
  254. } OutputStream;
  255. typedef struct OutputFile {
  256. AVFormatContext *ctx;
  257. AVDictionary *opts;
  258. int ost_index; /* index of the first stream in output_streams */
  259. int64_t recording_time; /* desired length of the resulting file in microseconds */
  260. int64_t start_time; /* start time in microseconds */
  261. uint64_t limit_filesize;
  262. int shortest;
  263. } OutputFile;
  264. extern InputStream **input_streams;
  265. extern int nb_input_streams;
  266. extern InputFile **input_files;
  267. extern int nb_input_files;
  268. extern OutputStream **output_streams;
  269. extern int nb_output_streams;
  270. extern OutputFile **output_files;
  271. extern int nb_output_files;
  272. extern FilterGraph **filtergraphs;
  273. extern int nb_filtergraphs;
  274. extern char *pass_logfilename_prefix;
  275. extern char *vstats_filename;
  276. extern float audio_drift_threshold;
  277. extern float dts_delta_threshold;
  278. extern int audio_volume;
  279. extern int audio_sync_method;
  280. extern int video_sync_method;
  281. extern int do_benchmark;
  282. extern int do_deinterlace;
  283. extern int do_hex_dump;
  284. extern int do_pkt_dump;
  285. extern int copy_ts;
  286. extern int copy_tb;
  287. extern int exit_on_error;
  288. extern int print_stats;
  289. extern int qp_hist;
  290. extern int same_quant;
  291. extern const AVIOInterruptCB int_cb;
  292. extern const OptionDef options[];
  293. void reset_options(OptionsContext *o);
  294. void show_usage(void);
  295. int opt_cpuflags(const char *opt, const char *arg);
  296. void opt_output_file(void *optctx, const char *filename);
  297. void assert_avoptions(AVDictionary *m);
  298. int guess_input_channel_layout(InputStream *ist);
  299. int configure_filtergraph(FilterGraph *fg);
  300. int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out);
  301. int ist_in_filtergraph(FilterGraph *fg, InputStream *ist);
  302. FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost);
  303. #endif /* AVCONV_H */