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.

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