It will be further developed with a few incompatible changes.
ffmpeg.c will stay as is for some time, so any scripts using it won't be
broken.
| ... | ... |
@@ -53,6 +53,7 @@ COMPILE_S = $(call COMPILE,AS) |
| 53 | 53 |
%.c %.h: TAG = GEN |
| 54 | 54 |
|
| 55 | 55 |
PROGS-$(CONFIG_FFMPEG) += ffmpeg |
| 56 |
+PROGS-$(CONFIG_AVCONV) += avconv |
|
| 56 | 57 |
PROGS-$(CONFIG_AVPLAY) += avplay |
| 57 | 58 |
PROGS-$(CONFIG_AVPROBE) += avprobe |
| 58 | 59 |
PROGS-$(CONFIG_AVSERVER) += avserver |
| ... | ... |
@@ -64,7 +65,7 @@ HOSTPROGS := $(TESTTOOLS:%=tests/%) |
| 64 | 64 |
TOOLS = qt-faststart trasher |
| 65 | 65 |
TOOLS-$(CONFIG_ZLIB) += cws2fws |
| 66 | 66 |
|
| 67 |
-BASENAMES = ffmpeg avplay avprobe avserver |
|
| 67 |
+BASENAMES = ffmpeg avconv avplay avprobe avserver |
|
| 68 | 68 |
ALLPROGS = $(BASENAMES:%=%$(EXESUF)) |
| 69 | 69 |
ALLMANPAGES = $(BASENAMES:%=%.1) |
| 70 | 70 |
|
| 71 | 71 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,4428 @@ |
| 0 |
+/* |
|
| 1 |
+ * avconv main |
|
| 2 |
+ * Copyright (c) 2000-2011 The libav developers. |
|
| 3 |
+ * |
|
| 4 |
+ * This file is part of Libav. |
|
| 5 |
+ * |
|
| 6 |
+ * Libav is free software; you can redistribute it and/or |
|
| 7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 8 |
+ * License as published by the Free Software Foundation; either |
|
| 9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 10 |
+ * |
|
| 11 |
+ * Libav is distributed in the hope that it will be useful, |
|
| 12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 |
+ * Lesser General Public License for more details. |
|
| 15 |
+ * |
|
| 16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 17 |
+ * License along with Libav; if not, write to the Free Software |
|
| 18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 19 |
+ */ |
|
| 20 |
+ |
|
| 21 |
+#include "config.h" |
|
| 22 |
+#include <ctype.h> |
|
| 23 |
+#include <string.h> |
|
| 24 |
+#include <math.h> |
|
| 25 |
+#include <stdlib.h> |
|
| 26 |
+#include <errno.h> |
|
| 27 |
+#include <signal.h> |
|
| 28 |
+#include <limits.h> |
|
| 29 |
+#include <unistd.h> |
|
| 30 |
+#include "libavformat/avformat.h" |
|
| 31 |
+#include "libavdevice/avdevice.h" |
|
| 32 |
+#include "libswscale/swscale.h" |
|
| 33 |
+#include "libavutil/opt.h" |
|
| 34 |
+#include "libavcodec/audioconvert.h" |
|
| 35 |
+#include "libavutil/audioconvert.h" |
|
| 36 |
+#include "libavutil/parseutils.h" |
|
| 37 |
+#include "libavutil/samplefmt.h" |
|
| 38 |
+#include "libavutil/colorspace.h" |
|
| 39 |
+#include "libavutil/fifo.h" |
|
| 40 |
+#include "libavutil/intreadwrite.h" |
|
| 41 |
+#include "libavutil/dict.h" |
|
| 42 |
+#include "libavutil/mathematics.h" |
|
| 43 |
+#include "libavutil/pixdesc.h" |
|
| 44 |
+#include "libavutil/avstring.h" |
|
| 45 |
+#include "libavutil/libm.h" |
|
| 46 |
+#include "libavformat/os_support.h" |
|
| 47 |
+ |
|
| 48 |
+#if CONFIG_AVFILTER |
|
| 49 |
+# include "libavfilter/avfilter.h" |
|
| 50 |
+# include "libavfilter/avfiltergraph.h" |
|
| 51 |
+# include "libavfilter/vsrc_buffer.h" |
|
| 52 |
+#endif |
|
| 53 |
+ |
|
| 54 |
+#if HAVE_SYS_RESOURCE_H |
|
| 55 |
+#include <sys/types.h> |
|
| 56 |
+#include <sys/time.h> |
|
| 57 |
+#include <sys/resource.h> |
|
| 58 |
+#elif HAVE_GETPROCESSTIMES |
|
| 59 |
+#include <windows.h> |
|
| 60 |
+#endif |
|
| 61 |
+#if HAVE_GETPROCESSMEMORYINFO |
|
| 62 |
+#include <windows.h> |
|
| 63 |
+#include <psapi.h> |
|
| 64 |
+#endif |
|
| 65 |
+ |
|
| 66 |
+#if HAVE_SYS_SELECT_H |
|
| 67 |
+#include <sys/select.h> |
|
| 68 |
+#endif |
|
| 69 |
+ |
|
| 70 |
+#include <time.h> |
|
| 71 |
+ |
|
| 72 |
+#include "cmdutils.h" |
|
| 73 |
+ |
|
| 74 |
+#include "libavutil/avassert.h" |
|
| 75 |
+ |
|
| 76 |
+const char program_name[] = "avconv"; |
|
| 77 |
+const int program_birth_year = 2000; |
|
| 78 |
+ |
|
| 79 |
+/* select an input stream for an output stream */ |
|
| 80 |
+typedef struct StreamMap {
|
|
| 81 |
+ int file_index; |
|
| 82 |
+ int stream_index; |
|
| 83 |
+ int sync_file_index; |
|
| 84 |
+ int sync_stream_index; |
|
| 85 |
+} StreamMap; |
|
| 86 |
+ |
|
| 87 |
+/** |
|
| 88 |
+ * select an input file for an output file |
|
| 89 |
+ */ |
|
| 90 |
+typedef struct MetadataMap {
|
|
| 91 |
+ int file; //< file index |
|
| 92 |
+ char type; //< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram |
|
| 93 |
+ int index; //< stream/chapter/program number |
|
| 94 |
+} MetadataMap; |
|
| 95 |
+ |
|
| 96 |
+typedef struct ChapterMap {
|
|
| 97 |
+ int in_file; |
|
| 98 |
+ int out_file; |
|
| 99 |
+} ChapterMap; |
|
| 100 |
+ |
|
| 101 |
+static const OptionDef options[]; |
|
| 102 |
+ |
|
| 103 |
+#define MAX_FILES 100 |
|
| 104 |
+ |
|
| 105 |
+static const char *last_asked_format = NULL; |
|
| 106 |
+static double *ts_scale; |
|
| 107 |
+static int nb_ts_scale; |
|
| 108 |
+ |
|
| 109 |
+static AVFormatContext *output_files[MAX_FILES]; |
|
| 110 |
+static AVDictionary *output_opts[MAX_FILES]; |
|
| 111 |
+static int nb_output_files = 0; |
|
| 112 |
+ |
|
| 113 |
+static StreamMap *stream_maps = NULL; |
|
| 114 |
+static int nb_stream_maps; |
|
| 115 |
+ |
|
| 116 |
+/* first item specifies output metadata, second is input */ |
|
| 117 |
+static MetadataMap (*meta_data_maps)[2] = NULL; |
|
| 118 |
+static int nb_meta_data_maps; |
|
| 119 |
+static int metadata_global_autocopy = 1; |
|
| 120 |
+static int metadata_streams_autocopy = 1; |
|
| 121 |
+static int metadata_chapters_autocopy = 1; |
|
| 122 |
+ |
|
| 123 |
+static ChapterMap *chapter_maps = NULL; |
|
| 124 |
+static int nb_chapter_maps; |
|
| 125 |
+ |
|
| 126 |
+/* indexed by output file stream index */ |
|
| 127 |
+static int *streamid_map = NULL; |
|
| 128 |
+static int nb_streamid_map = 0; |
|
| 129 |
+ |
|
| 130 |
+static int frame_width = 0; |
|
| 131 |
+static int frame_height = 0; |
|
| 132 |
+static float frame_aspect_ratio = 0; |
|
| 133 |
+static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; |
|
| 134 |
+static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE; |
|
| 135 |
+static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
|
|
| 136 |
+static AVRational frame_rate; |
|
| 137 |
+static float video_qscale = 0; |
|
| 138 |
+static uint16_t *intra_matrix = NULL; |
|
| 139 |
+static uint16_t *inter_matrix = NULL; |
|
| 140 |
+static const char *video_rc_override_string=NULL; |
|
| 141 |
+static int video_disable = 0; |
|
| 142 |
+static int video_discard = 0; |
|
| 143 |
+static char *video_codec_name = NULL; |
|
| 144 |
+static unsigned int video_codec_tag = 0; |
|
| 145 |
+static char *video_language = NULL; |
|
| 146 |
+static int same_quality = 0; |
|
| 147 |
+static int do_deinterlace = 0; |
|
| 148 |
+static int top_field_first = -1; |
|
| 149 |
+static int me_threshold = 0; |
|
| 150 |
+static int intra_dc_precision = 8; |
|
| 151 |
+static int loop_input = 0; |
|
| 152 |
+static int loop_output = AVFMT_NOOUTPUTLOOP; |
|
| 153 |
+static int qp_hist = 0; |
|
| 154 |
+#if CONFIG_AVFILTER |
|
| 155 |
+static char *vfilters = NULL; |
|
| 156 |
+#endif |
|
| 157 |
+ |
|
| 158 |
+static int intra_only = 0; |
|
| 159 |
+static int audio_sample_rate = 0; |
|
| 160 |
+#define QSCALE_NONE -99999 |
|
| 161 |
+static float audio_qscale = QSCALE_NONE; |
|
| 162 |
+static int audio_disable = 0; |
|
| 163 |
+static int audio_channels = 0; |
|
| 164 |
+static char *audio_codec_name = NULL; |
|
| 165 |
+static unsigned int audio_codec_tag = 0; |
|
| 166 |
+static char *audio_language = NULL; |
|
| 167 |
+ |
|
| 168 |
+static int subtitle_disable = 0; |
|
| 169 |
+static char *subtitle_codec_name = NULL; |
|
| 170 |
+static char *subtitle_language = NULL; |
|
| 171 |
+static unsigned int subtitle_codec_tag = 0; |
|
| 172 |
+ |
|
| 173 |
+static int data_disable = 0; |
|
| 174 |
+static char *data_codec_name = NULL; |
|
| 175 |
+static unsigned int data_codec_tag = 0; |
|
| 176 |
+ |
|
| 177 |
+static float mux_preload= 0.5; |
|
| 178 |
+static float mux_max_delay= 0.7; |
|
| 179 |
+ |
|
| 180 |
+static int64_t recording_time = INT64_MAX; |
|
| 181 |
+static int64_t start_time = 0; |
|
| 182 |
+static int64_t input_ts_offset = 0; |
|
| 183 |
+static int file_overwrite = 0; |
|
| 184 |
+static AVDictionary *metadata; |
|
| 185 |
+static int do_benchmark = 0; |
|
| 186 |
+static int do_hex_dump = 0; |
|
| 187 |
+static int do_pkt_dump = 0; |
|
| 188 |
+static int do_psnr = 0; |
|
| 189 |
+static int do_pass = 0; |
|
| 190 |
+static char *pass_logfilename_prefix = NULL; |
|
| 191 |
+static int audio_stream_copy = 0; |
|
| 192 |
+static int video_stream_copy = 0; |
|
| 193 |
+static int subtitle_stream_copy = 0; |
|
| 194 |
+static int data_stream_copy = 0; |
|
| 195 |
+static int video_sync_method= -1; |
|
| 196 |
+static int audio_sync_method= 0; |
|
| 197 |
+static float audio_drift_threshold= 0.1; |
|
| 198 |
+static int copy_ts= 0; |
|
| 199 |
+static int copy_tb; |
|
| 200 |
+static int opt_shortest = 0; |
|
| 201 |
+static char *vstats_filename; |
|
| 202 |
+static FILE *vstats_file; |
|
| 203 |
+static int opt_programid = 0; |
|
| 204 |
+static int copy_initial_nonkeyframes = 0; |
|
| 205 |
+ |
|
| 206 |
+static int rate_emu = 0; |
|
| 207 |
+ |
|
| 208 |
+static int audio_volume = 256; |
|
| 209 |
+ |
|
| 210 |
+static int exit_on_error = 0; |
|
| 211 |
+static int using_stdin = 0; |
|
| 212 |
+static int verbose = 1; |
|
| 213 |
+static int thread_count= 1; |
|
| 214 |
+static int64_t video_size = 0; |
|
| 215 |
+static int64_t audio_size = 0; |
|
| 216 |
+static int64_t extra_size = 0; |
|
| 217 |
+static int nb_frames_dup = 0; |
|
| 218 |
+static int nb_frames_drop = 0; |
|
| 219 |
+static int input_sync; |
|
| 220 |
+static uint64_t limit_filesize = 0; |
|
| 221 |
+static int force_fps = 0; |
|
| 222 |
+static char *forced_key_frames = NULL; |
|
| 223 |
+ |
|
| 224 |
+static float dts_delta_threshold = 10; |
|
| 225 |
+ |
|
| 226 |
+static int64_t timer_start; |
|
| 227 |
+ |
|
| 228 |
+static uint8_t *audio_buf; |
|
| 229 |
+static uint8_t *audio_out; |
|
| 230 |
+static unsigned int allocated_audio_out_size, allocated_audio_buf_size; |
|
| 231 |
+ |
|
| 232 |
+static short *samples; |
|
| 233 |
+ |
|
| 234 |
+static AVBitStreamFilterContext *video_bitstream_filters=NULL; |
|
| 235 |
+static AVBitStreamFilterContext *audio_bitstream_filters=NULL; |
|
| 236 |
+static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL; |
|
| 237 |
+ |
|
| 238 |
+#define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass" |
|
| 239 |
+ |
|
| 240 |
+struct InputStream; |
|
| 241 |
+ |
|
| 242 |
+typedef struct OutputStream {
|
|
| 243 |
+ int file_index; /* file index */ |
|
| 244 |
+ int index; /* stream index in the output file */ |
|
| 245 |
+ int source_index; /* InputStream index */ |
|
| 246 |
+ AVStream *st; /* stream in the output file */ |
|
| 247 |
+ int encoding_needed; /* true if encoding needed for this stream */ |
|
| 248 |
+ int frame_number; |
|
| 249 |
+ /* input pts and corresponding output pts |
|
| 250 |
+ for A/V sync */ |
|
| 251 |
+ //double sync_ipts; /* dts from the AVPacket of the demuxer in second units */ |
|
| 252 |
+ struct InputStream *sync_ist; /* input stream to sync against */ |
|
| 253 |
+ int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number |
|
| 254 |
+ AVBitStreamFilterContext *bitstream_filters; |
|
| 255 |
+ AVCodec *enc; |
|
| 256 |
+ |
|
| 257 |
+ /* video only */ |
|
| 258 |
+ int video_resample; |
|
| 259 |
+ AVFrame pict_tmp; /* temporary image for resampling */ |
|
| 260 |
+ struct SwsContext *img_resample_ctx; /* for image resampling */ |
|
| 261 |
+ int resample_height; |
|
| 262 |
+ int resample_width; |
|
| 263 |
+ int resample_pix_fmt; |
|
| 264 |
+ AVRational frame_rate; |
|
| 265 |
+ |
|
| 266 |
+ float frame_aspect_ratio; |
|
| 267 |
+ |
|
| 268 |
+ /* forced key frames */ |
|
| 269 |
+ int64_t *forced_kf_pts; |
|
| 270 |
+ int forced_kf_count; |
|
| 271 |
+ int forced_kf_index; |
|
| 272 |
+ |
|
| 273 |
+ /* audio only */ |
|
| 274 |
+ int audio_resample; |
|
| 275 |
+ ReSampleContext *resample; /* for audio resampling */ |
|
| 276 |
+ int resample_sample_fmt; |
|
| 277 |
+ int resample_channels; |
|
| 278 |
+ int resample_sample_rate; |
|
| 279 |
+ int reformat_pair; |
|
| 280 |
+ AVAudioConvert *reformat_ctx; |
|
| 281 |
+ AVFifoBuffer *fifo; /* for compression: one audio fifo per codec */ |
|
| 282 |
+ FILE *logfile; |
|
| 283 |
+ |
|
| 284 |
+#if CONFIG_AVFILTER |
|
| 285 |
+ AVFilterContext *output_video_filter; |
|
| 286 |
+ AVFilterContext *input_video_filter; |
|
| 287 |
+ AVFilterBufferRef *picref; |
|
| 288 |
+ char *avfilter; |
|
| 289 |
+ AVFilterGraph *graph; |
|
| 290 |
+#endif |
|
| 291 |
+ |
|
| 292 |
+ int sws_flags; |
|
| 293 |
+ AVDictionary *opts; |
|
| 294 |
+} OutputStream; |
|
| 295 |
+ |
|
| 296 |
+static OutputStream **output_streams_for_file[MAX_FILES] = { NULL };
|
|
| 297 |
+static int nb_output_streams_for_file[MAX_FILES] = { 0 };
|
|
| 298 |
+ |
|
| 299 |
+typedef struct InputStream {
|
|
| 300 |
+ int file_index; |
|
| 301 |
+ AVStream *st; |
|
| 302 |
+ int discard; /* true if stream data should be discarded */ |
|
| 303 |
+ int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ |
|
| 304 |
+ AVCodec *dec; |
|
| 305 |
+ |
|
| 306 |
+ int64_t start; /* time when read started */ |
|
| 307 |
+ int64_t next_pts; /* synthetic pts for cases where pkt.pts |
|
| 308 |
+ is not defined */ |
|
| 309 |
+ int64_t pts; /* current pts */ |
|
| 310 |
+ PtsCorrectionContext pts_ctx; |
|
| 311 |
+ double ts_scale; |
|
| 312 |
+ int is_start; /* is 1 at the start and after a discontinuity */ |
|
| 313 |
+ int showed_multi_packet_warning; |
|
| 314 |
+ int is_past_recording_time; |
|
| 315 |
+ AVDictionary *opts; |
|
| 316 |
+} InputStream; |
|
| 317 |
+ |
|
| 318 |
+typedef struct InputFile {
|
|
| 319 |
+ AVFormatContext *ctx; |
|
| 320 |
+ int eof_reached; /* true if eof reached */ |
|
| 321 |
+ int ist_index; /* index of first stream in ist_table */ |
|
| 322 |
+ int buffer_size; /* current total buffer size */ |
|
| 323 |
+ int64_t ts_offset; |
|
| 324 |
+} InputFile; |
|
| 325 |
+ |
|
| 326 |
+static InputStream *input_streams = NULL; |
|
| 327 |
+static int nb_input_streams = 0; |
|
| 328 |
+static InputFile *input_files = NULL; |
|
| 329 |
+static int nb_input_files = 0; |
|
| 330 |
+ |
|
| 331 |
+#if CONFIG_AVFILTER |
|
| 332 |
+ |
|
| 333 |
+static int configure_video_filters(InputStream *ist, OutputStream *ost) |
|
| 334 |
+{
|
|
| 335 |
+ AVFilterContext *last_filter, *filter; |
|
| 336 |
+ /** filter graph containing all filters including input & output */ |
|
| 337 |
+ AVCodecContext *codec = ost->st->codec; |
|
| 338 |
+ AVCodecContext *icodec = ist->st->codec; |
|
| 339 |
+ FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt };
|
|
| 340 |
+ AVRational sample_aspect_ratio; |
|
| 341 |
+ char args[255]; |
|
| 342 |
+ int ret; |
|
| 343 |
+ |
|
| 344 |
+ ost->graph = avfilter_graph_alloc(); |
|
| 345 |
+ |
|
| 346 |
+ if (ist->st->sample_aspect_ratio.num){
|
|
| 347 |
+ sample_aspect_ratio = ist->st->sample_aspect_ratio; |
|
| 348 |
+ }else |
|
| 349 |
+ sample_aspect_ratio = ist->st->codec->sample_aspect_ratio; |
|
| 350 |
+ |
|
| 351 |
+ snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width, |
|
| 352 |
+ ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE, |
|
| 353 |
+ sample_aspect_ratio.num, sample_aspect_ratio.den); |
|
| 354 |
+ |
|
| 355 |
+ ret = avfilter_graph_create_filter(&ost->input_video_filter, avfilter_get_by_name("buffer"),
|
|
| 356 |
+ "src", args, NULL, ost->graph); |
|
| 357 |
+ if (ret < 0) |
|
| 358 |
+ return ret; |
|
| 359 |
+ ret = avfilter_graph_create_filter(&ost->output_video_filter, &ffsink, |
|
| 360 |
+ "out", NULL, &ffsink_ctx, ost->graph); |
|
| 361 |
+ if (ret < 0) |
|
| 362 |
+ return ret; |
|
| 363 |
+ last_filter = ost->input_video_filter; |
|
| 364 |
+ |
|
| 365 |
+ if (codec->width != icodec->width || codec->height != icodec->height) {
|
|
| 366 |
+ snprintf(args, 255, "%d:%d:flags=0x%X", |
|
| 367 |
+ codec->width, |
|
| 368 |
+ codec->height, |
|
| 369 |
+ ost->sws_flags); |
|
| 370 |
+ if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
|
|
| 371 |
+ NULL, args, NULL, ost->graph)) < 0) |
|
| 372 |
+ return ret; |
|
| 373 |
+ if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0) |
|
| 374 |
+ return ret; |
|
| 375 |
+ last_filter = filter; |
|
| 376 |
+ } |
|
| 377 |
+ |
|
| 378 |
+ snprintf(args, sizeof(args), "flags=0x%X", ost->sws_flags); |
|
| 379 |
+ ost->graph->scale_sws_opts = av_strdup(args); |
|
| 380 |
+ |
|
| 381 |
+ if (ost->avfilter) {
|
|
| 382 |
+ AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut)); |
|
| 383 |
+ AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut)); |
|
| 384 |
+ |
|
| 385 |
+ outputs->name = av_strdup("in");
|
|
| 386 |
+ outputs->filter_ctx = last_filter; |
|
| 387 |
+ outputs->pad_idx = 0; |
|
| 388 |
+ outputs->next = NULL; |
|
| 389 |
+ |
|
| 390 |
+ inputs->name = av_strdup("out");
|
|
| 391 |
+ inputs->filter_ctx = ost->output_video_filter; |
|
| 392 |
+ inputs->pad_idx = 0; |
|
| 393 |
+ inputs->next = NULL; |
|
| 394 |
+ |
|
| 395 |
+ if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, inputs, outputs, NULL)) < 0) |
|
| 396 |
+ return ret; |
|
| 397 |
+ av_freep(&ost->avfilter); |
|
| 398 |
+ } else {
|
|
| 399 |
+ if ((ret = avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0) |
|
| 400 |
+ return ret; |
|
| 401 |
+ } |
|
| 402 |
+ |
|
| 403 |
+ if ((ret = avfilter_graph_config(ost->graph, NULL)) < 0) |
|
| 404 |
+ return ret; |
|
| 405 |
+ |
|
| 406 |
+ codec->width = ost->output_video_filter->inputs[0]->w; |
|
| 407 |
+ codec->height = ost->output_video_filter->inputs[0]->h; |
|
| 408 |
+ codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = |
|
| 409 |
+ ost->frame_aspect_ratio ? // overriden by the -aspect cli option |
|
| 410 |
+ av_d2q(ost->frame_aspect_ratio*codec->height/codec->width, 255) : |
|
| 411 |
+ ost->output_video_filter->inputs[0]->sample_aspect_ratio; |
|
| 412 |
+ |
|
| 413 |
+ return 0; |
|
| 414 |
+} |
|
| 415 |
+#endif /* CONFIG_AVFILTER */ |
|
| 416 |
+ |
|
| 417 |
+static void term_exit(void) |
|
| 418 |
+{
|
|
| 419 |
+ av_log(NULL, AV_LOG_QUIET, ""); |
|
| 420 |
+} |
|
| 421 |
+ |
|
| 422 |
+static volatile int received_sigterm = 0; |
|
| 423 |
+static volatile int received_nb_signals = 0; |
|
| 424 |
+ |
|
| 425 |
+static void |
|
| 426 |
+sigterm_handler(int sig) |
|
| 427 |
+{
|
|
| 428 |
+ received_sigterm = sig; |
|
| 429 |
+ received_nb_signals++; |
|
| 430 |
+ term_exit(); |
|
| 431 |
+} |
|
| 432 |
+ |
|
| 433 |
+static void term_init(void) |
|
| 434 |
+{
|
|
| 435 |
+ signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ |
|
| 436 |
+ signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ |
|
| 437 |
+#ifdef SIGXCPU |
|
| 438 |
+ signal(SIGXCPU, sigterm_handler); |
|
| 439 |
+#endif |
|
| 440 |
+} |
|
| 441 |
+ |
|
| 442 |
+static int decode_interrupt_cb(void) |
|
| 443 |
+{
|
|
| 444 |
+ return received_nb_signals > 1; |
|
| 445 |
+} |
|
| 446 |
+ |
|
| 447 |
+static int exit_program(int ret) |
|
| 448 |
+{
|
|
| 449 |
+ int i; |
|
| 450 |
+ |
|
| 451 |
+ /* close files */ |
|
| 452 |
+ for(i=0;i<nb_output_files;i++) {
|
|
| 453 |
+ AVFormatContext *s = output_files[i]; |
|
| 454 |
+ if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) |
|
| 455 |
+ avio_close(s->pb); |
|
| 456 |
+ avformat_free_context(s); |
|
| 457 |
+ av_free(output_streams_for_file[i]); |
|
| 458 |
+ av_dict_free(&output_opts[i]); |
|
| 459 |
+ } |
|
| 460 |
+ for(i=0;i<nb_input_files;i++) {
|
|
| 461 |
+ av_close_input_file(input_files[i].ctx); |
|
| 462 |
+ } |
|
| 463 |
+ for (i = 0; i < nb_input_streams; i++) |
|
| 464 |
+ av_dict_free(&input_streams[i].opts); |
|
| 465 |
+ |
|
| 466 |
+ av_free(intra_matrix); |
|
| 467 |
+ av_free(inter_matrix); |
|
| 468 |
+ |
|
| 469 |
+ if (vstats_file) |
|
| 470 |
+ fclose(vstats_file); |
|
| 471 |
+ av_free(vstats_filename); |
|
| 472 |
+ |
|
| 473 |
+ av_free(streamid_map); |
|
| 474 |
+ av_free(stream_maps); |
|
| 475 |
+ av_free(meta_data_maps); |
|
| 476 |
+ |
|
| 477 |
+ av_freep(&input_streams); |
|
| 478 |
+ av_freep(&input_files); |
|
| 479 |
+ |
|
| 480 |
+ av_free(video_codec_name); |
|
| 481 |
+ av_free(audio_codec_name); |
|
| 482 |
+ av_free(subtitle_codec_name); |
|
| 483 |
+ av_free(data_codec_name); |
|
| 484 |
+ |
|
| 485 |
+ uninit_opts(); |
|
| 486 |
+ av_free(audio_buf); |
|
| 487 |
+ av_free(audio_out); |
|
| 488 |
+ allocated_audio_buf_size= allocated_audio_out_size= 0; |
|
| 489 |
+ av_free(samples); |
|
| 490 |
+ |
|
| 491 |
+#if CONFIG_AVFILTER |
|
| 492 |
+ avfilter_uninit(); |
|
| 493 |
+#endif |
|
| 494 |
+ |
|
| 495 |
+ if (received_sigterm) {
|
|
| 496 |
+ fprintf(stderr, |
|
| 497 |
+ "Received signal %d: terminating.\n", |
|
| 498 |
+ (int) received_sigterm); |
|
| 499 |
+ exit (255); |
|
| 500 |
+ } |
|
| 501 |
+ |
|
| 502 |
+ exit(ret); /* not all OS-es handle main() return value */ |
|
| 503 |
+ return ret; |
|
| 504 |
+} |
|
| 505 |
+ |
|
| 506 |
+static void assert_avoptions(AVDictionary *m) |
|
| 507 |
+{
|
|
| 508 |
+ AVDictionaryEntry *t; |
|
| 509 |
+ if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
|
|
| 510 |
+ av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key); |
|
| 511 |
+ exit_program(1); |
|
| 512 |
+ } |
|
| 513 |
+} |
|
| 514 |
+ |
|
| 515 |
+static void assert_codec_experimental(AVCodecContext *c, int encoder) |
|
| 516 |
+{
|
|
| 517 |
+ const char *codec_string = encoder ? "encoder" : "decoder"; |
|
| 518 |
+ AVCodec *codec; |
|
| 519 |
+ if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL && |
|
| 520 |
+ c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
|
|
| 521 |
+ av_log(NULL, AV_LOG_ERROR, "%s '%s' is experimental and might produce bad " |
|
| 522 |
+ "results.\nAdd '-strict experimental' if you want to use it.\n", |
|
| 523 |
+ codec_string, c->codec->name); |
|
| 524 |
+ codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id); |
|
| 525 |
+ if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL)) |
|
| 526 |
+ av_log(NULL, AV_LOG_ERROR, "Or use the non experimental %s '%s'.\n", |
|
| 527 |
+ codec_string, codec->name); |
|
| 528 |
+ exit_program(1); |
|
| 529 |
+ } |
|
| 530 |
+} |
|
| 531 |
+ |
|
| 532 |
+/* similar to ff_dynarray_add() and av_fast_realloc() */ |
|
| 533 |
+static void *grow_array(void *array, int elem_size, int *size, int new_size) |
|
| 534 |
+{
|
|
| 535 |
+ if (new_size >= INT_MAX / elem_size) {
|
|
| 536 |
+ fprintf(stderr, "Array too big.\n"); |
|
| 537 |
+ exit_program(1); |
|
| 538 |
+ } |
|
| 539 |
+ if (*size < new_size) {
|
|
| 540 |
+ uint8_t *tmp = av_realloc(array, new_size*elem_size); |
|
| 541 |
+ if (!tmp) {
|
|
| 542 |
+ fprintf(stderr, "Could not alloc buffer.\n"); |
|
| 543 |
+ exit_program(1); |
|
| 544 |
+ } |
|
| 545 |
+ memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); |
|
| 546 |
+ *size = new_size; |
|
| 547 |
+ return tmp; |
|
| 548 |
+ } |
|
| 549 |
+ return array; |
|
| 550 |
+} |
|
| 551 |
+ |
|
| 552 |
+static void choose_sample_fmt(AVStream *st, AVCodec *codec) |
|
| 553 |
+{
|
|
| 554 |
+ if(codec && codec->sample_fmts){
|
|
| 555 |
+ const enum AVSampleFormat *p= codec->sample_fmts; |
|
| 556 |
+ for(; *p!=-1; p++){
|
|
| 557 |
+ if(*p == st->codec->sample_fmt) |
|
| 558 |
+ break; |
|
| 559 |
+ } |
|
| 560 |
+ if (*p == -1) {
|
|
| 561 |
+ av_log(NULL, AV_LOG_WARNING, |
|
| 562 |
+ "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n", |
|
| 563 |
+ av_get_sample_fmt_name(st->codec->sample_fmt), |
|
| 564 |
+ codec->name, |
|
| 565 |
+ av_get_sample_fmt_name(codec->sample_fmts[0])); |
|
| 566 |
+ st->codec->sample_fmt = codec->sample_fmts[0]; |
|
| 567 |
+ } |
|
| 568 |
+ } |
|
| 569 |
+} |
|
| 570 |
+ |
|
| 571 |
+/** |
|
| 572 |
+ * Update the requested input sample format based on the output sample format. |
|
| 573 |
+ * This is currently only used to request float output from decoders which |
|
| 574 |
+ * support multiple sample formats, one of which is AV_SAMPLE_FMT_FLT. |
|
| 575 |
+ * Ideally this will be removed in the future when decoders do not do format |
|
| 576 |
+ * conversion and only output in their native format. |
|
| 577 |
+ */ |
|
| 578 |
+static void update_sample_fmt(AVCodecContext *dec, AVCodec *dec_codec, |
|
| 579 |
+ AVCodecContext *enc) |
|
| 580 |
+{
|
|
| 581 |
+ /* if sample formats match or a decoder sample format has already been |
|
| 582 |
+ requested, just return */ |
|
| 583 |
+ if (enc->sample_fmt == dec->sample_fmt || |
|
| 584 |
+ dec->request_sample_fmt > AV_SAMPLE_FMT_NONE) |
|
| 585 |
+ return; |
|
| 586 |
+ |
|
| 587 |
+ /* if decoder supports more than one output format */ |
|
| 588 |
+ if (dec_codec && dec_codec->sample_fmts && |
|
| 589 |
+ dec_codec->sample_fmts[0] != AV_SAMPLE_FMT_NONE && |
|
| 590 |
+ dec_codec->sample_fmts[1] != AV_SAMPLE_FMT_NONE) {
|
|
| 591 |
+ const enum AVSampleFormat *p; |
|
| 592 |
+ int min_dec = -1, min_inc = -1; |
|
| 593 |
+ |
|
| 594 |
+ /* find a matching sample format in the encoder */ |
|
| 595 |
+ for (p = dec_codec->sample_fmts; *p != AV_SAMPLE_FMT_NONE; p++) {
|
|
| 596 |
+ if (*p == enc->sample_fmt) {
|
|
| 597 |
+ dec->request_sample_fmt = *p; |
|
| 598 |
+ return; |
|
| 599 |
+ } else if (*p > enc->sample_fmt) {
|
|
| 600 |
+ min_inc = FFMIN(min_inc, *p - enc->sample_fmt); |
|
| 601 |
+ } else |
|
| 602 |
+ min_dec = FFMIN(min_dec, enc->sample_fmt - *p); |
|
| 603 |
+ } |
|
| 604 |
+ |
|
| 605 |
+ /* if none match, provide the one that matches quality closest */ |
|
| 606 |
+ dec->request_sample_fmt = min_inc > 0 ? enc->sample_fmt + min_inc : |
|
| 607 |
+ enc->sample_fmt - min_dec; |
|
| 608 |
+ } |
|
| 609 |
+} |
|
| 610 |
+ |
|
| 611 |
+static void choose_sample_rate(AVStream *st, AVCodec *codec) |
|
| 612 |
+{
|
|
| 613 |
+ if(codec && codec->supported_samplerates){
|
|
| 614 |
+ const int *p= codec->supported_samplerates; |
|
| 615 |
+ int best=0; |
|
| 616 |
+ int best_dist=INT_MAX; |
|
| 617 |
+ for(; *p; p++){
|
|
| 618 |
+ int dist= abs(st->codec->sample_rate - *p); |
|
| 619 |
+ if(dist < best_dist){
|
|
| 620 |
+ best_dist= dist; |
|
| 621 |
+ best= *p; |
|
| 622 |
+ } |
|
| 623 |
+ } |
|
| 624 |
+ if(best_dist){
|
|
| 625 |
+ av_log(st->codec, AV_LOG_WARNING, "Requested sampling rate unsupported using closest supported (%d)\n", best); |
|
| 626 |
+ } |
|
| 627 |
+ st->codec->sample_rate= best; |
|
| 628 |
+ } |
|
| 629 |
+} |
|
| 630 |
+ |
|
| 631 |
+static void choose_pixel_fmt(AVStream *st, AVCodec *codec) |
|
| 632 |
+{
|
|
| 633 |
+ if(codec && codec->pix_fmts){
|
|
| 634 |
+ const enum PixelFormat *p= codec->pix_fmts; |
|
| 635 |
+ if(st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL){
|
|
| 636 |
+ if(st->codec->codec_id==CODEC_ID_MJPEG){
|
|
| 637 |
+ p= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE};
|
|
| 638 |
+ }else if(st->codec->codec_id==CODEC_ID_LJPEG){
|
|
| 639 |
+ p= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_BGRA, PIX_FMT_NONE};
|
|
| 640 |
+ } |
|
| 641 |
+ } |
|
| 642 |
+ for(; *p!=-1; p++){
|
|
| 643 |
+ if(*p == st->codec->pix_fmt) |
|
| 644 |
+ break; |
|
| 645 |
+ } |
|
| 646 |
+ if (*p == -1) {
|
|
| 647 |
+ if(st->codec->pix_fmt != PIX_FMT_NONE) |
|
| 648 |
+ av_log(NULL, AV_LOG_WARNING, |
|
| 649 |
+ "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n", |
|
| 650 |
+ av_pix_fmt_descriptors[st->codec->pix_fmt].name, |
|
| 651 |
+ codec->name, |
|
| 652 |
+ av_pix_fmt_descriptors[codec->pix_fmts[0]].name); |
|
| 653 |
+ st->codec->pix_fmt = codec->pix_fmts[0]; |
|
| 654 |
+ } |
|
| 655 |
+ } |
|
| 656 |
+} |
|
| 657 |
+ |
|
| 658 |
+static OutputStream *new_output_stream(AVFormatContext *oc, int file_idx, AVCodec *codec) |
|
| 659 |
+{
|
|
| 660 |
+ OutputStream *ost; |
|
| 661 |
+ AVStream *st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); |
|
| 662 |
+ int idx = oc->nb_streams - 1; |
|
| 663 |
+ |
|
| 664 |
+ if (!st) {
|
|
| 665 |
+ av_log(NULL, AV_LOG_ERROR, "Could not alloc stream.\n"); |
|
| 666 |
+ exit_program(1); |
|
| 667 |
+ } |
|
| 668 |
+ |
|
| 669 |
+ output_streams_for_file[file_idx] = |
|
| 670 |
+ grow_array(output_streams_for_file[file_idx], |
|
| 671 |
+ sizeof(*output_streams_for_file[file_idx]), |
|
| 672 |
+ &nb_output_streams_for_file[file_idx], |
|
| 673 |
+ oc->nb_streams); |
|
| 674 |
+ ost = output_streams_for_file[file_idx][idx] = |
|
| 675 |
+ av_mallocz(sizeof(OutputStream)); |
|
| 676 |
+ if (!ost) {
|
|
| 677 |
+ fprintf(stderr, "Could not alloc output stream\n"); |
|
| 678 |
+ exit_program(1); |
|
| 679 |
+ } |
|
| 680 |
+ ost->file_index = file_idx; |
|
| 681 |
+ ost->index = idx; |
|
| 682 |
+ ost->st = st; |
|
| 683 |
+ ost->enc = codec; |
|
| 684 |
+ if (codec) |
|
| 685 |
+ ost->opts = filter_codec_opts(codec_opts, codec->id, 1); |
|
| 686 |
+ |
|
| 687 |
+ avcodec_get_context_defaults3(st->codec, codec); |
|
| 688 |
+ |
|
| 689 |
+ ost->sws_flags = av_get_int(sws_opts, "sws_flags", NULL); |
|
| 690 |
+ return ost; |
|
| 691 |
+} |
|
| 692 |
+ |
|
| 693 |
+static int read_avserver_streams(AVFormatContext *s, const char *filename) |
|
| 694 |
+{
|
|
| 695 |
+ int i, err; |
|
| 696 |
+ AVFormatContext *ic = NULL; |
|
| 697 |
+ int nopts = 0; |
|
| 698 |
+ |
|
| 699 |
+ err = avformat_open_input(&ic, filename, NULL, NULL); |
|
| 700 |
+ if (err < 0) |
|
| 701 |
+ return err; |
|
| 702 |
+ /* copy stream format */ |
|
| 703 |
+ for(i=0;i<ic->nb_streams;i++) {
|
|
| 704 |
+ AVStream *st; |
|
| 705 |
+ OutputStream *ost; |
|
| 706 |
+ AVCodec *codec; |
|
| 707 |
+ |
|
| 708 |
+ codec = avcodec_find_encoder(ic->streams[i]->codec->codec_id); |
|
| 709 |
+ ost = new_output_stream(s, nb_output_files, codec); |
|
| 710 |
+ st = ost->st; |
|
| 711 |
+ |
|
| 712 |
+ // FIXME: a more elegant solution is needed |
|
| 713 |
+ memcpy(st, ic->streams[i], sizeof(AVStream)); |
|
| 714 |
+ st->info = NULL; |
|
| 715 |
+ avcodec_copy_context(st->codec, ic->streams[i]->codec); |
|
| 716 |
+ |
|
| 717 |
+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
|
|
| 718 |
+ if (audio_stream_copy) {
|
|
| 719 |
+ st->stream_copy = 1; |
|
| 720 |
+ } else |
|
| 721 |
+ choose_sample_fmt(st, codec); |
|
| 722 |
+ } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
| 723 |
+ if (video_stream_copy) {
|
|
| 724 |
+ st->stream_copy = 1; |
|
| 725 |
+ } else |
|
| 726 |
+ choose_pixel_fmt(st, codec); |
|
| 727 |
+ } |
|
| 728 |
+ |
|
| 729 |
+ if(st->codec->flags & CODEC_FLAG_BITEXACT) |
|
| 730 |
+ nopts = 1; |
|
| 731 |
+ } |
|
| 732 |
+ |
|
| 733 |
+ av_close_input_file(ic); |
|
| 734 |
+ return 0; |
|
| 735 |
+} |
|
| 736 |
+ |
|
| 737 |
+static double |
|
| 738 |
+get_sync_ipts(const OutputStream *ost) |
|
| 739 |
+{
|
|
| 740 |
+ const InputStream *ist = ost->sync_ist; |
|
| 741 |
+ return (double)(ist->pts - start_time)/AV_TIME_BASE; |
|
| 742 |
+} |
|
| 743 |
+ |
|
| 744 |
+static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){
|
|
| 745 |
+ int ret; |
|
| 746 |
+ |
|
| 747 |
+ while(bsfc){
|
|
| 748 |
+ AVPacket new_pkt= *pkt; |
|
| 749 |
+ int a= av_bitstream_filter_filter(bsfc, avctx, NULL, |
|
| 750 |
+ &new_pkt.data, &new_pkt.size, |
|
| 751 |
+ pkt->data, pkt->size, |
|
| 752 |
+ pkt->flags & AV_PKT_FLAG_KEY); |
|
| 753 |
+ if(a>0){
|
|
| 754 |
+ av_free_packet(pkt); |
|
| 755 |
+ new_pkt.destruct= av_destruct_packet; |
|
| 756 |
+ } else if(a<0){
|
|
| 757 |
+ fprintf(stderr, "%s failed for stream %d, codec %s", |
|
| 758 |
+ bsfc->filter->name, pkt->stream_index, |
|
| 759 |
+ avctx->codec ? avctx->codec->name : "copy"); |
|
| 760 |
+ print_error("", a);
|
|
| 761 |
+ if (exit_on_error) |
|
| 762 |
+ exit_program(1); |
|
| 763 |
+ } |
|
| 764 |
+ *pkt= new_pkt; |
|
| 765 |
+ |
|
| 766 |
+ bsfc= bsfc->next; |
|
| 767 |
+ } |
|
| 768 |
+ |
|
| 769 |
+ ret= av_interleaved_write_frame(s, pkt); |
|
| 770 |
+ if(ret < 0){
|
|
| 771 |
+ print_error("av_interleaved_write_frame()", ret);
|
|
| 772 |
+ exit_program(1); |
|
| 773 |
+ } |
|
| 774 |
+} |
|
| 775 |
+ |
|
| 776 |
+#define MAX_AUDIO_PACKET_SIZE (128 * 1024) |
|
| 777 |
+ |
|
| 778 |
+static void do_audio_out(AVFormatContext *s, |
|
| 779 |
+ OutputStream *ost, |
|
| 780 |
+ InputStream *ist, |
|
| 781 |
+ unsigned char *buf, int size) |
|
| 782 |
+{
|
|
| 783 |
+ uint8_t *buftmp; |
|
| 784 |
+ int64_t audio_out_size, audio_buf_size; |
|
| 785 |
+ int64_t allocated_for_size= size; |
|
| 786 |
+ |
|
| 787 |
+ int size_out, frame_bytes, ret, resample_changed; |
|
| 788 |
+ AVCodecContext *enc= ost->st->codec; |
|
| 789 |
+ AVCodecContext *dec= ist->st->codec; |
|
| 790 |
+ int osize = av_get_bytes_per_sample(enc->sample_fmt); |
|
| 791 |
+ int isize = av_get_bytes_per_sample(dec->sample_fmt); |
|
| 792 |
+ const int coded_bps = av_get_bits_per_sample(enc->codec->id); |
|
| 793 |
+ |
|
| 794 |
+need_realloc: |
|
| 795 |
+ audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels); |
|
| 796 |
+ audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate; |
|
| 797 |
+ audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API |
|
| 798 |
+ audio_buf_size= FFMAX(audio_buf_size, enc->frame_size); |
|
| 799 |
+ audio_buf_size*= osize*enc->channels; |
|
| 800 |
+ |
|
| 801 |
+ audio_out_size= FFMAX(audio_buf_size, enc->frame_size * osize * enc->channels); |
|
| 802 |
+ if(coded_bps > 8*osize) |
|
| 803 |
+ audio_out_size= audio_out_size * coded_bps / (8*osize); |
|
| 804 |
+ audio_out_size += FF_MIN_BUFFER_SIZE; |
|
| 805 |
+ |
|
| 806 |
+ if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){
|
|
| 807 |
+ fprintf(stderr, "Buffer sizes too large\n"); |
|
| 808 |
+ exit_program(1); |
|
| 809 |
+ } |
|
| 810 |
+ |
|
| 811 |
+ av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size); |
|
| 812 |
+ av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size); |
|
| 813 |
+ if (!audio_buf || !audio_out){
|
|
| 814 |
+ fprintf(stderr, "Out of memory in do_audio_out\n"); |
|
| 815 |
+ exit_program(1); |
|
| 816 |
+ } |
|
| 817 |
+ |
|
| 818 |
+ if (enc->channels != dec->channels || enc->sample_rate != dec->sample_rate) |
|
| 819 |
+ ost->audio_resample = 1; |
|
| 820 |
+ |
|
| 821 |
+ resample_changed = ost->resample_sample_fmt != dec->sample_fmt || |
|
| 822 |
+ ost->resample_channels != dec->channels || |
|
| 823 |
+ ost->resample_sample_rate != dec->sample_rate; |
|
| 824 |
+ |
|
| 825 |
+ if ((ost->audio_resample && !ost->resample) || resample_changed) {
|
|
| 826 |
+ if (resample_changed) {
|
|
| 827 |
+ av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n", |
|
| 828 |
+ ist->file_index, ist->st->index, |
|
| 829 |
+ ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels, |
|
| 830 |
+ dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), dec->channels); |
|
| 831 |
+ ost->resample_sample_fmt = dec->sample_fmt; |
|
| 832 |
+ ost->resample_channels = dec->channels; |
|
| 833 |
+ ost->resample_sample_rate = dec->sample_rate; |
|
| 834 |
+ if (ost->resample) |
|
| 835 |
+ audio_resample_close(ost->resample); |
|
| 836 |
+ } |
|
| 837 |
+ /* if audio_sync_method is >1 the resampler is needed for audio drift compensation */ |
|
| 838 |
+ if (audio_sync_method <= 1 && |
|
| 839 |
+ ost->resample_sample_fmt == enc->sample_fmt && |
|
| 840 |
+ ost->resample_channels == enc->channels && |
|
| 841 |
+ ost->resample_sample_rate == enc->sample_rate) {
|
|
| 842 |
+ ost->resample = NULL; |
|
| 843 |
+ ost->audio_resample = 0; |
|
| 844 |
+ } else if (ost->audio_resample) {
|
|
| 845 |
+ if (dec->sample_fmt != AV_SAMPLE_FMT_S16) |
|
| 846 |
+ fprintf(stderr, "Warning, using s16 intermediate sample format for resampling\n"); |
|
| 847 |
+ ost->resample = av_audio_resample_init(enc->channels, dec->channels, |
|
| 848 |
+ enc->sample_rate, dec->sample_rate, |
|
| 849 |
+ enc->sample_fmt, dec->sample_fmt, |
|
| 850 |
+ 16, 10, 0, 0.8); |
|
| 851 |
+ if (!ost->resample) {
|
|
| 852 |
+ fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n", |
|
| 853 |
+ dec->channels, dec->sample_rate, |
|
| 854 |
+ enc->channels, enc->sample_rate); |
|
| 855 |
+ exit_program(1); |
|
| 856 |
+ } |
|
| 857 |
+ } |
|
| 858 |
+ } |
|
| 859 |
+ |
|
| 860 |
+#define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b)) |
|
| 861 |
+ if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt && |
|
| 862 |
+ MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt)!=ost->reformat_pair) {
|
|
| 863 |
+ if (ost->reformat_ctx) |
|
| 864 |
+ av_audio_convert_free(ost->reformat_ctx); |
|
| 865 |
+ ost->reformat_ctx = av_audio_convert_alloc(enc->sample_fmt, 1, |
|
| 866 |
+ dec->sample_fmt, 1, NULL, 0); |
|
| 867 |
+ if (!ost->reformat_ctx) {
|
|
| 868 |
+ fprintf(stderr, "Cannot convert %s sample format to %s sample format\n", |
|
| 869 |
+ av_get_sample_fmt_name(dec->sample_fmt), |
|
| 870 |
+ av_get_sample_fmt_name(enc->sample_fmt)); |
|
| 871 |
+ exit_program(1); |
|
| 872 |
+ } |
|
| 873 |
+ ost->reformat_pair=MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt); |
|
| 874 |
+ } |
|
| 875 |
+ |
|
| 876 |
+ if(audio_sync_method){
|
|
| 877 |
+ double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts |
|
| 878 |
+ - av_fifo_size(ost->fifo)/(enc->channels * 2); |
|
| 879 |
+ double idelta= delta*dec->sample_rate / enc->sample_rate; |
|
| 880 |
+ int byte_delta= ((int)idelta)*2*dec->channels; |
|
| 881 |
+ |
|
| 882 |
+ //FIXME resample delay |
|
| 883 |
+ if(fabs(delta) > 50){
|
|
| 884 |
+ if(ist->is_start || fabs(delta) > audio_drift_threshold*enc->sample_rate){
|
|
| 885 |
+ if(byte_delta < 0){
|
|
| 886 |
+ byte_delta= FFMAX(byte_delta, -size); |
|
| 887 |
+ size += byte_delta; |
|
| 888 |
+ buf -= byte_delta; |
|
| 889 |
+ if(verbose > 2) |
|
| 890 |
+ fprintf(stderr, "discarding %d audio samples\n", (int)-delta); |
|
| 891 |
+ if(!size) |
|
| 892 |
+ return; |
|
| 893 |
+ ist->is_start=0; |
|
| 894 |
+ }else{
|
|
| 895 |
+ static uint8_t *input_tmp= NULL; |
|
| 896 |
+ input_tmp= av_realloc(input_tmp, byte_delta + size); |
|
| 897 |
+ |
|
| 898 |
+ if(byte_delta > allocated_for_size - size){
|
|
| 899 |
+ allocated_for_size= byte_delta + (int64_t)size; |
|
| 900 |
+ goto need_realloc; |
|
| 901 |
+ } |
|
| 902 |
+ ist->is_start=0; |
|
| 903 |
+ |
|
| 904 |
+ memset(input_tmp, 0, byte_delta); |
|
| 905 |
+ memcpy(input_tmp + byte_delta, buf, size); |
|
| 906 |
+ buf= input_tmp; |
|
| 907 |
+ size += byte_delta; |
|
| 908 |
+ if(verbose > 2) |
|
| 909 |
+ fprintf(stderr, "adding %d audio samples of silence\n", (int)delta); |
|
| 910 |
+ } |
|
| 911 |
+ }else if(audio_sync_method>1){
|
|
| 912 |
+ int comp= av_clip(delta, -audio_sync_method, audio_sync_method); |
|
| 913 |
+ av_assert0(ost->audio_resample); |
|
| 914 |
+ if(verbose > 2) |
|
| 915 |
+ fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate); |
|
| 916 |
+// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2)); |
|
| 917 |
+ av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate); |
|
| 918 |
+ } |
|
| 919 |
+ } |
|
| 920 |
+ }else |
|
| 921 |
+ ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate) |
|
| 922 |
+ - av_fifo_size(ost->fifo)/(enc->channels * 2); //FIXME wrong |
|
| 923 |
+ |
|
| 924 |
+ if (ost->audio_resample) {
|
|
| 925 |
+ buftmp = audio_buf; |
|
| 926 |
+ size_out = audio_resample(ost->resample, |
|
| 927 |
+ (short *)buftmp, (short *)buf, |
|
| 928 |
+ size / (dec->channels * isize)); |
|
| 929 |
+ size_out = size_out * enc->channels * osize; |
|
| 930 |
+ } else {
|
|
| 931 |
+ buftmp = buf; |
|
| 932 |
+ size_out = size; |
|
| 933 |
+ } |
|
| 934 |
+ |
|
| 935 |
+ if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt) {
|
|
| 936 |
+ const void *ibuf[6]= {buftmp};
|
|
| 937 |
+ void *obuf[6]= {audio_buf};
|
|
| 938 |
+ int istride[6]= {isize};
|
|
| 939 |
+ int ostride[6]= {osize};
|
|
| 940 |
+ int len= size_out/istride[0]; |
|
| 941 |
+ if (av_audio_convert(ost->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) {
|
|
| 942 |
+ printf("av_audio_convert() failed\n");
|
|
| 943 |
+ if (exit_on_error) |
|
| 944 |
+ exit_program(1); |
|
| 945 |
+ return; |
|
| 946 |
+ } |
|
| 947 |
+ buftmp = audio_buf; |
|
| 948 |
+ size_out = len*osize; |
|
| 949 |
+ } |
|
| 950 |
+ |
|
| 951 |
+ /* now encode as many frames as possible */ |
|
| 952 |
+ if (enc->frame_size > 1) {
|
|
| 953 |
+ /* output resampled raw samples */ |
|
| 954 |
+ if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) {
|
|
| 955 |
+ fprintf(stderr, "av_fifo_realloc2() failed\n"); |
|
| 956 |
+ exit_program(1); |
|
| 957 |
+ } |
|
| 958 |
+ av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL); |
|
| 959 |
+ |
|
| 960 |
+ frame_bytes = enc->frame_size * osize * enc->channels; |
|
| 961 |
+ |
|
| 962 |
+ while (av_fifo_size(ost->fifo) >= frame_bytes) {
|
|
| 963 |
+ AVPacket pkt; |
|
| 964 |
+ av_init_packet(&pkt); |
|
| 965 |
+ |
|
| 966 |
+ av_fifo_generic_read(ost->fifo, audio_buf, frame_bytes, NULL); |
|
| 967 |
+ |
|
| 968 |
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() |
|
| 969 |
+ |
|
| 970 |
+ ret = avcodec_encode_audio(enc, audio_out, audio_out_size, |
|
| 971 |
+ (short *)audio_buf); |
|
| 972 |
+ if (ret < 0) {
|
|
| 973 |
+ fprintf(stderr, "Audio encoding failed\n"); |
|
| 974 |
+ exit_program(1); |
|
| 975 |
+ } |
|
| 976 |
+ audio_size += ret; |
|
| 977 |
+ pkt.stream_index= ost->index; |
|
| 978 |
+ pkt.data= audio_out; |
|
| 979 |
+ pkt.size= ret; |
|
| 980 |
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) |
|
| 981 |
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); |
|
| 982 |
+ pkt.flags |= AV_PKT_FLAG_KEY; |
|
| 983 |
+ write_frame(s, &pkt, enc, ost->bitstream_filters); |
|
| 984 |
+ |
|
| 985 |
+ ost->sync_opts += enc->frame_size; |
|
| 986 |
+ } |
|
| 987 |
+ } else {
|
|
| 988 |
+ AVPacket pkt; |
|
| 989 |
+ av_init_packet(&pkt); |
|
| 990 |
+ |
|
| 991 |
+ ost->sync_opts += size_out / (osize * enc->channels); |
|
| 992 |
+ |
|
| 993 |
+ /* output a pcm frame */ |
|
| 994 |
+ /* determine the size of the coded buffer */ |
|
| 995 |
+ size_out /= osize; |
|
| 996 |
+ if (coded_bps) |
|
| 997 |
+ size_out = size_out*coded_bps/8; |
|
| 998 |
+ |
|
| 999 |
+ if(size_out > audio_out_size){
|
|
| 1000 |
+ fprintf(stderr, "Internal error, buffer size too small\n"); |
|
| 1001 |
+ exit_program(1); |
|
| 1002 |
+ } |
|
| 1003 |
+ |
|
| 1004 |
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() |
|
| 1005 |
+ ret = avcodec_encode_audio(enc, audio_out, size_out, |
|
| 1006 |
+ (short *)buftmp); |
|
| 1007 |
+ if (ret < 0) {
|
|
| 1008 |
+ fprintf(stderr, "Audio encoding failed\n"); |
|
| 1009 |
+ exit_program(1); |
|
| 1010 |
+ } |
|
| 1011 |
+ audio_size += ret; |
|
| 1012 |
+ pkt.stream_index= ost->index; |
|
| 1013 |
+ pkt.data= audio_out; |
|
| 1014 |
+ pkt.size= ret; |
|
| 1015 |
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) |
|
| 1016 |
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); |
|
| 1017 |
+ pkt.flags |= AV_PKT_FLAG_KEY; |
|
| 1018 |
+ write_frame(s, &pkt, enc, ost->bitstream_filters); |
|
| 1019 |
+ } |
|
| 1020 |
+} |
|
| 1021 |
+ |
|
| 1022 |
+static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp) |
|
| 1023 |
+{
|
|
| 1024 |
+ AVCodecContext *dec; |
|
| 1025 |
+ AVPicture *picture2; |
|
| 1026 |
+ AVPicture picture_tmp; |
|
| 1027 |
+ uint8_t *buf = 0; |
|
| 1028 |
+ |
|
| 1029 |
+ dec = ist->st->codec; |
|
| 1030 |
+ |
|
| 1031 |
+ /* deinterlace : must be done before any resize */ |
|
| 1032 |
+ if (do_deinterlace) {
|
|
| 1033 |
+ int size; |
|
| 1034 |
+ |
|
| 1035 |
+ /* create temporary picture */ |
|
| 1036 |
+ size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height); |
|
| 1037 |
+ buf = av_malloc(size); |
|
| 1038 |
+ if (!buf) |
|
| 1039 |
+ return; |
|
| 1040 |
+ |
|
| 1041 |
+ picture2 = &picture_tmp; |
|
| 1042 |
+ avpicture_fill(picture2, buf, dec->pix_fmt, dec->width, dec->height); |
|
| 1043 |
+ |
|
| 1044 |
+ if(avpicture_deinterlace(picture2, picture, |
|
| 1045 |
+ dec->pix_fmt, dec->width, dec->height) < 0) {
|
|
| 1046 |
+ /* if error, do not deinterlace */ |
|
| 1047 |
+ fprintf(stderr, "Deinterlacing failed\n"); |
|
| 1048 |
+ av_free(buf); |
|
| 1049 |
+ buf = NULL; |
|
| 1050 |
+ picture2 = picture; |
|
| 1051 |
+ } |
|
| 1052 |
+ } else {
|
|
| 1053 |
+ picture2 = picture; |
|
| 1054 |
+ } |
|
| 1055 |
+ |
|
| 1056 |
+ if (picture != picture2) |
|
| 1057 |
+ *picture = *picture2; |
|
| 1058 |
+ *bufp = buf; |
|
| 1059 |
+} |
|
| 1060 |
+ |
|
| 1061 |
+/* we begin to correct av delay at this threshold */ |
|
| 1062 |
+#define AV_DELAY_MAX 0.100 |
|
| 1063 |
+ |
|
| 1064 |
+static void do_subtitle_out(AVFormatContext *s, |
|
| 1065 |
+ OutputStream *ost, |
|
| 1066 |
+ InputStream *ist, |
|
| 1067 |
+ AVSubtitle *sub, |
|
| 1068 |
+ int64_t pts) |
|
| 1069 |
+{
|
|
| 1070 |
+ static uint8_t *subtitle_out = NULL; |
|
| 1071 |
+ int subtitle_out_max_size = 1024 * 1024; |
|
| 1072 |
+ int subtitle_out_size, nb, i; |
|
| 1073 |
+ AVCodecContext *enc; |
|
| 1074 |
+ AVPacket pkt; |
|
| 1075 |
+ |
|
| 1076 |
+ if (pts == AV_NOPTS_VALUE) {
|
|
| 1077 |
+ fprintf(stderr, "Subtitle packets must have a pts\n"); |
|
| 1078 |
+ if (exit_on_error) |
|
| 1079 |
+ exit_program(1); |
|
| 1080 |
+ return; |
|
| 1081 |
+ } |
|
| 1082 |
+ |
|
| 1083 |
+ enc = ost->st->codec; |
|
| 1084 |
+ |
|
| 1085 |
+ if (!subtitle_out) {
|
|
| 1086 |
+ subtitle_out = av_malloc(subtitle_out_max_size); |
|
| 1087 |
+ } |
|
| 1088 |
+ |
|
| 1089 |
+ /* Note: DVB subtitle need one packet to draw them and one other |
|
| 1090 |
+ packet to clear them */ |
|
| 1091 |
+ /* XXX: signal it in the codec context ? */ |
|
| 1092 |
+ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) |
|
| 1093 |
+ nb = 2; |
|
| 1094 |
+ else |
|
| 1095 |
+ nb = 1; |
|
| 1096 |
+ |
|
| 1097 |
+ for(i = 0; i < nb; i++) {
|
|
| 1098 |
+ sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q); |
|
| 1099 |
+ // start_display_time is required to be 0 |
|
| 1100 |
+ sub->pts += av_rescale_q(sub->start_display_time, (AVRational){1, 1000}, AV_TIME_BASE_Q);
|
|
| 1101 |
+ sub->end_display_time -= sub->start_display_time; |
|
| 1102 |
+ sub->start_display_time = 0; |
|
| 1103 |
+ subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, |
|
| 1104 |
+ subtitle_out_max_size, sub); |
|
| 1105 |
+ if (subtitle_out_size < 0) {
|
|
| 1106 |
+ fprintf(stderr, "Subtitle encoding failed\n"); |
|
| 1107 |
+ exit_program(1); |
|
| 1108 |
+ } |
|
| 1109 |
+ |
|
| 1110 |
+ av_init_packet(&pkt); |
|
| 1111 |
+ pkt.stream_index = ost->index; |
|
| 1112 |
+ pkt.data = subtitle_out; |
|
| 1113 |
+ pkt.size = subtitle_out_size; |
|
| 1114 |
+ pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base); |
|
| 1115 |
+ if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) {
|
|
| 1116 |
+ /* XXX: the pts correction is handled here. Maybe handling |
|
| 1117 |
+ it in the codec would be better */ |
|
| 1118 |
+ if (i == 0) |
|
| 1119 |
+ pkt.pts += 90 * sub->start_display_time; |
|
| 1120 |
+ else |
|
| 1121 |
+ pkt.pts += 90 * sub->end_display_time; |
|
| 1122 |
+ } |
|
| 1123 |
+ write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); |
|
| 1124 |
+ } |
|
| 1125 |
+} |
|
| 1126 |
+ |
|
| 1127 |
+static int bit_buffer_size= 1024*256; |
|
| 1128 |
+static uint8_t *bit_buffer= NULL; |
|
| 1129 |
+ |
|
| 1130 |
+static void do_video_out(AVFormatContext *s, |
|
| 1131 |
+ OutputStream *ost, |
|
| 1132 |
+ InputStream *ist, |
|
| 1133 |
+ AVFrame *in_picture, |
|
| 1134 |
+ int *frame_size, float quality) |
|
| 1135 |
+{
|
|
| 1136 |
+ int nb_frames, i, ret, resample_changed; |
|
| 1137 |
+ AVFrame *final_picture, *formatted_picture; |
|
| 1138 |
+ AVCodecContext *enc, *dec; |
|
| 1139 |
+ double sync_ipts; |
|
| 1140 |
+ |
|
| 1141 |
+ enc = ost->st->codec; |
|
| 1142 |
+ dec = ist->st->codec; |
|
| 1143 |
+ |
|
| 1144 |
+ sync_ipts = get_sync_ipts(ost) / av_q2d(enc->time_base); |
|
| 1145 |
+ |
|
| 1146 |
+ /* by default, we output a single frame */ |
|
| 1147 |
+ nb_frames = 1; |
|
| 1148 |
+ |
|
| 1149 |
+ *frame_size = 0; |
|
| 1150 |
+ |
|
| 1151 |
+ if(video_sync_method){
|
|
| 1152 |
+ double vdelta = sync_ipts - ost->sync_opts; |
|
| 1153 |
+ //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c |
|
| 1154 |
+ if (vdelta < -1.1) |
|
| 1155 |
+ nb_frames = 0; |
|
| 1156 |
+ else if (video_sync_method == 2 || (video_sync_method<0 && (s->oformat->flags & AVFMT_VARIABLE_FPS))){
|
|
| 1157 |
+ if(vdelta<=-0.6){
|
|
| 1158 |
+ nb_frames=0; |
|
| 1159 |
+ }else if(vdelta>0.6) |
|
| 1160 |
+ ost->sync_opts= lrintf(sync_ipts); |
|
| 1161 |
+ }else if (vdelta > 1.1) |
|
| 1162 |
+ nb_frames = lrintf(vdelta); |
|
| 1163 |
+//fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames); |
|
| 1164 |
+ if (nb_frames == 0){
|
|
| 1165 |
+ ++nb_frames_drop; |
|
| 1166 |
+ if (verbose>2) |
|
| 1167 |
+ fprintf(stderr, "*** drop!\n"); |
|
| 1168 |
+ }else if (nb_frames > 1) {
|
|
| 1169 |
+ nb_frames_dup += nb_frames - 1; |
|
| 1170 |
+ if (verbose>2) |
|
| 1171 |
+ fprintf(stderr, "*** %d dup!\n", nb_frames-1); |
|
| 1172 |
+ } |
|
| 1173 |
+ }else |
|
| 1174 |
+ ost->sync_opts= lrintf(sync_ipts); |
|
| 1175 |
+ |
|
| 1176 |
+ nb_frames= FFMIN(nb_frames, max_frames[AVMEDIA_TYPE_VIDEO] - ost->frame_number); |
|
| 1177 |
+ if (nb_frames <= 0) |
|
| 1178 |
+ return; |
|
| 1179 |
+ |
|
| 1180 |
+ formatted_picture = in_picture; |
|
| 1181 |
+ final_picture = formatted_picture; |
|
| 1182 |
+ |
|
| 1183 |
+ resample_changed = ost->resample_width != dec->width || |
|
| 1184 |
+ ost->resample_height != dec->height || |
|
| 1185 |
+ ost->resample_pix_fmt != dec->pix_fmt; |
|
| 1186 |
+ |
|
| 1187 |
+ if (resample_changed) {
|
|
| 1188 |
+ av_log(NULL, AV_LOG_INFO, |
|
| 1189 |
+ "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", |
|
| 1190 |
+ ist->file_index, ist->st->index, |
|
| 1191 |
+ ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt), |
|
| 1192 |
+ dec->width , dec->height , av_get_pix_fmt_name(dec->pix_fmt)); |
|
| 1193 |
+ if(!ost->video_resample) |
|
| 1194 |
+ exit_program(1); |
|
| 1195 |
+ } |
|
| 1196 |
+ |
|
| 1197 |
+#if !CONFIG_AVFILTER |
|
| 1198 |
+ if (ost->video_resample) {
|
|
| 1199 |
+ final_picture = &ost->pict_tmp; |
|
| 1200 |
+ if (resample_changed) {
|
|
| 1201 |
+ /* initialize a new scaler context */ |
|
| 1202 |
+ sws_freeContext(ost->img_resample_ctx); |
|
| 1203 |
+ ost->img_resample_ctx = sws_getContext( |
|
| 1204 |
+ ist->st->codec->width, |
|
| 1205 |
+ ist->st->codec->height, |
|
| 1206 |
+ ist->st->codec->pix_fmt, |
|
| 1207 |
+ ost->st->codec->width, |
|
| 1208 |
+ ost->st->codec->height, |
|
| 1209 |
+ ost->st->codec->pix_fmt, |
|
| 1210 |
+ ost->sws_flags, NULL, NULL, NULL); |
|
| 1211 |
+ if (ost->img_resample_ctx == NULL) {
|
|
| 1212 |
+ fprintf(stderr, "Cannot get resampling context\n"); |
|
| 1213 |
+ exit_program(1); |
|
| 1214 |
+ } |
|
| 1215 |
+ } |
|
| 1216 |
+ sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize, |
|
| 1217 |
+ 0, ost->resample_height, final_picture->data, final_picture->linesize); |
|
| 1218 |
+ } |
|
| 1219 |
+#endif |
|
| 1220 |
+ |
|
| 1221 |
+ /* duplicates frame if needed */ |
|
| 1222 |
+ for(i=0;i<nb_frames;i++) {
|
|
| 1223 |
+ AVPacket pkt; |
|
| 1224 |
+ av_init_packet(&pkt); |
|
| 1225 |
+ pkt.stream_index= ost->index; |
|
| 1226 |
+ |
|
| 1227 |
+ if (s->oformat->flags & AVFMT_RAWPICTURE) {
|
|
| 1228 |
+ /* raw pictures are written as AVPicture structure to |
|
| 1229 |
+ avoid any copies. We support temorarily the older |
|
| 1230 |
+ method. */ |
|
| 1231 |
+ AVFrame* old_frame = enc->coded_frame; |
|
| 1232 |
+ enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack |
|
| 1233 |
+ pkt.data= (uint8_t *)final_picture; |
|
| 1234 |
+ pkt.size= sizeof(AVPicture); |
|
| 1235 |
+ pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base); |
|
| 1236 |
+ pkt.flags |= AV_PKT_FLAG_KEY; |
|
| 1237 |
+ |
|
| 1238 |
+ write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); |
|
| 1239 |
+ enc->coded_frame = old_frame; |
|
| 1240 |
+ } else {
|
|
| 1241 |
+ AVFrame big_picture; |
|
| 1242 |
+ |
|
| 1243 |
+ big_picture= *final_picture; |
|
| 1244 |
+ /* better than nothing: use input picture interlaced |
|
| 1245 |
+ settings */ |
|
| 1246 |
+ big_picture.interlaced_frame = in_picture->interlaced_frame; |
|
| 1247 |
+ if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) {
|
|
| 1248 |
+ if(top_field_first == -1) |
|
| 1249 |
+ big_picture.top_field_first = in_picture->top_field_first; |
|
| 1250 |
+ else |
|
| 1251 |
+ big_picture.top_field_first = top_field_first; |
|
| 1252 |
+ } |
|
| 1253 |
+ |
|
| 1254 |
+ /* handles sameq here. This is not correct because it may |
|
| 1255 |
+ not be a global option */ |
|
| 1256 |
+ big_picture.quality = quality; |
|
| 1257 |
+ if(!me_threshold) |
|
| 1258 |
+ big_picture.pict_type = 0; |
|
| 1259 |
+// big_picture.pts = AV_NOPTS_VALUE; |
|
| 1260 |
+ big_picture.pts= ost->sync_opts; |
|
| 1261 |
+// big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->time_base.num, enc->time_base.den); |
|
| 1262 |
+//av_log(NULL, AV_LOG_DEBUG, "%"PRId64" -> encoder\n", ost->sync_opts); |
|
| 1263 |
+ if (ost->forced_kf_index < ost->forced_kf_count && |
|
| 1264 |
+ big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
|
|
| 1265 |
+ big_picture.pict_type = AV_PICTURE_TYPE_I; |
|
| 1266 |
+ ost->forced_kf_index++; |
|
| 1267 |
+ } |
|
| 1268 |
+ ret = avcodec_encode_video(enc, |
|
| 1269 |
+ bit_buffer, bit_buffer_size, |
|
| 1270 |
+ &big_picture); |
|
| 1271 |
+ if (ret < 0) {
|
|
| 1272 |
+ fprintf(stderr, "Video encoding failed\n"); |
|
| 1273 |
+ exit_program(1); |
|
| 1274 |
+ } |
|
| 1275 |
+ |
|
| 1276 |
+ if(ret>0){
|
|
| 1277 |
+ pkt.data= bit_buffer; |
|
| 1278 |
+ pkt.size= ret; |
|
| 1279 |
+ if(enc->coded_frame->pts != AV_NOPTS_VALUE) |
|
| 1280 |
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); |
|
| 1281 |
+/*av_log(NULL, AV_LOG_DEBUG, "encoder -> %"PRId64"/%"PRId64"\n", |
|
| 1282 |
+ pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1, |
|
| 1283 |
+ pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/ |
|
| 1284 |
+ |
|
| 1285 |
+ if(enc->coded_frame->key_frame) |
|
| 1286 |
+ pkt.flags |= AV_PKT_FLAG_KEY; |
|
| 1287 |
+ write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); |
|
| 1288 |
+ *frame_size = ret; |
|
| 1289 |
+ video_size += ret; |
|
| 1290 |
+ //fprintf(stderr,"\nFrame: %3d size: %5d type: %d", |
|
| 1291 |
+ // enc->frame_number-1, ret, enc->pict_type); |
|
| 1292 |
+ /* if two pass, output log */ |
|
| 1293 |
+ if (ost->logfile && enc->stats_out) {
|
|
| 1294 |
+ fprintf(ost->logfile, "%s", enc->stats_out); |
|
| 1295 |
+ } |
|
| 1296 |
+ } |
|
| 1297 |
+ } |
|
| 1298 |
+ ost->sync_opts++; |
|
| 1299 |
+ ost->frame_number++; |
|
| 1300 |
+ } |
|
| 1301 |
+} |
|
| 1302 |
+ |
|
| 1303 |
+static double psnr(double d){
|
|
| 1304 |
+ return -10.0*log(d)/log(10.0); |
|
| 1305 |
+} |
|
| 1306 |
+ |
|
| 1307 |
+static void do_video_stats(AVFormatContext *os, OutputStream *ost, |
|
| 1308 |
+ int frame_size) |
|
| 1309 |
+{
|
|
| 1310 |
+ AVCodecContext *enc; |
|
| 1311 |
+ int frame_number; |
|
| 1312 |
+ double ti1, bitrate, avg_bitrate; |
|
| 1313 |
+ |
|
| 1314 |
+ /* this is executed just the first time do_video_stats is called */ |
|
| 1315 |
+ if (!vstats_file) {
|
|
| 1316 |
+ vstats_file = fopen(vstats_filename, "w"); |
|
| 1317 |
+ if (!vstats_file) {
|
|
| 1318 |
+ perror("fopen");
|
|
| 1319 |
+ exit_program(1); |
|
| 1320 |
+ } |
|
| 1321 |
+ } |
|
| 1322 |
+ |
|
| 1323 |
+ enc = ost->st->codec; |
|
| 1324 |
+ if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
| 1325 |
+ frame_number = ost->frame_number; |
|
| 1326 |
+ fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA); |
|
| 1327 |
+ if (enc->flags&CODEC_FLAG_PSNR) |
|
| 1328 |
+ fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0))); |
|
| 1329 |
+ |
|
| 1330 |
+ fprintf(vstats_file,"f_size= %6d ", frame_size); |
|
| 1331 |
+ /* compute pts value */ |
|
| 1332 |
+ ti1 = ost->sync_opts * av_q2d(enc->time_base); |
|
| 1333 |
+ if (ti1 < 0.01) |
|
| 1334 |
+ ti1 = 0.01; |
|
| 1335 |
+ |
|
| 1336 |
+ bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; |
|
| 1337 |
+ avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0; |
|
| 1338 |
+ fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", |
|
| 1339 |
+ (double)video_size / 1024, ti1, bitrate, avg_bitrate); |
|
| 1340 |
+ fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type)); |
|
| 1341 |
+ } |
|
| 1342 |
+} |
|
| 1343 |
+ |
|
| 1344 |
+static void print_report(AVFormatContext **output_files, |
|
| 1345 |
+ OutputStream **ost_table, int nb_ostreams, |
|
| 1346 |
+ int is_last_report) |
|
| 1347 |
+{
|
|
| 1348 |
+ char buf[1024]; |
|
| 1349 |
+ OutputStream *ost; |
|
| 1350 |
+ AVFormatContext *oc; |
|
| 1351 |
+ int64_t total_size; |
|
| 1352 |
+ AVCodecContext *enc; |
|
| 1353 |
+ int frame_number, vid, i; |
|
| 1354 |
+ double bitrate, ti1, pts; |
|
| 1355 |
+ static int64_t last_time = -1; |
|
| 1356 |
+ static int qp_histogram[52]; |
|
| 1357 |
+ |
|
| 1358 |
+ if (!is_last_report) {
|
|
| 1359 |
+ int64_t cur_time; |
|
| 1360 |
+ /* display the report every 0.5 seconds */ |
|
| 1361 |
+ cur_time = av_gettime(); |
|
| 1362 |
+ if (last_time == -1) {
|
|
| 1363 |
+ last_time = cur_time; |
|
| 1364 |
+ return; |
|
| 1365 |
+ } |
|
| 1366 |
+ if ((cur_time - last_time) < 500000) |
|
| 1367 |
+ return; |
|
| 1368 |
+ last_time = cur_time; |
|
| 1369 |
+ } |
|
| 1370 |
+ |
|
| 1371 |
+ |
|
| 1372 |
+ oc = output_files[0]; |
|
| 1373 |
+ |
|
| 1374 |
+ total_size = avio_size(oc->pb); |
|
| 1375 |
+ if(total_size<0) // FIXME improve avio_size() so it works with non seekable output too |
|
| 1376 |
+ total_size= avio_tell(oc->pb); |
|
| 1377 |
+ |
|
| 1378 |
+ buf[0] = '\0'; |
|
| 1379 |
+ ti1 = 1e10; |
|
| 1380 |
+ vid = 0; |
|
| 1381 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 1382 |
+ float q = -1; |
|
| 1383 |
+ ost = ost_table[i]; |
|
| 1384 |
+ enc = ost->st->codec; |
|
| 1385 |
+ if (!ost->st->stream_copy && enc->coded_frame) |
|
| 1386 |
+ q = enc->coded_frame->quality/(float)FF_QP2LAMBDA; |
|
| 1387 |
+ if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
| 1388 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q); |
|
| 1389 |
+ } |
|
| 1390 |
+ if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
| 1391 |
+ float t = (av_gettime()-timer_start) / 1000000.0; |
|
| 1392 |
+ |
|
| 1393 |
+ frame_number = ost->frame_number; |
|
| 1394 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ", |
|
| 1395 |
+ frame_number, (t>1)?(int)(frame_number/t+0.5) : 0, q); |
|
| 1396 |
+ if(is_last_report) |
|
| 1397 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L"); |
|
| 1398 |
+ if(qp_hist){
|
|
| 1399 |
+ int j; |
|
| 1400 |
+ int qp = lrintf(q); |
|
| 1401 |
+ if(qp>=0 && qp<FF_ARRAY_ELEMS(qp_histogram)) |
|
| 1402 |
+ qp_histogram[qp]++; |
|
| 1403 |
+ for(j=0; j<32; j++) |
|
| 1404 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log(qp_histogram[j]+1)/log(2))); |
|
| 1405 |
+ } |
|
| 1406 |
+ if (enc->flags&CODEC_FLAG_PSNR){
|
|
| 1407 |
+ int j; |
|
| 1408 |
+ double error, error_sum=0; |
|
| 1409 |
+ double scale, scale_sum=0; |
|
| 1410 |
+ char type[3]= {'Y','U','V'};
|
|
| 1411 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR="); |
|
| 1412 |
+ for(j=0; j<3; j++){
|
|
| 1413 |
+ if(is_last_report){
|
|
| 1414 |
+ error= enc->error[j]; |
|
| 1415 |
+ scale= enc->width*enc->height*255.0*255.0*frame_number; |
|
| 1416 |
+ }else{
|
|
| 1417 |
+ error= enc->coded_frame->error[j]; |
|
| 1418 |
+ scale= enc->width*enc->height*255.0*255.0; |
|
| 1419 |
+ } |
|
| 1420 |
+ if(j) scale/=4; |
|
| 1421 |
+ error_sum += error; |
|
| 1422 |
+ scale_sum += scale; |
|
| 1423 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], psnr(error/scale)); |
|
| 1424 |
+ } |
|
| 1425 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum/scale_sum)); |
|
| 1426 |
+ } |
|
| 1427 |
+ vid = 1; |
|
| 1428 |
+ } |
|
| 1429 |
+ /* compute min output value */ |
|
| 1430 |
+ pts = (double)ost->st->pts.val * av_q2d(ost->st->time_base); |
|
| 1431 |
+ if ((pts < ti1) && (pts > 0)) |
|
| 1432 |
+ ti1 = pts; |
|
| 1433 |
+ } |
|
| 1434 |
+ if (ti1 < 0.01) |
|
| 1435 |
+ ti1 = 0.01; |
|
| 1436 |
+ |
|
| 1437 |
+ if (verbose > 0 || is_last_report) {
|
|
| 1438 |
+ bitrate = (double)(total_size * 8) / ti1 / 1000.0; |
|
| 1439 |
+ |
|
| 1440 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), |
|
| 1441 |
+ "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s", |
|
| 1442 |
+ (double)total_size / 1024, ti1, bitrate); |
|
| 1443 |
+ |
|
| 1444 |
+ if (nb_frames_dup || nb_frames_drop) |
|
| 1445 |
+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", |
|
| 1446 |
+ nb_frames_dup, nb_frames_drop); |
|
| 1447 |
+ |
|
| 1448 |
+ if (verbose >= 0) |
|
| 1449 |
+ fprintf(stderr, "%s \r", buf); |
|
| 1450 |
+ |
|
| 1451 |
+ fflush(stderr); |
|
| 1452 |
+ } |
|
| 1453 |
+ |
|
| 1454 |
+ if (is_last_report && verbose >= 0){
|
|
| 1455 |
+ int64_t raw= audio_size + video_size + extra_size; |
|
| 1456 |
+ fprintf(stderr, "\n"); |
|
| 1457 |
+ fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n", |
|
| 1458 |
+ video_size/1024.0, |
|
| 1459 |
+ audio_size/1024.0, |
|
| 1460 |
+ extra_size/1024.0, |
|
| 1461 |
+ 100.0*(total_size - raw)/raw |
|
| 1462 |
+ ); |
|
| 1463 |
+ } |
|
| 1464 |
+} |
|
| 1465 |
+ |
|
| 1466 |
+static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size) |
|
| 1467 |
+{
|
|
| 1468 |
+ int fill_char = 0x00; |
|
| 1469 |
+ if (sample_fmt == AV_SAMPLE_FMT_U8) |
|
| 1470 |
+ fill_char = 0x80; |
|
| 1471 |
+ memset(buf, fill_char, size); |
|
| 1472 |
+} |
|
| 1473 |
+ |
|
| 1474 |
+/* pkt = NULL means EOF (needed to flush decoder buffers) */ |
|
| 1475 |
+static int output_packet(InputStream *ist, int ist_index, |
|
| 1476 |
+ OutputStream **ost_table, int nb_ostreams, |
|
| 1477 |
+ const AVPacket *pkt) |
|
| 1478 |
+{
|
|
| 1479 |
+ AVFormatContext *os; |
|
| 1480 |
+ OutputStream *ost; |
|
| 1481 |
+ int ret, i; |
|
| 1482 |
+ int got_output; |
|
| 1483 |
+ AVFrame picture; |
|
| 1484 |
+ void *buffer_to_free = NULL; |
|
| 1485 |
+ static unsigned int samples_size= 0; |
|
| 1486 |
+ AVSubtitle subtitle, *subtitle_to_free; |
|
| 1487 |
+ int64_t pkt_pts = AV_NOPTS_VALUE; |
|
| 1488 |
+#if CONFIG_AVFILTER |
|
| 1489 |
+ int frame_available; |
|
| 1490 |
+#endif |
|
| 1491 |
+ float quality; |
|
| 1492 |
+ |
|
| 1493 |
+ AVPacket avpkt; |
|
| 1494 |
+ int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt); |
|
| 1495 |
+ |
|
| 1496 |
+ if(ist->next_pts == AV_NOPTS_VALUE) |
|
| 1497 |
+ ist->next_pts= ist->pts; |
|
| 1498 |
+ |
|
| 1499 |
+ if (pkt == NULL) {
|
|
| 1500 |
+ /* EOF handling */ |
|
| 1501 |
+ av_init_packet(&avpkt); |
|
| 1502 |
+ avpkt.data = NULL; |
|
| 1503 |
+ avpkt.size = 0; |
|
| 1504 |
+ goto handle_eof; |
|
| 1505 |
+ } else {
|
|
| 1506 |
+ avpkt = *pkt; |
|
| 1507 |
+ } |
|
| 1508 |
+ |
|
| 1509 |
+ if(pkt->dts != AV_NOPTS_VALUE) |
|
| 1510 |
+ ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); |
|
| 1511 |
+ if(pkt->pts != AV_NOPTS_VALUE) |
|
| 1512 |
+ pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q); |
|
| 1513 |
+ |
|
| 1514 |
+ //while we have more to decode or while the decoder did output something on EOF |
|
| 1515 |
+ while (avpkt.size > 0 || (!pkt && got_output)) {
|
|
| 1516 |
+ uint8_t *data_buf, *decoded_data_buf; |
|
| 1517 |
+ int data_size, decoded_data_size; |
|
| 1518 |
+ handle_eof: |
|
| 1519 |
+ ist->pts= ist->next_pts; |
|
| 1520 |
+ |
|
| 1521 |
+ if(avpkt.size && avpkt.size != pkt->size && |
|
| 1522 |
+ ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){
|
|
| 1523 |
+ fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index); |
|
| 1524 |
+ ist->showed_multi_packet_warning=1; |
|
| 1525 |
+ } |
|
| 1526 |
+ |
|
| 1527 |
+ /* decode the packet if needed */ |
|
| 1528 |
+ decoded_data_buf = NULL; /* fail safe */ |
|
| 1529 |
+ decoded_data_size= 0; |
|
| 1530 |
+ data_buf = avpkt.data; |
|
| 1531 |
+ data_size = avpkt.size; |
|
| 1532 |
+ subtitle_to_free = NULL; |
|
| 1533 |
+ if (ist->decoding_needed) {
|
|
| 1534 |
+ switch(ist->st->codec->codec_type) {
|
|
| 1535 |
+ case AVMEDIA_TYPE_AUDIO:{
|
|
| 1536 |
+ if(pkt && samples_size < FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
|
|
| 1537 |
+ samples_size = FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE); |
|
| 1538 |
+ av_free(samples); |
|
| 1539 |
+ samples= av_malloc(samples_size); |
|
| 1540 |
+ } |
|
| 1541 |
+ decoded_data_size= samples_size; |
|
| 1542 |
+ /* XXX: could avoid copy if PCM 16 bits with same |
|
| 1543 |
+ endianness as CPU */ |
|
| 1544 |
+ ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size, |
|
| 1545 |
+ &avpkt); |
|
| 1546 |
+ if (ret < 0) |
|
| 1547 |
+ return ret; |
|
| 1548 |
+ avpkt.data += ret; |
|
| 1549 |
+ avpkt.size -= ret; |
|
| 1550 |
+ data_size = ret; |
|
| 1551 |
+ got_output = decoded_data_size > 0; |
|
| 1552 |
+ /* Some bug in mpeg audio decoder gives */ |
|
| 1553 |
+ /* decoded_data_size < 0, it seems they are overflows */ |
|
| 1554 |
+ if (!got_output) {
|
|
| 1555 |
+ /* no audio frame */ |
|
| 1556 |
+ continue; |
|
| 1557 |
+ } |
|
| 1558 |
+ decoded_data_buf = (uint8_t *)samples; |
|
| 1559 |
+ ist->next_pts += ((int64_t)AV_TIME_BASE/bps * decoded_data_size) / |
|
| 1560 |
+ (ist->st->codec->sample_rate * ist->st->codec->channels); |
|
| 1561 |
+ break;} |
|
| 1562 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 1563 |
+ decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2; |
|
| 1564 |
+ /* XXX: allocate picture correctly */ |
|
| 1565 |
+ avcodec_get_frame_defaults(&picture); |
|
| 1566 |
+ avpkt.pts = pkt_pts; |
|
| 1567 |
+ avpkt.dts = ist->pts; |
|
| 1568 |
+ pkt_pts = AV_NOPTS_VALUE; |
|
| 1569 |
+ |
|
| 1570 |
+ ret = avcodec_decode_video2(ist->st->codec, |
|
| 1571 |
+ &picture, &got_output, &avpkt); |
|
| 1572 |
+ quality = same_quality ? picture.quality : 0; |
|
| 1573 |
+ if (ret < 0) |
|
| 1574 |
+ return ret; |
|
| 1575 |
+ if (!got_output) {
|
|
| 1576 |
+ /* no picture yet */ |
|
| 1577 |
+ goto discard_packet; |
|
| 1578 |
+ } |
|
| 1579 |
+ ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, picture.pkt_pts, picture.pkt_dts); |
|
| 1580 |
+ if (ist->st->codec->time_base.num != 0) {
|
|
| 1581 |
+ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; |
|
| 1582 |
+ ist->next_pts += ((int64_t)AV_TIME_BASE * |
|
| 1583 |
+ ist->st->codec->time_base.num * ticks) / |
|
| 1584 |
+ ist->st->codec->time_base.den; |
|
| 1585 |
+ } |
|
| 1586 |
+ avpkt.size = 0; |
|
| 1587 |
+ buffer_to_free = NULL; |
|
| 1588 |
+ pre_process_video_frame(ist, (AVPicture *)&picture, &buffer_to_free); |
|
| 1589 |
+ break; |
|
| 1590 |
+ case AVMEDIA_TYPE_SUBTITLE: |
|
| 1591 |
+ ret = avcodec_decode_subtitle2(ist->st->codec, |
|
| 1592 |
+ &subtitle, &got_output, &avpkt); |
|
| 1593 |
+ if (ret < 0) |
|
| 1594 |
+ return ret; |
|
| 1595 |
+ if (!got_output) {
|
|
| 1596 |
+ goto discard_packet; |
|
| 1597 |
+ } |
|
| 1598 |
+ subtitle_to_free = &subtitle; |
|
| 1599 |
+ avpkt.size = 0; |
|
| 1600 |
+ break; |
|
| 1601 |
+ default: |
|
| 1602 |
+ return -1; |
|
| 1603 |
+ } |
|
| 1604 |
+ } else {
|
|
| 1605 |
+ switch(ist->st->codec->codec_type) {
|
|
| 1606 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 1607 |
+ ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / |
|
| 1608 |
+ ist->st->codec->sample_rate; |
|
| 1609 |
+ break; |
|
| 1610 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 1611 |
+ if (ist->st->codec->time_base.num != 0) {
|
|
| 1612 |
+ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; |
|
| 1613 |
+ ist->next_pts += ((int64_t)AV_TIME_BASE * |
|
| 1614 |
+ ist->st->codec->time_base.num * ticks) / |
|
| 1615 |
+ ist->st->codec->time_base.den; |
|
| 1616 |
+ } |
|
| 1617 |
+ break; |
|
| 1618 |
+ } |
|
| 1619 |
+ ret = avpkt.size; |
|
| 1620 |
+ avpkt.size = 0; |
|
| 1621 |
+ } |
|
| 1622 |
+ |
|
| 1623 |
+#if CONFIG_AVFILTER |
|
| 1624 |
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
| 1625 |
+ for (i = 0; i < nb_ostreams; i++) {
|
|
| 1626 |
+ ost = ost_table[i]; |
|
| 1627 |
+ if (ost->input_video_filter && ost->source_index == ist_index) {
|
|
| 1628 |
+ AVRational sar; |
|
| 1629 |
+ if (ist->st->sample_aspect_ratio.num) |
|
| 1630 |
+ sar = ist->st->sample_aspect_ratio; |
|
| 1631 |
+ else |
|
| 1632 |
+ sar = ist->st->codec->sample_aspect_ratio; |
|
| 1633 |
+ // add it to be filtered |
|
| 1634 |
+ av_vsrc_buffer_add_frame(ost->input_video_filter, &picture, |
|
| 1635 |
+ ist->pts, |
|
| 1636 |
+ sar); |
|
| 1637 |
+ } |
|
| 1638 |
+ } |
|
| 1639 |
+ } |
|
| 1640 |
+#endif |
|
| 1641 |
+ |
|
| 1642 |
+ // preprocess audio (volume) |
|
| 1643 |
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
|
|
| 1644 |
+ if (audio_volume != 256) {
|
|
| 1645 |
+ short *volp; |
|
| 1646 |
+ volp = samples; |
|
| 1647 |
+ for(i=0;i<(decoded_data_size / sizeof(short));i++) {
|
|
| 1648 |
+ int v = ((*volp) * audio_volume + 128) >> 8; |
|
| 1649 |
+ if (v < -32768) v = -32768; |
|
| 1650 |
+ if (v > 32767) v = 32767; |
|
| 1651 |
+ *volp++ = v; |
|
| 1652 |
+ } |
|
| 1653 |
+ } |
|
| 1654 |
+ } |
|
| 1655 |
+ |
|
| 1656 |
+ /* frame rate emulation */ |
|
| 1657 |
+ if (rate_emu) {
|
|
| 1658 |
+ int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE); |
|
| 1659 |
+ int64_t now = av_gettime() - ist->start; |
|
| 1660 |
+ if (pts > now) |
|
| 1661 |
+ usleep(pts - now); |
|
| 1662 |
+ } |
|
| 1663 |
+ /* if output time reached then transcode raw format, |
|
| 1664 |
+ encode packets and output them */ |
|
| 1665 |
+ if (start_time == 0 || ist->pts >= start_time) |
|
| 1666 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 1667 |
+ int frame_size; |
|
| 1668 |
+ |
|
| 1669 |
+ ost = ost_table[i]; |
|
| 1670 |
+ if (ost->source_index == ist_index) {
|
|
| 1671 |
+#if CONFIG_AVFILTER |
|
| 1672 |
+ frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || |
|
| 1673 |
+ !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]); |
|
| 1674 |
+ while (frame_available) {
|
|
| 1675 |
+ AVRational ist_pts_tb; |
|
| 1676 |
+ if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter) |
|
| 1677 |
+ get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb); |
|
| 1678 |
+ if (ost->picref) |
|
| 1679 |
+ ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); |
|
| 1680 |
+#endif |
|
| 1681 |
+ os = output_files[ost->file_index]; |
|
| 1682 |
+ |
|
| 1683 |
+ /* set the input output pts pairs */ |
|
| 1684 |
+ //ost->sync_ipts = (double)(ist->pts + input_files[ist->file_index].ts_offset - start_time)/ AV_TIME_BASE; |
|
| 1685 |
+ |
|
| 1686 |
+ if (ost->encoding_needed) {
|
|
| 1687 |
+ av_assert0(ist->decoding_needed); |
|
| 1688 |
+ switch(ost->st->codec->codec_type) {
|
|
| 1689 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 1690 |
+ do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size); |
|
| 1691 |
+ break; |
|
| 1692 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 1693 |
+#if CONFIG_AVFILTER |
|
| 1694 |
+ if (ost->picref->video && !ost->frame_aspect_ratio) |
|
| 1695 |
+ ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect; |
|
| 1696 |
+#endif |
|
| 1697 |
+ do_video_out(os, ost, ist, &picture, &frame_size, |
|
| 1698 |
+ same_quality ? quality : ost->st->codec->global_quality); |
|
| 1699 |
+ if (vstats_filename && frame_size) |
|
| 1700 |
+ do_video_stats(os, ost, frame_size); |
|
| 1701 |
+ break; |
|
| 1702 |
+ case AVMEDIA_TYPE_SUBTITLE: |
|
| 1703 |
+ do_subtitle_out(os, ost, ist, &subtitle, |
|
| 1704 |
+ pkt->pts); |
|
| 1705 |
+ break; |
|
| 1706 |
+ default: |
|
| 1707 |
+ abort(); |
|
| 1708 |
+ } |
|
| 1709 |
+ } else {
|
|
| 1710 |
+ AVFrame avframe; //FIXME/XXX remove this |
|
| 1711 |
+ AVPacket opkt; |
|
| 1712 |
+ int64_t ost_tb_start_time= av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base); |
|
| 1713 |
+ |
|
| 1714 |
+ av_init_packet(&opkt); |
|
| 1715 |
+ |
|
| 1716 |
+ if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes) |
|
| 1717 |
+#if !CONFIG_AVFILTER |
|
| 1718 |
+ continue; |
|
| 1719 |
+#else |
|
| 1720 |
+ goto cont; |
|
| 1721 |
+#endif |
|
| 1722 |
+ |
|
| 1723 |
+ /* no reencoding needed : output the packet directly */ |
|
| 1724 |
+ /* force the input stream PTS */ |
|
| 1725 |
+ |
|
| 1726 |
+ avcodec_get_frame_defaults(&avframe); |
|
| 1727 |
+ ost->st->codec->coded_frame= &avframe; |
|
| 1728 |
+ avframe.key_frame = pkt->flags & AV_PKT_FLAG_KEY; |
|
| 1729 |
+ |
|
| 1730 |
+ if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) |
|
| 1731 |
+ audio_size += data_size; |
|
| 1732 |
+ else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
|
| 1733 |
+ video_size += data_size; |
|
| 1734 |
+ ost->sync_opts++; |
|
| 1735 |
+ } |
|
| 1736 |
+ |
|
| 1737 |
+ opkt.stream_index= ost->index; |
|
| 1738 |
+ if(pkt->pts != AV_NOPTS_VALUE) |
|
| 1739 |
+ opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time; |
|
| 1740 |
+ else |
|
| 1741 |
+ opkt.pts= AV_NOPTS_VALUE; |
|
| 1742 |
+ |
|
| 1743 |
+ if (pkt->dts == AV_NOPTS_VALUE) |
|
| 1744 |
+ opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base); |
|
| 1745 |
+ else |
|
| 1746 |
+ opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base); |
|
| 1747 |
+ opkt.dts -= ost_tb_start_time; |
|
| 1748 |
+ |
|
| 1749 |
+ opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base); |
|
| 1750 |
+ opkt.flags= pkt->flags; |
|
| 1751 |
+ |
|
| 1752 |
+ //FIXME remove the following 2 lines they shall be replaced by the bitstream filters |
|
| 1753 |
+ if( ost->st->codec->codec_id != CODEC_ID_H264 |
|
| 1754 |
+ && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO |
|
| 1755 |
+ && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO |
|
| 1756 |
+ ) {
|
|
| 1757 |
+ if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY)) |
|
| 1758 |
+ opkt.destruct= av_destruct_packet; |
|
| 1759 |
+ } else {
|
|
| 1760 |
+ opkt.data = data_buf; |
|
| 1761 |
+ opkt.size = data_size; |
|
| 1762 |
+ } |
|
| 1763 |
+ |
|
| 1764 |
+ write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters); |
|
| 1765 |
+ ost->st->codec->frame_number++; |
|
| 1766 |
+ ost->frame_number++; |
|
| 1767 |
+ av_free_packet(&opkt); |
|
| 1768 |
+ } |
|
| 1769 |
+#if CONFIG_AVFILTER |
|
| 1770 |
+ cont: |
|
| 1771 |
+ frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && |
|
| 1772 |
+ ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]); |
|
| 1773 |
+ if (ost->picref) |
|
| 1774 |
+ avfilter_unref_buffer(ost->picref); |
|
| 1775 |
+ } |
|
| 1776 |
+#endif |
|
| 1777 |
+ } |
|
| 1778 |
+ } |
|
| 1779 |
+ |
|
| 1780 |
+ av_free(buffer_to_free); |
|
| 1781 |
+ /* XXX: allocate the subtitles in the codec ? */ |
|
| 1782 |
+ if (subtitle_to_free) {
|
|
| 1783 |
+ avsubtitle_free(subtitle_to_free); |
|
| 1784 |
+ subtitle_to_free = NULL; |
|
| 1785 |
+ } |
|
| 1786 |
+ } |
|
| 1787 |
+ discard_packet: |
|
| 1788 |
+ if (pkt == NULL) {
|
|
| 1789 |
+ /* EOF handling */ |
|
| 1790 |
+ |
|
| 1791 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 1792 |
+ ost = ost_table[i]; |
|
| 1793 |
+ if (ost->source_index == ist_index) {
|
|
| 1794 |
+ AVCodecContext *enc= ost->st->codec; |
|
| 1795 |
+ os = output_files[ost->file_index]; |
|
| 1796 |
+ |
|
| 1797 |
+ if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1) |
|
| 1798 |
+ continue; |
|
| 1799 |
+ if(ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE)) |
|
| 1800 |
+ continue; |
|
| 1801 |
+ |
|
| 1802 |
+ if (ost->encoding_needed) {
|
|
| 1803 |
+ for(;;) {
|
|
| 1804 |
+ AVPacket pkt; |
|
| 1805 |
+ int fifo_bytes; |
|
| 1806 |
+ av_init_packet(&pkt); |
|
| 1807 |
+ pkt.stream_index= ost->index; |
|
| 1808 |
+ |
|
| 1809 |
+ switch(ost->st->codec->codec_type) {
|
|
| 1810 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 1811 |
+ fifo_bytes = av_fifo_size(ost->fifo); |
|
| 1812 |
+ ret = 0; |
|
| 1813 |
+ /* encode any samples remaining in fifo */ |
|
| 1814 |
+ if (fifo_bytes > 0) {
|
|
| 1815 |
+ int osize = av_get_bytes_per_sample(enc->sample_fmt); |
|
| 1816 |
+ int fs_tmp = enc->frame_size; |
|
| 1817 |
+ |
|
| 1818 |
+ av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL); |
|
| 1819 |
+ if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
|
|
| 1820 |
+ enc->frame_size = fifo_bytes / (osize * enc->channels); |
|
| 1821 |
+ } else { /* pad */
|
|
| 1822 |
+ int frame_bytes = enc->frame_size*osize*enc->channels; |
|
| 1823 |
+ if (allocated_audio_buf_size < frame_bytes) |
|
| 1824 |
+ exit_program(1); |
|
| 1825 |
+ generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes); |
|
| 1826 |
+ } |
|
| 1827 |
+ |
|
| 1828 |
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf); |
|
| 1829 |
+ pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den, |
|
| 1830 |
+ ost->st->time_base.num, enc->sample_rate); |
|
| 1831 |
+ enc->frame_size = fs_tmp; |
|
| 1832 |
+ } |
|
| 1833 |
+ if(ret <= 0) {
|
|
| 1834 |
+ ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL); |
|
| 1835 |
+ } |
|
| 1836 |
+ if (ret < 0) {
|
|
| 1837 |
+ fprintf(stderr, "Audio encoding failed\n"); |
|
| 1838 |
+ exit_program(1); |
|
| 1839 |
+ } |
|
| 1840 |
+ audio_size += ret; |
|
| 1841 |
+ pkt.flags |= AV_PKT_FLAG_KEY; |
|
| 1842 |
+ break; |
|
| 1843 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 1844 |
+ ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL); |
|
| 1845 |
+ if (ret < 0) {
|
|
| 1846 |
+ fprintf(stderr, "Video encoding failed\n"); |
|
| 1847 |
+ exit_program(1); |
|
| 1848 |
+ } |
|
| 1849 |
+ video_size += ret; |
|
| 1850 |
+ if(enc->coded_frame && enc->coded_frame->key_frame) |
|
| 1851 |
+ pkt.flags |= AV_PKT_FLAG_KEY; |
|
| 1852 |
+ if (ost->logfile && enc->stats_out) {
|
|
| 1853 |
+ fprintf(ost->logfile, "%s", enc->stats_out); |
|
| 1854 |
+ } |
|
| 1855 |
+ break; |
|
| 1856 |
+ default: |
|
| 1857 |
+ ret=-1; |
|
| 1858 |
+ } |
|
| 1859 |
+ |
|
| 1860 |
+ if(ret<=0) |
|
| 1861 |
+ break; |
|
| 1862 |
+ pkt.data= bit_buffer; |
|
| 1863 |
+ pkt.size= ret; |
|
| 1864 |
+ if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) |
|
| 1865 |
+ pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); |
|
| 1866 |
+ write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters); |
|
| 1867 |
+ } |
|
| 1868 |
+ } |
|
| 1869 |
+ } |
|
| 1870 |
+ } |
|
| 1871 |
+ } |
|
| 1872 |
+ |
|
| 1873 |
+ return 0; |
|
| 1874 |
+} |
|
| 1875 |
+ |
|
| 1876 |
+static void print_sdp(AVFormatContext **avc, int n) |
|
| 1877 |
+{
|
|
| 1878 |
+ char sdp[2048]; |
|
| 1879 |
+ |
|
| 1880 |
+ av_sdp_create(avc, n, sdp, sizeof(sdp)); |
|
| 1881 |
+ printf("SDP:\n%s\n", sdp);
|
|
| 1882 |
+ fflush(stdout); |
|
| 1883 |
+} |
|
| 1884 |
+ |
|
| 1885 |
+static int copy_chapters(int infile, int outfile) |
|
| 1886 |
+{
|
|
| 1887 |
+ AVFormatContext *is = input_files[infile].ctx; |
|
| 1888 |
+ AVFormatContext *os = output_files[outfile]; |
|
| 1889 |
+ int i; |
|
| 1890 |
+ |
|
| 1891 |
+ for (i = 0; i < is->nb_chapters; i++) {
|
|
| 1892 |
+ AVChapter *in_ch = is->chapters[i], *out_ch; |
|
| 1893 |
+ int64_t ts_off = av_rescale_q(start_time - input_files[infile].ts_offset, |
|
| 1894 |
+ AV_TIME_BASE_Q, in_ch->time_base); |
|
| 1895 |
+ int64_t rt = (recording_time == INT64_MAX) ? INT64_MAX : |
|
| 1896 |
+ av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base); |
|
| 1897 |
+ |
|
| 1898 |
+ |
|
| 1899 |
+ if (in_ch->end < ts_off) |
|
| 1900 |
+ continue; |
|
| 1901 |
+ if (rt != INT64_MAX && in_ch->start > rt + ts_off) |
|
| 1902 |
+ break; |
|
| 1903 |
+ |
|
| 1904 |
+ out_ch = av_mallocz(sizeof(AVChapter)); |
|
| 1905 |
+ if (!out_ch) |
|
| 1906 |
+ return AVERROR(ENOMEM); |
|
| 1907 |
+ |
|
| 1908 |
+ out_ch->id = in_ch->id; |
|
| 1909 |
+ out_ch->time_base = in_ch->time_base; |
|
| 1910 |
+ out_ch->start = FFMAX(0, in_ch->start - ts_off); |
|
| 1911 |
+ out_ch->end = FFMIN(rt, in_ch->end - ts_off); |
|
| 1912 |
+ |
|
| 1913 |
+ if (metadata_chapters_autocopy) |
|
| 1914 |
+ av_dict_copy(&out_ch->metadata, in_ch->metadata, 0); |
|
| 1915 |
+ |
|
| 1916 |
+ os->nb_chapters++; |
|
| 1917 |
+ os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters); |
|
| 1918 |
+ if (!os->chapters) |
|
| 1919 |
+ return AVERROR(ENOMEM); |
|
| 1920 |
+ os->chapters[os->nb_chapters - 1] = out_ch; |
|
| 1921 |
+ } |
|
| 1922 |
+ return 0; |
|
| 1923 |
+} |
|
| 1924 |
+ |
|
| 1925 |
+static void parse_forced_key_frames(char *kf, OutputStream *ost, |
|
| 1926 |
+ AVCodecContext *avctx) |
|
| 1927 |
+{
|
|
| 1928 |
+ char *p; |
|
| 1929 |
+ int n = 1, i; |
|
| 1930 |
+ int64_t t; |
|
| 1931 |
+ |
|
| 1932 |
+ for (p = kf; *p; p++) |
|
| 1933 |
+ if (*p == ',') |
|
| 1934 |
+ n++; |
|
| 1935 |
+ ost->forced_kf_count = n; |
|
| 1936 |
+ ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n); |
|
| 1937 |
+ if (!ost->forced_kf_pts) {
|
|
| 1938 |
+ av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); |
|
| 1939 |
+ exit_program(1); |
|
| 1940 |
+ } |
|
| 1941 |
+ for (i = 0; i < n; i++) {
|
|
| 1942 |
+ p = i ? strchr(p, ',') + 1 : kf; |
|
| 1943 |
+ t = parse_time_or_die("force_key_frames", p, 1);
|
|
| 1944 |
+ ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); |
|
| 1945 |
+ } |
|
| 1946 |
+} |
|
| 1947 |
+ |
|
| 1948 |
+/* |
|
| 1949 |
+ * The following code is the main loop of the file converter |
|
| 1950 |
+ */ |
|
| 1951 |
+static int transcode(AVFormatContext **output_files, |
|
| 1952 |
+ int nb_output_files, |
|
| 1953 |
+ InputFile *input_files, |
|
| 1954 |
+ int nb_input_files, |
|
| 1955 |
+ StreamMap *stream_maps, int nb_stream_maps) |
|
| 1956 |
+{
|
|
| 1957 |
+ int ret = 0, i, j, k, n, nb_ostreams = 0; |
|
| 1958 |
+ AVFormatContext *is, *os; |
|
| 1959 |
+ AVCodecContext *codec, *icodec; |
|
| 1960 |
+ OutputStream *ost, **ost_table = NULL; |
|
| 1961 |
+ InputStream *ist; |
|
| 1962 |
+ char error[1024]; |
|
| 1963 |
+ int want_sdp = 1; |
|
| 1964 |
+ uint8_t no_packet[MAX_FILES]={0};
|
|
| 1965 |
+ int no_packet_count=0; |
|
| 1966 |
+ |
|
| 1967 |
+ if (rate_emu) |
|
| 1968 |
+ for (i = 0; i < nb_input_streams; i++) |
|
| 1969 |
+ input_streams[i].start = av_gettime(); |
|
| 1970 |
+ |
|
| 1971 |
+ /* output stream init */ |
|
| 1972 |
+ nb_ostreams = 0; |
|
| 1973 |
+ for(i=0;i<nb_output_files;i++) {
|
|
| 1974 |
+ os = output_files[i]; |
|
| 1975 |
+ if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) {
|
|
| 1976 |
+ av_dump_format(output_files[i], i, output_files[i]->filename, 1); |
|
| 1977 |
+ fprintf(stderr, "Output file #%d does not contain any stream\n", i); |
|
| 1978 |
+ ret = AVERROR(EINVAL); |
|
| 1979 |
+ goto fail; |
|
| 1980 |
+ } |
|
| 1981 |
+ nb_ostreams += os->nb_streams; |
|
| 1982 |
+ } |
|
| 1983 |
+ if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
|
|
| 1984 |
+ fprintf(stderr, "Number of stream maps must match number of output streams\n"); |
|
| 1985 |
+ ret = AVERROR(EINVAL); |
|
| 1986 |
+ goto fail; |
|
| 1987 |
+ } |
|
| 1988 |
+ |
|
| 1989 |
+ /* Sanity check the mapping args -- do the input files & streams exist? */ |
|
| 1990 |
+ for(i=0;i<nb_stream_maps;i++) {
|
|
| 1991 |
+ int fi = stream_maps[i].file_index; |
|
| 1992 |
+ int si = stream_maps[i].stream_index; |
|
| 1993 |
+ |
|
| 1994 |
+ if (fi < 0 || fi > nb_input_files - 1 || |
|
| 1995 |
+ si < 0 || si > input_files[fi].ctx->nb_streams - 1) {
|
|
| 1996 |
+ fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); |
|
| 1997 |
+ ret = AVERROR(EINVAL); |
|
| 1998 |
+ goto fail; |
|
| 1999 |
+ } |
|
| 2000 |
+ fi = stream_maps[i].sync_file_index; |
|
| 2001 |
+ si = stream_maps[i].sync_stream_index; |
|
| 2002 |
+ if (fi < 0 || fi > nb_input_files - 1 || |
|
| 2003 |
+ si < 0 || si > input_files[fi].ctx->nb_streams - 1) {
|
|
| 2004 |
+ fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); |
|
| 2005 |
+ ret = AVERROR(EINVAL); |
|
| 2006 |
+ goto fail; |
|
| 2007 |
+ } |
|
| 2008 |
+ } |
|
| 2009 |
+ |
|
| 2010 |
+ ost_table = av_mallocz(sizeof(OutputStream *) * nb_ostreams); |
|
| 2011 |
+ if (!ost_table) |
|
| 2012 |
+ goto fail; |
|
| 2013 |
+ n = 0; |
|
| 2014 |
+ for(k=0;k<nb_output_files;k++) {
|
|
| 2015 |
+ os = output_files[k]; |
|
| 2016 |
+ for(i=0;i<os->nb_streams;i++,n++) {
|
|
| 2017 |
+ int found; |
|
| 2018 |
+ ost = ost_table[n] = output_streams_for_file[k][i]; |
|
| 2019 |
+ if (nb_stream_maps > 0) {
|
|
| 2020 |
+ ost->source_index = input_files[stream_maps[n].file_index].ist_index + |
|
| 2021 |
+ stream_maps[n].stream_index; |
|
| 2022 |
+ |
|
| 2023 |
+ /* Sanity check that the stream types match */ |
|
| 2024 |
+ if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) {
|
|
| 2025 |
+ int i= ost->file_index; |
|
| 2026 |
+ av_dump_format(output_files[i], i, output_files[i]->filename, 1); |
|
| 2027 |
+ fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", |
|
| 2028 |
+ stream_maps[n].file_index, stream_maps[n].stream_index, |
|
| 2029 |
+ ost->file_index, ost->index); |
|
| 2030 |
+ exit_program(1); |
|
| 2031 |
+ } |
|
| 2032 |
+ |
|
| 2033 |
+ } else {
|
|
| 2034 |
+ int best_nb_frames=-1; |
|
| 2035 |
+ /* get corresponding input stream index : we select the first one with the right type */ |
|
| 2036 |
+ found = 0; |
|
| 2037 |
+ for (j = 0; j < nb_input_streams; j++) {
|
|
| 2038 |
+ int skip=0; |
|
| 2039 |
+ ist = &input_streams[j]; |
|
| 2040 |
+ if(opt_programid){
|
|
| 2041 |
+ int pi,si; |
|
| 2042 |
+ AVFormatContext *f = input_files[ist->file_index].ctx; |
|
| 2043 |
+ skip=1; |
|
| 2044 |
+ for(pi=0; pi<f->nb_programs; pi++){
|
|
| 2045 |
+ AVProgram *p= f->programs[pi]; |
|
| 2046 |
+ if(p->id == opt_programid) |
|
| 2047 |
+ for(si=0; si<p->nb_stream_indexes; si++){
|
|
| 2048 |
+ if(f->streams[ p->stream_index[si] ] == ist->st) |
|
| 2049 |
+ skip=0; |
|
| 2050 |
+ } |
|
| 2051 |
+ } |
|
| 2052 |
+ } |
|
| 2053 |
+ if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && |
|
| 2054 |
+ ist->st->codec->codec_type == ost->st->codec->codec_type) {
|
|
| 2055 |
+ if(best_nb_frames < ist->st->codec_info_nb_frames){
|
|
| 2056 |
+ best_nb_frames= ist->st->codec_info_nb_frames; |
|
| 2057 |
+ ost->source_index = j; |
|
| 2058 |
+ found = 1; |
|
| 2059 |
+ } |
|
| 2060 |
+ } |
|
| 2061 |
+ } |
|
| 2062 |
+ |
|
| 2063 |
+ if (!found) {
|
|
| 2064 |
+ if(! opt_programid) {
|
|
| 2065 |
+ /* try again and reuse existing stream */ |
|
| 2066 |
+ for (j = 0; j < nb_input_streams; j++) {
|
|
| 2067 |
+ ist = &input_streams[j]; |
|
| 2068 |
+ if ( ist->st->codec->codec_type == ost->st->codec->codec_type |
|
| 2069 |
+ && ist->st->discard != AVDISCARD_ALL) {
|
|
| 2070 |
+ ost->source_index = j; |
|
| 2071 |
+ found = 1; |
|
| 2072 |
+ } |
|
| 2073 |
+ } |
|
| 2074 |
+ } |
|
| 2075 |
+ if (!found) {
|
|
| 2076 |
+ int i= ost->file_index; |
|
| 2077 |
+ av_dump_format(output_files[i], i, output_files[i]->filename, 1); |
|
| 2078 |
+ fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", |
|
| 2079 |
+ ost->file_index, ost->index); |
|
| 2080 |
+ exit_program(1); |
|
| 2081 |
+ } |
|
| 2082 |
+ } |
|
| 2083 |
+ } |
|
| 2084 |
+ ist = &input_streams[ost->source_index]; |
|
| 2085 |
+ ist->discard = 0; |
|
| 2086 |
+ ost->sync_ist = (nb_stream_maps > 0) ? |
|
| 2087 |
+ &input_streams[input_files[stream_maps[n].sync_file_index].ist_index + |
|
| 2088 |
+ stream_maps[n].sync_stream_index] : ist; |
|
| 2089 |
+ } |
|
| 2090 |
+ } |
|
| 2091 |
+ |
|
| 2092 |
+ /* for each output stream, we compute the right encoding parameters */ |
|
| 2093 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 2094 |
+ ost = ost_table[i]; |
|
| 2095 |
+ os = output_files[ost->file_index]; |
|
| 2096 |
+ ist = &input_streams[ost->source_index]; |
|
| 2097 |
+ |
|
| 2098 |
+ codec = ost->st->codec; |
|
| 2099 |
+ icodec = ist->st->codec; |
|
| 2100 |
+ |
|
| 2101 |
+ if (metadata_streams_autocopy) |
|
| 2102 |
+ av_dict_copy(&ost->st->metadata, ist->st->metadata, |
|
| 2103 |
+ AV_DICT_DONT_OVERWRITE); |
|
| 2104 |
+ |
|
| 2105 |
+ ost->st->disposition = ist->st->disposition; |
|
| 2106 |
+ codec->bits_per_raw_sample= icodec->bits_per_raw_sample; |
|
| 2107 |
+ codec->chroma_sample_location = icodec->chroma_sample_location; |
|
| 2108 |
+ |
|
| 2109 |
+ if (ost->st->stream_copy) {
|
|
| 2110 |
+ uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE; |
|
| 2111 |
+ |
|
| 2112 |
+ if (extra_size > INT_MAX) |
|
| 2113 |
+ goto fail; |
|
| 2114 |
+ |
|
| 2115 |
+ /* if stream_copy is selected, no need to decode or encode */ |
|
| 2116 |
+ codec->codec_id = icodec->codec_id; |
|
| 2117 |
+ codec->codec_type = icodec->codec_type; |
|
| 2118 |
+ |
|
| 2119 |
+ if(!codec->codec_tag){
|
|
| 2120 |
+ if( !os->oformat->codec_tag |
|
| 2121 |
+ || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id |
|
| 2122 |
+ || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) |
|
| 2123 |
+ codec->codec_tag = icodec->codec_tag; |
|
| 2124 |
+ } |
|
| 2125 |
+ |
|
| 2126 |
+ codec->bit_rate = icodec->bit_rate; |
|
| 2127 |
+ codec->rc_max_rate = icodec->rc_max_rate; |
|
| 2128 |
+ codec->rc_buffer_size = icodec->rc_buffer_size; |
|
| 2129 |
+ codec->extradata= av_mallocz(extra_size); |
|
| 2130 |
+ if (!codec->extradata) |
|
| 2131 |
+ goto fail; |
|
| 2132 |
+ memcpy(codec->extradata, icodec->extradata, icodec->extradata_size); |
|
| 2133 |
+ codec->extradata_size= icodec->extradata_size; |
|
| 2134 |
+ if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){
|
|
| 2135 |
+ codec->time_base = icodec->time_base; |
|
| 2136 |
+ codec->time_base.num *= icodec->ticks_per_frame; |
|
| 2137 |
+ av_reduce(&codec->time_base.num, &codec->time_base.den, |
|
| 2138 |
+ codec->time_base.num, codec->time_base.den, INT_MAX); |
|
| 2139 |
+ }else |
|
| 2140 |
+ codec->time_base = ist->st->time_base; |
|
| 2141 |
+ switch(codec->codec_type) {
|
|
| 2142 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 2143 |
+ if(audio_volume != 256) {
|
|
| 2144 |
+ fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); |
|
| 2145 |
+ exit_program(1); |
|
| 2146 |
+ } |
|
| 2147 |
+ codec->channel_layout = icodec->channel_layout; |
|
| 2148 |
+ codec->sample_rate = icodec->sample_rate; |
|
| 2149 |
+ codec->channels = icodec->channels; |
|
| 2150 |
+ codec->frame_size = icodec->frame_size; |
|
| 2151 |
+ codec->audio_service_type = icodec->audio_service_type; |
|
| 2152 |
+ codec->block_align= icodec->block_align; |
|
| 2153 |
+ if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) |
|
| 2154 |
+ codec->block_align= 0; |
|
| 2155 |
+ if(codec->codec_id == CODEC_ID_AC3) |
|
| 2156 |
+ codec->block_align= 0; |
|
| 2157 |
+ break; |
|
| 2158 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 2159 |
+ codec->pix_fmt = icodec->pix_fmt; |
|
| 2160 |
+ codec->width = icodec->width; |
|
| 2161 |
+ codec->height = icodec->height; |
|
| 2162 |
+ codec->has_b_frames = icodec->has_b_frames; |
|
| 2163 |
+ if (!codec->sample_aspect_ratio.num) {
|
|
| 2164 |
+ codec->sample_aspect_ratio = |
|
| 2165 |
+ ost->st->sample_aspect_ratio = |
|
| 2166 |
+ ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : |
|
| 2167 |
+ ist->st->codec->sample_aspect_ratio.num ? |
|
| 2168 |
+ ist->st->codec->sample_aspect_ratio : (AVRational){0, 1};
|
|
| 2169 |
+ } |
|
| 2170 |
+ break; |
|
| 2171 |
+ case AVMEDIA_TYPE_SUBTITLE: |
|
| 2172 |
+ codec->width = icodec->width; |
|
| 2173 |
+ codec->height = icodec->height; |
|
| 2174 |
+ break; |
|
| 2175 |
+ case AVMEDIA_TYPE_DATA: |
|
| 2176 |
+ break; |
|
| 2177 |
+ default: |
|
| 2178 |
+ abort(); |
|
| 2179 |
+ } |
|
| 2180 |
+ } else {
|
|
| 2181 |
+ if (!ost->enc) |
|
| 2182 |
+ ost->enc = avcodec_find_encoder(ost->st->codec->codec_id); |
|
| 2183 |
+ switch(codec->codec_type) {
|
|
| 2184 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 2185 |
+ ost->fifo= av_fifo_alloc(1024); |
|
| 2186 |
+ if(!ost->fifo) |
|
| 2187 |
+ goto fail; |
|
| 2188 |
+ ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); |
|
| 2189 |
+ if (!codec->sample_rate) {
|
|
| 2190 |
+ codec->sample_rate = icodec->sample_rate; |
|
| 2191 |
+ if (icodec->lowres) |
|
| 2192 |
+ codec->sample_rate >>= icodec->lowres; |
|
| 2193 |
+ } |
|
| 2194 |
+ choose_sample_rate(ost->st, ost->enc); |
|
| 2195 |
+ codec->time_base = (AVRational){1, codec->sample_rate};
|
|
| 2196 |
+ if (codec->sample_fmt == AV_SAMPLE_FMT_NONE) |
|
| 2197 |
+ codec->sample_fmt = icodec->sample_fmt; |
|
| 2198 |
+ choose_sample_fmt(ost->st, ost->enc); |
|
| 2199 |
+ if (!codec->channels) |
|
| 2200 |
+ codec->channels = icodec->channels; |
|
| 2201 |
+ codec->channel_layout = icodec->channel_layout; |
|
| 2202 |
+ if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) |
|
| 2203 |
+ codec->channel_layout = 0; |
|
| 2204 |
+ ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; |
|
| 2205 |
+ icodec->request_channels = codec->channels; |
|
| 2206 |
+ ist->decoding_needed = 1; |
|
| 2207 |
+ ost->encoding_needed = 1; |
|
| 2208 |
+ ost->resample_sample_fmt = icodec->sample_fmt; |
|
| 2209 |
+ ost->resample_sample_rate = icodec->sample_rate; |
|
| 2210 |
+ ost->resample_channels = icodec->channels; |
|
| 2211 |
+ break; |
|
| 2212 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 2213 |
+ if (codec->pix_fmt == PIX_FMT_NONE) |
|
| 2214 |
+ codec->pix_fmt = icodec->pix_fmt; |
|
| 2215 |
+ choose_pixel_fmt(ost->st, ost->enc); |
|
| 2216 |
+ |
|
| 2217 |
+ if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {
|
|
| 2218 |
+ fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n"); |
|
| 2219 |
+ exit_program(1); |
|
| 2220 |
+ } |
|
| 2221 |
+ |
|
| 2222 |
+ if (!codec->width || !codec->height) {
|
|
| 2223 |
+ codec->width = icodec->width; |
|
| 2224 |
+ codec->height = icodec->height; |
|
| 2225 |
+ } |
|
| 2226 |
+ |
|
| 2227 |
+ ost->video_resample = codec->width != icodec->width || |
|
| 2228 |
+ codec->height != icodec->height || |
|
| 2229 |
+ codec->pix_fmt != icodec->pix_fmt; |
|
| 2230 |
+ if (ost->video_resample) {
|
|
| 2231 |
+#if !CONFIG_AVFILTER |
|
| 2232 |
+ avcodec_get_frame_defaults(&ost->pict_tmp); |
|
| 2233 |
+ if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt, |
|
| 2234 |
+ codec->width, codec->height)) {
|
|
| 2235 |
+ fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); |
|
| 2236 |
+ exit_program(1); |
|
| 2237 |
+ } |
|
| 2238 |
+ ost->img_resample_ctx = sws_getContext( |
|
| 2239 |
+ icodec->width, |
|
| 2240 |
+ icodec->height, |
|
| 2241 |
+ icodec->pix_fmt, |
|
| 2242 |
+ codec->width, |
|
| 2243 |
+ codec->height, |
|
| 2244 |
+ codec->pix_fmt, |
|
| 2245 |
+ ost->sws_flags, NULL, NULL, NULL); |
|
| 2246 |
+ if (ost->img_resample_ctx == NULL) {
|
|
| 2247 |
+ fprintf(stderr, "Cannot get resampling context\n"); |
|
| 2248 |
+ exit_program(1); |
|
| 2249 |
+ } |
|
| 2250 |
+#endif |
|
| 2251 |
+ codec->bits_per_raw_sample= 0; |
|
| 2252 |
+ } |
|
| 2253 |
+ |
|
| 2254 |
+ ost->resample_height = icodec->height; |
|
| 2255 |
+ ost->resample_width = icodec->width; |
|
| 2256 |
+ ost->resample_pix_fmt= icodec->pix_fmt; |
|
| 2257 |
+ ost->encoding_needed = 1; |
|
| 2258 |
+ ist->decoding_needed = 1; |
|
| 2259 |
+ |
|
| 2260 |
+ if (!ost->frame_rate.num) |
|
| 2261 |
+ ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1};
|
|
| 2262 |
+ if (ost->enc && ost->enc->supported_framerates && !force_fps) {
|
|
| 2263 |
+ int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); |
|
| 2264 |
+ ost->frame_rate = ost->enc->supported_framerates[idx]; |
|
| 2265 |
+ } |
|
| 2266 |
+ codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num};
|
|
| 2267 |
+ |
|
| 2268 |
+#if CONFIG_AVFILTER |
|
| 2269 |
+ if (configure_video_filters(ist, ost)) {
|
|
| 2270 |
+ fprintf(stderr, "Error opening filters!\n"); |
|
| 2271 |
+ exit(1); |
|
| 2272 |
+ } |
|
| 2273 |
+#endif |
|
| 2274 |
+ break; |
|
| 2275 |
+ case AVMEDIA_TYPE_SUBTITLE: |
|
| 2276 |
+ ost->encoding_needed = 1; |
|
| 2277 |
+ ist->decoding_needed = 1; |
|
| 2278 |
+ break; |
|
| 2279 |
+ default: |
|
| 2280 |
+ abort(); |
|
| 2281 |
+ break; |
|
| 2282 |
+ } |
|
| 2283 |
+ /* two pass mode */ |
|
| 2284 |
+ if (ost->encoding_needed && |
|
| 2285 |
+ (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) {
|
|
| 2286 |
+ char logfilename[1024]; |
|
| 2287 |
+ FILE *f; |
|
| 2288 |
+ |
|
| 2289 |
+ snprintf(logfilename, sizeof(logfilename), "%s-%d.log", |
|
| 2290 |
+ pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, |
|
| 2291 |
+ i); |
|
| 2292 |
+ if (codec->flags & CODEC_FLAG_PASS1) {
|
|
| 2293 |
+ f = fopen(logfilename, "wb"); |
|
| 2294 |
+ if (!f) {
|
|
| 2295 |
+ fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno)); |
|
| 2296 |
+ exit_program(1); |
|
| 2297 |
+ } |
|
| 2298 |
+ ost->logfile = f; |
|
| 2299 |
+ } else {
|
|
| 2300 |
+ char *logbuffer; |
|
| 2301 |
+ size_t logbuffer_size; |
|
| 2302 |
+ if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) {
|
|
| 2303 |
+ fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename); |
|
| 2304 |
+ exit_program(1); |
|
| 2305 |
+ } |
|
| 2306 |
+ codec->stats_in = logbuffer; |
|
| 2307 |
+ } |
|
| 2308 |
+ } |
|
| 2309 |
+ } |
|
| 2310 |
+ if(codec->codec_type == AVMEDIA_TYPE_VIDEO){
|
|
| 2311 |
+ int size= codec->width * codec->height; |
|
| 2312 |
+ bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 200); |
|
| 2313 |
+ } |
|
| 2314 |
+ } |
|
| 2315 |
+ |
|
| 2316 |
+ if (!bit_buffer) |
|
| 2317 |
+ bit_buffer = av_malloc(bit_buffer_size); |
|
| 2318 |
+ if (!bit_buffer) {
|
|
| 2319 |
+ fprintf(stderr, "Cannot allocate %d bytes output buffer\n", |
|
| 2320 |
+ bit_buffer_size); |
|
| 2321 |
+ ret = AVERROR(ENOMEM); |
|
| 2322 |
+ goto fail; |
|
| 2323 |
+ } |
|
| 2324 |
+ |
|
| 2325 |
+ /* open each encoder */ |
|
| 2326 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 2327 |
+ ost = ost_table[i]; |
|
| 2328 |
+ if (ost->encoding_needed) {
|
|
| 2329 |
+ AVCodec *codec = ost->enc; |
|
| 2330 |
+ AVCodecContext *dec = input_streams[ost->source_index].st->codec; |
|
| 2331 |
+ if (!codec) {
|
|
| 2332 |
+ snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d", |
|
| 2333 |
+ ost->st->codec->codec_id, ost->file_index, ost->index); |
|
| 2334 |
+ ret = AVERROR(EINVAL); |
|
| 2335 |
+ goto dump_format; |
|
| 2336 |
+ } |
|
| 2337 |
+ if (dec->subtitle_header) {
|
|
| 2338 |
+ ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); |
|
| 2339 |
+ if (!ost->st->codec->subtitle_header) {
|
|
| 2340 |
+ ret = AVERROR(ENOMEM); |
|
| 2341 |
+ goto dump_format; |
|
| 2342 |
+ } |
|
| 2343 |
+ memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); |
|
| 2344 |
+ ost->st->codec->subtitle_header_size = dec->subtitle_header_size; |
|
| 2345 |
+ } |
|
| 2346 |
+ if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) {
|
|
| 2347 |
+ snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", |
|
| 2348 |
+ ost->file_index, ost->index); |
|
| 2349 |
+ ret = AVERROR(EINVAL); |
|
| 2350 |
+ goto dump_format; |
|
| 2351 |
+ } |
|
| 2352 |
+ assert_codec_experimental(ost->st->codec, 1); |
|
| 2353 |
+ assert_avoptions(ost->opts); |
|
| 2354 |
+ if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) |
|
| 2355 |
+ av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." |
|
| 2356 |
+ "It takes bits/s as argument, not kbits/s\n"); |
|
| 2357 |
+ extra_size += ost->st->codec->extradata_size; |
|
| 2358 |
+ } |
|
| 2359 |
+ } |
|
| 2360 |
+ |
|
| 2361 |
+ /* open each decoder */ |
|
| 2362 |
+ for (i = 0; i < nb_input_streams; i++) {
|
|
| 2363 |
+ ist = &input_streams[i]; |
|
| 2364 |
+ if (ist->decoding_needed) {
|
|
| 2365 |
+ AVCodec *codec = ist->dec; |
|
| 2366 |
+ if (!codec) |
|
| 2367 |
+ codec = avcodec_find_decoder(ist->st->codec->codec_id); |
|
| 2368 |
+ if (!codec) {
|
|
| 2369 |
+ snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d", |
|
| 2370 |
+ ist->st->codec->codec_id, ist->file_index, ist->st->index); |
|
| 2371 |
+ ret = AVERROR(EINVAL); |
|
| 2372 |
+ goto dump_format; |
|
| 2373 |
+ } |
|
| 2374 |
+ |
|
| 2375 |
+ /* update requested sample format for the decoder based on the |
|
| 2376 |
+ corresponding encoder sample format */ |
|
| 2377 |
+ for (j = 0; j < nb_ostreams; j++) {
|
|
| 2378 |
+ ost = ost_table[j]; |
|
| 2379 |
+ if (ost->source_index == i) {
|
|
| 2380 |
+ update_sample_fmt(ist->st->codec, codec, ost->st->codec); |
|
| 2381 |
+ break; |
|
| 2382 |
+ } |
|
| 2383 |
+ } |
|
| 2384 |
+ |
|
| 2385 |
+ if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) {
|
|
| 2386 |
+ snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d", |
|
| 2387 |
+ ist->file_index, ist->st->index); |
|
| 2388 |
+ ret = AVERROR(EINVAL); |
|
| 2389 |
+ goto dump_format; |
|
| 2390 |
+ } |
|
| 2391 |
+ assert_codec_experimental(ist->st->codec, 0); |
|
| 2392 |
+ assert_avoptions(ost->opts); |
|
| 2393 |
+ //if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) |
|
| 2394 |
+ // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD; |
|
| 2395 |
+ } |
|
| 2396 |
+ } |
|
| 2397 |
+ |
|
| 2398 |
+ /* init pts */ |
|
| 2399 |
+ for (i = 0; i < nb_input_streams; i++) {
|
|
| 2400 |
+ AVStream *st; |
|
| 2401 |
+ ist = &input_streams[i]; |
|
| 2402 |
+ st= ist->st; |
|
| 2403 |
+ ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0; |
|
| 2404 |
+ ist->next_pts = AV_NOPTS_VALUE; |
|
| 2405 |
+ init_pts_correction(&ist->pts_ctx); |
|
| 2406 |
+ ist->is_start = 1; |
|
| 2407 |
+ } |
|
| 2408 |
+ |
|
| 2409 |
+ /* set meta data information from input file if required */ |
|
| 2410 |
+ for (i=0;i<nb_meta_data_maps;i++) {
|
|
| 2411 |
+ AVFormatContext *files[2]; |
|
| 2412 |
+ AVDictionary **meta[2]; |
|
| 2413 |
+ int j; |
|
| 2414 |
+ |
|
| 2415 |
+#define METADATA_CHECK_INDEX(index, nb_elems, desc)\ |
|
| 2416 |
+ if ((index) < 0 || (index) >= (nb_elems)) {\
|
|
| 2417 |
+ snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\ |
|
| 2418 |
+ (desc), (index));\ |
|
| 2419 |
+ ret = AVERROR(EINVAL);\ |
|
| 2420 |
+ goto dump_format;\ |
|
| 2421 |
+ } |
|
| 2422 |
+ |
|
| 2423 |
+ int out_file_index = meta_data_maps[i][0].file; |
|
| 2424 |
+ int in_file_index = meta_data_maps[i][1].file; |
|
| 2425 |
+ if (in_file_index < 0 || out_file_index < 0) |
|
| 2426 |
+ continue; |
|
| 2427 |
+ METADATA_CHECK_INDEX(out_file_index, nb_output_files, "output file") |
|
| 2428 |
+ METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file") |
|
| 2429 |
+ |
|
| 2430 |
+ files[0] = output_files[out_file_index]; |
|
| 2431 |
+ files[1] = input_files[in_file_index].ctx; |
|
| 2432 |
+ |
|
| 2433 |
+ for (j = 0; j < 2; j++) {
|
|
| 2434 |
+ MetadataMap *map = &meta_data_maps[i][j]; |
|
| 2435 |
+ |
|
| 2436 |
+ switch (map->type) {
|
|
| 2437 |
+ case 'g': |
|
| 2438 |
+ meta[j] = &files[j]->metadata; |
|
| 2439 |
+ break; |
|
| 2440 |
+ case 's': |
|
| 2441 |
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream") |
|
| 2442 |
+ meta[j] = &files[j]->streams[map->index]->metadata; |
|
| 2443 |
+ break; |
|
| 2444 |
+ case 'c': |
|
| 2445 |
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter") |
|
| 2446 |
+ meta[j] = &files[j]->chapters[map->index]->metadata; |
|
| 2447 |
+ break; |
|
| 2448 |
+ case 'p': |
|
| 2449 |
+ METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program") |
|
| 2450 |
+ meta[j] = &files[j]->programs[map->index]->metadata; |
|
| 2451 |
+ break; |
|
| 2452 |
+ } |
|
| 2453 |
+ } |
|
| 2454 |
+ |
|
| 2455 |
+ av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE); |
|
| 2456 |
+ } |
|
| 2457 |
+ |
|
| 2458 |
+ /* copy global metadata by default */ |
|
| 2459 |
+ if (metadata_global_autocopy) {
|
|
| 2460 |
+ |
|
| 2461 |
+ for (i = 0; i < nb_output_files; i++) |
|
| 2462 |
+ av_dict_copy(&output_files[i]->metadata, input_files[0].ctx->metadata, |
|
| 2463 |
+ AV_DICT_DONT_OVERWRITE); |
|
| 2464 |
+ } |
|
| 2465 |
+ |
|
| 2466 |
+ /* copy chapters according to chapter maps */ |
|
| 2467 |
+ for (i = 0; i < nb_chapter_maps; i++) {
|
|
| 2468 |
+ int infile = chapter_maps[i].in_file; |
|
| 2469 |
+ int outfile = chapter_maps[i].out_file; |
|
| 2470 |
+ |
|
| 2471 |
+ if (infile < 0 || outfile < 0) |
|
| 2472 |
+ continue; |
|
| 2473 |
+ if (infile >= nb_input_files) {
|
|
| 2474 |
+ snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile); |
|
| 2475 |
+ ret = AVERROR(EINVAL); |
|
| 2476 |
+ goto dump_format; |
|
| 2477 |
+ } |
|
| 2478 |
+ if (outfile >= nb_output_files) {
|
|
| 2479 |
+ snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile); |
|
| 2480 |
+ ret = AVERROR(EINVAL); |
|
| 2481 |
+ goto dump_format; |
|
| 2482 |
+ } |
|
| 2483 |
+ copy_chapters(infile, outfile); |
|
| 2484 |
+ } |
|
| 2485 |
+ |
|
| 2486 |
+ /* copy chapters from the first input file that has them*/ |
|
| 2487 |
+ if (!nb_chapter_maps) |
|
| 2488 |
+ for (i = 0; i < nb_input_files; i++) {
|
|
| 2489 |
+ if (!input_files[i].ctx->nb_chapters) |
|
| 2490 |
+ continue; |
|
| 2491 |
+ |
|
| 2492 |
+ for (j = 0; j < nb_output_files; j++) |
|
| 2493 |
+ if ((ret = copy_chapters(i, j)) < 0) |
|
| 2494 |
+ goto dump_format; |
|
| 2495 |
+ break; |
|
| 2496 |
+ } |
|
| 2497 |
+ |
|
| 2498 |
+ /* open files and write file headers */ |
|
| 2499 |
+ for(i=0;i<nb_output_files;i++) {
|
|
| 2500 |
+ os = output_files[i]; |
|
| 2501 |
+ if (avformat_write_header(os, &output_opts[i]) < 0) {
|
|
| 2502 |
+ snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); |
|
| 2503 |
+ ret = AVERROR(EINVAL); |
|
| 2504 |
+ goto dump_format; |
|
| 2505 |
+ } |
|
| 2506 |
+ assert_avoptions(output_opts[i]); |
|
| 2507 |
+ if (strcmp(output_files[i]->oformat->name, "rtp")) {
|
|
| 2508 |
+ want_sdp = 0; |
|
| 2509 |
+ } |
|
| 2510 |
+ } |
|
| 2511 |
+ |
|
| 2512 |
+ dump_format: |
|
| 2513 |
+ /* dump the file output parameters - cannot be done before in case |
|
| 2514 |
+ of stream copy */ |
|
| 2515 |
+ for(i=0;i<nb_output_files;i++) {
|
|
| 2516 |
+ av_dump_format(output_files[i], i, output_files[i]->filename, 1); |
|
| 2517 |
+ } |
|
| 2518 |
+ |
|
| 2519 |
+ /* dump the stream mapping */ |
|
| 2520 |
+ if (verbose >= 0) {
|
|
| 2521 |
+ fprintf(stderr, "Stream mapping:\n"); |
|
| 2522 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 2523 |
+ ost = ost_table[i]; |
|
| 2524 |
+ fprintf(stderr, " Stream #%d.%d -> #%d.%d", |
|
| 2525 |
+ input_streams[ost->source_index].file_index, |
|
| 2526 |
+ input_streams[ost->source_index].st->index, |
|
| 2527 |
+ ost->file_index, |
|
| 2528 |
+ ost->index); |
|
| 2529 |
+ if (ost->sync_ist != &input_streams[ost->source_index]) |
|
| 2530 |
+ fprintf(stderr, " [sync #%d.%d]", |
|
| 2531 |
+ ost->sync_ist->file_index, |
|
| 2532 |
+ ost->sync_ist->st->index); |
|
| 2533 |
+ fprintf(stderr, "\n"); |
|
| 2534 |
+ } |
|
| 2535 |
+ } |
|
| 2536 |
+ |
|
| 2537 |
+ if (ret) {
|
|
| 2538 |
+ fprintf(stderr, "%s\n", error); |
|
| 2539 |
+ goto fail; |
|
| 2540 |
+ } |
|
| 2541 |
+ |
|
| 2542 |
+ if (want_sdp) {
|
|
| 2543 |
+ print_sdp(output_files, nb_output_files); |
|
| 2544 |
+ } |
|
| 2545 |
+ |
|
| 2546 |
+ if (verbose >= 0) |
|
| 2547 |
+ fprintf(stderr, "Press ctrl-c to stop encoding\n"); |
|
| 2548 |
+ term_init(); |
|
| 2549 |
+ |
|
| 2550 |
+ timer_start = av_gettime(); |
|
| 2551 |
+ |
|
| 2552 |
+ for(; received_sigterm == 0;) {
|
|
| 2553 |
+ int file_index, ist_index; |
|
| 2554 |
+ AVPacket pkt; |
|
| 2555 |
+ double ipts_min; |
|
| 2556 |
+ double opts_min; |
|
| 2557 |
+ |
|
| 2558 |
+ redo: |
|
| 2559 |
+ ipts_min= 1e100; |
|
| 2560 |
+ opts_min= 1e100; |
|
| 2561 |
+ |
|
| 2562 |
+ /* select the stream that we must read now by looking at the |
|
| 2563 |
+ smallest output pts */ |
|
| 2564 |
+ file_index = -1; |
|
| 2565 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 2566 |
+ double ipts, opts; |
|
| 2567 |
+ ost = ost_table[i]; |
|
| 2568 |
+ os = output_files[ost->file_index]; |
|
| 2569 |
+ ist = &input_streams[ost->source_index]; |
|
| 2570 |
+ if(ist->is_past_recording_time || no_packet[ist->file_index]) |
|
| 2571 |
+ continue; |
|
| 2572 |
+ opts = ost->st->pts.val * av_q2d(ost->st->time_base); |
|
| 2573 |
+ ipts = (double)ist->pts; |
|
| 2574 |
+ if (!input_files[ist->file_index].eof_reached){
|
|
| 2575 |
+ if(ipts < ipts_min) {
|
|
| 2576 |
+ ipts_min = ipts; |
|
| 2577 |
+ if(input_sync ) file_index = ist->file_index; |
|
| 2578 |
+ } |
|
| 2579 |
+ if(opts < opts_min) {
|
|
| 2580 |
+ opts_min = opts; |
|
| 2581 |
+ if(!input_sync) file_index = ist->file_index; |
|
| 2582 |
+ } |
|
| 2583 |
+ } |
|
| 2584 |
+ if(ost->frame_number >= max_frames[ost->st->codec->codec_type]){
|
|
| 2585 |
+ file_index= -1; |
|
| 2586 |
+ break; |
|
| 2587 |
+ } |
|
| 2588 |
+ } |
|
| 2589 |
+ /* if none, if is finished */ |
|
| 2590 |
+ if (file_index < 0) {
|
|
| 2591 |
+ if(no_packet_count){
|
|
| 2592 |
+ no_packet_count=0; |
|
| 2593 |
+ memset(no_packet, 0, sizeof(no_packet)); |
|
| 2594 |
+ usleep(10000); |
|
| 2595 |
+ continue; |
|
| 2596 |
+ } |
|
| 2597 |
+ break; |
|
| 2598 |
+ } |
|
| 2599 |
+ |
|
| 2600 |
+ /* finish if limit size exhausted */ |
|
| 2601 |
+ if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0]->pb)) |
|
| 2602 |
+ break; |
|
| 2603 |
+ |
|
| 2604 |
+ /* read a frame from it and output it in the fifo */ |
|
| 2605 |
+ is = input_files[file_index].ctx; |
|
| 2606 |
+ ret= av_read_frame(is, &pkt); |
|
| 2607 |
+ if(ret == AVERROR(EAGAIN)){
|
|
| 2608 |
+ no_packet[file_index]=1; |
|
| 2609 |
+ no_packet_count++; |
|
| 2610 |
+ continue; |
|
| 2611 |
+ } |
|
| 2612 |
+ if (ret < 0) {
|
|
| 2613 |
+ input_files[file_index].eof_reached = 1; |
|
| 2614 |
+ if (opt_shortest) |
|
| 2615 |
+ break; |
|
| 2616 |
+ else |
|
| 2617 |
+ continue; |
|
| 2618 |
+ } |
|
| 2619 |
+ |
|
| 2620 |
+ no_packet_count=0; |
|
| 2621 |
+ memset(no_packet, 0, sizeof(no_packet)); |
|
| 2622 |
+ |
|
| 2623 |
+ if (do_pkt_dump) {
|
|
| 2624 |
+ av_pkt_dump_log2(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump, |
|
| 2625 |
+ is->streams[pkt.stream_index]); |
|
| 2626 |
+ } |
|
| 2627 |
+ /* the following test is needed in case new streams appear |
|
| 2628 |
+ dynamically in stream : we ignore them */ |
|
| 2629 |
+ if (pkt.stream_index >= input_files[file_index].ctx->nb_streams) |
|
| 2630 |
+ goto discard_packet; |
|
| 2631 |
+ ist_index = input_files[file_index].ist_index + pkt.stream_index; |
|
| 2632 |
+ ist = &input_streams[ist_index]; |
|
| 2633 |
+ if (ist->discard) |
|
| 2634 |
+ goto discard_packet; |
|
| 2635 |
+ |
|
| 2636 |
+ if (pkt.dts != AV_NOPTS_VALUE) |
|
| 2637 |
+ pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); |
|
| 2638 |
+ if (pkt.pts != AV_NOPTS_VALUE) |
|
| 2639 |
+ pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); |
|
| 2640 |
+ |
|
| 2641 |
+ if (ist->ts_scale) {
|
|
| 2642 |
+ if(pkt.pts != AV_NOPTS_VALUE) |
|
| 2643 |
+ pkt.pts *= ist->ts_scale; |
|
| 2644 |
+ if(pkt.dts != AV_NOPTS_VALUE) |
|
| 2645 |
+ pkt.dts *= ist->ts_scale; |
|
| 2646 |
+ } |
|
| 2647 |
+ |
|
| 2648 |
+// fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files[ist->file_index].ts_offset, ist->st->codec->codec_type); |
|
| 2649 |
+ if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE |
|
| 2650 |
+ && (is->iformat->flags & AVFMT_TS_DISCONT)) {
|
|
| 2651 |
+ int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); |
|
| 2652 |
+ int64_t delta= pkt_dts - ist->next_pts; |
|
| 2653 |
+ if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){
|
|
| 2654 |
+ input_files[ist->file_index].ts_offset -= delta; |
|
| 2655 |
+ if (verbose > 2) |
|
| 2656 |
+ fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", |
|
| 2657 |
+ delta, input_files[ist->file_index].ts_offset); |
|
| 2658 |
+ pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); |
|
| 2659 |
+ if(pkt.pts != AV_NOPTS_VALUE) |
|
| 2660 |
+ pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); |
|
| 2661 |
+ } |
|
| 2662 |
+ } |
|
| 2663 |
+ |
|
| 2664 |
+ /* finish if recording time exhausted */ |
|
| 2665 |
+ if (recording_time != INT64_MAX && |
|
| 2666 |
+ av_compare_ts(pkt.pts, ist->st->time_base, recording_time + start_time, (AVRational){1, 1000000}) >= 0) {
|
|
| 2667 |
+ ist->is_past_recording_time = 1; |
|
| 2668 |
+ goto discard_packet; |
|
| 2669 |
+ } |
|
| 2670 |
+ |
|
| 2671 |
+ //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size); |
|
| 2672 |
+ if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
|
|
| 2673 |
+ |
|
| 2674 |
+ if (verbose >= 0) |
|
| 2675 |
+ fprintf(stderr, "Error while decoding stream #%d.%d\n", |
|
| 2676 |
+ ist->file_index, ist->st->index); |
|
| 2677 |
+ if (exit_on_error) |
|
| 2678 |
+ exit_program(1); |
|
| 2679 |
+ av_free_packet(&pkt); |
|
| 2680 |
+ goto redo; |
|
| 2681 |
+ } |
|
| 2682 |
+ |
|
| 2683 |
+ discard_packet: |
|
| 2684 |
+ av_free_packet(&pkt); |
|
| 2685 |
+ |
|
| 2686 |
+ /* dump report by using the output first video and audio streams */ |
|
| 2687 |
+ print_report(output_files, ost_table, nb_ostreams, 0); |
|
| 2688 |
+ } |
|
| 2689 |
+ |
|
| 2690 |
+ /* at the end of stream, we must flush the decoder buffers */ |
|
| 2691 |
+ for (i = 0; i < nb_input_streams; i++) {
|
|
| 2692 |
+ ist = &input_streams[i]; |
|
| 2693 |
+ if (ist->decoding_needed) {
|
|
| 2694 |
+ output_packet(ist, i, ost_table, nb_ostreams, NULL); |
|
| 2695 |
+ } |
|
| 2696 |
+ } |
|
| 2697 |
+ |
|
| 2698 |
+ term_exit(); |
|
| 2699 |
+ |
|
| 2700 |
+ /* write the trailer if needed and close file */ |
|
| 2701 |
+ for(i=0;i<nb_output_files;i++) {
|
|
| 2702 |
+ os = output_files[i]; |
|
| 2703 |
+ av_write_trailer(os); |
|
| 2704 |
+ } |
|
| 2705 |
+ |
|
| 2706 |
+ /* dump report by using the first video and audio streams */ |
|
| 2707 |
+ print_report(output_files, ost_table, nb_ostreams, 1); |
|
| 2708 |
+ |
|
| 2709 |
+ /* close each encoder */ |
|
| 2710 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 2711 |
+ ost = ost_table[i]; |
|
| 2712 |
+ if (ost->encoding_needed) {
|
|
| 2713 |
+ av_freep(&ost->st->codec->stats_in); |
|
| 2714 |
+ avcodec_close(ost->st->codec); |
|
| 2715 |
+ } |
|
| 2716 |
+#if CONFIG_AVFILTER |
|
| 2717 |
+ avfilter_graph_free(&ost->graph); |
|
| 2718 |
+#endif |
|
| 2719 |
+ } |
|
| 2720 |
+ |
|
| 2721 |
+ /* close each decoder */ |
|
| 2722 |
+ for (i = 0; i < nb_input_streams; i++) {
|
|
| 2723 |
+ ist = &input_streams[i]; |
|
| 2724 |
+ if (ist->decoding_needed) {
|
|
| 2725 |
+ avcodec_close(ist->st->codec); |
|
| 2726 |
+ } |
|
| 2727 |
+ } |
|
| 2728 |
+ |
|
| 2729 |
+ /* finished ! */ |
|
| 2730 |
+ ret = 0; |
|
| 2731 |
+ |
|
| 2732 |
+ fail: |
|
| 2733 |
+ av_freep(&bit_buffer); |
|
| 2734 |
+ |
|
| 2735 |
+ if (ost_table) {
|
|
| 2736 |
+ for(i=0;i<nb_ostreams;i++) {
|
|
| 2737 |
+ ost = ost_table[i]; |
|
| 2738 |
+ if (ost) {
|
|
| 2739 |
+ if (ost->st->stream_copy) |
|
| 2740 |
+ av_freep(&ost->st->codec->extradata); |
|
| 2741 |
+ if (ost->logfile) {
|
|
| 2742 |
+ fclose(ost->logfile); |
|
| 2743 |
+ ost->logfile = NULL; |
|
| 2744 |
+ } |
|
| 2745 |
+ av_fifo_free(ost->fifo); /* works even if fifo is not |
|
| 2746 |
+ initialized but set to zero */ |
|
| 2747 |
+ av_freep(&ost->st->codec->subtitle_header); |
|
| 2748 |
+ av_free(ost->pict_tmp.data[0]); |
|
| 2749 |
+ av_free(ost->forced_kf_pts); |
|
| 2750 |
+ if (ost->video_resample) |
|
| 2751 |
+ sws_freeContext(ost->img_resample_ctx); |
|
| 2752 |
+ if (ost->resample) |
|
| 2753 |
+ audio_resample_close(ost->resample); |
|
| 2754 |
+ if (ost->reformat_ctx) |
|
| 2755 |
+ av_audio_convert_free(ost->reformat_ctx); |
|
| 2756 |
+ av_dict_free(&ost->opts); |
|
| 2757 |
+ av_free(ost); |
|
| 2758 |
+ } |
|
| 2759 |
+ } |
|
| 2760 |
+ av_free(ost_table); |
|
| 2761 |
+ } |
|
| 2762 |
+ return ret; |
|
| 2763 |
+} |
|
| 2764 |
+ |
|
| 2765 |
+static int opt_format(const char *opt, const char *arg) |
|
| 2766 |
+{
|
|
| 2767 |
+ last_asked_format = arg; |
|
| 2768 |
+ return 0; |
|
| 2769 |
+} |
|
| 2770 |
+ |
|
| 2771 |
+static int opt_video_rc_override_string(const char *opt, const char *arg) |
|
| 2772 |
+{
|
|
| 2773 |
+ video_rc_override_string = arg; |
|
| 2774 |
+ return 0; |
|
| 2775 |
+} |
|
| 2776 |
+ |
|
| 2777 |
+static int opt_me_threshold(const char *opt, const char *arg) |
|
| 2778 |
+{
|
|
| 2779 |
+ me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); |
|
| 2780 |
+ return 0; |
|
| 2781 |
+} |
|
| 2782 |
+ |
|
| 2783 |
+static int opt_verbose(const char *opt, const char *arg) |
|
| 2784 |
+{
|
|
| 2785 |
+ verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10); |
|
| 2786 |
+ return 0; |
|
| 2787 |
+} |
|
| 2788 |
+ |
|
| 2789 |
+static int opt_frame_rate(const char *opt, const char *arg) |
|
| 2790 |
+{
|
|
| 2791 |
+ if (av_parse_video_rate(&frame_rate, arg) < 0) {
|
|
| 2792 |
+ fprintf(stderr, "Incorrect value for %s: %s\n", opt, arg); |
|
| 2793 |
+ exit_program(1); |
|
| 2794 |
+ } |
|
| 2795 |
+ return 0; |
|
| 2796 |
+} |
|
| 2797 |
+ |
|
| 2798 |
+static int opt_frame_crop(const char *opt, const char *arg) |
|
| 2799 |
+{
|
|
| 2800 |
+ fprintf(stderr, "Option '%s' has been removed, use the crop filter instead\n", opt); |
|
| 2801 |
+ return AVERROR(EINVAL); |
|
| 2802 |
+} |
|
| 2803 |
+ |
|
| 2804 |
+static int opt_frame_size(const char *opt, const char *arg) |
|
| 2805 |
+{
|
|
| 2806 |
+ if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) {
|
|
| 2807 |
+ fprintf(stderr, "Incorrect frame size\n"); |
|
| 2808 |
+ return AVERROR(EINVAL); |
|
| 2809 |
+ } |
|
| 2810 |
+ return 0; |
|
| 2811 |
+} |
|
| 2812 |
+ |
|
| 2813 |
+static int opt_pad(const char *opt, const char *arg) {
|
|
| 2814 |
+ fprintf(stderr, "Option '%s' has been removed, use the pad filter instead\n", opt); |
|
| 2815 |
+ return -1; |
|
| 2816 |
+} |
|
| 2817 |
+ |
|
| 2818 |
+static int opt_frame_pix_fmt(const char *opt, const char *arg) |
|
| 2819 |
+{
|
|
| 2820 |
+ if (strcmp(arg, "list")) {
|
|
| 2821 |
+ frame_pix_fmt = av_get_pix_fmt(arg); |
|
| 2822 |
+ if (frame_pix_fmt == PIX_FMT_NONE) {
|
|
| 2823 |
+ fprintf(stderr, "Unknown pixel format requested: %s\n", arg); |
|
| 2824 |
+ return AVERROR(EINVAL); |
|
| 2825 |
+ } |
|
| 2826 |
+ } else {
|
|
| 2827 |
+ show_pix_fmts(); |
|
| 2828 |
+ exit_program(0); |
|
| 2829 |
+ } |
|
| 2830 |
+ return 0; |
|
| 2831 |
+} |
|
| 2832 |
+ |
|
| 2833 |
+static int opt_frame_aspect_ratio(const char *opt, const char *arg) |
|
| 2834 |
+{
|
|
| 2835 |
+ int x = 0, y = 0; |
|
| 2836 |
+ double ar = 0; |
|
| 2837 |
+ const char *p; |
|
| 2838 |
+ char *end; |
|
| 2839 |
+ |
|
| 2840 |
+ p = strchr(arg, ':'); |
|
| 2841 |
+ if (p) {
|
|
| 2842 |
+ x = strtol(arg, &end, 10); |
|
| 2843 |
+ if (end == p) |
|
| 2844 |
+ y = strtol(end+1, &end, 10); |
|
| 2845 |
+ if (x > 0 && y > 0) |
|
| 2846 |
+ ar = (double)x / (double)y; |
|
| 2847 |
+ } else |
|
| 2848 |
+ ar = strtod(arg, NULL); |
|
| 2849 |
+ |
|
| 2850 |
+ if (!ar) {
|
|
| 2851 |
+ fprintf(stderr, "Incorrect aspect ratio specification.\n"); |
|
| 2852 |
+ return AVERROR(EINVAL); |
|
| 2853 |
+ } |
|
| 2854 |
+ frame_aspect_ratio = ar; |
|
| 2855 |
+ return 0; |
|
| 2856 |
+} |
|
| 2857 |
+ |
|
| 2858 |
+static int opt_metadata(const char *opt, const char *arg) |
|
| 2859 |
+{
|
|
| 2860 |
+ char *mid= strchr(arg, '='); |
|
| 2861 |
+ |
|
| 2862 |
+ if(!mid){
|
|
| 2863 |
+ fprintf(stderr, "Missing =\n"); |
|
| 2864 |
+ exit_program(1); |
|
| 2865 |
+ } |
|
| 2866 |
+ *mid++= 0; |
|
| 2867 |
+ |
|
| 2868 |
+ av_dict_set(&metadata, arg, mid, 0); |
|
| 2869 |
+ |
|
| 2870 |
+ return 0; |
|
| 2871 |
+} |
|
| 2872 |
+ |
|
| 2873 |
+static int opt_qscale(const char *opt, const char *arg) |
|
| 2874 |
+{
|
|
| 2875 |
+ video_qscale = parse_number_or_die(opt, arg, OPT_FLOAT, 0, 255); |
|
| 2876 |
+ if (video_qscale == 0) {
|
|
| 2877 |
+ fprintf(stderr, "qscale must be > 0.0 and <= 255\n"); |
|
| 2878 |
+ return AVERROR(EINVAL); |
|
| 2879 |
+ } |
|
| 2880 |
+ return 0; |
|
| 2881 |
+} |
|
| 2882 |
+ |
|
| 2883 |
+static int opt_top_field_first(const char *opt, const char *arg) |
|
| 2884 |
+{
|
|
| 2885 |
+ top_field_first = parse_number_or_die(opt, arg, OPT_INT, 0, 1); |
|
| 2886 |
+ return 0; |
|
| 2887 |
+} |
|
| 2888 |
+ |
|
| 2889 |
+static int opt_thread_count(const char *opt, const char *arg) |
|
| 2890 |
+{
|
|
| 2891 |
+ thread_count= parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); |
|
| 2892 |
+#if !HAVE_THREADS |
|
| 2893 |
+ if (verbose >= 0) |
|
| 2894 |
+ fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n"); |
|
| 2895 |
+#endif |
|
| 2896 |
+ return 0; |
|
| 2897 |
+} |
|
| 2898 |
+ |
|
| 2899 |
+static int opt_audio_sample_fmt(const char *opt, const char *arg) |
|
| 2900 |
+{
|
|
| 2901 |
+ if (strcmp(arg, "list")) {
|
|
| 2902 |
+ audio_sample_fmt = av_get_sample_fmt(arg); |
|
| 2903 |
+ if (audio_sample_fmt == AV_SAMPLE_FMT_NONE) {
|
|
| 2904 |
+ av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg); |
|
| 2905 |
+ return AVERROR(EINVAL); |
|
| 2906 |
+ } |
|
| 2907 |
+ } else {
|
|
| 2908 |
+ int i; |
|
| 2909 |
+ char fmt_str[128]; |
|
| 2910 |
+ for (i = -1; i < AV_SAMPLE_FMT_NB; i++) |
|
| 2911 |
+ printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
|
|
| 2912 |
+ exit_program(0); |
|
| 2913 |
+ } |
|
| 2914 |
+ return 0; |
|
| 2915 |
+} |
|
| 2916 |
+ |
|
| 2917 |
+static int opt_audio_rate(const char *opt, const char *arg) |
|
| 2918 |
+{
|
|
| 2919 |
+ audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); |
|
| 2920 |
+ return 0; |
|
| 2921 |
+} |
|
| 2922 |
+ |
|
| 2923 |
+static int opt_audio_channels(const char *opt, const char *arg) |
|
| 2924 |
+{
|
|
| 2925 |
+ audio_channels = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); |
|
| 2926 |
+ return 0; |
|
| 2927 |
+} |
|
| 2928 |
+ |
|
| 2929 |
+static int opt_video_channel(const char *opt, const char *arg) |
|
| 2930 |
+{
|
|
| 2931 |
+ av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n"); |
|
| 2932 |
+ opt_default("channel", arg);
|
|
| 2933 |
+ return 0; |
|
| 2934 |
+} |
|
| 2935 |
+ |
|
| 2936 |
+static int opt_video_standard(const char *opt, const char *arg) |
|
| 2937 |
+{
|
|
| 2938 |
+ av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n"); |
|
| 2939 |
+ opt_default("standard", arg);
|
|
| 2940 |
+ return 0; |
|
| 2941 |
+} |
|
| 2942 |
+ |
|
| 2943 |
+static int opt_codec(int *pstream_copy, char **pcodec_name, |
|
| 2944 |
+ int codec_type, const char *arg) |
|
| 2945 |
+{
|
|
| 2946 |
+ av_freep(pcodec_name); |
|
| 2947 |
+ if (!strcmp(arg, "copy")) {
|
|
| 2948 |
+ *pstream_copy = 1; |
|
| 2949 |
+ } else {
|
|
| 2950 |
+ *pcodec_name = av_strdup(arg); |
|
| 2951 |
+ } |
|
| 2952 |
+ return 0; |
|
| 2953 |
+} |
|
| 2954 |
+ |
|
| 2955 |
+static int opt_audio_codec(const char *opt, const char *arg) |
|
| 2956 |
+{
|
|
| 2957 |
+ return opt_codec(&audio_stream_copy, &audio_codec_name, AVMEDIA_TYPE_AUDIO, arg); |
|
| 2958 |
+} |
|
| 2959 |
+ |
|
| 2960 |
+static int opt_video_codec(const char *opt, const char *arg) |
|
| 2961 |
+{
|
|
| 2962 |
+ return opt_codec(&video_stream_copy, &video_codec_name, AVMEDIA_TYPE_VIDEO, arg); |
|
| 2963 |
+} |
|
| 2964 |
+ |
|
| 2965 |
+static int opt_subtitle_codec(const char *opt, const char *arg) |
|
| 2966 |
+{
|
|
| 2967 |
+ return opt_codec(&subtitle_stream_copy, &subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, arg); |
|
| 2968 |
+} |
|
| 2969 |
+ |
|
| 2970 |
+static int opt_data_codec(const char *opt, const char *arg) |
|
| 2971 |
+{
|
|
| 2972 |
+ return opt_codec(&data_stream_copy, &data_codec_name, AVMEDIA_TYPE_DATA, arg); |
|
| 2973 |
+} |
|
| 2974 |
+ |
|
| 2975 |
+static int opt_codec_tag(const char *opt, const char *arg) |
|
| 2976 |
+{
|
|
| 2977 |
+ char *tail; |
|
| 2978 |
+ uint32_t *codec_tag; |
|
| 2979 |
+ |
|
| 2980 |
+ codec_tag = !strcmp(opt, "atag") ? &audio_codec_tag : |
|
| 2981 |
+ !strcmp(opt, "vtag") ? &video_codec_tag : |
|
| 2982 |
+ !strcmp(opt, "stag") ? &subtitle_codec_tag : NULL; |
|
| 2983 |
+ if (!codec_tag) |
|
| 2984 |
+ return -1; |
|
| 2985 |
+ |
|
| 2986 |
+ *codec_tag = strtol(arg, &tail, 0); |
|
| 2987 |
+ if (!tail || *tail) |
|
| 2988 |
+ *codec_tag = AV_RL32(arg); |
|
| 2989 |
+ |
|
| 2990 |
+ return 0; |
|
| 2991 |
+} |
|
| 2992 |
+ |
|
| 2993 |
+static int opt_map(const char *opt, const char *arg) |
|
| 2994 |
+{
|
|
| 2995 |
+ StreamMap *m; |
|
| 2996 |
+ char *p; |
|
| 2997 |
+ |
|
| 2998 |
+ stream_maps = grow_array(stream_maps, sizeof(*stream_maps), &nb_stream_maps, nb_stream_maps + 1); |
|
| 2999 |
+ m = &stream_maps[nb_stream_maps-1]; |
|
| 3000 |
+ |
|
| 3001 |
+ m->file_index = strtol(arg, &p, 0); |
|
| 3002 |
+ if (*p) |
|
| 3003 |
+ p++; |
|
| 3004 |
+ |
|
| 3005 |
+ m->stream_index = strtol(p, &p, 0); |
|
| 3006 |
+ if (*p) {
|
|
| 3007 |
+ p++; |
|
| 3008 |
+ m->sync_file_index = strtol(p, &p, 0); |
|
| 3009 |
+ if (*p) |
|
| 3010 |
+ p++; |
|
| 3011 |
+ m->sync_stream_index = strtol(p, &p, 0); |
|
| 3012 |
+ } else {
|
|
| 3013 |
+ m->sync_file_index = m->file_index; |
|
| 3014 |
+ m->sync_stream_index = m->stream_index; |
|
| 3015 |
+ } |
|
| 3016 |
+ return 0; |
|
| 3017 |
+} |
|
| 3018 |
+ |
|
| 3019 |
+static void parse_meta_type(char *arg, char *type, int *index, char **endptr) |
|
| 3020 |
+{
|
|
| 3021 |
+ *endptr = arg; |
|
| 3022 |
+ if (*arg == ',') {
|
|
| 3023 |
+ *type = *(++arg); |
|
| 3024 |
+ switch (*arg) {
|
|
| 3025 |
+ case 'g': |
|
| 3026 |
+ break; |
|
| 3027 |
+ case 's': |
|
| 3028 |
+ case 'c': |
|
| 3029 |
+ case 'p': |
|
| 3030 |
+ *index = strtol(++arg, endptr, 0); |
|
| 3031 |
+ break; |
|
| 3032 |
+ default: |
|
| 3033 |
+ fprintf(stderr, "Invalid metadata type %c.\n", *arg); |
|
| 3034 |
+ exit_program(1); |
|
| 3035 |
+ } |
|
| 3036 |
+ } else |
|
| 3037 |
+ *type = 'g'; |
|
| 3038 |
+} |
|
| 3039 |
+ |
|
| 3040 |
+static int opt_map_metadata(const char *opt, const char *arg) |
|
| 3041 |
+{
|
|
| 3042 |
+ MetadataMap *m, *m1; |
|
| 3043 |
+ char *p; |
|
| 3044 |
+ |
|
| 3045 |
+ meta_data_maps = grow_array(meta_data_maps, sizeof(*meta_data_maps), |
|
| 3046 |
+ &nb_meta_data_maps, nb_meta_data_maps + 1); |
|
| 3047 |
+ |
|
| 3048 |
+ m = &meta_data_maps[nb_meta_data_maps - 1][0]; |
|
| 3049 |
+ m->file = strtol(arg, &p, 0); |
|
| 3050 |
+ parse_meta_type(p, &m->type, &m->index, &p); |
|
| 3051 |
+ if (*p) |
|
| 3052 |
+ p++; |
|
| 3053 |
+ |
|
| 3054 |
+ m1 = &meta_data_maps[nb_meta_data_maps - 1][1]; |
|
| 3055 |
+ m1->file = strtol(p, &p, 0); |
|
| 3056 |
+ parse_meta_type(p, &m1->type, &m1->index, &p); |
|
| 3057 |
+ |
|
| 3058 |
+ if (m->type == 'g' || m1->type == 'g') |
|
| 3059 |
+ metadata_global_autocopy = 0; |
|
| 3060 |
+ if (m->type == 's' || m1->type == 's') |
|
| 3061 |
+ metadata_streams_autocopy = 0; |
|
| 3062 |
+ if (m->type == 'c' || m1->type == 'c') |
|
| 3063 |
+ metadata_chapters_autocopy = 0; |
|
| 3064 |
+ |
|
| 3065 |
+ return 0; |
|
| 3066 |
+} |
|
| 3067 |
+ |
|
| 3068 |
+static int opt_map_meta_data(const char *opt, const char *arg) |
|
| 3069 |
+{
|
|
| 3070 |
+ fprintf(stderr, "-map_meta_data is deprecated and will be removed soon. " |
|
| 3071 |
+ "Use -map_metadata instead.\n"); |
|
| 3072 |
+ return opt_map_metadata(opt, arg); |
|
| 3073 |
+} |
|
| 3074 |
+ |
|
| 3075 |
+static int opt_map_chapters(const char *opt, const char *arg) |
|
| 3076 |
+{
|
|
| 3077 |
+ ChapterMap *c; |
|
| 3078 |
+ char *p; |
|
| 3079 |
+ |
|
| 3080 |
+ chapter_maps = grow_array(chapter_maps, sizeof(*chapter_maps), &nb_chapter_maps, |
|
| 3081 |
+ nb_chapter_maps + 1); |
|
| 3082 |
+ c = &chapter_maps[nb_chapter_maps - 1]; |
|
| 3083 |
+ c->out_file = strtol(arg, &p, 0); |
|
| 3084 |
+ if (*p) |
|
| 3085 |
+ p++; |
|
| 3086 |
+ |
|
| 3087 |
+ c->in_file = strtol(p, &p, 0); |
|
| 3088 |
+ return 0; |
|
| 3089 |
+} |
|
| 3090 |
+ |
|
| 3091 |
+static int opt_input_ts_scale(const char *opt, const char *arg) |
|
| 3092 |
+{
|
|
| 3093 |
+ unsigned int stream; |
|
| 3094 |
+ double scale; |
|
| 3095 |
+ char *p; |
|
| 3096 |
+ |
|
| 3097 |
+ stream = strtol(arg, &p, 0); |
|
| 3098 |
+ if (*p) |
|
| 3099 |
+ p++; |
|
| 3100 |
+ scale= strtod(p, &p); |
|
| 3101 |
+ |
|
| 3102 |
+ ts_scale = grow_array(ts_scale, sizeof(*ts_scale), &nb_ts_scale, stream + 1); |
|
| 3103 |
+ ts_scale[stream] = scale; |
|
| 3104 |
+ return 0; |
|
| 3105 |
+} |
|
| 3106 |
+ |
|
| 3107 |
+static int opt_recording_time(const char *opt, const char *arg) |
|
| 3108 |
+{
|
|
| 3109 |
+ recording_time = parse_time_or_die(opt, arg, 1); |
|
| 3110 |
+ return 0; |
|
| 3111 |
+} |
|
| 3112 |
+ |
|
| 3113 |
+static int opt_start_time(const char *opt, const char *arg) |
|
| 3114 |
+{
|
|
| 3115 |
+ start_time = parse_time_or_die(opt, arg, 1); |
|
| 3116 |
+ return 0; |
|
| 3117 |
+} |
|
| 3118 |
+ |
|
| 3119 |
+static int opt_recording_timestamp(const char *opt, const char *arg) |
|
| 3120 |
+{
|
|
| 3121 |
+ char buf[128]; |
|
| 3122 |
+ int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6; |
|
| 3123 |
+ struct tm time = *gmtime((time_t*)&recording_timestamp); |
|
| 3124 |
+ strftime(buf, sizeof(buf), "creation_time=%FT%T%z", &time); |
|
| 3125 |
+ opt_metadata("metadata", buf);
|
|
| 3126 |
+ |
|
| 3127 |
+ av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata " |
|
| 3128 |
+ "tag instead.\n", opt); |
|
| 3129 |
+ return 0; |
|
| 3130 |
+} |
|
| 3131 |
+ |
|
| 3132 |
+static int opt_input_ts_offset(const char *opt, const char *arg) |
|
| 3133 |
+{
|
|
| 3134 |
+ input_ts_offset = parse_time_or_die(opt, arg, 1); |
|
| 3135 |
+ return 0; |
|
| 3136 |
+} |
|
| 3137 |
+ |
|
| 3138 |
+static enum CodecID find_codec_or_die(const char *name, int type, int encoder) |
|
| 3139 |
+{
|
|
| 3140 |
+ const char *codec_string = encoder ? "encoder" : "decoder"; |
|
| 3141 |
+ AVCodec *codec; |
|
| 3142 |
+ |
|
| 3143 |
+ if(!name) |
|
| 3144 |
+ return CODEC_ID_NONE; |
|
| 3145 |
+ codec = encoder ? |
|
| 3146 |
+ avcodec_find_encoder_by_name(name) : |
|
| 3147 |
+ avcodec_find_decoder_by_name(name); |
|
| 3148 |
+ if(!codec) {
|
|
| 3149 |
+ fprintf(stderr, "Unknown %s '%s'\n", codec_string, name); |
|
| 3150 |
+ exit_program(1); |
|
| 3151 |
+ } |
|
| 3152 |
+ if(codec->type != type) {
|
|
| 3153 |
+ fprintf(stderr, "Invalid %s type '%s'\n", codec_string, name); |
|
| 3154 |
+ exit_program(1); |
|
| 3155 |
+ } |
|
| 3156 |
+ return codec->id; |
|
| 3157 |
+} |
|
| 3158 |
+ |
|
| 3159 |
+static int opt_input_file(const char *opt, const char *filename) |
|
| 3160 |
+{
|
|
| 3161 |
+ AVFormatContext *ic; |
|
| 3162 |
+ AVInputFormat *file_iformat = NULL; |
|
| 3163 |
+ int err, i, ret, rfps, rfps_base; |
|
| 3164 |
+ int64_t timestamp; |
|
| 3165 |
+ uint8_t buf[128]; |
|
| 3166 |
+ AVDictionary **opts; |
|
| 3167 |
+ int orig_nb_streams; // number of streams before avformat_find_stream_info |
|
| 3168 |
+ |
|
| 3169 |
+ if (last_asked_format) {
|
|
| 3170 |
+ if (!(file_iformat = av_find_input_format(last_asked_format))) {
|
|
| 3171 |
+ fprintf(stderr, "Unknown input format: '%s'\n", last_asked_format); |
|
| 3172 |
+ exit_program(1); |
|
| 3173 |
+ } |
|
| 3174 |
+ last_asked_format = NULL; |
|
| 3175 |
+ } |
|
| 3176 |
+ |
|
| 3177 |
+ if (!strcmp(filename, "-")) |
|
| 3178 |
+ filename = "pipe:"; |
|
| 3179 |
+ |
|
| 3180 |
+ using_stdin |= !strncmp(filename, "pipe:", 5) || |
|
| 3181 |
+ !strcmp(filename, "/dev/stdin"); |
|
| 3182 |
+ |
|
| 3183 |
+ /* get default parameters from command line */ |
|
| 3184 |
+ ic = avformat_alloc_context(); |
|
| 3185 |
+ if (!ic) {
|
|
| 3186 |
+ print_error(filename, AVERROR(ENOMEM)); |
|
| 3187 |
+ exit_program(1); |
|
| 3188 |
+ } |
|
| 3189 |
+ if (audio_sample_rate) {
|
|
| 3190 |
+ snprintf(buf, sizeof(buf), "%d", audio_sample_rate); |
|
| 3191 |
+ av_dict_set(&format_opts, "sample_rate", buf, 0); |
|
| 3192 |
+ } |
|
| 3193 |
+ if (audio_channels) {
|
|
| 3194 |
+ snprintf(buf, sizeof(buf), "%d", audio_channels); |
|
| 3195 |
+ av_dict_set(&format_opts, "channels", buf, 0); |
|
| 3196 |
+ } |
|
| 3197 |
+ if (frame_rate.num) {
|
|
| 3198 |
+ snprintf(buf, sizeof(buf), "%d/%d", frame_rate.num, frame_rate.den); |
|
| 3199 |
+ av_dict_set(&format_opts, "framerate", buf, 0); |
|
| 3200 |
+ } |
|
| 3201 |
+ if (frame_width && frame_height) {
|
|
| 3202 |
+ snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height); |
|
| 3203 |
+ av_dict_set(&format_opts, "video_size", buf, 0); |
|
| 3204 |
+ } |
|
| 3205 |
+ if (frame_pix_fmt != PIX_FMT_NONE) |
|
| 3206 |
+ av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0); |
|
| 3207 |
+ |
|
| 3208 |
+ ic->video_codec_id = |
|
| 3209 |
+ find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0); |
|
| 3210 |
+ ic->audio_codec_id = |
|
| 3211 |
+ find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0); |
|
| 3212 |
+ ic->subtitle_codec_id= |
|
| 3213 |
+ find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0); |
|
| 3214 |
+ ic->flags |= AVFMT_FLAG_NONBLOCK; |
|
| 3215 |
+ |
|
| 3216 |
+ /* open the input file with generic libav function */ |
|
| 3217 |
+ err = avformat_open_input(&ic, filename, file_iformat, &format_opts); |
|
| 3218 |
+ if (err < 0) {
|
|
| 3219 |
+ print_error(filename, err); |
|
| 3220 |
+ exit_program(1); |
|
| 3221 |
+ } |
|
| 3222 |
+ assert_avoptions(format_opts); |
|
| 3223 |
+ |
|
| 3224 |
+ if(opt_programid) {
|
|
| 3225 |
+ int i, j; |
|
| 3226 |
+ int found=0; |
|
| 3227 |
+ for(i=0; i<ic->nb_streams; i++){
|
|
| 3228 |
+ ic->streams[i]->discard= AVDISCARD_ALL; |
|
| 3229 |
+ } |
|
| 3230 |
+ for(i=0; i<ic->nb_programs; i++){
|
|
| 3231 |
+ AVProgram *p= ic->programs[i]; |
|
| 3232 |
+ if(p->id != opt_programid){
|
|
| 3233 |
+ p->discard = AVDISCARD_ALL; |
|
| 3234 |
+ }else{
|
|
| 3235 |
+ found=1; |
|
| 3236 |
+ for(j=0; j<p->nb_stream_indexes; j++){
|
|
| 3237 |
+ ic->streams[p->stream_index[j]]->discard= AVDISCARD_DEFAULT; |
|
| 3238 |
+ } |
|
| 3239 |
+ } |
|
| 3240 |
+ } |
|
| 3241 |
+ if(!found){
|
|
| 3242 |
+ fprintf(stderr, "Specified program id not found\n"); |
|
| 3243 |
+ exit_program(1); |
|
| 3244 |
+ } |
|
| 3245 |
+ opt_programid=0; |
|
| 3246 |
+ } |
|
| 3247 |
+ |
|
| 3248 |
+ if (loop_input) {
|
|
| 3249 |
+ av_log(NULL, AV_LOG_WARNING, "-loop_input is deprecated, use -loop 1\n"); |
|
| 3250 |
+ ic->loop_input = loop_input; |
|
| 3251 |
+ } |
|
| 3252 |
+ |
|
| 3253 |
+ /* Set AVCodecContext options for avformat_find_stream_info */ |
|
| 3254 |
+ opts = setup_find_stream_info_opts(ic, codec_opts); |
|
| 3255 |
+ orig_nb_streams = ic->nb_streams; |
|
| 3256 |
+ |
|
| 3257 |
+ /* If not enough info to get the stream parameters, we decode the |
|
| 3258 |
+ first frames to get it. (used in mpeg case for example) */ |
|
| 3259 |
+ ret = avformat_find_stream_info(ic, opts); |
|
| 3260 |
+ if (ret < 0 && verbose >= 0) {
|
|
| 3261 |
+ fprintf(stderr, "%s: could not find codec parameters\n", filename); |
|
| 3262 |
+ av_close_input_file(ic); |
|
| 3263 |
+ exit_program(1); |
|
| 3264 |
+ } |
|
| 3265 |
+ |
|
| 3266 |
+ timestamp = start_time; |
|
| 3267 |
+ /* add the stream start time */ |
|
| 3268 |
+ if (ic->start_time != AV_NOPTS_VALUE) |
|
| 3269 |
+ timestamp += ic->start_time; |
|
| 3270 |
+ |
|
| 3271 |
+ /* if seeking requested, we execute it */ |
|
| 3272 |
+ if (start_time != 0) {
|
|
| 3273 |
+ ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD); |
|
| 3274 |
+ if (ret < 0) {
|
|
| 3275 |
+ fprintf(stderr, "%s: could not seek to position %0.3f\n", |
|
| 3276 |
+ filename, (double)timestamp / AV_TIME_BASE); |
|
| 3277 |
+ } |
|
| 3278 |
+ /* reset seek info */ |
|
| 3279 |
+ start_time = 0; |
|
| 3280 |
+ } |
|
| 3281 |
+ |
|
| 3282 |
+ /* update the current parameters so that they match the one of the input stream */ |
|
| 3283 |
+ for(i=0;i<ic->nb_streams;i++) {
|
|
| 3284 |
+ AVStream *st = ic->streams[i]; |
|
| 3285 |
+ AVCodecContext *dec = st->codec; |
|
| 3286 |
+ InputStream *ist; |
|
| 3287 |
+ |
|
| 3288 |
+ dec->thread_count = thread_count; |
|
| 3289 |
+ |
|
| 3290 |
+ input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1); |
|
| 3291 |
+ ist = &input_streams[nb_input_streams - 1]; |
|
| 3292 |
+ ist->st = st; |
|
| 3293 |
+ ist->file_index = nb_input_files; |
|
| 3294 |
+ ist->discard = 1; |
|
| 3295 |
+ ist->opts = filter_codec_opts(codec_opts, ist->st->codec->codec_id, 0); |
|
| 3296 |
+ |
|
| 3297 |
+ if (i < nb_ts_scale) |
|
| 3298 |
+ ist->ts_scale = ts_scale[i]; |
|
| 3299 |
+ |
|
| 3300 |
+ switch (dec->codec_type) {
|
|
| 3301 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 3302 |
+ ist->dec = avcodec_find_decoder_by_name(audio_codec_name); |
|
| 3303 |
+ if(audio_disable) |
|
| 3304 |
+ st->discard= AVDISCARD_ALL; |
|
| 3305 |
+ break; |
|
| 3306 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 3307 |
+ ist->dec = avcodec_find_decoder_by_name(video_codec_name); |
|
| 3308 |
+ rfps = ic->streams[i]->r_frame_rate.num; |
|
| 3309 |
+ rfps_base = ic->streams[i]->r_frame_rate.den; |
|
| 3310 |
+ if (dec->lowres) {
|
|
| 3311 |
+ dec->flags |= CODEC_FLAG_EMU_EDGE; |
|
| 3312 |
+ dec->height >>= dec->lowres; |
|
| 3313 |
+ dec->width >>= dec->lowres; |
|
| 3314 |
+ } |
|
| 3315 |
+ if(me_threshold) |
|
| 3316 |
+ dec->debug |= FF_DEBUG_MV; |
|
| 3317 |
+ |
|
| 3318 |
+ if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {
|
|
| 3319 |
+ |
|
| 3320 |
+ if (verbose >= 0) |
|
| 3321 |
+ fprintf(stderr,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n", |
|
| 3322 |
+ i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num, |
|
| 3323 |
+ |
|
| 3324 |
+ (float)rfps / rfps_base, rfps, rfps_base); |
|
| 3325 |
+ } |
|
| 3326 |
+ |
|
| 3327 |
+ if(video_disable) |
|
| 3328 |
+ st->discard= AVDISCARD_ALL; |
|
| 3329 |
+ else if(video_discard) |
|
| 3330 |
+ st->discard= video_discard; |
|
| 3331 |
+ break; |
|
| 3332 |
+ case AVMEDIA_TYPE_DATA: |
|
| 3333 |
+ break; |
|
| 3334 |
+ case AVMEDIA_TYPE_SUBTITLE: |
|
| 3335 |
+ ist->dec = avcodec_find_decoder_by_name(subtitle_codec_name); |
|
| 3336 |
+ if(subtitle_disable) |
|
| 3337 |
+ st->discard = AVDISCARD_ALL; |
|
| 3338 |
+ break; |
|
| 3339 |
+ case AVMEDIA_TYPE_ATTACHMENT: |
|
| 3340 |
+ case AVMEDIA_TYPE_UNKNOWN: |
|
| 3341 |
+ break; |
|
| 3342 |
+ default: |
|
| 3343 |
+ abort(); |
|
| 3344 |
+ } |
|
| 3345 |
+ } |
|
| 3346 |
+ |
|
| 3347 |
+ /* dump the file content */ |
|
| 3348 |
+ if (verbose >= 0) |
|
| 3349 |
+ av_dump_format(ic, nb_input_files, filename, 0); |
|
| 3350 |
+ |
|
| 3351 |
+ input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); |
|
| 3352 |
+ input_files[nb_input_files - 1].ctx = ic; |
|
| 3353 |
+ input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; |
|
| 3354 |
+ input_files[nb_input_files - 1].ts_offset = input_ts_offset - (copy_ts ? 0 : timestamp); |
|
| 3355 |
+ |
|
| 3356 |
+ frame_rate = (AVRational){0, 0};
|
|
| 3357 |
+ frame_pix_fmt = PIX_FMT_NONE; |
|
| 3358 |
+ frame_height = 0; |
|
| 3359 |
+ frame_width = 0; |
|
| 3360 |
+ audio_sample_rate = 0; |
|
| 3361 |
+ audio_channels = 0; |
|
| 3362 |
+ audio_sample_fmt = AV_SAMPLE_FMT_NONE; |
|
| 3363 |
+ av_freep(&ts_scale); |
|
| 3364 |
+ nb_ts_scale = 0; |
|
| 3365 |
+ |
|
| 3366 |
+ for (i = 0; i < orig_nb_streams; i++) |
|
| 3367 |
+ av_dict_free(&opts[i]); |
|
| 3368 |
+ av_freep(&opts); |
|
| 3369 |
+ av_freep(&video_codec_name); |
|
| 3370 |
+ av_freep(&audio_codec_name); |
|
| 3371 |
+ av_freep(&subtitle_codec_name); |
|
| 3372 |
+ uninit_opts(); |
|
| 3373 |
+ init_opts(); |
|
| 3374 |
+ return 0; |
|
| 3375 |
+} |
|
| 3376 |
+ |
|
| 3377 |
+static void check_inputs(int *has_video_ptr, |
|
| 3378 |
+ int *has_audio_ptr, |
|
| 3379 |
+ int *has_subtitle_ptr, |
|
| 3380 |
+ int *has_data_ptr) |
|
| 3381 |
+{
|
|
| 3382 |
+ int has_video, has_audio, has_subtitle, has_data, i, j; |
|
| 3383 |
+ AVFormatContext *ic; |
|
| 3384 |
+ |
|
| 3385 |
+ has_video = 0; |
|
| 3386 |
+ has_audio = 0; |
|
| 3387 |
+ has_subtitle = 0; |
|
| 3388 |
+ has_data = 0; |
|
| 3389 |
+ |
|
| 3390 |
+ for(j=0;j<nb_input_files;j++) {
|
|
| 3391 |
+ ic = input_files[j].ctx; |
|
| 3392 |
+ for(i=0;i<ic->nb_streams;i++) {
|
|
| 3393 |
+ AVCodecContext *enc = ic->streams[i]->codec; |
|
| 3394 |
+ switch(enc->codec_type) {
|
|
| 3395 |
+ case AVMEDIA_TYPE_AUDIO: |
|
| 3396 |
+ has_audio = 1; |
|
| 3397 |
+ break; |
|
| 3398 |
+ case AVMEDIA_TYPE_VIDEO: |
|
| 3399 |
+ has_video = 1; |
|
| 3400 |
+ break; |
|
| 3401 |
+ case AVMEDIA_TYPE_SUBTITLE: |
|
| 3402 |
+ has_subtitle = 1; |
|
| 3403 |
+ break; |
|
| 3404 |
+ case AVMEDIA_TYPE_DATA: |
|
| 3405 |
+ case AVMEDIA_TYPE_ATTACHMENT: |
|
| 3406 |
+ case AVMEDIA_TYPE_UNKNOWN: |
|
| 3407 |
+ has_data = 1; |
|
| 3408 |
+ break; |
|
| 3409 |
+ default: |
|
| 3410 |
+ abort(); |
|
| 3411 |
+ } |
|
| 3412 |
+ } |
|
| 3413 |
+ } |
|
| 3414 |
+ *has_video_ptr = has_video; |
|
| 3415 |
+ *has_audio_ptr = has_audio; |
|
| 3416 |
+ *has_subtitle_ptr = has_subtitle; |
|
| 3417 |
+ *has_data_ptr = has_data; |
|
| 3418 |
+} |
|
| 3419 |
+ |
|
| 3420 |
+static void new_video_stream(AVFormatContext *oc, int file_idx) |
|
| 3421 |
+{
|
|
| 3422 |
+ AVStream *st; |
|
| 3423 |
+ OutputStream *ost; |
|
| 3424 |
+ AVCodecContext *video_enc; |
|
| 3425 |
+ enum CodecID codec_id = CODEC_ID_NONE; |
|
| 3426 |
+ AVCodec *codec= NULL; |
|
| 3427 |
+ |
|
| 3428 |
+ if(!video_stream_copy){
|
|
| 3429 |
+ if (video_codec_name) {
|
|
| 3430 |
+ codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1); |
|
| 3431 |
+ codec = avcodec_find_encoder_by_name(video_codec_name); |
|
| 3432 |
+ } else {
|
|
| 3433 |
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO); |
|
| 3434 |
+ codec = avcodec_find_encoder(codec_id); |
|
| 3435 |
+ } |
|
| 3436 |
+ } |
|
| 3437 |
+ |
|
| 3438 |
+ ost = new_output_stream(oc, file_idx, codec); |
|
| 3439 |
+ st = ost->st; |
|
| 3440 |
+ if (!video_stream_copy) {
|
|
| 3441 |
+ ost->frame_aspect_ratio = frame_aspect_ratio; |
|
| 3442 |
+ frame_aspect_ratio = 0; |
|
| 3443 |
+#if CONFIG_AVFILTER |
|
| 3444 |
+ ost->avfilter= vfilters; |
|
| 3445 |
+ vfilters = NULL; |
|
| 3446 |
+#endif |
|
| 3447 |
+ } |
|
| 3448 |
+ |
|
| 3449 |
+ ost->bitstream_filters = video_bitstream_filters; |
|
| 3450 |
+ video_bitstream_filters= NULL; |
|
| 3451 |
+ |
|
| 3452 |
+ st->codec->thread_count= thread_count; |
|
| 3453 |
+ |
|
| 3454 |
+ video_enc = st->codec; |
|
| 3455 |
+ |
|
| 3456 |
+ if(video_codec_tag) |
|
| 3457 |
+ video_enc->codec_tag= video_codec_tag; |
|
| 3458 |
+ |
|
| 3459 |
+ if(oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
|
| 3460 |
+ video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
| 3461 |
+ } |
|
| 3462 |
+ |
|
| 3463 |
+ video_enc->codec_type = AVMEDIA_TYPE_VIDEO; |
|
| 3464 |
+ if (video_stream_copy) {
|
|
| 3465 |
+ st->stream_copy = 1; |
|
| 3466 |
+ video_enc->sample_aspect_ratio = |
|
| 3467 |
+ st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); |
|
| 3468 |
+ } else {
|
|
| 3469 |
+ const char *p; |
|
| 3470 |
+ int i; |
|
| 3471 |
+ |
|
| 3472 |
+ if (frame_rate.num) |
|
| 3473 |
+ ost->frame_rate = frame_rate; |
|
| 3474 |
+ video_enc->codec_id = codec_id; |
|
| 3475 |
+ |
|
| 3476 |
+ video_enc->width = frame_width; |
|
| 3477 |
+ video_enc->height = frame_height; |
|
| 3478 |
+ video_enc->pix_fmt = frame_pix_fmt; |
|
| 3479 |
+ st->sample_aspect_ratio = video_enc->sample_aspect_ratio; |
|
| 3480 |
+ |
|
| 3481 |
+ if (intra_only) |
|
| 3482 |
+ video_enc->gop_size = 0; |
|
| 3483 |
+ if (video_qscale || same_quality) {
|
|
| 3484 |
+ video_enc->flags |= CODEC_FLAG_QSCALE; |
|
| 3485 |
+ video_enc->global_quality = FF_QP2LAMBDA * video_qscale; |
|
| 3486 |
+ } |
|
| 3487 |
+ |
|
| 3488 |
+ if(intra_matrix) |
|
| 3489 |
+ video_enc->intra_matrix = intra_matrix; |
|
| 3490 |
+ if(inter_matrix) |
|
| 3491 |
+ video_enc->inter_matrix = inter_matrix; |
|
| 3492 |
+ |
|
| 3493 |
+ p= video_rc_override_string; |
|
| 3494 |
+ for(i=0; p; i++){
|
|
| 3495 |
+ int start, end, q; |
|
| 3496 |
+ int e=sscanf(p, "%d,%d,%d", &start, &end, &q); |
|
| 3497 |
+ if(e!=3){
|
|
| 3498 |
+ fprintf(stderr, "error parsing rc_override\n"); |
|
| 3499 |
+ exit_program(1); |
|
| 3500 |
+ } |
|
| 3501 |
+ video_enc->rc_override= |
|
| 3502 |
+ av_realloc(video_enc->rc_override, |
|
| 3503 |
+ sizeof(RcOverride)*(i+1)); |
|
| 3504 |
+ video_enc->rc_override[i].start_frame= start; |
|
| 3505 |
+ video_enc->rc_override[i].end_frame = end; |
|
| 3506 |
+ if(q>0){
|
|
| 3507 |
+ video_enc->rc_override[i].qscale= q; |
|
| 3508 |
+ video_enc->rc_override[i].quality_factor= 1.0; |
|
| 3509 |
+ } |
|
| 3510 |
+ else{
|
|
| 3511 |
+ video_enc->rc_override[i].qscale= 0; |
|
| 3512 |
+ video_enc->rc_override[i].quality_factor= -q/100.0; |
|
| 3513 |
+ } |
|
| 3514 |
+ p= strchr(p, '/'); |
|
| 3515 |
+ if(p) p++; |
|
| 3516 |
+ } |
|
| 3517 |
+ video_enc->rc_override_count=i; |
|
| 3518 |
+ if (!video_enc->rc_initial_buffer_occupancy) |
|
| 3519 |
+ video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4; |
|
| 3520 |
+ video_enc->me_threshold= me_threshold; |
|
| 3521 |
+ video_enc->intra_dc_precision= intra_dc_precision - 8; |
|
| 3522 |
+ |
|
| 3523 |
+ if (do_psnr) |
|
| 3524 |
+ video_enc->flags|= CODEC_FLAG_PSNR; |
|
| 3525 |
+ |
|
| 3526 |
+ /* two pass mode */ |
|
| 3527 |
+ if (do_pass) {
|
|
| 3528 |
+ if (do_pass == 1) {
|
|
| 3529 |
+ video_enc->flags |= CODEC_FLAG_PASS1; |
|
| 3530 |
+ } else {
|
|
| 3531 |
+ video_enc->flags |= CODEC_FLAG_PASS2; |
|
| 3532 |
+ } |
|
| 3533 |
+ } |
|
| 3534 |
+ |
|
| 3535 |
+ if (forced_key_frames) |
|
| 3536 |
+ parse_forced_key_frames(forced_key_frames, ost, video_enc); |
|
| 3537 |
+ } |
|
| 3538 |
+ if (video_language) {
|
|
| 3539 |
+ av_dict_set(&st->metadata, "language", video_language, 0); |
|
| 3540 |
+ av_freep(&video_language); |
|
| 3541 |
+ } |
|
| 3542 |
+ |
|
| 3543 |
+ /* reset some key parameters */ |
|
| 3544 |
+ video_disable = 0; |
|
| 3545 |
+ av_freep(&video_codec_name); |
|
| 3546 |
+ av_freep(&forced_key_frames); |
|
| 3547 |
+ video_stream_copy = 0; |
|
| 3548 |
+ frame_pix_fmt = PIX_FMT_NONE; |
|
| 3549 |
+} |
|
| 3550 |
+ |
|
| 3551 |
+static void new_audio_stream(AVFormatContext *oc, int file_idx) |
|
| 3552 |
+{
|
|
| 3553 |
+ AVStream *st; |
|
| 3554 |
+ OutputStream *ost; |
|
| 3555 |
+ AVCodec *codec= NULL; |
|
| 3556 |
+ AVCodecContext *audio_enc; |
|
| 3557 |
+ enum CodecID codec_id = CODEC_ID_NONE; |
|
| 3558 |
+ |
|
| 3559 |
+ if(!audio_stream_copy){
|
|
| 3560 |
+ if (audio_codec_name) {
|
|
| 3561 |
+ codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1); |
|
| 3562 |
+ codec = avcodec_find_encoder_by_name(audio_codec_name); |
|
| 3563 |
+ } else {
|
|
| 3564 |
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO); |
|
| 3565 |
+ codec = avcodec_find_encoder(codec_id); |
|
| 3566 |
+ } |
|
| 3567 |
+ } |
|
| 3568 |
+ ost = new_output_stream(oc, file_idx, codec); |
|
| 3569 |
+ st = ost->st; |
|
| 3570 |
+ |
|
| 3571 |
+ ost->bitstream_filters = audio_bitstream_filters; |
|
| 3572 |
+ audio_bitstream_filters= NULL; |
|
| 3573 |
+ |
|
| 3574 |
+ st->codec->thread_count= thread_count; |
|
| 3575 |
+ |
|
| 3576 |
+ audio_enc = st->codec; |
|
| 3577 |
+ audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; |
|
| 3578 |
+ |
|
| 3579 |
+ if(audio_codec_tag) |
|
| 3580 |
+ audio_enc->codec_tag= audio_codec_tag; |
|
| 3581 |
+ |
|
| 3582 |
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
|
| 3583 |
+ audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
| 3584 |
+ } |
|
| 3585 |
+ if (audio_stream_copy) {
|
|
| 3586 |
+ st->stream_copy = 1; |
|
| 3587 |
+ } else {
|
|
| 3588 |
+ audio_enc->codec_id = codec_id; |
|
| 3589 |
+ |
|
| 3590 |
+ if (audio_qscale > QSCALE_NONE) {
|
|
| 3591 |
+ audio_enc->flags |= CODEC_FLAG_QSCALE; |
|
| 3592 |
+ audio_enc->global_quality = FF_QP2LAMBDA * audio_qscale; |
|
| 3593 |
+ } |
|
| 3594 |
+ if (audio_channels) |
|
| 3595 |
+ audio_enc->channels = audio_channels; |
|
| 3596 |
+ if (audio_sample_fmt != AV_SAMPLE_FMT_NONE) |
|
| 3597 |
+ audio_enc->sample_fmt = audio_sample_fmt; |
|
| 3598 |
+ if (audio_sample_rate) |
|
| 3599 |
+ audio_enc->sample_rate = audio_sample_rate; |
|
| 3600 |
+ } |
|
| 3601 |
+ if (audio_language) {
|
|
| 3602 |
+ av_dict_set(&st->metadata, "language", audio_language, 0); |
|
| 3603 |
+ av_freep(&audio_language); |
|
| 3604 |
+ } |
|
| 3605 |
+ |
|
| 3606 |
+ /* reset some key parameters */ |
|
| 3607 |
+ audio_disable = 0; |
|
| 3608 |
+ av_freep(&audio_codec_name); |
|
| 3609 |
+ audio_stream_copy = 0; |
|
| 3610 |
+} |
|
| 3611 |
+ |
|
| 3612 |
+static void new_data_stream(AVFormatContext *oc, int file_idx) |
|
| 3613 |
+{
|
|
| 3614 |
+ AVStream *st; |
|
| 3615 |
+ OutputStream *ost; |
|
| 3616 |
+ AVCodecContext *data_enc; |
|
| 3617 |
+ |
|
| 3618 |
+ ost = new_output_stream(oc, file_idx, NULL); |
|
| 3619 |
+ st = ost->st; |
|
| 3620 |
+ data_enc = st->codec; |
|
| 3621 |
+ if (!data_stream_copy) {
|
|
| 3622 |
+ fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n"); |
|
| 3623 |
+ exit_program(1); |
|
| 3624 |
+ } |
|
| 3625 |
+ |
|
| 3626 |
+ data_enc->codec_type = AVMEDIA_TYPE_DATA; |
|
| 3627 |
+ |
|
| 3628 |
+ if (data_codec_tag) |
|
| 3629 |
+ data_enc->codec_tag= data_codec_tag; |
|
| 3630 |
+ |
|
| 3631 |
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
|
| 3632 |
+ data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
| 3633 |
+ } |
|
| 3634 |
+ if (data_stream_copy) {
|
|
| 3635 |
+ st->stream_copy = 1; |
|
| 3636 |
+ } |
|
| 3637 |
+ |
|
| 3638 |
+ data_disable = 0; |
|
| 3639 |
+ av_freep(&data_codec_name); |
|
| 3640 |
+ data_stream_copy = 0; |
|
| 3641 |
+} |
|
| 3642 |
+ |
|
| 3643 |
+static void new_subtitle_stream(AVFormatContext *oc, int file_idx) |
|
| 3644 |
+{
|
|
| 3645 |
+ AVStream *st; |
|
| 3646 |
+ OutputStream *ost; |
|
| 3647 |
+ AVCodec *codec=NULL; |
|
| 3648 |
+ AVCodecContext *subtitle_enc; |
|
| 3649 |
+ enum CodecID codec_id = CODEC_ID_NONE; |
|
| 3650 |
+ |
|
| 3651 |
+ if(!subtitle_stream_copy){
|
|
| 3652 |
+ if (subtitle_codec_name) {
|
|
| 3653 |
+ codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1); |
|
| 3654 |
+ codec = avcodec_find_encoder_by_name(subtitle_codec_name); |
|
| 3655 |
+ } else {
|
|
| 3656 |
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_SUBTITLE); |
|
| 3657 |
+ codec = avcodec_find_encoder(codec_id); |
|
| 3658 |
+ } |
|
| 3659 |
+ } |
|
| 3660 |
+ ost = new_output_stream(oc, file_idx, codec); |
|
| 3661 |
+ st = ost->st; |
|
| 3662 |
+ subtitle_enc = st->codec; |
|
| 3663 |
+ |
|
| 3664 |
+ ost->bitstream_filters = subtitle_bitstream_filters; |
|
| 3665 |
+ subtitle_bitstream_filters= NULL; |
|
| 3666 |
+ |
|
| 3667 |
+ subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; |
|
| 3668 |
+ |
|
| 3669 |
+ if(subtitle_codec_tag) |
|
| 3670 |
+ subtitle_enc->codec_tag= subtitle_codec_tag; |
|
| 3671 |
+ |
|
| 3672 |
+ if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
|
|
| 3673 |
+ subtitle_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
| 3674 |
+ } |
|
| 3675 |
+ if (subtitle_stream_copy) {
|
|
| 3676 |
+ st->stream_copy = 1; |
|
| 3677 |
+ } else {
|
|
| 3678 |
+ subtitle_enc->codec_id = codec_id; |
|
| 3679 |
+ } |
|
| 3680 |
+ |
|
| 3681 |
+ if (subtitle_language) {
|
|
| 3682 |
+ av_dict_set(&st->metadata, "language", subtitle_language, 0); |
|
| 3683 |
+ av_freep(&subtitle_language); |
|
| 3684 |
+ } |
|
| 3685 |
+ |
|
| 3686 |
+ subtitle_disable = 0; |
|
| 3687 |
+ av_freep(&subtitle_codec_name); |
|
| 3688 |
+ subtitle_stream_copy = 0; |
|
| 3689 |
+} |
|
| 3690 |
+ |
|
| 3691 |
+static int opt_new_stream(const char *opt, const char *arg) |
|
| 3692 |
+{
|
|
| 3693 |
+ AVFormatContext *oc; |
|
| 3694 |
+ int file_idx = nb_output_files - 1; |
|
| 3695 |
+ if (nb_output_files <= 0) {
|
|
| 3696 |
+ fprintf(stderr, "At least one output file must be specified\n"); |
|
| 3697 |
+ exit_program(1); |
|
| 3698 |
+ } |
|
| 3699 |
+ oc = output_files[file_idx]; |
|
| 3700 |
+ |
|
| 3701 |
+ if (!strcmp(opt, "newvideo" )) new_video_stream (oc, file_idx); |
|
| 3702 |
+ else if (!strcmp(opt, "newaudio" )) new_audio_stream (oc, file_idx); |
|
| 3703 |
+ else if (!strcmp(opt, "newsubtitle")) new_subtitle_stream(oc, file_idx); |
|
| 3704 |
+ else if (!strcmp(opt, "newdata" )) new_data_stream (oc, file_idx); |
|
| 3705 |
+ else av_assert0(0); |
|
| 3706 |
+ return 0; |
|
| 3707 |
+} |
|
| 3708 |
+ |
|
| 3709 |
+/* arg format is "output-stream-index:streamid-value". */ |
|
| 3710 |
+static int opt_streamid(const char *opt, const char *arg) |
|
| 3711 |
+{
|
|
| 3712 |
+ int idx; |
|
| 3713 |
+ char *p; |
|
| 3714 |
+ char idx_str[16]; |
|
| 3715 |
+ |
|
| 3716 |
+ av_strlcpy(idx_str, arg, sizeof(idx_str)); |
|
| 3717 |
+ p = strchr(idx_str, ':'); |
|
| 3718 |
+ if (!p) {
|
|
| 3719 |
+ fprintf(stderr, |
|
| 3720 |
+ "Invalid value '%s' for option '%s', required syntax is 'index:value'\n", |
|
| 3721 |
+ arg, opt); |
|
| 3722 |
+ exit_program(1); |
|
| 3723 |
+ } |
|
| 3724 |
+ *p++ = '\0'; |
|
| 3725 |
+ idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, INT_MAX); |
|
| 3726 |
+ streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1); |
|
| 3727 |
+ streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); |
|
| 3728 |
+ return 0; |
|
| 3729 |
+} |
|
| 3730 |
+ |
|
| 3731 |
+static void opt_output_file(const char *filename) |
|
| 3732 |
+{
|
|
| 3733 |
+ AVFormatContext *oc; |
|
| 3734 |
+ int err, use_video, use_audio, use_subtitle, use_data; |
|
| 3735 |
+ int input_has_video, input_has_audio, input_has_subtitle, input_has_data; |
|
| 3736 |
+ AVOutputFormat *file_oformat; |
|
| 3737 |
+ |
|
| 3738 |
+ if (!strcmp(filename, "-")) |
|
| 3739 |
+ filename = "pipe:"; |
|
| 3740 |
+ |
|
| 3741 |
+ oc = avformat_alloc_context(); |
|
| 3742 |
+ if (!oc) {
|
|
| 3743 |
+ print_error(filename, AVERROR(ENOMEM)); |
|
| 3744 |
+ exit_program(1); |
|
| 3745 |
+ } |
|
| 3746 |
+ |
|
| 3747 |
+ if (last_asked_format) {
|
|
| 3748 |
+ file_oformat = av_guess_format(last_asked_format, NULL, NULL); |
|
| 3749 |
+ if (!file_oformat) {
|
|
| 3750 |
+ fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format); |
|
| 3751 |
+ exit_program(1); |
|
| 3752 |
+ } |
|
| 3753 |
+ last_asked_format = NULL; |
|
| 3754 |
+ } else {
|
|
| 3755 |
+ file_oformat = av_guess_format(NULL, filename, NULL); |
|
| 3756 |
+ if (!file_oformat) {
|
|
| 3757 |
+ fprintf(stderr, "Unable to find a suitable output format for '%s'\n", |
|
| 3758 |
+ filename); |
|
| 3759 |
+ exit_program(1); |
|
| 3760 |
+ } |
|
| 3761 |
+ } |
|
| 3762 |
+ |
|
| 3763 |
+ oc->oformat = file_oformat; |
|
| 3764 |
+ av_strlcpy(oc->filename, filename, sizeof(oc->filename)); |
|
| 3765 |
+ |
|
| 3766 |
+ if (!strcmp(file_oformat->name, "ffm") && |
|
| 3767 |
+ av_strstart(filename, "http:", NULL)) {
|
|
| 3768 |
+ /* special case for files sent to avserver: we get the stream |
|
| 3769 |
+ parameters from avserver */ |
|
| 3770 |
+ int err = read_avserver_streams(oc, filename); |
|
| 3771 |
+ if (err < 0) {
|
|
| 3772 |
+ print_error(filename, err); |
|
| 3773 |
+ exit_program(1); |
|
| 3774 |
+ } |
|
| 3775 |
+ } else {
|
|
| 3776 |
+ use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; |
|
| 3777 |
+ use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; |
|
| 3778 |
+ use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; |
|
| 3779 |
+ use_data = data_stream_copy || data_codec_name; /* XXX once generic data codec will be available add a ->data_codec reference and use it here */ |
|
| 3780 |
+ |
|
| 3781 |
+ /* disable if no corresponding type found */ |
|
| 3782 |
+ check_inputs(&input_has_video, |
|
| 3783 |
+ &input_has_audio, |
|
| 3784 |
+ &input_has_subtitle, |
|
| 3785 |
+ &input_has_data); |
|
| 3786 |
+ |
|
| 3787 |
+ if (!input_has_video) |
|
| 3788 |
+ use_video = 0; |
|
| 3789 |
+ if (!input_has_audio) |
|
| 3790 |
+ use_audio = 0; |
|
| 3791 |
+ if (!input_has_subtitle) |
|
| 3792 |
+ use_subtitle = 0; |
|
| 3793 |
+ if (!input_has_data) |
|
| 3794 |
+ use_data = 0; |
|
| 3795 |
+ |
|
| 3796 |
+ /* manual disable */ |
|
| 3797 |
+ if (audio_disable) use_audio = 0; |
|
| 3798 |
+ if (video_disable) use_video = 0; |
|
| 3799 |
+ if (subtitle_disable) use_subtitle = 0; |
|
| 3800 |
+ if (data_disable) use_data = 0; |
|
| 3801 |
+ |
|
| 3802 |
+ if (use_video) new_video_stream(oc, nb_output_files); |
|
| 3803 |
+ if (use_audio) new_audio_stream(oc, nb_output_files); |
|
| 3804 |
+ if (use_subtitle) new_subtitle_stream(oc, nb_output_files); |
|
| 3805 |
+ if (use_data) new_data_stream(oc, nb_output_files); |
|
| 3806 |
+ |
|
| 3807 |
+ av_dict_copy(&oc->metadata, metadata, 0); |
|
| 3808 |
+ av_dict_free(&metadata); |
|
| 3809 |
+ } |
|
| 3810 |
+ |
|
| 3811 |
+ av_dict_copy(&output_opts[nb_output_files], format_opts, 0); |
|
| 3812 |
+ output_files[nb_output_files++] = oc; |
|
| 3813 |
+ |
|
| 3814 |
+ /* check filename in case of an image number is expected */ |
|
| 3815 |
+ if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
|
|
| 3816 |
+ if (!av_filename_number_test(oc->filename)) {
|
|
| 3817 |
+ print_error(oc->filename, AVERROR(EINVAL)); |
|
| 3818 |
+ exit_program(1); |
|
| 3819 |
+ } |
|
| 3820 |
+ } |
|
| 3821 |
+ |
|
| 3822 |
+ if (!(oc->oformat->flags & AVFMT_NOFILE)) {
|
|
| 3823 |
+ /* test if it already exists to avoid loosing precious files */ |
|
| 3824 |
+ if (!file_overwrite && |
|
| 3825 |
+ (strchr(filename, ':') == NULL || |
|
| 3826 |
+ filename[1] == ':' || |
|
| 3827 |
+ av_strstart(filename, "file:", NULL))) {
|
|
| 3828 |
+ if (avio_check(filename, 0) == 0) {
|
|
| 3829 |
+ if (!using_stdin) {
|
|
| 3830 |
+ fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); |
|
| 3831 |
+ fflush(stderr); |
|
| 3832 |
+ if (!read_yesno()) {
|
|
| 3833 |
+ fprintf(stderr, "Not overwriting - exiting\n"); |
|
| 3834 |
+ exit_program(1); |
|
| 3835 |
+ } |
|
| 3836 |
+ } |
|
| 3837 |
+ else {
|
|
| 3838 |
+ fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); |
|
| 3839 |
+ exit_program(1); |
|
| 3840 |
+ } |
|
| 3841 |
+ } |
|
| 3842 |
+ } |
|
| 3843 |
+ |
|
| 3844 |
+ /* open the file */ |
|
| 3845 |
+ if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
|
|
| 3846 |
+ print_error(filename, err); |
|
| 3847 |
+ exit_program(1); |
|
| 3848 |
+ } |
|
| 3849 |
+ } |
|
| 3850 |
+ |
|
| 3851 |
+ oc->preload= (int)(mux_preload*AV_TIME_BASE); |
|
| 3852 |
+ oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); |
|
| 3853 |
+ if (loop_output >= 0) {
|
|
| 3854 |
+ av_log(NULL, AV_LOG_WARNING, "-loop_output is deprecated, use -loop\n"); |
|
| 3855 |
+ oc->loop_output = loop_output; |
|
| 3856 |
+ } |
|
| 3857 |
+ oc->flags |= AVFMT_FLAG_NONBLOCK; |
|
| 3858 |
+ |
|
| 3859 |
+ frame_rate = (AVRational){0, 0};
|
|
| 3860 |
+ frame_width = 0; |
|
| 3861 |
+ frame_height = 0; |
|
| 3862 |
+ audio_sample_rate = 0; |
|
| 3863 |
+ audio_channels = 0; |
|
| 3864 |
+ audio_sample_fmt = AV_SAMPLE_FMT_NONE; |
|
| 3865 |
+ |
|
| 3866 |
+ av_freep(&forced_key_frames); |
|
| 3867 |
+ uninit_opts(); |
|
| 3868 |
+ init_opts(); |
|
| 3869 |
+} |
|
| 3870 |
+ |
|
| 3871 |
+/* same option as mencoder */ |
|
| 3872 |
+static int opt_pass(const char *opt, const char *arg) |
|
| 3873 |
+{
|
|
| 3874 |
+ do_pass = parse_number_or_die(opt, arg, OPT_INT, 1, 2); |
|
| 3875 |
+ return 0; |
|
| 3876 |
+} |
|
| 3877 |
+ |
|
| 3878 |
+static int64_t getutime(void) |
|
| 3879 |
+{
|
|
| 3880 |
+#if HAVE_GETRUSAGE |
|
| 3881 |
+ struct rusage rusage; |
|
| 3882 |
+ |
|
| 3883 |
+ getrusage(RUSAGE_SELF, &rusage); |
|
| 3884 |
+ return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec; |
|
| 3885 |
+#elif HAVE_GETPROCESSTIMES |
|
| 3886 |
+ HANDLE proc; |
|
| 3887 |
+ FILETIME c, e, k, u; |
|
| 3888 |
+ proc = GetCurrentProcess(); |
|
| 3889 |
+ GetProcessTimes(proc, &c, &e, &k, &u); |
|
| 3890 |
+ return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10; |
|
| 3891 |
+#else |
|
| 3892 |
+ return av_gettime(); |
|
| 3893 |
+#endif |
|
| 3894 |
+} |
|
| 3895 |
+ |
|
| 3896 |
+static int64_t getmaxrss(void) |
|
| 3897 |
+{
|
|
| 3898 |
+#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS |
|
| 3899 |
+ struct rusage rusage; |
|
| 3900 |
+ getrusage(RUSAGE_SELF, &rusage); |
|
| 3901 |
+ return (int64_t)rusage.ru_maxrss * 1024; |
|
| 3902 |
+#elif HAVE_GETPROCESSMEMORYINFO |
|
| 3903 |
+ HANDLE proc; |
|
| 3904 |
+ PROCESS_MEMORY_COUNTERS memcounters; |
|
| 3905 |
+ proc = GetCurrentProcess(); |
|
| 3906 |
+ memcounters.cb = sizeof(memcounters); |
|
| 3907 |
+ GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters)); |
|
| 3908 |
+ return memcounters.PeakPagefileUsage; |
|
| 3909 |
+#else |
|
| 3910 |
+ return 0; |
|
| 3911 |
+#endif |
|
| 3912 |
+} |
|
| 3913 |
+ |
|
| 3914 |
+static void parse_matrix_coeffs(uint16_t *dest, const char *str) |
|
| 3915 |
+{
|
|
| 3916 |
+ int i; |
|
| 3917 |
+ const char *p = str; |
|
| 3918 |
+ for(i = 0;; i++) {
|
|
| 3919 |
+ dest[i] = atoi(p); |
|
| 3920 |
+ if(i == 63) |
|
| 3921 |
+ break; |
|
| 3922 |
+ p = strchr(p, ','); |
|
| 3923 |
+ if(!p) {
|
|
| 3924 |
+ fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i); |
|
| 3925 |
+ exit_program(1); |
|
| 3926 |
+ } |
|
| 3927 |
+ p++; |
|
| 3928 |
+ } |
|
| 3929 |
+} |
|
| 3930 |
+ |
|
| 3931 |
+static void opt_inter_matrix(const char *arg) |
|
| 3932 |
+{
|
|
| 3933 |
+ inter_matrix = av_mallocz(sizeof(uint16_t) * 64); |
|
| 3934 |
+ parse_matrix_coeffs(inter_matrix, arg); |
|
| 3935 |
+} |
|
| 3936 |
+ |
|
| 3937 |
+static void opt_intra_matrix(const char *arg) |
|
| 3938 |
+{
|
|
| 3939 |
+ intra_matrix = av_mallocz(sizeof(uint16_t) * 64); |
|
| 3940 |
+ parse_matrix_coeffs(intra_matrix, arg); |
|
| 3941 |
+} |
|
| 3942 |
+ |
|
| 3943 |
+static void show_usage(void) |
|
| 3944 |
+{
|
|
| 3945 |
+ printf("Hyper fast Audio and Video encoder\n");
|
|
| 3946 |
+ printf("usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
|
|
| 3947 |
+ printf("\n");
|
|
| 3948 |
+} |
|
| 3949 |
+ |
|
| 3950 |
+static void show_help(void) |
|
| 3951 |
+{
|
|
| 3952 |
+ AVCodec *c; |
|
| 3953 |
+ AVOutputFormat *oformat = NULL; |
|
| 3954 |
+ AVInputFormat *iformat = NULL; |
|
| 3955 |
+ |
|
| 3956 |
+ av_log_set_callback(log_callback_help); |
|
| 3957 |
+ show_usage(); |
|
| 3958 |
+ show_help_options(options, "Main options:\n", |
|
| 3959 |
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | OPT_GRAB, 0); |
|
| 3960 |
+ show_help_options(options, "\nAdvanced options:\n", |
|
| 3961 |
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | OPT_GRAB, |
|
| 3962 |
+ OPT_EXPERT); |
|
| 3963 |
+ show_help_options(options, "\nVideo options:\n", |
|
| 3964 |
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, |
|
| 3965 |
+ OPT_VIDEO); |
|
| 3966 |
+ show_help_options(options, "\nAdvanced Video options:\n", |
|
| 3967 |
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, |
|
| 3968 |
+ OPT_VIDEO | OPT_EXPERT); |
|
| 3969 |
+ show_help_options(options, "\nAudio options:\n", |
|
| 3970 |
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, |
|
| 3971 |
+ OPT_AUDIO); |
|
| 3972 |
+ show_help_options(options, "\nAdvanced Audio options:\n", |
|
| 3973 |
+ OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, |
|
| 3974 |
+ OPT_AUDIO | OPT_EXPERT); |
|
| 3975 |
+ show_help_options(options, "\nSubtitle options:\n", |
|
| 3976 |
+ OPT_SUBTITLE | OPT_GRAB, |
|
| 3977 |
+ OPT_SUBTITLE); |
|
| 3978 |
+ show_help_options(options, "\nAudio/Video grab options:\n", |
|
| 3979 |
+ OPT_GRAB, |
|
| 3980 |
+ OPT_GRAB); |
|
| 3981 |
+ printf("\n");
|
|
| 3982 |
+ av_opt_show2(avcodec_opts[0], NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); |
|
| 3983 |
+ printf("\n");
|
|
| 3984 |
+ |
|
| 3985 |
+ /* individual codec options */ |
|
| 3986 |
+ c = NULL; |
|
| 3987 |
+ while ((c = av_codec_next(c))) {
|
|
| 3988 |
+ if (c->priv_class) {
|
|
| 3989 |
+ av_opt_show2(&c->priv_class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); |
|
| 3990 |
+ printf("\n");
|
|
| 3991 |
+ } |
|
| 3992 |
+ } |
|
| 3993 |
+ |
|
| 3994 |
+ av_opt_show2(avformat_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); |
|
| 3995 |
+ printf("\n");
|
|
| 3996 |
+ |
|
| 3997 |
+ /* individual muxer options */ |
|
| 3998 |
+ while ((oformat = av_oformat_next(oformat))) {
|
|
| 3999 |
+ if (oformat->priv_class) {
|
|
| 4000 |
+ av_opt_show2(&oformat->priv_class, NULL, AV_OPT_FLAG_ENCODING_PARAM, 0); |
|
| 4001 |
+ printf("\n");
|
|
| 4002 |
+ } |
|
| 4003 |
+ } |
|
| 4004 |
+ |
|
| 4005 |
+ /* individual demuxer options */ |
|
| 4006 |
+ while ((iformat = av_iformat_next(iformat))) {
|
|
| 4007 |
+ if (iformat->priv_class) {
|
|
| 4008 |
+ av_opt_show2(&iformat->priv_class, NULL, AV_OPT_FLAG_DECODING_PARAM, 0); |
|
| 4009 |
+ printf("\n");
|
|
| 4010 |
+ } |
|
| 4011 |
+ } |
|
| 4012 |
+ |
|
| 4013 |
+ av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); |
|
| 4014 |
+} |
|
| 4015 |
+ |
|
| 4016 |
+static int opt_target(const char *opt, const char *arg) |
|
| 4017 |
+{
|
|
| 4018 |
+ enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
|
|
| 4019 |
+ static const char *const frame_rates[] = {"25", "30000/1001", "24000/1001"};
|
|
| 4020 |
+ |
|
| 4021 |
+ if(!strncmp(arg, "pal-", 4)) {
|
|
| 4022 |
+ norm = PAL; |
|
| 4023 |
+ arg += 4; |
|
| 4024 |
+ } else if(!strncmp(arg, "ntsc-", 5)) {
|
|
| 4025 |
+ norm = NTSC; |
|
| 4026 |
+ arg += 5; |
|
| 4027 |
+ } else if(!strncmp(arg, "film-", 5)) {
|
|
| 4028 |
+ norm = FILM; |
|
| 4029 |
+ arg += 5; |
|
| 4030 |
+ } else {
|
|
| 4031 |
+ int fr; |
|
| 4032 |
+ /* Calculate FR via float to avoid int overflow */ |
|
| 4033 |
+ fr = (int)(frame_rate.num * 1000.0 / frame_rate.den); |
|
| 4034 |
+ if(fr == 25000) {
|
|
| 4035 |
+ norm = PAL; |
|
| 4036 |
+ } else if((fr == 29970) || (fr == 23976)) {
|
|
| 4037 |
+ norm = NTSC; |
|
| 4038 |
+ } else {
|
|
| 4039 |
+ /* Try to determine PAL/NTSC by peeking in the input files */ |
|
| 4040 |
+ if(nb_input_files) {
|
|
| 4041 |
+ int i, j; |
|
| 4042 |
+ for (j = 0; j < nb_input_files; j++) {
|
|
| 4043 |
+ for (i = 0; i < input_files[j].ctx->nb_streams; i++) {
|
|
| 4044 |
+ AVCodecContext *c = input_files[j].ctx->streams[i]->codec; |
|
| 4045 |
+ if(c->codec_type != AVMEDIA_TYPE_VIDEO) |
|
| 4046 |
+ continue; |
|
| 4047 |
+ fr = c->time_base.den * 1000 / c->time_base.num; |
|
| 4048 |
+ if(fr == 25000) {
|
|
| 4049 |
+ norm = PAL; |
|
| 4050 |
+ break; |
|
| 4051 |
+ } else if((fr == 29970) || (fr == 23976)) {
|
|
| 4052 |
+ norm = NTSC; |
|
| 4053 |
+ break; |
|
| 4054 |
+ } |
|
| 4055 |
+ } |
|
| 4056 |
+ if(norm != UNKNOWN) |
|
| 4057 |
+ break; |
|
| 4058 |
+ } |
|
| 4059 |
+ } |
|
| 4060 |
+ } |
|
| 4061 |
+ if(verbose > 0 && norm != UNKNOWN) |
|
| 4062 |
+ fprintf(stderr, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC"); |
|
| 4063 |
+ } |
|
| 4064 |
+ |
|
| 4065 |
+ if(norm == UNKNOWN) {
|
|
| 4066 |
+ fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n"); |
|
| 4067 |
+ fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n"); |
|
| 4068 |
+ fprintf(stderr, "or set a framerate with \"-r xxx\".\n"); |
|
| 4069 |
+ exit_program(1); |
|
| 4070 |
+ } |
|
| 4071 |
+ |
|
| 4072 |
+ if(!strcmp(arg, "vcd")) {
|
|
| 4073 |
+ opt_video_codec("vcodec", "mpeg1video");
|
|
| 4074 |
+ opt_audio_codec("vcodec", "mp2");
|
|
| 4075 |
+ opt_format("f", "vcd");
|
|
| 4076 |
+ |
|
| 4077 |
+ opt_frame_size("s", norm == PAL ? "352x288" : "352x240");
|
|
| 4078 |
+ opt_frame_rate("r", frame_rates[norm]);
|
|
| 4079 |
+ opt_default("g", norm == PAL ? "15" : "18");
|
|
| 4080 |
+ |
|
| 4081 |
+ opt_default("b", "1150000");
|
|
| 4082 |
+ opt_default("maxrate", "1150000");
|
|
| 4083 |
+ opt_default("minrate", "1150000");
|
|
| 4084 |
+ opt_default("bufsize", "327680"); // 40*1024*8;
|
|
| 4085 |
+ |
|
| 4086 |
+ opt_default("ab", "224000");
|
|
| 4087 |
+ audio_sample_rate = 44100; |
|
| 4088 |
+ audio_channels = 2; |
|
| 4089 |
+ |
|
| 4090 |
+ opt_default("packetsize", "2324");
|
|
| 4091 |
+ opt_default("muxrate", "1411200"); // 2352 * 75 * 8;
|
|
| 4092 |
+ |
|
| 4093 |
+ /* We have to offset the PTS, so that it is consistent with the SCR. |
|
| 4094 |
+ SCR starts at 36000, but the first two packs contain only padding |
|
| 4095 |
+ and the first pack from the other stream, respectively, may also have |
|
| 4096 |
+ been written before. |
|
| 4097 |
+ So the real data starts at SCR 36000+3*1200. */ |
|
| 4098 |
+ mux_preload= (36000+3*1200) / 90000.0; //0.44 |
|
| 4099 |
+ } else if(!strcmp(arg, "svcd")) {
|
|
| 4100 |
+ |
|
| 4101 |
+ opt_video_codec("vcodec", "mpeg2video");
|
|
| 4102 |
+ opt_audio_codec("acodec", "mp2");
|
|
| 4103 |
+ opt_format("f", "svcd");
|
|
| 4104 |
+ |
|
| 4105 |
+ opt_frame_size("s", norm == PAL ? "480x576" : "480x480");
|
|
| 4106 |
+ opt_frame_rate("r", frame_rates[norm]);
|
|
| 4107 |
+ opt_default("g", norm == PAL ? "15" : "18");
|
|
| 4108 |
+ |
|
| 4109 |
+ opt_default("b", "2040000");
|
|
| 4110 |
+ opt_default("maxrate", "2516000");
|
|
| 4111 |
+ opt_default("minrate", "0"); //1145000;
|
|
| 4112 |
+ opt_default("bufsize", "1835008"); //224*1024*8;
|
|
| 4113 |
+ opt_default("flags", "+scan_offset");
|
|
| 4114 |
+ |
|
| 4115 |
+ |
|
| 4116 |
+ opt_default("ab", "224000");
|
|
| 4117 |
+ audio_sample_rate = 44100; |
|
| 4118 |
+ |
|
| 4119 |
+ opt_default("packetsize", "2324");
|
|
| 4120 |
+ |
|
| 4121 |
+ } else if(!strcmp(arg, "dvd")) {
|
|
| 4122 |
+ |
|
| 4123 |
+ opt_video_codec("vcodec", "mpeg2video");
|
|
| 4124 |
+ opt_audio_codec("vcodec", "ac3");
|
|
| 4125 |
+ opt_format("f", "dvd");
|
|
| 4126 |
+ |
|
| 4127 |
+ opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480");
|
|
| 4128 |
+ opt_frame_rate("r", frame_rates[norm]);
|
|
| 4129 |
+ opt_default("g", norm == PAL ? "15" : "18");
|
|
| 4130 |
+ |
|
| 4131 |
+ opt_default("b", "6000000");
|
|
| 4132 |
+ opt_default("maxrate", "9000000");
|
|
| 4133 |
+ opt_default("minrate", "0"); //1500000;
|
|
| 4134 |
+ opt_default("bufsize", "1835008"); //224*1024*8;
|
|
| 4135 |
+ |
|
| 4136 |
+ opt_default("packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
|
|
| 4137 |
+ opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
|
|
| 4138 |
+ |
|
| 4139 |
+ opt_default("ab", "448000");
|
|
| 4140 |
+ audio_sample_rate = 48000; |
|
| 4141 |
+ |
|
| 4142 |
+ } else if(!strncmp(arg, "dv", 2)) {
|
|
| 4143 |
+ |
|
| 4144 |
+ opt_format("f", "dv");
|
|
| 4145 |
+ |
|
| 4146 |
+ opt_frame_size("s", norm == PAL ? "720x576" : "720x480");
|
|
| 4147 |
+ opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
|
|
| 4148 |
+ norm == PAL ? "yuv420p" : "yuv411p"); |
|
| 4149 |
+ opt_frame_rate("r", frame_rates[norm]);
|
|
| 4150 |
+ |
|
| 4151 |
+ audio_sample_rate = 48000; |
|
| 4152 |
+ audio_channels = 2; |
|
| 4153 |
+ |
|
| 4154 |
+ } else {
|
|
| 4155 |
+ fprintf(stderr, "Unknown target: %s\n", arg); |
|
| 4156 |
+ return AVERROR(EINVAL); |
|
| 4157 |
+ } |
|
| 4158 |
+ return 0; |
|
| 4159 |
+} |
|
| 4160 |
+ |
|
| 4161 |
+static int opt_vstats_file(const char *opt, const char *arg) |
|
| 4162 |
+{
|
|
| 4163 |
+ av_free (vstats_filename); |
|
| 4164 |
+ vstats_filename=av_strdup (arg); |
|
| 4165 |
+ return 0; |
|
| 4166 |
+} |
|
| 4167 |
+ |
|
| 4168 |
+static int opt_vstats(const char *opt, const char *arg) |
|
| 4169 |
+{
|
|
| 4170 |
+ char filename[40]; |
|
| 4171 |
+ time_t today2 = time(NULL); |
|
| 4172 |
+ struct tm *today = localtime(&today2); |
|
| 4173 |
+ |
|
| 4174 |
+ snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, |
|
| 4175 |
+ today->tm_sec); |
|
| 4176 |
+ return opt_vstats_file(opt, filename); |
|
| 4177 |
+} |
|
| 4178 |
+ |
|
| 4179 |
+static int opt_bsf(const char *opt, const char *arg) |
|
| 4180 |
+{
|
|
| 4181 |
+ AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '=' |
|
| 4182 |
+ AVBitStreamFilterContext **bsfp; |
|
| 4183 |
+ |
|
| 4184 |
+ if(!bsfc){
|
|
| 4185 |
+ fprintf(stderr, "Unknown bitstream filter %s\n", arg); |
|
| 4186 |
+ exit_program(1); |
|
| 4187 |
+ } |
|
| 4188 |
+ |
|
| 4189 |
+ bsfp= *opt == 'v' ? &video_bitstream_filters : |
|
| 4190 |
+ *opt == 'a' ? &audio_bitstream_filters : |
|
| 4191 |
+ &subtitle_bitstream_filters; |
|
| 4192 |
+ while(*bsfp) |
|
| 4193 |
+ bsfp= &(*bsfp)->next; |
|
| 4194 |
+ |
|
| 4195 |
+ *bsfp= bsfc; |
|
| 4196 |
+ |
|
| 4197 |
+ return 0; |
|
| 4198 |
+} |
|
| 4199 |
+ |
|
| 4200 |
+static int opt_preset(const char *opt, const char *arg) |
|
| 4201 |
+{
|
|
| 4202 |
+ FILE *f=NULL; |
|
| 4203 |
+ char filename[1000], tmp[1000], tmp2[1000], line[1000]; |
|
| 4204 |
+ char *codec_name = *opt == 'v' ? video_codec_name : |
|
| 4205 |
+ *opt == 'a' ? audio_codec_name : |
|
| 4206 |
+ subtitle_codec_name; |
|
| 4207 |
+ |
|
| 4208 |
+ if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
|
|
| 4209 |
+ fprintf(stderr, "File for preset '%s' not found\n", arg); |
|
| 4210 |
+ exit_program(1); |
|
| 4211 |
+ } |
|
| 4212 |
+ |
|
| 4213 |
+ while(!feof(f)){
|
|
| 4214 |
+ int e= fscanf(f, "%999[^\n]\n", line) - 1; |
|
| 4215 |
+ if(line[0] == '#' && !e) |
|
| 4216 |
+ continue; |
|
| 4217 |
+ e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2; |
|
| 4218 |
+ if(e){
|
|
| 4219 |
+ fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line); |
|
| 4220 |
+ exit_program(1); |
|
| 4221 |
+ } |
|
| 4222 |
+ if(!strcmp(tmp, "acodec")){
|
|
| 4223 |
+ opt_audio_codec(tmp, tmp2); |
|
| 4224 |
+ }else if(!strcmp(tmp, "vcodec")){
|
|
| 4225 |
+ opt_video_codec(tmp, tmp2); |
|
| 4226 |
+ }else if(!strcmp(tmp, "scodec")){
|
|
| 4227 |
+ opt_subtitle_codec(tmp, tmp2); |
|
| 4228 |
+ }else if(!strcmp(tmp, "dcodec")){
|
|
| 4229 |
+ opt_data_codec(tmp, tmp2); |
|
| 4230 |
+ }else if(opt_default(tmp, tmp2) < 0){
|
|
| 4231 |
+ fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2); |
|
| 4232 |
+ exit_program(1); |
|
| 4233 |
+ } |
|
| 4234 |
+ } |
|
| 4235 |
+ |
|
| 4236 |
+ fclose(f); |
|
| 4237 |
+ |
|
| 4238 |
+ return 0; |
|
| 4239 |
+} |
|
| 4240 |
+ |
|
| 4241 |
+static const OptionDef options[] = {
|
|
| 4242 |
+ /* main options */ |
|
| 4243 |
+#include "cmdutils_common_opts.h" |
|
| 4244 |
+ { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
|
|
| 4245 |
+ { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
|
|
| 4246 |
+ { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
|
|
| 4247 |
+ { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file.stream[:syncfile.syncstream]" },
|
|
| 4248 |
+ { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "DEPRECATED set meta data information of outfile from infile",
|
|
| 4249 |
+ "outfile[,metadata]:infile[,metadata]" }, |
|
| 4250 |
+ { "map_metadata", HAS_ARG | OPT_EXPERT, {(void*)opt_map_metadata}, "set metadata information of outfile from infile",
|
|
| 4251 |
+ "outfile[,metadata]:infile[,metadata]" }, |
|
| 4252 |
+ { "map_chapters", HAS_ARG | OPT_EXPERT, {(void*)opt_map_chapters}, "set chapters mapping", "outfile:infile" },
|
|
| 4253 |
+ { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
|
|
| 4254 |
+ { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, //
|
|
| 4255 |
+ { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
|
|
| 4256 |
+ { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
|
|
| 4257 |
+ { "itsscale", HAS_ARG, {(void*)opt_input_ts_scale}, "set the input ts scale", "stream:scale" },
|
|
| 4258 |
+ { "timestamp", HAS_ARG, {(void*)opt_recording_timestamp}, "set the recording timestamp ('now' to set the current time)", "time" },
|
|
| 4259 |
+ { "metadata", HAS_ARG, {(void*)opt_metadata}, "add metadata", "string=string" },
|
|
| 4260 |
+ { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[AVMEDIA_TYPE_DATA]}, "set the number of data frames to record", "number" },
|
|
| 4261 |
+ { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
|
|
| 4262 |
+ "add timings for benchmarking" }, |
|
| 4263 |
+ { "timelimit", HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" },
|
|
| 4264 |
+ { "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump},
|
|
| 4265 |
+ "dump each input packet" }, |
|
| 4266 |
+ { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
|
|
| 4267 |
+ "when dumping packets, also dump the payload" }, |
|
| 4268 |
+ { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" },
|
|
| 4269 |
+ { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "deprecated, use -loop" },
|
|
| 4270 |
+ { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "deprecated, use -loop", "" },
|
|
| 4271 |
+ { "v", HAS_ARG, {(void*)opt_verbose}, "set the verbosity level", "number" },
|
|
| 4272 |
+ { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
|
|
| 4273 |
+ { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
|
|
| 4274 |
+ { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
|
|
| 4275 |
+ { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" },
|
|
| 4276 |
+ { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "threshold" },
|
|
| 4277 |
+ { "copyts", OPT_BOOL | OPT_EXPERT, {(void*)©_ts}, "copy timestamps" },
|
|
| 4278 |
+ { "copytb", OPT_BOOL | OPT_EXPERT, {(void*)©_tb}, "copy input stream time base when stream copying" },
|
|
| 4279 |
+ { "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, //
|
|
| 4280 |
+ { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "threshold" },
|
|
| 4281 |
+ { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" },
|
|
| 4282 |
+ { "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" },
|
|
| 4283 |
+ { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)©_initial_nonkeyframes}, "copy initial non-keyframes" },
|
|
| 4284 |
+ |
|
| 4285 |
+ /* video options */ |
|
| 4286 |
+ { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[AVMEDIA_TYPE_VIDEO]}, "set the number of video frames to record", "number" },
|
|
| 4287 |
+ { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
|
|
| 4288 |
+ { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
|
|
| 4289 |
+ { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
|
|
| 4290 |
+ { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" },
|
|
| 4291 |
+ { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
|
|
| 4292 |
+ { "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
|
|
| 4293 |
+ { "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
|
|
| 4294 |
+ { "cropright", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop}, "Removed, use the crop filter instead", "size" },
|
|
| 4295 |
+ { "padtop", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" },
|
|
| 4296 |
+ { "padbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" },
|
|
| 4297 |
+ { "padleft", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" },
|
|
| 4298 |
+ { "padright", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "size" },
|
|
| 4299 |
+ { "padcolor", HAS_ARG | OPT_VIDEO, {(void*)opt_pad}, "Removed, use the pad filter instead", "color" },
|
|
| 4300 |
+ { "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"},
|
|
| 4301 |
+ { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
|
|
| 4302 |
+ { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" },
|
|
| 4303 |
+ { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" },
|
|
| 4304 |
+ { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
|
|
| 4305 |
+ { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" },
|
|
| 4306 |
+ { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "threshold" },
|
|
| 4307 |
+ { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality},
|
|
| 4308 |
+ "use same quantizer as source (implies VBR)" }, |
|
| 4309 |
+ { "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" },
|
|
| 4310 |
+ { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" },
|
|
| 4311 |
+ { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace},
|
|
| 4312 |
+ "deinterlace pictures" }, |
|
| 4313 |
+ { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" },
|
|
| 4314 |
+ { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" },
|
|
| 4315 |
+ { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" },
|
|
| 4316 |
+#if CONFIG_AVFILTER |
|
| 4317 |
+ { "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" },
|
|
| 4318 |
+#endif |
|
| 4319 |
+ { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
|
|
| 4320 |
+ { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
|
|
| 4321 |
+ { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
|
|
| 4322 |
+ { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
|
|
| 4323 |
+ { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_codec_tag}, "force video tag/fourcc", "fourcc/tag" },
|
|
| 4324 |
+ { "newvideo", OPT_VIDEO, {(void*)opt_new_stream}, "add a new video stream to the current output stream" },
|
|
| 4325 |
+ { "vlang", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void *)&video_language}, "set the ISO 639 language code (3 letters) of the current video stream" , "code" },
|
|
| 4326 |
+ { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
|
|
| 4327 |
+ { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" },
|
|
| 4328 |
+ { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" },
|
|
| 4329 |
+ { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void *)&forced_key_frames}, "force key frames at specified timestamps", "timestamps" },
|
|
| 4330 |
+ |
|
| 4331 |
+ /* audio options */ |
|
| 4332 |
+ { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[AVMEDIA_TYPE_AUDIO]}, "set the number of audio frames to record", "number" },
|
|
| 4333 |
+ { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
|
|
| 4334 |
+ { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" },
|
|
| 4335 |
+ { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" },
|
|
| 4336 |
+ { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" },
|
|
| 4337 |
+ { "acodec", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" },
|
|
| 4338 |
+ { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_codec_tag}, "force audio tag/fourcc", "fourcc/tag" },
|
|
| 4339 |
+ { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, //
|
|
| 4340 |
+ { "newaudio", OPT_AUDIO, {(void*)opt_new_stream}, "add a new audio stream to the current output stream" },
|
|
| 4341 |
+ { "alang", HAS_ARG | OPT_STRING | OPT_AUDIO, {(void *)&audio_language}, "set the ISO 639 language code (3 letters) of the current audio stream" , "code" },
|
|
| 4342 |
+ { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO, {(void*)opt_audio_sample_fmt}, "set sample format, 'list' as argument shows all the sample formats supported", "format" },
|
|
| 4343 |
+ |
|
| 4344 |
+ /* subtitle options */ |
|
| 4345 |
+ { "sn", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_disable}, "disable subtitle" },
|
|
| 4346 |
+ { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" },
|
|
| 4347 |
+ { "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_stream}, "add a new subtitle stream to the current output stream" },
|
|
| 4348 |
+ { "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" },
|
|
| 4349 |
+ { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE, {(void*)opt_codec_tag}, "force subtitle tag/fourcc", "fourcc/tag" },
|
|
| 4350 |
+ |
|
| 4351 |
+ /* grab options */ |
|
| 4352 |
+ { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "deprecated, use -channel", "channel" },
|
|
| 4353 |
+ { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "deprecated, use -standard", "standard" },
|
|
| 4354 |
+ { "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
|
|
| 4355 |
+ |
|
| 4356 |
+ /* muxer options */ |
|
| 4357 |
+ { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_max_delay}, "set the maximum demux-decode delay", "seconds" },
|
|
| 4358 |
+ { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_preload}, "set the initial demux-decode delay", "seconds" },
|
|
| 4359 |
+ |
|
| 4360 |
+ { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" },
|
|
| 4361 |
+ { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" },
|
|
| 4362 |
+ { "sbsf", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream_filter" },
|
|
| 4363 |
+ |
|
| 4364 |
+ { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_preset}, "set the audio options to the indicated preset", "preset" },
|
|
| 4365 |
+ { "vpre", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_preset}, "set the video options to the indicated preset", "preset" },
|
|
| 4366 |
+ { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_preset}, "set the subtitle options to the indicated preset", "preset" },
|
|
| 4367 |
+ { "fpre", HAS_ARG | OPT_EXPERT, {(void*)opt_preset}, "set options from indicated preset file", "filename" },
|
|
| 4368 |
+ /* data codec support */ |
|
| 4369 |
+ { "dcodec", HAS_ARG | OPT_DATA, {(void*)opt_data_codec}, "force data codec ('copy' to copy stream)", "codec" },
|
|
| 4370 |
+ |
|
| 4371 |
+ { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
|
|
| 4372 |
+ { NULL, },
|
|
| 4373 |
+}; |
|
| 4374 |
+ |
|
| 4375 |
+int main(int argc, char **argv) |
|
| 4376 |
+{
|
|
| 4377 |
+ int64_t ti; |
|
| 4378 |
+ |
|
| 4379 |
+ av_log_set_flags(AV_LOG_SKIP_REPEATED); |
|
| 4380 |
+ |
|
| 4381 |
+ avcodec_register_all(); |
|
| 4382 |
+#if CONFIG_AVDEVICE |
|
| 4383 |
+ avdevice_register_all(); |
|
| 4384 |
+#endif |
|
| 4385 |
+#if CONFIG_AVFILTER |
|
| 4386 |
+ avfilter_register_all(); |
|
| 4387 |
+#endif |
|
| 4388 |
+ av_register_all(); |
|
| 4389 |
+ |
|
| 4390 |
+ avio_set_interrupt_cb(decode_interrupt_cb); |
|
| 4391 |
+ |
|
| 4392 |
+ init_opts(); |
|
| 4393 |
+ |
|
| 4394 |
+ show_banner(); |
|
| 4395 |
+ |
|
| 4396 |
+ /* parse options */ |
|
| 4397 |
+ parse_options(argc, argv, options, opt_output_file); |
|
| 4398 |
+ |
|
| 4399 |
+ if(nb_output_files <= 0 && nb_input_files == 0) {
|
|
| 4400 |
+ show_usage(); |
|
| 4401 |
+ fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name); |
|
| 4402 |
+ exit_program(1); |
|
| 4403 |
+ } |
|
| 4404 |
+ |
|
| 4405 |
+ /* file converter / grab */ |
|
| 4406 |
+ if (nb_output_files <= 0) {
|
|
| 4407 |
+ fprintf(stderr, "At least one output file must be specified\n"); |
|
| 4408 |
+ exit_program(1); |
|
| 4409 |
+ } |
|
| 4410 |
+ |
|
| 4411 |
+ if (nb_input_files == 0) {
|
|
| 4412 |
+ fprintf(stderr, "At least one input file must be specified\n"); |
|
| 4413 |
+ exit_program(1); |
|
| 4414 |
+ } |
|
| 4415 |
+ |
|
| 4416 |
+ ti = getutime(); |
|
| 4417 |
+ if (transcode(output_files, nb_output_files, input_files, nb_input_files, |
|
| 4418 |
+ stream_maps, nb_stream_maps) < 0) |
|
| 4419 |
+ exit_program(1); |
|
| 4420 |
+ ti = getutime() - ti; |
|
| 4421 |
+ if (do_benchmark) {
|
|
| 4422 |
+ int maxrss = getmaxrss() / 1024; |
|
| 4423 |
+ printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
|
|
| 4424 |
+ } |
|
| 4425 |
+ |
|
| 4426 |
+ return exit_program(0); |
|
| 4427 |
+} |
| ... | ... |
@@ -754,9 +754,9 @@ FILE *get_preset_file(char *filename, size_t filename_size, |
| 754 | 754 |
{
|
| 755 | 755 |
FILE *f = NULL; |
| 756 | 756 |
int i; |
| 757 |
- const char *base[3]= { getenv("FFMPEG_DATADIR"),
|
|
| 757 |
+ const char *base[3]= { getenv("AVCONV_DATADIR"),
|
|
| 758 | 758 |
getenv("HOME"),
|
| 759 |
- FFMPEG_DATADIR, |
|
| 759 |
+ AVCONV_DATADIR, |
|
| 760 | 760 |
}; |
| 761 | 761 |
|
| 762 | 762 |
if (is_path) {
|
| ... | ... |
@@ -766,11 +766,11 @@ FILE *get_preset_file(char *filename, size_t filename_size, |
| 766 | 766 |
for (i = 0; i < 3 && !f; i++) {
|
| 767 | 767 |
if (!base[i]) |
| 768 | 768 |
continue; |
| 769 |
- snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", preset_name); |
|
| 769 |
+ snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.avconv", preset_name); |
|
| 770 | 770 |
f = fopen(filename, "r"); |
| 771 | 771 |
if (!f && codec_name) {
|
| 772 | 772 |
snprintf(filename, filename_size, |
| 773 |
- "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec_name, preset_name); |
|
| 773 |
+ "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.avconv", codec_name, preset_name); |
|
| 774 | 774 |
f = fopen(filename, "r"); |
| 775 | 775 |
} |
| 776 | 776 |
} |
| ... | ... |
@@ -65,7 +65,7 @@ Standard options: |
| 65 | 65 |
--disable-logging do not log configure debug information |
| 66 | 66 |
--prefix=PREFIX install in PREFIX [$prefix] |
| 67 | 67 |
--bindir=DIR install binaries in DIR [PREFIX/bin] |
| 68 |
- --datadir=DIR install data files in DIR [PREFIX/share/ffmpeg] |
|
| 68 |
+ --datadir=DIR install data files in DIR [PREFIX/share/avconv] |
|
| 69 | 69 |
--libdir=DIR install libs in DIR [PREFIX/lib] |
| 70 | 70 |
--shlibdir=DIR install shared libs in DIR [PREFIX/lib] |
| 71 | 71 |
--incdir=DIR install includes in DIR [PREFIX/include] |
| ... | ... |
@@ -81,6 +81,7 @@ Configuration options: |
| 81 | 81 |
and binaries will be unredistributable [no] |
| 82 | 82 |
--disable-doc do not build documentation |
| 83 | 83 |
--disable-ffmpeg disable ffmpeg build |
| 84 |
+ --disable-avconv disable avconv build |
|
| 84 | 85 |
--disable-avplay disable avplay build |
| 85 | 86 |
--disable-avprobe disable avprobe build |
| 86 | 87 |
--disable-avserver disable avserver build |
| ... | ... |
@@ -913,6 +914,7 @@ CONFIG_LIST=" |
| 913 | 913 |
dxva2 |
| 914 | 914 |
fastdiv |
| 915 | 915 |
ffmpeg |
| 916 |
+ avconv |
|
| 916 | 917 |
avplay |
| 917 | 918 |
avprobe |
| 918 | 919 |
avserver |
| ... | ... |
@@ -1489,6 +1491,8 @@ postproc_deps="gpl" |
| 1489 | 1489 |
# programs |
| 1490 | 1490 |
ffmpeg_deps="avcodec avformat swscale" |
| 1491 | 1491 |
ffmpeg_select="buffer_filter" |
| 1492 |
+av_deps="avcodec avformat swscale" |
|
| 1493 |
+av_select="buffer_filter" |
|
| 1492 | 1494 |
avplay_deps="avcodec avformat swscale sdl" |
| 1493 | 1495 |
avplay_select="rdft" |
| 1494 | 1496 |
avprobe_deps="avcodec avformat" |
| ... | ... |
@@ -1595,7 +1599,7 @@ logfile="config.log" |
| 1595 | 1595 |
# installation paths |
| 1596 | 1596 |
prefix_default="/usr/local" |
| 1597 | 1597 |
bindir_default='${prefix}/bin'
|
| 1598 |
-datadir_default='${prefix}/share/ffmpeg'
|
|
| 1598 |
+datadir_default='${prefix}/share/avconv'
|
|
| 1599 | 1599 |
incdir_default='${prefix}/include'
|
| 1600 | 1600 |
libdir_default='${prefix}/lib'
|
| 1601 | 1601 |
mandir_default='${prefix}/share/man'
|
| ... | ... |
@@ -1635,6 +1639,7 @@ enable debug |
| 1635 | 1635 |
enable doc |
| 1636 | 1636 |
enable fastdiv |
| 1637 | 1637 |
enable ffmpeg |
| 1638 |
+enable avconv |
|
| 1638 | 1639 |
enable avplay |
| 1639 | 1640 |
enable avprobe |
| 1640 | 1641 |
enable avserver |
| ... | ... |
@@ -3284,7 +3289,7 @@ cat > $TMPH <<EOF |
| 3284 | 3284 |
#define LIBAV_CONFIG_H |
| 3285 | 3285 |
#define LIBAV_CONFIGURATION "$(c_escape $LIBAV_CONFIGURATION)" |
| 3286 | 3286 |
#define LIBAV_LICENSE "$(c_escape $license)" |
| 3287 |
-#define FFMPEG_DATADIR "$(eval c_escape $datadir)" |
|
| 3287 |
+#define AVCONV_DATADIR "$(eval c_escape $datadir)" |
|
| 3288 | 3288 |
#define CC_TYPE "$cc_type" |
| 3289 | 3289 |
#define CC_VERSION $cc_version |
| 3290 | 3290 |
#define restrict $_restrict |
| 3291 | 3291 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,1065 @@ |
| 0 |
+\input texinfo @c -*- texinfo -*- |
|
| 1 |
+ |
|
| 2 |
+@settitle avconv Documentation |
|
| 3 |
+@titlepage |
|
| 4 |
+@center @titlefont{avconv Documentation}
|
|
| 5 |
+@end titlepage |
|
| 6 |
+ |
|
| 7 |
+@top |
|
| 8 |
+ |
|
| 9 |
+@contents |
|
| 10 |
+ |
|
| 11 |
+@chapter Synopsis |
|
| 12 |
+ |
|
| 13 |
+The generic syntax is: |
|
| 14 |
+ |
|
| 15 |
+@example |
|
| 16 |
+@c man begin SYNOPSIS |
|
| 17 |
+avconv [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}...
|
|
| 18 |
+@c man end |
|
| 19 |
+@end example |
|
| 20 |
+ |
|
| 21 |
+@chapter Description |
|
| 22 |
+@c man begin DESCRIPTION |
|
| 23 |
+ |
|
| 24 |
+avconv is a very fast video and audio converter that can also grab from |
|
| 25 |
+a live audio/video source. It can also convert between arbitrary sample |
|
| 26 |
+rates and resize video on the fly with a high quality polyphase filter. |
|
| 27 |
+ |
|
| 28 |
+The command line interface is designed to be intuitive, in the sense |
|
| 29 |
+that avconv tries to figure out all parameters that can possibly be |
|
| 30 |
+derived automatically. You usually only have to specify the target |
|
| 31 |
+bitrate you want. |
|
| 32 |
+ |
|
| 33 |
+As a general rule, options are applied to the next specified |
|
| 34 |
+file. Therefore, order is important, and you can have the same |
|
| 35 |
+option on the command line multiple times. Each occurrence is |
|
| 36 |
+then applied to the next input or output file. |
|
| 37 |
+ |
|
| 38 |
+@itemize |
|
| 39 |
+@item |
|
| 40 |
+To set the video bitrate of the output file to 64kbit/s: |
|
| 41 |
+@example |
|
| 42 |
+avconv -i input.avi -b 64k output.avi |
|
| 43 |
+@end example |
|
| 44 |
+ |
|
| 45 |
+@item |
|
| 46 |
+To force the frame rate of the output file to 24 fps: |
|
| 47 |
+@example |
|
| 48 |
+avconv -i input.avi -r 24 output.avi |
|
| 49 |
+@end example |
|
| 50 |
+ |
|
| 51 |
+@item |
|
| 52 |
+To force the frame rate of the input file (valid for raw formats only) |
|
| 53 |
+to 1 fps and the frame rate of the output file to 24 fps: |
|
| 54 |
+@example |
|
| 55 |
+avconv -r 1 -i input.m2v -r 24 output.avi |
|
| 56 |
+@end example |
|
| 57 |
+@end itemize |
|
| 58 |
+ |
|
| 59 |
+The format option may be needed for raw input files. |
|
| 60 |
+ |
|
| 61 |
+By default avconv tries to convert as losslessly as possible: It |
|
| 62 |
+uses the same audio and video parameters for the outputs as the one |
|
| 63 |
+specified for the inputs. |
|
| 64 |
+ |
|
| 65 |
+@c man end DESCRIPTION |
|
| 66 |
+ |
|
| 67 |
+@chapter Options |
|
| 68 |
+@c man begin OPTIONS |
|
| 69 |
+ |
|
| 70 |
+@include fftools-common-opts.texi |
|
| 71 |
+ |
|
| 72 |
+@section Main options |
|
| 73 |
+ |
|
| 74 |
+@table @option |
|
| 75 |
+ |
|
| 76 |
+@item -f @var{fmt}
|
|
| 77 |
+Force format. |
|
| 78 |
+ |
|
| 79 |
+@item -i @var{filename}
|
|
| 80 |
+input file name |
|
| 81 |
+ |
|
| 82 |
+@item -y |
|
| 83 |
+Overwrite output files. |
|
| 84 |
+ |
|
| 85 |
+@item -t @var{duration}
|
|
| 86 |
+Restrict the transcoded/captured video sequence |
|
| 87 |
+to the duration specified in seconds. |
|
| 88 |
+@code{hh:mm:ss[.xxx]} syntax is also supported.
|
|
| 89 |
+ |
|
| 90 |
+@item -fs @var{limit_size}
|
|
| 91 |
+Set the file size limit. |
|
| 92 |
+ |
|
| 93 |
+@item -ss @var{position}
|
|
| 94 |
+Seek to given time position in seconds. |
|
| 95 |
+@code{hh:mm:ss[.xxx]} syntax is also supported.
|
|
| 96 |
+ |
|
| 97 |
+@item -itsoffset @var{offset}
|
|
| 98 |
+Set the input time offset in seconds. |
|
| 99 |
+@code{[-]hh:mm:ss[.xxx]} syntax is also supported.
|
|
| 100 |
+This option affects all the input files that follow it. |
|
| 101 |
+The offset is added to the timestamps of the input files. |
|
| 102 |
+Specifying a positive offset means that the corresponding |
|
| 103 |
+streams are delayed by 'offset' seconds. |
|
| 104 |
+ |
|
| 105 |
+@item -timestamp @var{time}
|
|
| 106 |
+Set the recording timestamp in the container. |
|
| 107 |
+The syntax for @var{time} is:
|
|
| 108 |
+@example |
|
| 109 |
+now|([(YYYY-MM-DD|YYYYMMDD)[T|t| ]]((HH[:MM[:SS[.m...]]])|(HH[MM[SS[.m...]]]))[Z|z]) |
|
| 110 |
+@end example |
|
| 111 |
+If the value is "now" it takes the current time. |
|
| 112 |
+Time is local time unless 'Z' or 'z' is appended, in which case it is |
|
| 113 |
+interpreted as UTC. |
|
| 114 |
+If the year-month-day part is not specified it takes the current |
|
| 115 |
+year-month-day. |
|
| 116 |
+ |
|
| 117 |
+@item -metadata @var{key}=@var{value}
|
|
| 118 |
+Set a metadata key/value pair. |
|
| 119 |
+ |
|
| 120 |
+For example, for setting the title in the output file: |
|
| 121 |
+@example |
|
| 122 |
+avconv -i in.avi -metadata title="my title" out.flv |
|
| 123 |
+@end example |
|
| 124 |
+ |
|
| 125 |
+@item -v @var{number}
|
|
| 126 |
+Set the logging verbosity level. |
|
| 127 |
+ |
|
| 128 |
+@item -target @var{type}
|
|
| 129 |
+Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd",
|
|
| 130 |
+"ntsc-svcd", ... ). All the format options (bitrate, codecs, |
|
| 131 |
+buffer sizes) are then set automatically. You can just type: |
|
| 132 |
+ |
|
| 133 |
+@example |
|
| 134 |
+avconv -i myfile.avi -target vcd /tmp/vcd.mpg |
|
| 135 |
+@end example |
|
| 136 |
+ |
|
| 137 |
+Nevertheless you can specify additional options as long as you know |
|
| 138 |
+they do not conflict with the standard, as in: |
|
| 139 |
+ |
|
| 140 |
+@example |
|
| 141 |
+avconv -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg |
|
| 142 |
+@end example |
|
| 143 |
+ |
|
| 144 |
+@item -dframes @var{number}
|
|
| 145 |
+Set the number of data frames to record. |
|
| 146 |
+ |
|
| 147 |
+@item -scodec @var{codec}
|
|
| 148 |
+Force subtitle codec ('copy' to copy stream).
|
|
| 149 |
+ |
|
| 150 |
+@item -newsubtitle |
|
| 151 |
+Add a new subtitle stream to the current output stream. |
|
| 152 |
+ |
|
| 153 |
+@item -slang @var{code}
|
|
| 154 |
+Set the ISO 639 language code (3 letters) of the current subtitle stream. |
|
| 155 |
+ |
|
| 156 |
+@end table |
|
| 157 |
+ |
|
| 158 |
+@section Video Options |
|
| 159 |
+ |
|
| 160 |
+@table @option |
|
| 161 |
+@item -vframes @var{number}
|
|
| 162 |
+Set the number of video frames to record. |
|
| 163 |
+@item -r @var{fps}
|
|
| 164 |
+Set frame rate (Hz value, fraction or abbreviation), (default = 25). |
|
| 165 |
+@item -s @var{size}
|
|
| 166 |
+Set frame size. The format is @samp{wxh} (avserver default = 160x128, avconv default = same as source).
|
|
| 167 |
+The following abbreviations are recognized: |
|
| 168 |
+@table @samp |
|
| 169 |
+@item sqcif |
|
| 170 |
+128x96 |
|
| 171 |
+@item qcif |
|
| 172 |
+176x144 |
|
| 173 |
+@item cif |
|
| 174 |
+352x288 |
|
| 175 |
+@item 4cif |
|
| 176 |
+704x576 |
|
| 177 |
+@item 16cif |
|
| 178 |
+1408x1152 |
|
| 179 |
+@item qqvga |
|
| 180 |
+160x120 |
|
| 181 |
+@item qvga |
|
| 182 |
+320x240 |
|
| 183 |
+@item vga |
|
| 184 |
+640x480 |
|
| 185 |
+@item svga |
|
| 186 |
+800x600 |
|
| 187 |
+@item xga |
|
| 188 |
+1024x768 |
|
| 189 |
+@item uxga |
|
| 190 |
+1600x1200 |
|
| 191 |
+@item qxga |
|
| 192 |
+2048x1536 |
|
| 193 |
+@item sxga |
|
| 194 |
+1280x1024 |
|
| 195 |
+@item qsxga |
|
| 196 |
+2560x2048 |
|
| 197 |
+@item hsxga |
|
| 198 |
+5120x4096 |
|
| 199 |
+@item wvga |
|
| 200 |
+852x480 |
|
| 201 |
+@item wxga |
|
| 202 |
+1366x768 |
|
| 203 |
+@item wsxga |
|
| 204 |
+1600x1024 |
|
| 205 |
+@item wuxga |
|
| 206 |
+1920x1200 |
|
| 207 |
+@item woxga |
|
| 208 |
+2560x1600 |
|
| 209 |
+@item wqsxga |
|
| 210 |
+3200x2048 |
|
| 211 |
+@item wquxga |
|
| 212 |
+3840x2400 |
|
| 213 |
+@item whsxga |
|
| 214 |
+6400x4096 |
|
| 215 |
+@item whuxga |
|
| 216 |
+7680x4800 |
|
| 217 |
+@item cga |
|
| 218 |
+320x200 |
|
| 219 |
+@item ega |
|
| 220 |
+640x350 |
|
| 221 |
+@item hd480 |
|
| 222 |
+852x480 |
|
| 223 |
+@item hd720 |
|
| 224 |
+1280x720 |
|
| 225 |
+@item hd1080 |
|
| 226 |
+1920x1080 |
|
| 227 |
+@end table |
|
| 228 |
+ |
|
| 229 |
+@item -aspect @var{aspect}
|
|
| 230 |
+Set the video display aspect ratio specified by @var{aspect}.
|
|
| 231 |
+ |
|
| 232 |
+@var{aspect} can be a floating point number string, or a string of the
|
|
| 233 |
+form @var{num}:@var{den}, where @var{num} and @var{den} are the
|
|
| 234 |
+numerator and denominator of the aspect ratio. For example "4:3", |
|
| 235 |
+"16:9", "1.3333", and "1.7777" are valid argument values. |
|
| 236 |
+ |
|
| 237 |
+@item -croptop @var{size}
|
|
| 238 |
+@item -cropbottom @var{size}
|
|
| 239 |
+@item -cropleft @var{size}
|
|
| 240 |
+@item -cropright @var{size}
|
|
| 241 |
+All the crop options have been removed. Use -vf |
|
| 242 |
+crop=width:height:x:y instead. |
|
| 243 |
+ |
|
| 244 |
+@item -padtop @var{size}
|
|
| 245 |
+@item -padbottom @var{size}
|
|
| 246 |
+@item -padleft @var{size}
|
|
| 247 |
+@item -padright @var{size}
|
|
| 248 |
+@item -padcolor @var{hex_color}
|
|
| 249 |
+All the pad options have been removed. Use -vf |
|
| 250 |
+pad=width:height:x:y:color instead. |
|
| 251 |
+@item -vn |
|
| 252 |
+Disable video recording. |
|
| 253 |
+@item -bt @var{tolerance}
|
|
| 254 |
+Set video bitrate tolerance (in bits, default 4000k). |
|
| 255 |
+Has a minimum value of: (target_bitrate/target_framerate). |
|
| 256 |
+In 1-pass mode, bitrate tolerance specifies how far ratecontrol is |
|
| 257 |
+willing to deviate from the target average bitrate value. This is |
|
| 258 |
+not related to min/max bitrate. Lowering tolerance too much has |
|
| 259 |
+an adverse effect on quality. |
|
| 260 |
+@item -maxrate @var{bitrate}
|
|
| 261 |
+Set max video bitrate (in bit/s). |
|
| 262 |
+Requires -bufsize to be set. |
|
| 263 |
+@item -minrate @var{bitrate}
|
|
| 264 |
+Set min video bitrate (in bit/s). |
|
| 265 |
+Most useful in setting up a CBR encode: |
|
| 266 |
+@example |
|
| 267 |
+avconv -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v |
|
| 268 |
+@end example |
|
| 269 |
+It is of little use elsewise. |
|
| 270 |
+@item -bufsize @var{size}
|
|
| 271 |
+Set video buffer verifier buffer size (in bits). |
|
| 272 |
+@item -vcodec @var{codec}
|
|
| 273 |
+Force video codec to @var{codec}. Use the @code{copy} special value to
|
|
| 274 |
+tell that the raw codec data must be copied as is. |
|
| 275 |
+@item -sameq |
|
| 276 |
+Use same quantizer as source (implies VBR). |
|
| 277 |
+ |
|
| 278 |
+@item -pass @var{n}
|
|
| 279 |
+Select the pass number (1 or 2). It is used to do two-pass |
|
| 280 |
+video encoding. The statistics of the video are recorded in the first |
|
| 281 |
+pass into a log file (see also the option -passlogfile), |
|
| 282 |
+and in the second pass that log file is used to generate the video |
|
| 283 |
+at the exact requested bitrate. |
|
| 284 |
+On pass 1, you may just deactivate audio and set output to null, |
|
| 285 |
+examples for Windows and Unix: |
|
| 286 |
+@example |
|
| 287 |
+avconv -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y NUL |
|
| 288 |
+avconv -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y /dev/null |
|
| 289 |
+@end example |
|
| 290 |
+ |
|
| 291 |
+@item -passlogfile @var{prefix}
|
|
| 292 |
+Set two-pass log file name prefix to @var{prefix}, the default file name
|
|
| 293 |
+prefix is ``av2pass''. The complete file name will be |
|
| 294 |
+@file{PREFIX-N.log}, where N is a number specific to the output
|
|
| 295 |
+stream. |
|
| 296 |
+ |
|
| 297 |
+@item -newvideo |
|
| 298 |
+Add a new video stream to the current output stream. |
|
| 299 |
+ |
|
| 300 |
+@item -vlang @var{code}
|
|
| 301 |
+Set the ISO 639 language code (3 letters) of the current video stream. |
|
| 302 |
+ |
|
| 303 |
+@item -vf @var{filter_graph}
|
|
| 304 |
+@var{filter_graph} is a description of the filter graph to apply to
|
|
| 305 |
+the input video. |
|
| 306 |
+Use the option "-filters" to show all the available filters (including |
|
| 307 |
+also sources and sinks). |
|
| 308 |
+ |
|
| 309 |
+@end table |
|
| 310 |
+ |
|
| 311 |
+@section Advanced Video Options |
|
| 312 |
+ |
|
| 313 |
+@table @option |
|
| 314 |
+@item -pix_fmt @var{format}
|
|
| 315 |
+Set pixel format. Use 'list' as parameter to show all the supported |
|
| 316 |
+pixel formats. |
|
| 317 |
+@item -sws_flags @var{flags}
|
|
| 318 |
+Set SwScaler flags. |
|
| 319 |
+@item -g @var{gop_size}
|
|
| 320 |
+Set the group of pictures size. |
|
| 321 |
+@item -intra |
|
| 322 |
+Use only intra frames. |
|
| 323 |
+@item -vdt @var{n}
|
|
| 324 |
+Discard threshold. |
|
| 325 |
+@item -qscale @var{q}
|
|
| 326 |
+Use fixed video quantizer scale (VBR). |
|
| 327 |
+@item -qmin @var{q}
|
|
| 328 |
+minimum video quantizer scale (VBR) |
|
| 329 |
+@item -qmax @var{q}
|
|
| 330 |
+maximum video quantizer scale (VBR) |
|
| 331 |
+@item -qdiff @var{q}
|
|
| 332 |
+maximum difference between the quantizer scales (VBR) |
|
| 333 |
+@item -qblur @var{blur}
|
|
| 334 |
+video quantizer scale blur (VBR) (range 0.0 - 1.0) |
|
| 335 |
+@item -qcomp @var{compression}
|
|
| 336 |
+video quantizer scale compression (VBR) (default 0.5). |
|
| 337 |
+Constant of ratecontrol equation. Recommended range for default rc_eq: 0.0-1.0 |
|
| 338 |
+ |
|
| 339 |
+@item -lmin @var{lambda}
|
|
| 340 |
+minimum video lagrange factor (VBR) |
|
| 341 |
+@item -lmax @var{lambda}
|
|
| 342 |
+max video lagrange factor (VBR) |
|
| 343 |
+@item -mblmin @var{lambda}
|
|
| 344 |
+minimum macroblock quantizer scale (VBR) |
|
| 345 |
+@item -mblmax @var{lambda}
|
|
| 346 |
+maximum macroblock quantizer scale (VBR) |
|
| 347 |
+ |
|
| 348 |
+These four options (lmin, lmax, mblmin, mblmax) use 'lambda' units, |
|
| 349 |
+but you may use the QP2LAMBDA constant to easily convert from 'q' units: |
|
| 350 |
+@example |
|
| 351 |
+avconv -i src.ext -lmax 21*QP2LAMBDA dst.ext |
|
| 352 |
+@end example |
|
| 353 |
+ |
|
| 354 |
+@item -rc_init_cplx @var{complexity}
|
|
| 355 |
+initial complexity for single pass encoding |
|
| 356 |
+@item -b_qfactor @var{factor}
|
|
| 357 |
+qp factor between P- and B-frames |
|
| 358 |
+@item -i_qfactor @var{factor}
|
|
| 359 |
+qp factor between P- and I-frames |
|
| 360 |
+@item -b_qoffset @var{offset}
|
|
| 361 |
+qp offset between P- and B-frames |
|
| 362 |
+@item -i_qoffset @var{offset}
|
|
| 363 |
+qp offset between P- and I-frames |
|
| 364 |
+@item -rc_eq @var{equation}
|
|
| 365 |
+Set rate control equation (see section "Expression Evaluation") |
|
| 366 |
+(default = @code{tex^qComp}).
|
|
| 367 |
+ |
|
| 368 |
+When computing the rate control equation expression, besides the |
|
| 369 |
+standard functions defined in the section "Expression Evaluation", the |
|
| 370 |
+following functions are available: |
|
| 371 |
+@table @var |
|
| 372 |
+@item bits2qp(bits) |
|
| 373 |
+@item qp2bits(qp) |
|
| 374 |
+@end table |
|
| 375 |
+ |
|
| 376 |
+and the following constants are available: |
|
| 377 |
+@table @var |
|
| 378 |
+@item iTex |
|
| 379 |
+@item pTex |
|
| 380 |
+@item tex |
|
| 381 |
+@item mv |
|
| 382 |
+@item fCode |
|
| 383 |
+@item iCount |
|
| 384 |
+@item mcVar |
|
| 385 |
+@item var |
|
| 386 |
+@item isI |
|
| 387 |
+@item isP |
|
| 388 |
+@item isB |
|
| 389 |
+@item avgQP |
|
| 390 |
+@item qComp |
|
| 391 |
+@item avgIITex |
|
| 392 |
+@item avgPITex |
|
| 393 |
+@item avgPPTex |
|
| 394 |
+@item avgBPTex |
|
| 395 |
+@item avgTex |
|
| 396 |
+@end table |
|
| 397 |
+ |
|
| 398 |
+@item -rc_override @var{override}
|
|
| 399 |
+rate control override for specific intervals |
|
| 400 |
+@item -me_method @var{method}
|
|
| 401 |
+Set motion estimation method to @var{method}.
|
|
| 402 |
+Available methods are (from lowest to best quality): |
|
| 403 |
+@table @samp |
|
| 404 |
+@item zero |
|
| 405 |
+Try just the (0, 0) vector. |
|
| 406 |
+@item phods |
|
| 407 |
+@item log |
|
| 408 |
+@item x1 |
|
| 409 |
+@item hex |
|
| 410 |
+@item umh |
|
| 411 |
+@item epzs |
|
| 412 |
+(default method) |
|
| 413 |
+@item full |
|
| 414 |
+exhaustive search (slow and marginally better than epzs) |
|
| 415 |
+@end table |
|
| 416 |
+ |
|
| 417 |
+@item -dct_algo @var{algo}
|
|
| 418 |
+Set DCT algorithm to @var{algo}. Available values are:
|
|
| 419 |
+@table @samp |
|
| 420 |
+@item 0 |
|
| 421 |
+FF_DCT_AUTO (default) |
|
| 422 |
+@item 1 |
|
| 423 |
+FF_DCT_FASTINT |
|
| 424 |
+@item 2 |
|
| 425 |
+FF_DCT_INT |
|
| 426 |
+@item 3 |
|
| 427 |
+FF_DCT_MMX |
|
| 428 |
+@item 4 |
|
| 429 |
+FF_DCT_MLIB |
|
| 430 |
+@item 5 |
|
| 431 |
+FF_DCT_ALTIVEC |
|
| 432 |
+@end table |
|
| 433 |
+ |
|
| 434 |
+@item -idct_algo @var{algo}
|
|
| 435 |
+Set IDCT algorithm to @var{algo}. Available values are:
|
|
| 436 |
+@table @samp |
|
| 437 |
+@item 0 |
|
| 438 |
+FF_IDCT_AUTO (default) |
|
| 439 |
+@item 1 |
|
| 440 |
+FF_IDCT_INT |
|
| 441 |
+@item 2 |
|
| 442 |
+FF_IDCT_SIMPLE |
|
| 443 |
+@item 3 |
|
| 444 |
+FF_IDCT_SIMPLEMMX |
|
| 445 |
+@item 4 |
|
| 446 |
+FF_IDCT_LIBMPEG2MMX |
|
| 447 |
+@item 5 |
|
| 448 |
+FF_IDCT_PS2 |
|
| 449 |
+@item 6 |
|
| 450 |
+FF_IDCT_MLIB |
|
| 451 |
+@item 7 |
|
| 452 |
+FF_IDCT_ARM |
|
| 453 |
+@item 8 |
|
| 454 |
+FF_IDCT_ALTIVEC |
|
| 455 |
+@item 9 |
|
| 456 |
+FF_IDCT_SH4 |
|
| 457 |
+@item 10 |
|
| 458 |
+FF_IDCT_SIMPLEARM |
|
| 459 |
+@end table |
|
| 460 |
+ |
|
| 461 |
+@item -er @var{n}
|
|
| 462 |
+Set error resilience to @var{n}.
|
|
| 463 |
+@table @samp |
|
| 464 |
+@item 1 |
|
| 465 |
+FF_ER_CAREFUL (default) |
|
| 466 |
+@item 2 |
|
| 467 |
+FF_ER_COMPLIANT |
|
| 468 |
+@item 3 |
|
| 469 |
+FF_ER_AGGRESSIVE |
|
| 470 |
+@item 4 |
|
| 471 |
+FF_ER_VERY_AGGRESSIVE |
|
| 472 |
+@end table |
|
| 473 |
+ |
|
| 474 |
+@item -ec @var{bit_mask}
|
|
| 475 |
+Set error concealment to @var{bit_mask}. @var{bit_mask} is a bit mask of
|
|
| 476 |
+the following values: |
|
| 477 |
+@table @samp |
|
| 478 |
+@item 1 |
|
| 479 |
+FF_EC_GUESS_MVS (default = enabled) |
|
| 480 |
+@item 2 |
|
| 481 |
+FF_EC_DEBLOCK (default = enabled) |
|
| 482 |
+@end table |
|
| 483 |
+ |
|
| 484 |
+@item -bf @var{frames}
|
|
| 485 |
+Use 'frames' B-frames (supported for MPEG-1, MPEG-2 and MPEG-4). |
|
| 486 |
+@item -mbd @var{mode}
|
|
| 487 |
+macroblock decision |
|
| 488 |
+@table @samp |
|
| 489 |
+@item 0 |
|
| 490 |
+FF_MB_DECISION_SIMPLE: Use mb_cmp (cannot change it yet in avconv). |
|
| 491 |
+@item 1 |
|
| 492 |
+FF_MB_DECISION_BITS: Choose the one which needs the fewest bits. |
|
| 493 |
+@item 2 |
|
| 494 |
+FF_MB_DECISION_RD: rate distortion |
|
| 495 |
+@end table |
|
| 496 |
+ |
|
| 497 |
+@item -4mv |
|
| 498 |
+Use four motion vector by macroblock (MPEG-4 only). |
|
| 499 |
+@item -part |
|
| 500 |
+Use data partitioning (MPEG-4 only). |
|
| 501 |
+@item -bug @var{param}
|
|
| 502 |
+Work around encoder bugs that are not auto-detected. |
|
| 503 |
+@item -strict @var{strictness}
|
|
| 504 |
+How strictly to follow the standards. |
|
| 505 |
+@item -aic |
|
| 506 |
+Enable Advanced intra coding (h263+). |
|
| 507 |
+@item -umv |
|
| 508 |
+Enable Unlimited Motion Vector (h263+) |
|
| 509 |
+ |
|
| 510 |
+@item -deinterlace |
|
| 511 |
+Deinterlace pictures. |
|
| 512 |
+@item -ilme |
|
| 513 |
+Force interlacing support in encoder (MPEG-2 and MPEG-4 only). |
|
| 514 |
+Use this option if your input file is interlaced and you want |
|
| 515 |
+to keep the interlaced format for minimum losses. |
|
| 516 |
+The alternative is to deinterlace the input stream with |
|
| 517 |
+@option{-deinterlace}, but deinterlacing introduces losses.
|
|
| 518 |
+@item -psnr |
|
| 519 |
+Calculate PSNR of compressed frames. |
|
| 520 |
+@item -vstats |
|
| 521 |
+Dump video coding statistics to @file{vstats_HHMMSS.log}.
|
|
| 522 |
+@item -vstats_file @var{file}
|
|
| 523 |
+Dump video coding statistics to @var{file}.
|
|
| 524 |
+@item -top @var{n}
|
|
| 525 |
+top=1/bottom=0/auto=-1 field first |
|
| 526 |
+@item -dc @var{precision}
|
|
| 527 |
+Intra_dc_precision. |
|
| 528 |
+@item -vtag @var{fourcc/tag}
|
|
| 529 |
+Force video tag/fourcc. |
|
| 530 |
+@item -qphist |
|
| 531 |
+Show QP histogram. |
|
| 532 |
+@item -vbsf @var{bitstream_filter}
|
|
| 533 |
+Bitstream filters available are "dump_extra", "remove_extra", "noise", "h264_mp4toannexb", "imxdump", "mjpegadump", "mjpeg2jpeg". |
|
| 534 |
+@example |
|
| 535 |
+avconv -i h264.mp4 -vcodec copy -vbsf h264_mp4toannexb -an out.h264 |
|
| 536 |
+@end example |
|
| 537 |
+@item -force_key_frames @var{time}[,@var{time}...]
|
|
| 538 |
+Force key frames at the specified timestamps, more precisely at the first |
|
| 539 |
+frames after each specified time. |
|
| 540 |
+This option can be useful to ensure that a seek point is present at a |
|
| 541 |
+chapter mark or any other designated place in the output file. |
|
| 542 |
+The timestamps must be specified in ascending order. |
|
| 543 |
+@end table |
|
| 544 |
+ |
|
| 545 |
+@section Audio Options |
|
| 546 |
+ |
|
| 547 |
+@table @option |
|
| 548 |
+@item -aframes @var{number}
|
|
| 549 |
+Set the number of audio frames to record. |
|
| 550 |
+@item -ar @var{freq}
|
|
| 551 |
+Set the audio sampling frequency. For output streams it is set by |
|
| 552 |
+default to the frequency of the corresponding input stream. For input |
|
| 553 |
+streams this option only makes sense for audio grabbing devices and raw |
|
| 554 |
+demuxers and is mapped to the corresponding demuxer options. |
|
| 555 |
+@item -aq @var{q}
|
|
| 556 |
+Set the audio quality (codec-specific, VBR). |
|
| 557 |
+@item -ac @var{channels}
|
|
| 558 |
+Set the number of audio channels. For output streams it is set by |
|
| 559 |
+default to the number of input audio channels. For input streams |
|
| 560 |
+this option only makes sense for audio grabbing devices and raw demuxers |
|
| 561 |
+and is mapped to the corresponding demuxer options. |
|
| 562 |
+@item -an |
|
| 563 |
+Disable audio recording. |
|
| 564 |
+@item -acodec @var{codec}
|
|
| 565 |
+Force audio codec to @var{codec}. Use the @code{copy} special value to
|
|
| 566 |
+specify that the raw codec data must be copied as is. |
|
| 567 |
+@item -newaudio |
|
| 568 |
+Add a new audio track to the output file. If you want to specify parameters, |
|
| 569 |
+do so before @code{-newaudio} (@code{-acodec}, @code{-ab}, etc..).
|
|
| 570 |
+ |
|
| 571 |
+Mapping will be done automatically, if the number of output streams is equal to |
|
| 572 |
+the number of input streams, else it will pick the first one that matches. You |
|
| 573 |
+can override the mapping using @code{-map} as usual.
|
|
| 574 |
+ |
|
| 575 |
+Example: |
|
| 576 |
+@example |
|
| 577 |
+avconv -i file.mpg -vcodec copy -acodec ac3 -ab 384k test.mpg -acodec mp2 -ab 192k -newaudio |
|
| 578 |
+@end example |
|
| 579 |
+@item -alang @var{code}
|
|
| 580 |
+Set the ISO 639 language code (3 letters) of the current audio stream. |
|
| 581 |
+@end table |
|
| 582 |
+ |
|
| 583 |
+@section Advanced Audio options: |
|
| 584 |
+ |
|
| 585 |
+@table @option |
|
| 586 |
+@item -atag @var{fourcc/tag}
|
|
| 587 |
+Force audio tag/fourcc. |
|
| 588 |
+@item -audio_service_type @var{type}
|
|
| 589 |
+Set the type of service that the audio stream contains. |
|
| 590 |
+@table @option |
|
| 591 |
+@item ma |
|
| 592 |
+Main Audio Service (default) |
|
| 593 |
+@item ef |
|
| 594 |
+Effects |
|
| 595 |
+@item vi |
|
| 596 |
+Visually Impaired |
|
| 597 |
+@item hi |
|
| 598 |
+Hearing Impaired |
|
| 599 |
+@item di |
|
| 600 |
+Dialogue |
|
| 601 |
+@item co |
|
| 602 |
+Commentary |
|
| 603 |
+@item em |
|
| 604 |
+Emergency |
|
| 605 |
+@item vo |
|
| 606 |
+Voice Over |
|
| 607 |
+@item ka |
|
| 608 |
+Karaoke |
|
| 609 |
+@end table |
|
| 610 |
+@item -absf @var{bitstream_filter}
|
|
| 611 |
+Bitstream filters available are "dump_extra", "remove_extra", "noise", "mp3comp", "mp3decomp". |
|
| 612 |
+@end table |
|
| 613 |
+ |
|
| 614 |
+@section Subtitle options: |
|
| 615 |
+ |
|
| 616 |
+@table @option |
|
| 617 |
+@item -scodec @var{codec}
|
|
| 618 |
+Force subtitle codec ('copy' to copy stream).
|
|
| 619 |
+@item -newsubtitle |
|
| 620 |
+Add a new subtitle stream to the current output stream. |
|
| 621 |
+@item -slang @var{code}
|
|
| 622 |
+Set the ISO 639 language code (3 letters) of the current subtitle stream. |
|
| 623 |
+@item -sn |
|
| 624 |
+Disable subtitle recording. |
|
| 625 |
+@item -sbsf @var{bitstream_filter}
|
|
| 626 |
+Bitstream filters available are "mov2textsub", "text2movsub". |
|
| 627 |
+@example |
|
| 628 |
+avconv -i file.mov -an -vn -sbsf mov2textsub -scodec copy -f rawvideo sub.txt |
|
| 629 |
+@end example |
|
| 630 |
+@end table |
|
| 631 |
+ |
|
| 632 |
+@section Audio/Video grab options |
|
| 633 |
+ |
|
| 634 |
+@table @option |
|
| 635 |
+@item -vc @var{channel}
|
|
| 636 |
+Set video grab channel (DV1394 only). |
|
| 637 |
+@item -tvstd @var{standard}
|
|
| 638 |
+Set television standard (NTSC, PAL (SECAM)). |
|
| 639 |
+@item -isync |
|
| 640 |
+Synchronize read on input. |
|
| 641 |
+@end table |
|
| 642 |
+ |
|
| 643 |
+@section Advanced options |
|
| 644 |
+ |
|
| 645 |
+@table @option |
|
| 646 |
+@item -map @var{input_file_id}.@var{input_stream_id}[:@var{sync_file_id}.@var{sync_stream_id}]
|
|
| 647 |
+ |
|
| 648 |
+Designate an input stream as a source for the output file. Each input |
|
| 649 |
+stream is identified by the input file index @var{input_file_id} and
|
|
| 650 |
+the input stream index @var{input_stream_id} within the input
|
|
| 651 |
+file. Both indexes start at 0. If specified, |
|
| 652 |
+@var{sync_file_id}.@var{sync_stream_id} sets which input stream
|
|
| 653 |
+is used as a presentation sync reference. |
|
| 654 |
+ |
|
| 655 |
+The @code{-map} options must be specified just after the output file.
|
|
| 656 |
+If any @code{-map} options are used, the number of @code{-map} options
|
|
| 657 |
+on the command line must match the number of streams in the output |
|
| 658 |
+file. The first @code{-map} option on the command line specifies the
|
|
| 659 |
+source for output stream 0, the second @code{-map} option specifies
|
|
| 660 |
+the source for output stream 1, etc. |
|
| 661 |
+ |
|
| 662 |
+For example, if you have two audio streams in the first input file, |
|
| 663 |
+these streams are identified by "0.0" and "0.1". You can use |
|
| 664 |
+@code{-map} to select which stream to place in an output file. For
|
|
| 665 |
+example: |
|
| 666 |
+@example |
|
| 667 |
+avconv -i INPUT out.wav -map 0.1 |
|
| 668 |
+@end example |
|
| 669 |
+will map the input stream in @file{INPUT} identified by "0.1" to
|
|
| 670 |
+the (single) output stream in @file{out.wav}.
|
|
| 671 |
+ |
|
| 672 |
+For example, to select the stream with index 2 from input file |
|
| 673 |
+@file{a.mov} (specified by the identifier "0.2"), and stream with
|
|
| 674 |
+index 6 from input @file{b.mov} (specified by the identifier "1.6"),
|
|
| 675 |
+and copy them to the output file @file{out.mov}:
|
|
| 676 |
+@example |
|
| 677 |
+avconv -i a.mov -i b.mov -vcodec copy -acodec copy out.mov -map 0.2 -map 1.6 |
|
| 678 |
+@end example |
|
| 679 |
+ |
|
| 680 |
+To add more streams to the output file, you can use the |
|
| 681 |
+@code{-newaudio}, @code{-newvideo}, @code{-newsubtitle} options.
|
|
| 682 |
+ |
|
| 683 |
+@item -map_meta_data @var{outfile}[,@var{metadata}]:@var{infile}[,@var{metadata}]
|
|
| 684 |
+Deprecated, use @var{-map_metadata} instead.
|
|
| 685 |
+ |
|
| 686 |
+@item -map_metadata @var{outfile}[,@var{metadata}]:@var{infile}[,@var{metadata}]
|
|
| 687 |
+Set metadata information of @var{outfile} from @var{infile}. Note that those
|
|
| 688 |
+are file indices (zero-based), not filenames. |
|
| 689 |
+Optional @var{metadata} parameters specify, which metadata to copy - (g)lobal
|
|
| 690 |
+(i.e. metadata that applies to the whole file), per-(s)tream, per-(c)hapter or |
|
| 691 |
+per-(p)rogram. All metadata specifiers other than global must be followed by the |
|
| 692 |
+stream/chapter/program number. If metadata specifier is omitted, it defaults to |
|
| 693 |
+global. |
|
| 694 |
+ |
|
| 695 |
+By default, global metadata is copied from the first input file to all output files, |
|
| 696 |
+per-stream and per-chapter metadata is copied along with streams/chapters. These |
|
| 697 |
+default mappings are disabled by creating any mapping of the relevant type. A negative |
|
| 698 |
+file index can be used to create a dummy mapping that just disables automatic copying. |
|
| 699 |
+ |
|
| 700 |
+For example to copy metadata from the first stream of the input file to global metadata |
|
| 701 |
+of the output file: |
|
| 702 |
+@example |
|
| 703 |
+avconv -i in.ogg -map_metadata 0:0,s0 out.mp3 |
|
| 704 |
+@end example |
|
| 705 |
+@item -map_chapters @var{outfile}:@var{infile}
|
|
| 706 |
+Copy chapters from @var{infile} to @var{outfile}. If no chapter mapping is specified,
|
|
| 707 |
+then chapters are copied from the first input file with at least one chapter to all |
|
| 708 |
+output files. Use a negative file index to disable any chapter copying. |
|
| 709 |
+@item -debug |
|
| 710 |
+Print specific debug info. |
|
| 711 |
+@item -benchmark |
|
| 712 |
+Show benchmarking information at the end of an encode. |
|
| 713 |
+Shows CPU time used and maximum memory consumption. |
|
| 714 |
+Maximum memory consumption is not supported on all systems, |
|
| 715 |
+it will usually display as 0 if not supported. |
|
| 716 |
+@item -dump |
|
| 717 |
+Dump each input packet. |
|
| 718 |
+@item -hex |
|
| 719 |
+When dumping packets, also dump the payload. |
|
| 720 |
+@item -bitexact |
|
| 721 |
+Only use bit exact algorithms (for codec testing). |
|
| 722 |
+@item -ps @var{size}
|
|
| 723 |
+Set RTP payload size in bytes. |
|
| 724 |
+@item -re |
|
| 725 |
+Read input at native frame rate. Mainly used to simulate a grab device. |
|
| 726 |
+@item -loop_input |
|
| 727 |
+Loop over the input stream. Currently it works only for image |
|
| 728 |
+streams. This option is used for automatic AVserver testing. |
|
| 729 |
+This option is deprecated, use -loop. |
|
| 730 |
+@item -loop_output @var{number_of_times}
|
|
| 731 |
+Repeatedly loop output for formats that support looping such as animated GIF |
|
| 732 |
+(0 will loop the output infinitely). |
|
| 733 |
+This option is deprecated, use -loop. |
|
| 734 |
+@item -threads @var{count}
|
|
| 735 |
+Thread count. |
|
| 736 |
+@item -vsync @var{parameter}
|
|
| 737 |
+Video sync method. |
|
| 738 |
+ |
|
| 739 |
+@table @option |
|
| 740 |
+@item 0 |
|
| 741 |
+Each frame is passed with its timestamp from the demuxer to the muxer. |
|
| 742 |
+@item 1 |
|
| 743 |
+Frames will be duplicated and dropped to achieve exactly the requested |
|
| 744 |
+constant framerate. |
|
| 745 |
+@item 2 |
|
| 746 |
+Frames are passed through with their timestamp or dropped so as to |
|
| 747 |
+prevent 2 frames from having the same timestamp. |
|
| 748 |
+@item -1 |
|
| 749 |
+Chooses between 1 and 2 depending on muxer capabilities. This is the |
|
| 750 |
+default method. |
|
| 751 |
+@end table |
|
| 752 |
+ |
|
| 753 |
+With -map you can select from which stream the timestamps should be |
|
| 754 |
+taken. You can leave either video or audio unchanged and sync the |
|
| 755 |
+remaining stream(s) to the unchanged one. |
|
| 756 |
+ |
|
| 757 |
+@item -async @var{samples_per_second}
|
|
| 758 |
+Audio sync method. "Stretches/squeezes" the audio stream to match the timestamps, |
|
| 759 |
+the parameter is the maximum samples per second by which the audio is changed. |
|
| 760 |
+-async 1 is a special case where only the start of the audio stream is corrected |
|
| 761 |
+without any later correction. |
|
| 762 |
+@item -copyts |
|
| 763 |
+Copy timestamps from input to output. |
|
| 764 |
+@item -copytb |
|
| 765 |
+Copy input stream time base from input to output when stream copying. |
|
| 766 |
+@item -shortest |
|
| 767 |
+Finish encoding when the shortest input stream ends. |
|
| 768 |
+@item -dts_delta_threshold |
|
| 769 |
+Timestamp discontinuity delta threshold. |
|
| 770 |
+@item -muxdelay @var{seconds}
|
|
| 771 |
+Set the maximum demux-decode delay. |
|
| 772 |
+@item -muxpreload @var{seconds}
|
|
| 773 |
+Set the initial demux-decode delay. |
|
| 774 |
+@item -streamid @var{output-stream-index}:@var{new-value}
|
|
| 775 |
+Assign a new stream-id value to an output stream. This option should be |
|
| 776 |
+specified prior to the output filename to which it applies. |
|
| 777 |
+For the situation where multiple output files exist, a streamid |
|
| 778 |
+may be reassigned to a different value. |
|
| 779 |
+ |
|
| 780 |
+For example, to set the stream 0 PID to 33 and the stream 1 PID to 36 for |
|
| 781 |
+an output mpegts file: |
|
| 782 |
+@example |
|
| 783 |
+avconv -i infile -streamid 0:33 -streamid 1:36 out.ts |
|
| 784 |
+@end example |
|
| 785 |
+@end table |
|
| 786 |
+ |
|
| 787 |
+@section Preset files |
|
| 788 |
+ |
|
| 789 |
+A preset file contains a sequence of @var{option}=@var{value} pairs,
|
|
| 790 |
+one for each line, specifying a sequence of options which would be |
|
| 791 |
+awkward to specify on the command line. Lines starting with the hash |
|
| 792 |
+('#') character are ignored and are used to provide comments. Check
|
|
| 793 |
+the @file{ffpresets} directory in the Libav source tree for examples.
|
|
| 794 |
+ |
|
| 795 |
+Preset files are specified with the @code{vpre}, @code{apre},
|
|
| 796 |
+@code{spre}, and @code{fpre} options. The @code{fpre} option takes the
|
|
| 797 |
+filename of the preset instead of a preset name as input and can be |
|
| 798 |
+used for any kind of codec. For the @code{vpre}, @code{apre}, and
|
|
| 799 |
+@code{spre} options, the options specified in a preset file are
|
|
| 800 |
+applied to the currently selected codec of the same type as the preset |
|
| 801 |
+option. |
|
| 802 |
+ |
|
| 803 |
+The argument passed to the @code{vpre}, @code{apre}, and @code{spre}
|
|
| 804 |
+preset options identifies the preset file to use according to the |
|
| 805 |
+following rules: |
|
| 806 |
+ |
|
| 807 |
+First avconv searches for a file named @var{arg}.ffpreset in the
|
|
| 808 |
+directories @file{$av_DATADIR} (if set), and @file{$HOME/.avconv}, and in
|
|
| 809 |
+the datadir defined at configuration time (usually @file{PREFIX/share/avconv})
|
|
| 810 |
+in that order. For example, if the argument is @code{libx264-max}, it will
|
|
| 811 |
+search for the file @file{libx264-max.ffpreset}.
|
|
| 812 |
+ |
|
| 813 |
+If no such file is found, then avconv will search for a file named |
|
| 814 |
+@var{codec_name}-@var{arg}.ffpreset in the above-mentioned
|
|
| 815 |
+directories, where @var{codec_name} is the name of the codec to which
|
|
| 816 |
+the preset file options will be applied. For example, if you select |
|
| 817 |
+the video codec with @code{-vcodec libx264} and use @code{-vpre max},
|
|
| 818 |
+then it will search for the file @file{libx264-max.ffpreset}.
|
|
| 819 |
+@c man end |
|
| 820 |
+ |
|
| 821 |
+@chapter Tips |
|
| 822 |
+@c man begin TIPS |
|
| 823 |
+ |
|
| 824 |
+@itemize |
|
| 825 |
+@item |
|
| 826 |
+For streaming at very low bitrate application, use a low frame rate |
|
| 827 |
+and a small GOP size. This is especially true for RealVideo where |
|
| 828 |
+the Linux player does not seem to be very fast, so it can miss |
|
| 829 |
+frames. An example is: |
|
| 830 |
+ |
|
| 831 |
+@example |
|
| 832 |
+avconv -g 3 -r 3 -t 10 -b 50k -s qcif -f rv10 /tmp/b.rm |
|
| 833 |
+@end example |
|
| 834 |
+ |
|
| 835 |
+@item |
|
| 836 |
+The parameter 'q' which is displayed while encoding is the current |
|
| 837 |
+quantizer. The value 1 indicates that a very good quality could |
|
| 838 |
+be achieved. The value 31 indicates the worst quality. If q=31 appears |
|
| 839 |
+too often, it means that the encoder cannot compress enough to meet |
|
| 840 |
+your bitrate. You must either increase the bitrate, decrease the |
|
| 841 |
+frame rate or decrease the frame size. |
|
| 842 |
+ |
|
| 843 |
+@item |
|
| 844 |
+If your computer is not fast enough, you can speed up the |
|
| 845 |
+compression at the expense of the compression ratio. You can use |
|
| 846 |
+'-me zero' to speed up motion estimation, and '-intra' to disable |
|
| 847 |
+motion estimation completely (you have only I-frames, which means it |
|
| 848 |
+is about as good as JPEG compression). |
|
| 849 |
+ |
|
| 850 |
+@item |
|
| 851 |
+To have very low audio bitrates, reduce the sampling frequency |
|
| 852 |
+(down to 22050 Hz for MPEG audio, 22050 or 11025 for AC-3). |
|
| 853 |
+ |
|
| 854 |
+@item |
|
| 855 |
+To have a constant quality (but a variable bitrate), use the option |
|
| 856 |
+'-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst |
|
| 857 |
+quality). |
|
| 858 |
+ |
|
| 859 |
+@item |
|
| 860 |
+When converting video files, you can use the '-sameq' option which |
|
| 861 |
+uses the same quality factor in the encoder as in the decoder. |
|
| 862 |
+It allows almost lossless encoding. |
|
| 863 |
+ |
|
| 864 |
+@end itemize |
|
| 865 |
+@c man end TIPS |
|
| 866 |
+ |
|
| 867 |
+@chapter Examples |
|
| 868 |
+@c man begin EXAMPLES |
|
| 869 |
+ |
|
| 870 |
+@section Video and Audio grabbing |
|
| 871 |
+ |
|
| 872 |
+If you specify the input format and device then avconv can grab video |
|
| 873 |
+and audio directly. |
|
| 874 |
+ |
|
| 875 |
+@example |
|
| 876 |
+avconv -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg |
|
| 877 |
+@end example |
|
| 878 |
+ |
|
| 879 |
+Note that you must activate the right video source and channel before |
|
| 880 |
+launching avconv with any TV viewer such as |
|
| 881 |
+@uref{http://linux.bytesex.org/xawtv/, xawtv} by Gerd Knorr. You also
|
|
| 882 |
+have to set the audio recording levels correctly with a |
|
| 883 |
+standard mixer. |
|
| 884 |
+ |
|
| 885 |
+@section X11 grabbing |
|
| 886 |
+ |
|
| 887 |
+Grab the X11 display with avconv via |
|
| 888 |
+ |
|
| 889 |
+@example |
|
| 890 |
+avconv -f x11grab -s cif -r 25 -i :0.0 /tmp/out.mpg |
|
| 891 |
+@end example |
|
| 892 |
+ |
|
| 893 |
+0.0 is display.screen number of your X11 server, same as |
|
| 894 |
+the DISPLAY environment variable. |
|
| 895 |
+ |
|
| 896 |
+@example |
|
| 897 |
+avconv -f x11grab -s cif -r 25 -i :0.0+10,20 /tmp/out.mpg |
|
| 898 |
+@end example |
|
| 899 |
+ |
|
| 900 |
+0.0 is display.screen number of your X11 server, same as the DISPLAY environment |
|
| 901 |
+variable. 10 is the x-offset and 20 the y-offset for the grabbing. |
|
| 902 |
+ |
|
| 903 |
+@section Video and Audio file format conversion |
|
| 904 |
+ |
|
| 905 |
+Any supported file format and protocol can serve as input to avconv: |
|
| 906 |
+ |
|
| 907 |
+Examples: |
|
| 908 |
+@itemize |
|
| 909 |
+@item |
|
| 910 |
+You can use YUV files as input: |
|
| 911 |
+ |
|
| 912 |
+@example |
|
| 913 |
+avconv -i /tmp/test%d.Y /tmp/out.mpg |
|
| 914 |
+@end example |
|
| 915 |
+ |
|
| 916 |
+It will use the files: |
|
| 917 |
+@example |
|
| 918 |
+/tmp/test0.Y, /tmp/test0.U, /tmp/test0.V, |
|
| 919 |
+/tmp/test1.Y, /tmp/test1.U, /tmp/test1.V, etc... |
|
| 920 |
+@end example |
|
| 921 |
+ |
|
| 922 |
+The Y files use twice the resolution of the U and V files. They are |
|
| 923 |
+raw files, without header. They can be generated by all decent video |
|
| 924 |
+decoders. You must specify the size of the image with the @option{-s} option
|
|
| 925 |
+if avconv cannot guess it. |
|
| 926 |
+ |
|
| 927 |
+@item |
|
| 928 |
+You can input from a raw YUV420P file: |
|
| 929 |
+ |
|
| 930 |
+@example |
|
| 931 |
+avconv -i /tmp/test.yuv /tmp/out.avi |
|
| 932 |
+@end example |
|
| 933 |
+ |
|
| 934 |
+test.yuv is a file containing raw YUV planar data. Each frame is composed |
|
| 935 |
+of the Y plane followed by the U and V planes at half vertical and |
|
| 936 |
+horizontal resolution. |
|
| 937 |
+ |
|
| 938 |
+@item |
|
| 939 |
+You can output to a raw YUV420P file: |
|
| 940 |
+ |
|
| 941 |
+@example |
|
| 942 |
+avconv -i mydivx.avi hugefile.yuv |
|
| 943 |
+@end example |
|
| 944 |
+ |
|
| 945 |
+@item |
|
| 946 |
+You can set several input files and output files: |
|
| 947 |
+ |
|
| 948 |
+@example |
|
| 949 |
+avconv -i /tmp/a.wav -s 640x480 -i /tmp/a.yuv /tmp/a.mpg |
|
| 950 |
+@end example |
|
| 951 |
+ |
|
| 952 |
+Converts the audio file a.wav and the raw YUV video file a.yuv |
|
| 953 |
+to MPEG file a.mpg. |
|
| 954 |
+ |
|
| 955 |
+@item |
|
| 956 |
+You can also do audio and video conversions at the same time: |
|
| 957 |
+ |
|
| 958 |
+@example |
|
| 959 |
+avconv -i /tmp/a.wav -ar 22050 /tmp/a.mp2 |
|
| 960 |
+@end example |
|
| 961 |
+ |
|
| 962 |
+Converts a.wav to MPEG audio at 22050 Hz sample rate. |
|
| 963 |
+ |
|
| 964 |
+@item |
|
| 965 |
+You can encode to several formats at the same time and define a |
|
| 966 |
+mapping from input stream to output streams: |
|
| 967 |
+ |
|
| 968 |
+@example |
|
| 969 |
+avconv -i /tmp/a.wav -ab 64k /tmp/a.mp2 -ab 128k /tmp/b.mp2 -map 0:0 -map 0:0 |
|
| 970 |
+@end example |
|
| 971 |
+ |
|
| 972 |
+Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map |
|
| 973 |
+file:index' specifies which input stream is used for each output |
|
| 974 |
+stream, in the order of the definition of output streams. |
|
| 975 |
+ |
|
| 976 |
+@item |
|
| 977 |
+You can transcode decrypted VOBs: |
|
| 978 |
+ |
|
| 979 |
+@example |
|
| 980 |
+avconv -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k snatch.avi |
|
| 981 |
+@end example |
|
| 982 |
+ |
|
| 983 |
+This is a typical DVD ripping example; the input is a VOB file, the |
|
| 984 |
+output an AVI file with MPEG-4 video and MP3 audio. Note that in this |
|
| 985 |
+command we use B-frames so the MPEG-4 stream is DivX5 compatible, and |
|
| 986 |
+GOP size is 300 which means one intra frame every 10 seconds for 29.97fps |
|
| 987 |
+input video. Furthermore, the audio stream is MP3-encoded so you need |
|
| 988 |
+to enable LAME support by passing @code{--enable-libmp3lame} to configure.
|
|
| 989 |
+The mapping is particularly useful for DVD transcoding |
|
| 990 |
+to get the desired audio language. |
|
| 991 |
+ |
|
| 992 |
+NOTE: To see the supported input formats, use @code{avconv -formats}.
|
|
| 993 |
+ |
|
| 994 |
+@item |
|
| 995 |
+You can extract images from a video, or create a video from many images: |
|
| 996 |
+ |
|
| 997 |
+For extracting images from a video: |
|
| 998 |
+@example |
|
| 999 |
+avconv -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg |
|
| 1000 |
+@end example |
|
| 1001 |
+ |
|
| 1002 |
+This will extract one video frame per second from the video and will |
|
| 1003 |
+output them in files named @file{foo-001.jpeg}, @file{foo-002.jpeg},
|
|
| 1004 |
+etc. Images will be rescaled to fit the new WxH values. |
|
| 1005 |
+ |
|
| 1006 |
+If you want to extract just a limited number of frames, you can use the |
|
| 1007 |
+above command in combination with the -vframes or -t option, or in |
|
| 1008 |
+combination with -ss to start extracting from a certain point in time. |
|
| 1009 |
+ |
|
| 1010 |
+For creating a video from many images: |
|
| 1011 |
+@example |
|
| 1012 |
+avconv -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi |
|
| 1013 |
+@end example |
|
| 1014 |
+ |
|
| 1015 |
+The syntax @code{foo-%03d.jpeg} specifies to use a decimal number
|
|
| 1016 |
+composed of three digits padded with zeroes to express the sequence |
|
| 1017 |
+number. It is the same syntax supported by the C printf function, but |
|
| 1018 |
+only formats accepting a normal integer are suitable. |
|
| 1019 |
+ |
|
| 1020 |
+@item |
|
| 1021 |
+You can put many streams of the same type in the output: |
|
| 1022 |
+ |
|
| 1023 |
+@example |
|
| 1024 |
+avconv -i test1.avi -i test2.avi -vcodec copy -acodec copy -vcodec copy -acodec copy test12.avi -newvideo -newaudio |
|
| 1025 |
+@end example |
|
| 1026 |
+ |
|
| 1027 |
+In addition to the first video and audio streams, the resulting |
|
| 1028 |
+output file @file{test12.avi} will contain the second video
|
|
| 1029 |
+and the second audio stream found in the input streams list. |
|
| 1030 |
+ |
|
| 1031 |
+The @code{-newvideo}, @code{-newaudio} and @code{-newsubtitle}
|
|
| 1032 |
+options have to be specified immediately after the name of the output |
|
| 1033 |
+file to which you want to add them. |
|
| 1034 |
+ |
|
| 1035 |
+@end itemize |
|
| 1036 |
+@c man end EXAMPLES |
|
| 1037 |
+ |
|
| 1038 |
+@include eval.texi |
|
| 1039 |
+@include encoders.texi |
|
| 1040 |
+@include demuxers.texi |
|
| 1041 |
+@include muxers.texi |
|
| 1042 |
+@include indevs.texi |
|
| 1043 |
+@include outdevs.texi |
|
| 1044 |
+@include protocols.texi |
|
| 1045 |
+@include bitstream_filters.texi |
|
| 1046 |
+@include filters.texi |
|
| 1047 |
+@include metadata.texi |
|
| 1048 |
+ |
|
| 1049 |
+@ignore |
|
| 1050 |
+ |
|
| 1051 |
+@setfilename avconv |
|
| 1052 |
+@settitle avconv video converter |
|
| 1053 |
+ |
|
| 1054 |
+@c man begin SEEALSO |
|
| 1055 |
+avplay(1), avprobe(1), avserver(1) and the Libav HTML documentation |
|
| 1056 |
+@c man end |
|
| 1057 |
+ |
|
| 1058 |
+@c man begin AUTHORS |
|
| 1059 |
+The Libav developers |
|
| 1060 |
+@c man end |
|
| 1061 |
+ |
|
| 1062 |
+@end ignore |
|
| 1063 |
+ |
|
| 1064 |
+@bye |
| ... | ... |
@@ -170,7 +170,7 @@ Seek to percentage in file corresponding to fraction of width. |
| 170 | 170 |
@settitle AVplay media player |
| 171 | 171 |
|
| 172 | 172 |
@c man begin SEEALSO |
| 173 |
-ffmpeg(1), avprobe(1), avserver(1) and the Libav HTML documentation |
|
| 173 |
+avconv(1), avprobe(1), avserver(1) and the Libav HTML documentation |
|
| 174 | 174 |
@c man end |
| 175 | 175 |
|
| 176 | 176 |
@c man begin AUTHORS |
| ... | ... |
@@ -122,7 +122,7 @@ with name "STREAM". |
| 122 | 122 |
@settitle avprobe media prober |
| 123 | 123 |
|
| 124 | 124 |
@c man begin SEEALSO |
| 125 |
-ffmpeg(1), avplay(1), avserver(1) and the Libav HTML documentation |
|
| 125 |
+avconv(1), avplay(1), avserver(1) and the Libav HTML documentation |
|
| 126 | 126 |
@c man end |
| 127 | 127 |
|
| 128 | 128 |
@c man begin AUTHORS |
| ... | ... |
@@ -265,7 +265,7 @@ rather than as a daemon. |
| 265 | 265 |
|
| 266 | 266 |
@c man begin SEEALSO |
| 267 | 267 |
|
| 268 |
-ffmpeg(1), avplay(1), avprobe(1), the @file{ffmpeg/doc/avserver.conf}
|
|
| 268 |
+avconv(1), avplay(1), avprobe(1), the @file{ffmpeg/doc/avserver.conf}
|
|
| 269 | 269 |
example and the Libav HTML documentation |
| 270 | 270 |
@c man end |
| 271 | 271 |
|
| ... | ... |
@@ -2,8 +2,8 @@ AREF = fate-acodec-aref |
| 2 | 2 |
VREF = fate-vsynth1-vref fate-vsynth2-vref |
| 3 | 3 |
REFS = $(AREF) $(VREF) |
| 4 | 4 |
|
| 5 |
-$(VREF): ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm |
|
| 6 |
-$(AREF): ffmpeg$(EXESUF) tests/data/asynth1.sw |
|
| 5 |
+$(VREF): avconv$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm |
|
| 6 |
+$(AREF): avconv$(EXESUF) tests/data/asynth1.sw |
|
| 7 | 7 |
|
| 8 | 8 |
tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF) |
| 9 | 9 |
@mkdir -p tests/vsynth1 |
| ... | ... |
@@ -84,7 +84,7 @@ FATE_UTILS = base64 tiny_psnr |
| 84 | 84 |
|
| 85 | 85 |
fate: $(FATE) |
| 86 | 86 |
|
| 87 |
-$(FATE): ffmpeg$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF)) |
|
| 87 |
+$(FATE): avconv$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF)) |
|
| 88 | 88 |
@echo "TEST $(@:fate-%=%)" |
| 89 | 89 |
$(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' '$(THREAD_TYPE)' |
| 90 | 90 |
|
| ... | ... |
@@ -1,6 +1,6 @@ |
| 1 | 1 |
#!/bin/sh |
| 2 | 2 |
# |
| 3 |
-# automatic regression test for ffmpeg |
|
| 3 |
+# automatic regression test for avconv |
|
| 4 | 4 |
# |
| 5 | 5 |
# |
| 6 | 6 |
#set -x |
| ... | ... |
@@ -13,10 +13,10 @@ eval do_$test=y |
| 13 | 13 |
|
| 14 | 14 |
# generate reference for quality check |
| 15 | 15 |
if [ -n "$do_vref" ]; then |
| 16 |
-do_ffmpeg $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo |
|
| 16 |
+do_avconv $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo |
|
| 17 | 17 |
fi |
| 18 | 18 |
if [ -n "$do_aref" ]; then |
| 19 |
-do_ffmpeg $pcm_ref -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav |
|
| 19 |
+do_avconv $pcm_ref -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav |
|
| 20 | 20 |
fi |
| 21 | 21 |
|
| 22 | 22 |
if [ -n "$do_mpeg" ] ; then |
| ... | ... |
@@ -58,7 +58,7 @@ do_video_decoding |
| 58 | 58 |
|
| 59 | 59 |
# mpeg2 encoding interlaced |
| 60 | 60 |
file=${outfile}mpeg2reuse.mpg
|
| 61 |
-do_ffmpeg $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -sameq -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
|
|
| 61 |
+do_avconv $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -sameq -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
|
|
| 62 | 62 |
do_video_decoding |
| 63 | 63 |
fi |
| 64 | 64 |
|
| ... | ... |
@@ -320,12 +320,12 @@ fi |
| 320 | 320 |
|
| 321 | 321 |
if [ -n "$do_wmav1" ] ; then |
| 322 | 322 |
do_audio_encoding wmav1.asf "-acodec wmav1" |
| 323 |
-do_ffmpeg_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav |
|
| 323 |
+do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav |
|
| 324 | 324 |
$tiny_psnr $pcm_dst $pcm_ref 2 8192 |
| 325 | 325 |
fi |
| 326 | 326 |
if [ -n "$do_wmav2" ] ; then |
| 327 | 327 |
do_audio_encoding wmav2.asf "-acodec wmav2" |
| 328 |
-do_ffmpeg_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav |
|
| 328 |
+do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav |
|
| 329 | 329 |
$tiny_psnr $pcm_dst $pcm_ref 2 8192 |
| 330 | 330 |
fi |
| 331 | 331 |
|
| ... | ... |
@@ -49,28 +49,28 @@ run(){
|
| 49 | 49 |
$target_exec $target_path/"$@" |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
-ffmpeg(){
|
|
| 53 |
- run ffmpeg -v 0 -threads $threads -thread_type $thread_type "$@" |
|
| 52 |
+avconv(){
|
|
| 53 |
+ run avconv -v 0 -threads $threads -thread_type $thread_type "$@" |
|
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
framecrc(){
|
| 57 |
- ffmpeg "$@" -f framecrc - |
|
| 57 |
+ avconv "$@" -f framecrc - |
|
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
framemd5(){
|
| 61 |
- ffmpeg "$@" -f framemd5 - |
|
| 61 |
+ avconv "$@" -f framemd5 - |
|
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
crc(){
|
| 65 |
- ffmpeg "$@" -f crc - |
|
| 65 |
+ avconv "$@" -f crc - |
|
| 66 | 66 |
} |
| 67 | 67 |
|
| 68 | 68 |
md5(){
|
| 69 |
- ffmpeg "$@" md5: |
|
| 69 |
+ avconv "$@" md5: |
|
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 | 72 |
pcm(){
|
| 73 |
- ffmpeg "$@" -vn -f s16le - |
|
| 73 |
+ avconv "$@" -vn -f s16le - |
|
| 74 | 74 |
} |
| 75 | 75 |
|
| 76 | 76 |
regtest(){
|
| ... | ... |
@@ -14,15 +14,15 @@ eval do_$test=y |
| 14 | 14 |
do_lavf() |
| 15 | 15 |
{
|
| 16 | 16 |
file=${outfile}lavf.$1
|
| 17 |
- do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -ab 64k -t 1 -qscale 10 $2 |
|
| 18 |
- do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file $3 |
|
| 17 |
+ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -ab 64k -t 1 -qscale 10 $2 |
|
| 18 |
+ do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
do_streamed_images() |
| 22 | 22 |
{
|
| 23 | 23 |
file=${outfile}${1}pipe.$1
|
| 24 |
- do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10 |
|
| 25 |
- do_ffmpeg_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file |
|
| 24 |
+ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10 |
|
| 25 |
+ do_avconv_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file |
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 | 28 |
do_image_formats() |
| ... | ... |
@@ -30,17 +30,17 @@ do_image_formats() |
| 30 | 30 |
outfile="$datadir/images/$1/" |
| 31 | 31 |
mkdir -p "$outfile" |
| 32 | 32 |
file=${outfile}%02d.$1
|
| 33 |
- run_ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $2 $ENC_OPTS $3 -t 0.5 -y -qscale 10 $target_path/$file |
|
| 33 |
+ run_avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $2 $ENC_OPTS $3 -t 0.5 -y -qscale 10 $target_path/$file |
|
| 34 | 34 |
do_md5sum ${outfile}02.$1
|
| 35 |
- do_ffmpeg_crc $file $DEC_OPTS $3 -i $target_path/$file |
|
| 35 |
+ do_avconv_crc $file $DEC_OPTS $3 -i $target_path/$file |
|
| 36 | 36 |
wc -c ${outfile}02.$1
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
do_audio_only() |
| 40 | 40 |
{
|
| 41 | 41 |
file=${outfile}lavf.$1
|
| 42 |
- do_ffmpeg $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3 |
|
| 43 |
- do_ffmpeg_crc $file $DEC_OPTS $4 -i $target_path/$file |
|
| 42 |
+ do_avconv $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3 |
|
| 43 |
+ do_avconv_crc $file $DEC_OPTS $4 -i $target_path/$file |
|
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
if [ -n "$do_avi" ] ; then |
| ... | ... |
@@ -53,9 +53,9 @@ fi |
| 53 | 53 |
|
| 54 | 54 |
if [ -n "$do_rm" ] ; then |
| 55 | 55 |
file=${outfile}lavf.rm
|
| 56 |
-do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed -ab 64k |
|
| 56 |
+do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed -ab 64k |
|
| 57 | 57 |
# broken |
| 58 |
-#do_ffmpeg_crc $file -i $target_path/$file |
|
| 58 |
+#do_avconv_crc $file -i $target_path/$file |
|
| 59 | 59 |
fi |
| 60 | 60 |
|
| 61 | 61 |
if [ -n "$do_mpg" ] ; then |
| ... | ... |
@@ -110,8 +110,8 @@ fi |
| 110 | 110 |
# streamed images |
| 111 | 111 |
# mjpeg |
| 112 | 112 |
#file=${outfile}lavf.mjpeg
|
| 113 |
-#do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src |
|
| 114 |
-#do_ffmpeg_crc $file -i $target_path/$file |
|
| 113 |
+#do_avconv $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src |
|
| 114 |
+#do_avconv_crc $file -i $target_path/$file |
|
| 115 | 115 |
|
| 116 | 116 |
if [ -n "$do_pbmpipe" ] ; then |
| 117 | 117 |
do_streamed_images pbm |
| ... | ... |
@@ -127,14 +127,14 @@ fi |
| 127 | 127 |
|
| 128 | 128 |
if [ -n "$do_gif" ] ; then |
| 129 | 129 |
file=${outfile}lavf.gif
|
| 130 |
-do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 -pix_fmt rgb24 |
|
| 131 |
-do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file -pix_fmt rgb24 |
|
| 130 |
+do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 -pix_fmt rgb24 |
|
| 131 |
+do_avconv_crc $file $DEC_OPTS -i $target_path/$file -pix_fmt rgb24 |
|
| 132 | 132 |
fi |
| 133 | 133 |
|
| 134 | 134 |
if [ -n "$do_yuv4mpeg" ] ; then |
| 135 | 135 |
file=${outfile}lavf.y4m
|
| 136 |
-do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 |
|
| 137 |
-#do_ffmpeg_crc $file -i $target_path/$file |
|
| 136 |
+do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 |
|
| 137 |
+#do_avconv_crc $file -i $target_path/$file |
|
| 138 | 138 |
fi |
| 139 | 139 |
|
| 140 | 140 |
# image formats |
| ... | ... |
@@ -227,9 +227,9 @@ conversions="yuv420p yuv422p yuv444p yuyv422 yuv410p yuv411p yuvj420p \ |
| 227 | 227 |
monob yuv440p yuvj440p" |
| 228 | 228 |
for pix_fmt in $conversions ; do |
| 229 | 229 |
file=${outfile}${pix_fmt}.yuv
|
| 230 |
- run_ffmpeg $DEC_OPTS -r 1 -t 1 -f image2 -vcodec pgmyuv -i $raw_src \ |
|
| 230 |
+ run_avconv $DEC_OPTS -r 1 -t 1 -f image2 -vcodec pgmyuv -i $raw_src \ |
|
| 231 | 231 |
$ENC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst |
| 232 |
- do_ffmpeg $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \ |
|
| 232 |
+ do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \ |
|
| 233 | 233 |
$ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p |
| 234 | 234 |
done |
| 235 | 235 |
fi |
| ... | ... |
@@ -16,7 +16,7 @@ do_video_filter() {
|
| 16 | 16 |
filters=$2 |
| 17 | 17 |
shift 2 |
| 18 | 18 |
printf '%-20s' $label |
| 19 |
- run_ffmpeg $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \ |
|
| 19 |
+ run_avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \ |
|
| 20 | 20 |
$ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5: |
| 21 | 21 |
} |
| 22 | 22 |
|
| ... | ... |
@@ -49,7 +49,7 @@ do_lavfi_pixfmts(){
|
| 49 | 49 |
out_fmts=${outfile}${1}_out_fmts
|
| 50 | 50 |
|
| 51 | 51 |
# exclude pixel formats which are not supported as input |
| 52 |
- $ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts |
|
| 52 |
+ $avconv -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts |
|
| 53 | 53 |
$showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
|
| 54 | 54 |
|
| 55 | 55 |
pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
|
| ... | ... |
@@ -70,7 +70,7 @@ do_lavfi_pixfmts "scale" "200:100" |
| 70 | 70 |
do_lavfi_pixfmts "vflip" "" |
| 71 | 71 |
|
| 72 | 72 |
if [ -n "$do_pixdesc" ]; then |
| 73 |
- pix_fmts="$($ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2 | sort)" |
|
| 73 |
+ pix_fmts="$($avconv -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2 | sort)" |
|
| 74 | 74 |
for pix_fmt in $pix_fmts; do |
| 75 | 75 |
do_video_filter $pix_fmt "slicify=random,format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt |
| 76 | 76 |
done |
| ... | ... |
@@ -1,6 +1,6 @@ |
| 1 | 1 |
#!/bin/sh |
| 2 | 2 |
# |
| 3 |
-# common regression functions for ffmpeg |
|
| 3 |
+# common regression functions for avconv |
|
| 4 | 4 |
# |
| 5 | 5 |
# |
| 6 | 6 |
|
| ... | ... |
@@ -18,7 +18,7 @@ this="$test.$test_ref" |
| 18 | 18 |
outfile="$datadir/$test_ref/" |
| 19 | 19 |
|
| 20 | 20 |
# various files |
| 21 |
-ffmpeg="$target_exec ${target_path}/ffmpeg"
|
|
| 21 |
+avconv="$target_exec ${target_path}/avconv"
|
|
| 22 | 22 |
tiny_psnr="tests/tiny_psnr" |
| 23 | 23 |
raw_src="${target_path}/$raw_src_dir/%02d.pgm"
|
| 24 | 24 |
raw_dst="$datadir/$this.out.yuv" |
| ... | ... |
@@ -43,23 +43,23 @@ echov(){
|
| 43 | 43 |
|
| 44 | 44 |
. $(dirname $0)/md5.sh |
| 45 | 45 |
|
| 46 |
-FFMPEG_OPTS="-v 0 -y" |
|
| 46 |
+AVCONV_OPTS="-v 0 -y" |
|
| 47 | 47 |
COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact" |
| 48 | 48 |
DEC_OPTS="$COMMON_OPTS -threads $threads" |
| 49 | 49 |
ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint" |
| 50 | 50 |
|
| 51 |
-run_ffmpeg() |
|
| 51 |
+run_avconv() |
|
| 52 | 52 |
{
|
| 53 |
- $echov $ffmpeg $FFMPEG_OPTS $* |
|
| 54 |
- $ffmpeg $FFMPEG_OPTS $* |
|
| 53 |
+ $echov $avconv $AVCONV_OPTS $* |
|
| 54 |
+ $avconv $AVCONV_OPTS $* |
|
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 |
-do_ffmpeg() |
|
| 57 |
+do_avconv() |
|
| 58 | 58 |
{
|
| 59 | 59 |
f="$1" |
| 60 | 60 |
shift |
| 61 | 61 |
set -- $* ${target_path}/$f
|
| 62 |
- run_ffmpeg $* |
|
| 62 |
+ run_avconv $* |
|
| 63 | 63 |
do_md5sum $f |
| 64 | 64 |
if [ $f = $raw_dst ] ; then |
| 65 | 65 |
$tiny_psnr $f $raw_ref |
| ... | ... |
@@ -70,12 +70,12 @@ do_ffmpeg() |
| 70 | 70 |
fi |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 |
-do_ffmpeg_nomd5() |
|
| 73 |
+do_avconv_nomd5() |
|
| 74 | 74 |
{
|
| 75 | 75 |
f="$1" |
| 76 | 76 |
shift |
| 77 | 77 |
set -- $* ${target_path}/$f
|
| 78 |
- run_ffmpeg $* |
|
| 78 |
+ run_avconv $* |
|
| 79 | 79 |
if [ $f = $raw_dst ] ; then |
| 80 | 80 |
$tiny_psnr $f $raw_ref |
| 81 | 81 |
elif [ $f = $pcm_dst ] ; then |
| ... | ... |
@@ -85,32 +85,32 @@ do_ffmpeg_nomd5() |
| 85 | 85 |
fi |
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 |
-do_ffmpeg_crc() |
|
| 88 |
+do_avconv_crc() |
|
| 89 | 89 |
{
|
| 90 | 90 |
f="$1" |
| 91 | 91 |
shift |
| 92 |
- run_ffmpeg $* -f crc "$target_crcfile" |
|
| 92 |
+ run_avconv $* -f crc "$target_crcfile" |
|
| 93 | 93 |
echo "$f $(cat $crcfile)" |
| 94 | 94 |
} |
| 95 | 95 |
|
| 96 | 96 |
do_video_decoding() |
| 97 | 97 |
{
|
| 98 |
- do_ffmpeg $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2 |
|
| 98 |
+ do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2 |
|
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
do_video_encoding() |
| 102 | 102 |
{
|
| 103 | 103 |
file=${outfile}$1
|
| 104 |
- do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2 |
|
| 104 |
+ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2 |
|
| 105 | 105 |
} |
| 106 | 106 |
|
| 107 | 107 |
do_audio_encoding() |
| 108 | 108 |
{
|
| 109 | 109 |
file=${outfile}$1
|
| 110 |
- do_ffmpeg $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2 |
|
| 110 |
+ do_avconv $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2 |
|
| 111 | 111 |
} |
| 112 | 112 |
|
| 113 | 113 |
do_audio_decoding() |
| 114 | 114 |
{
|
| 115 |
- do_ffmpeg $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav |
|
| 115 |
+ do_avconv $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav |
|
| 116 | 116 |
} |