X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=avconv.c;h=c7a5c71b027d508be538f4dbe02aacb47c923475;hb=618b067d2132b0336e609bc311e85c557ffb30ed;hp=68dff49f735196f5b881e611a2ba7eafe587f13d;hpb=35c5d7d1ef7b623779c860887f9ddbeb3265c71c;p=ffmpeg diff --git a/avconv.c b/avconv.c index 68dff49f735..c7a5c71b027 100644 --- a/avconv.c +++ b/avconv.c @@ -97,47 +97,16 @@ typedef struct MetadataMap { static const OptionDef options[]; -/* indexed by output file stream index */ -static int *streamid_map = NULL; -static int nb_streamid_map = 0; - -static int frame_width = 0; -static int frame_height = 0; -static float frame_aspect_ratio = 0; -static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; -static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE; -static AVRational frame_rate; -static float video_qscale = 0; -static uint16_t *intra_matrix = NULL; -static uint16_t *inter_matrix = NULL; -static const char *video_rc_override_string=NULL; -static int video_disable = 0; static int video_discard = 0; static int same_quant = 0; static int do_deinterlace = 0; -static int top_field_first = -1; -static int me_threshold = 0; static int intra_dc_precision = 8; static int qp_hist = 0; -#if CONFIG_AVFILTER -static char *vfilters = NULL; -#endif - -static int audio_sample_rate = 0; -#define QSCALE_NONE -99999 -static float audio_qscale = QSCALE_NONE; -static int audio_disable = 0; -static int audio_channels = 0; - -static int subtitle_disable = 0; - -static int data_disable = 0; static int file_overwrite = 0; static int do_benchmark = 0; static int do_hex_dump = 0; static int do_pkt_dump = 0; -static int do_psnr = 0; static int do_pass = 0; static char *pass_logfilename_prefix = NULL; static int video_sync_method= -1; @@ -148,22 +117,18 @@ static int copy_tb; static int opt_shortest = 0; static char *vstats_filename; static FILE *vstats_file; -static int opt_programid = 0; static int copy_initial_nonkeyframes = 0; static int audio_volume = 256; static int exit_on_error = 0; static int using_stdin = 0; -static int verbose = 1; static int64_t video_size = 0; static int64_t audio_size = 0; static int64_t extra_size = 0; static int nb_frames_dup = 0; static int nb_frames_drop = 0; static int input_sync; -static int force_fps = 0; -static char *forced_key_frames = NULL; static float dts_delta_threshold = 10; @@ -228,6 +193,8 @@ typedef struct OutputStream { int resample_width; int resample_pix_fmt; AVRational frame_rate; + int force_fps; + int top_field_first; float frame_aspect_ratio; @@ -287,6 +254,16 @@ typedef struct OptionsContext { SpecifierOpt *codec_names; int nb_codec_names; + SpecifierOpt *audio_channels; + int nb_audio_channels; + SpecifierOpt *audio_sample_rate; + int nb_audio_sample_rate; + SpecifierOpt *frame_rates; + int nb_frame_rates; + SpecifierOpt *frame_sizes; + int nb_frame_sizes; + SpecifierOpt *frame_pix_fmts; + int nb_frame_pix_fmts; /* input options */ int64_t input_ts_offset; @@ -312,6 +289,15 @@ typedef struct OptionsContext { float mux_preload; float mux_max_delay; + int video_disable; + int audio_disable; + int subtitle_disable; + int data_disable; + + /* indexed by output file stream index */ + int *streamid_map; + int nb_streamid_map; + SpecifierOpt *metadata; int nb_metadata; SpecifierOpt *max_frames; @@ -320,6 +306,28 @@ typedef struct OptionsContext { int nb_bitstream_filters; SpecifierOpt *codec_tags; int nb_codec_tags; + SpecifierOpt *sample_fmts; + int nb_sample_fmts; + SpecifierOpt *qscale; + int nb_qscale; + SpecifierOpt *forced_key_frames; + int nb_forced_key_frames; + SpecifierOpt *force_fps; + int nb_force_fps; + SpecifierOpt *frame_aspect_ratios; + int nb_frame_aspect_ratios; + SpecifierOpt *rc_overrides; + int nb_rc_overrides; + SpecifierOpt *intra_matrices; + int nb_intra_matrices; + SpecifierOpt *inter_matrices; + int nb_inter_matrices; + SpecifierOpt *top_field_first; + int nb_top_field_first; +#if CONFIG_AVFILTER + SpecifierOpt *filters; + int nb_filters; +#endif } OptionsContext; #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ @@ -359,6 +367,7 @@ static void reset_options(OptionsContext *o) av_freep(&o->stream_maps); av_freep(&o->meta_data_maps); + av_freep(&o->streamid_map); memset(o, 0, sizeof(*o)); @@ -506,9 +515,6 @@ void exit_program(int ret) for (i = 0; i < nb_input_streams; i++) av_dict_free(&input_streams[i].opts); - av_free(intra_matrix); - av_free(inter_matrix); - if (vstats_file) fclose(vstats_file); av_free(vstats_filename); @@ -529,9 +535,8 @@ void exit_program(int ret) #endif if (received_sigterm) { - fprintf(stderr, - "Received signal %d: terminating.\n", - (int) received_sigterm); + av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n", + (int) received_sigterm); exit (255); } @@ -542,7 +547,7 @@ static void assert_avoptions(AVDictionary *m) { AVDictionaryEntry *t; if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) { - av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key); + av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); exit_program(1); } } @@ -553,12 +558,12 @@ static void assert_codec_experimental(AVCodecContext *c, int encoder) AVCodec *codec; if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL && c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { - av_log(NULL, AV_LOG_ERROR, "%s '%s' is experimental and might produce bad " + av_log(NULL, AV_LOG_FATAL, "%s '%s' is experimental and might produce bad " "results.\nAdd '-strict experimental' if you want to use it.\n", codec_string, c->codec->name); codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id); if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL)) - av_log(NULL, AV_LOG_ERROR, "Or use the non experimental %s '%s'.\n", + av_log(NULL, AV_LOG_FATAL, "Or use the non experimental %s '%s'.\n", codec_string, codec->name); exit_program(1); } @@ -691,9 +696,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx av_free_packet(pkt); new_pkt.destruct= av_destruct_packet; } else if(a<0){ - fprintf(stderr, "%s failed for stream %d, codec %s", - bsfc->filter->name, pkt->stream_index, - avctx->codec ? avctx->codec->name : "copy"); + av_log(NULL, AV_LOG_ERROR, "%s failed for stream %d, codec %s", + bsfc->filter->name, pkt->stream_index, + avctx->codec ? avctx->codec->name : "copy"); print_error("", a); if (exit_on_error) exit_program(1); @@ -739,14 +744,14 @@ need_realloc: audio_out_size += FF_MIN_BUFFER_SIZE; if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){ - fprintf(stderr, "Buffer sizes too large\n"); + av_log(NULL, AV_LOG_FATAL, "Buffer sizes too large\n"); exit_program(1); } av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size); av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size); if (!audio_buf || !audio_out){ - fprintf(stderr, "Out of memory in do_audio_out\n"); + av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n"); exit_program(1); } @@ -778,15 +783,15 @@ need_realloc: ost->audio_resample = 0; } else if (ost->audio_resample) { if (dec->sample_fmt != AV_SAMPLE_FMT_S16) - fprintf(stderr, "Warning, using s16 intermediate sample format for resampling\n"); + av_log(NULL, AV_LOG_WARNING, "Using s16 intermediate sample format for resampling\n"); ost->resample = av_audio_resample_init(enc->channels, dec->channels, enc->sample_rate, dec->sample_rate, enc->sample_fmt, dec->sample_fmt, 16, 10, 0, 0.8); if (!ost->resample) { - fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n", - dec->channels, dec->sample_rate, - enc->channels, enc->sample_rate); + av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n", + dec->channels, dec->sample_rate, + enc->channels, enc->sample_rate); exit_program(1); } } @@ -800,9 +805,9 @@ need_realloc: ost->reformat_ctx = av_audio_convert_alloc(enc->sample_fmt, 1, dec->sample_fmt, 1, NULL, 0); if (!ost->reformat_ctx) { - fprintf(stderr, "Cannot convert %s sample format to %s sample format\n", - av_get_sample_fmt_name(dec->sample_fmt), - av_get_sample_fmt_name(enc->sample_fmt)); + av_log(NULL, AV_LOG_FATAL, "Cannot convert %s sample format to %s sample format\n", + av_get_sample_fmt_name(dec->sample_fmt), + av_get_sample_fmt_name(enc->sample_fmt)); exit_program(1); } ost->reformat_pair=MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt); @@ -821,8 +826,7 @@ need_realloc: byte_delta= FFMAX(byte_delta, -size); size += byte_delta; buf -= byte_delta; - if(verbose > 2) - fprintf(stderr, "discarding %d audio samples\n", (int)-delta); + av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n", (int)-delta); if(!size) return; ist->is_start=0; @@ -840,14 +844,13 @@ need_realloc: memcpy(input_tmp + byte_delta, buf, size); buf= input_tmp; size += byte_delta; - if(verbose > 2) - fprintf(stderr, "adding %d audio samples of silence\n", (int)delta); + av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", (int)delta); } }else if(audio_sync_method>1){ int comp= av_clip(delta, -audio_sync_method, audio_sync_method); av_assert0(ost->audio_resample); - if(verbose > 2) - fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate); + av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n", + delta, comp, enc->sample_rate); // 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)); av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate); } @@ -887,7 +890,7 @@ need_realloc: if (enc->frame_size > 1) { /* output resampled raw samples */ if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) { - fprintf(stderr, "av_fifo_realloc2() failed\n"); + av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n"); exit_program(1); } av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL); @@ -905,7 +908,7 @@ need_realloc: ret = avcodec_encode_audio(enc, audio_out, audio_out_size, (short *)audio_buf); if (ret < 0) { - fprintf(stderr, "Audio encoding failed\n"); + av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); exit_program(1); } audio_size += ret; @@ -932,7 +935,7 @@ need_realloc: size_out = size_out*coded_bps/8; if(size_out > audio_out_size){ - fprintf(stderr, "Internal error, buffer size too small\n"); + av_log(NULL, AV_LOG_FATAL, "Internal error, buffer size too small\n"); exit_program(1); } @@ -940,7 +943,7 @@ need_realloc: ret = avcodec_encode_audio(enc, audio_out, size_out, (short *)buftmp); if (ret < 0) { - fprintf(stderr, "Audio encoding failed\n"); + av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); exit_program(1); } audio_size += ret; @@ -979,7 +982,7 @@ static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void * if(avpicture_deinterlace(picture2, picture, dec->pix_fmt, dec->width, dec->height) < 0) { /* if error, do not deinterlace */ - fprintf(stderr, "Deinterlacing failed\n"); + av_log(NULL, AV_LOG_WARNING, "Deinterlacing failed\n"); av_free(buf); buf = NULL; picture2 = picture; @@ -1006,7 +1009,7 @@ static void do_subtitle_out(AVFormatContext *s, AVPacket pkt; if (pts == AV_NOPTS_VALUE) { - fprintf(stderr, "Subtitle packets must have a pts\n"); + av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n"); if (exit_on_error) exit_program(1); return; @@ -1035,7 +1038,7 @@ static void do_subtitle_out(AVFormatContext *s, subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, subtitle_out_max_size, sub); if (subtitle_out_size < 0) { - fprintf(stderr, "Subtitle encoding failed\n"); + av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n"); exit_program(1); } @@ -1097,7 +1100,7 @@ static void do_video_resample(OutputStream *ost, ost->st->codec->pix_fmt, ost->sws_flags, NULL, NULL, NULL); if (ost->img_resample_ctx == NULL) { - fprintf(stderr, "Cannot get resampling context\n"); + av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n"); exit_program(1); } } @@ -1108,7 +1111,7 @@ static void do_video_resample(OutputStream *ost, if (resample_changed) { avfilter_graph_free(&ost->graph); if (configure_video_filters(ist, ost)) { - fprintf(stderr, "Error reinitializing filters!\n"); + av_log(NULL, AV_LOG_FATAL, "Error reinitializing filters!\n"); exit_program(1); } } @@ -1160,12 +1163,10 @@ static void do_video_out(AVFormatContext *s, //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); if (nb_frames == 0){ ++nb_frames_drop; - if (verbose>2) - fprintf(stderr, "*** drop!\n"); + av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n"); }else if (nb_frames > 1) { nb_frames_dup += nb_frames - 1; - if (verbose>2) - fprintf(stderr, "*** %d dup!\n", nb_frames-1); + av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames-1); } }else ost->sync_opts= lrintf(sync_ipts); @@ -1202,16 +1203,16 @@ static void do_video_out(AVFormatContext *s, settings */ big_picture.interlaced_frame = in_picture->interlaced_frame; if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) { - if(top_field_first == -1) + if (ost->top_field_first == -1) big_picture.top_field_first = in_picture->top_field_first; else - big_picture.top_field_first = top_field_first; + big_picture.top_field_first = !!ost->top_field_first; } /* handles same_quant here. This is not correct because it may not be a global option */ big_picture.quality = quality; - if(!me_threshold) + if (!enc->me_threshold) big_picture.pict_type = 0; // big_picture.pts = AV_NOPTS_VALUE; big_picture.pts= ost->sync_opts; @@ -1226,7 +1227,7 @@ static void do_video_out(AVFormatContext *s, bit_buffer, bit_buffer_size, &big_picture); if (ret < 0) { - fprintf(stderr, "Video encoding failed\n"); + av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); exit_program(1); } @@ -1391,31 +1392,28 @@ static void print_report(OutputFile *output_files, if (ti1 < 0.01) ti1 = 0.01; - if (verbose > 0 || is_last_report) { - bitrate = (double)(total_size * 8) / ti1 / 1000.0; + bitrate = (double)(total_size * 8) / ti1 / 1000.0; - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s", (double)total_size / 1024, ti1, bitrate); - if (nb_frames_dup || nb_frames_drop) - snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", - nb_frames_dup, nb_frames_drop); + if (nb_frames_dup || nb_frames_drop) + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", + nb_frames_dup, nb_frames_drop); - if (verbose >= 0) - fprintf(stderr, "%s \r", buf); + av_log(NULL, is_last_report ? AV_LOG_WARNING : AV_LOG_INFO, "%s \r", buf); - fflush(stderr); - } + fflush(stderr); - if (is_last_report && verbose >= 0){ + if (is_last_report) { int64_t raw= audio_size + video_size + extra_size; - fprintf(stderr, "\n"); - fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n", - video_size/1024.0, - audio_size/1024.0, - extra_size/1024.0, - 100.0*(total_size - raw)/raw + av_log(NULL, AV_LOG_INFO, "\n"); + av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n", + video_size/1024.0, + audio_size/1024.0, + extra_size/1024.0, + 100.0*(total_size - raw)/raw ); } } @@ -1479,7 +1477,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams) ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL); } if (ret < 0) { - fprintf(stderr, "Audio encoding failed\n"); + av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); exit_program(1); } audio_size += ret; @@ -1488,7 +1486,7 @@ static void flush_encoders(OutputStream *ost_table, int nb_ostreams) case AVMEDIA_TYPE_VIDEO: ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL); if (ret < 0) { - fprintf(stderr, "Video encoding failed\n"); + av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); exit_program(1); } video_size += ret; @@ -1560,11 +1558,10 @@ static int output_packet(InputStream *ist, int ist_index, handle_eof: ist->pts= ist->next_pts; - if(avpkt.size && avpkt.size != pkt->size && - ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){ - fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index); + if(avpkt.size && avpkt.size != pkt->size) + av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING, + "Multiple frames in a packet from stream %d\n", pkt->stream_index); ist->showed_multi_packet_warning=1; - } /* decode the packet if needed */ decoded_data_buf = NULL; /* fail safe */ @@ -1748,7 +1745,6 @@ static int output_packet(InputStream *ist, int ist_index, abort(); } } else { - AVFrame avframe; //FIXME/XXX remove this AVPacket opkt; int64_t ost_tb_start_time= av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base); @@ -1764,10 +1760,6 @@ static int output_packet(InputStream *ist, int ist_index, /* no reencoding needed : output the packet directly */ /* force the input stream PTS */ - avcodec_get_frame_defaults(&avframe); - ost->st->codec->coded_frame= &avframe; - avframe.key_frame = pkt->flags & AV_PKT_FLAG_KEY; - if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) audio_size += data_size; else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -1891,7 +1883,7 @@ static int transcode_init(OutputFile *output_files, InputFile *input_files, int nb_input_files) { - int ret = 0, i, j; + int ret = 0, i, j, k; AVFormatContext *os; AVCodecContext *codec, *icodec; OutputStream *ost; @@ -1912,7 +1904,7 @@ static int transcode_init(OutputFile *output_files, os = output_files[i].ctx; if (!os->nb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(os, i, os->filename, 1); - fprintf(stderr, "Output file #%d does not contain any stream\n", i); + av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i); return AVERROR(EINVAL); } } @@ -1967,7 +1959,7 @@ static int transcode_init(OutputFile *output_files, switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: if(audio_volume != 256) { - fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); + av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n"); exit_program(1); } codec->channel_layout = icodec->channel_layout; @@ -2042,7 +2034,7 @@ static int transcode_init(OutputFile *output_files, choose_pixel_fmt(ost->st, ost->enc); if (ost->st->codec->pix_fmt == PIX_FMT_NONE) { - fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n"); + av_log(NULL, AV_LOG_FATAL, "Video pixel format is unknown, stream cannot be encoded\n"); exit_program(1); } @@ -2059,7 +2051,7 @@ static int transcode_init(OutputFile *output_files, avcodec_get_frame_defaults(&ost->pict_tmp); if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt, codec->width, codec->height)) { - fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); + av_log(NULL, AV_LOG_FATAL, "Cannot allocate temp picture, check pix fmt\n"); exit_program(1); } ost->img_resample_ctx = sws_getContext( @@ -2071,7 +2063,7 @@ static int transcode_init(OutputFile *output_files, codec->pix_fmt, ost->sws_flags, NULL, NULL, NULL); if (ost->img_resample_ctx == NULL) { - fprintf(stderr, "Cannot get resampling context\n"); + av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n"); exit_program(1); } #endif @@ -2086,7 +2078,7 @@ static int transcode_init(OutputFile *output_files, if (!ost->frame_rate.num) ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; - if (ost->enc && ost->enc->supported_framerates && !force_fps) { + if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) { int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[idx]; } @@ -2094,7 +2086,7 @@ static int transcode_init(OutputFile *output_files, #if CONFIG_AVFILTER if (configure_video_filters(ist, ost)) { - fprintf(stderr, "Error opening filters!\n"); + av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n"); exit(1); } #endif @@ -2119,7 +2111,8 @@ static int transcode_init(OutputFile *output_files, if (codec->flags & CODEC_FLAG_PASS1) { f = fopen(logfilename, "wb"); if (!f) { - fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno)); + av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n", + logfilename, strerror(errno)); exit_program(1); } ost->logfile = f; @@ -2127,7 +2120,8 @@ static int transcode_init(OutputFile *output_files, char *logbuffer; size_t logbuffer_size; if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { - fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename); + av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n", + logfilename); exit_program(1); } codec->stats_in = logbuffer; @@ -2143,8 +2137,8 @@ static int transcode_init(OutputFile *output_files, if (!bit_buffer) bit_buffer = av_malloc(bit_buffer_size); if (!bit_buffer) { - fprintf(stderr, "Cannot allocate %d bytes output buffer\n", - bit_buffer_size); + av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n", + bit_buffer_size); return AVERROR(ENOMEM); } @@ -2181,6 +2175,9 @@ static int transcode_init(OutputFile *output_files, av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." "It takes bits/s as argument, not kbits/s\n"); extra_size += ost->st->codec->extradata_size; + + if (ost->st->codec->me_threshold) + input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV; } } @@ -2189,6 +2186,22 @@ static int transcode_init(OutputFile *output_files, if ((ret = init_input_stream(i, output_streams, nb_output_streams, error, sizeof(error))) < 0) goto dump_format; + /* discard unused programs */ + for (i = 0; i < nb_input_files; i++) { + InputFile *ifile = &input_files[i]; + for (j = 0; j < ifile->ctx->nb_programs; j++) { + AVProgram *p = ifile->ctx->programs[j]; + int discard = AVDISCARD_ALL; + + for (k = 0; k < p->nb_stream_indexes; k++) + if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) { + discard = AVDISCARD_DEFAULT; + break; + } + p->discard = discard; + } + } + /* open files and write file headers */ for (i = 0; i < nb_output_files; i++) { os = output_files[i].ctx; @@ -2211,31 +2224,29 @@ static int transcode_init(OutputFile *output_files, } /* dump the stream mapping */ - if (verbose >= 0) { - fprintf(stderr, "Stream mapping:\n"); - for (i = 0; i < nb_output_streams;i ++) { - ost = &output_streams[i]; - fprintf(stderr, " Stream #%d.%d -> #%d.%d", - input_streams[ost->source_index].file_index, - input_streams[ost->source_index].st->index, - ost->file_index, - ost->index); - if (ost->sync_ist != &input_streams[ost->source_index]) - fprintf(stderr, " [sync #%d.%d]", - ost->sync_ist->file_index, - ost->sync_ist->st->index); - if (ost->st->stream_copy) - fprintf(stderr, " (copy)"); - else - fprintf(stderr, " (%s -> %s)", input_streams[ost->source_index].dec ? - input_streams[ost->source_index].dec->name : "?", - ost->enc ? ost->enc->name : "?"); - fprintf(stderr, "\n"); - } + av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); + for (i = 0; i < nb_output_streams; i++) { + ost = &output_streams[i]; + av_log(NULL, AV_LOG_INFO, " Stream #%d.%d -> #%d.%d", + input_streams[ost->source_index].file_index, + input_streams[ost->source_index].st->index, + ost->file_index, + ost->index); + if (ost->sync_ist != &input_streams[ost->source_index]) + av_log(NULL, AV_LOG_INFO, " [sync #%d.%d]", + ost->sync_ist->file_index, + ost->sync_ist->st->index); + if (ost->st->stream_copy) + av_log(NULL, AV_LOG_INFO, " (copy)"); + else + av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ? + input_streams[ost->source_index].dec->name : "?", + ost->enc ? ost->enc->name : "?"); + av_log(NULL, AV_LOG_INFO, "\n"); } if (ret) { - fprintf(stderr, "%s\n", error); + av_log(NULL, AV_LOG_ERROR, "%s\n", error); return ret; } @@ -2269,8 +2280,7 @@ static int transcode(OutputFile *output_files, if (ret < 0) goto fail; - if (verbose >= 0) - fprintf(stderr, "Press ctrl-c to stop encoding\n"); + av_log(NULL, AV_LOG_INFO, "Press ctrl-c to stop encoding\n"); term_init(); timer_start = av_gettime(); @@ -2312,8 +2322,8 @@ static int transcode(OutputFile *output_files, } if (ost->frame_number >= ost->max_frames) { int j; - for (j = of->ost_index; j < of->ctx->nb_streams; j++) - output_streams[j].is_past_recording_time = 1; + for (j = 0; j < of->ctx->nb_streams; j++) + output_streams[of->ost_index + j].is_past_recording_time = 1; continue; } } @@ -2377,9 +2387,8 @@ static int transcode(OutputFile *output_files, int64_t delta= pkt_dts - ist->next_pts; if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1pts)&& !copy_ts){ input_files[ist->file_index].ts_offset -= delta; - if (verbose > 2) - fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", - delta, input_files[ist->file_index].ts_offset); + av_log(NULL, AV_LOG_DEBUG, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", + delta, input_files[ist->file_index].ts_offset); pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); if(pkt.pts != AV_NOPTS_VALUE) pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); @@ -2389,9 +2398,8 @@ static int transcode(OutputFile *output_files, //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size); if (output_packet(ist, ist_index, output_streams, nb_output_streams, &pkt) < 0) { - if (verbose >= 0) - fprintf(stderr, "Error while decoding stream #%d.%d\n", - ist->file_index, ist->st->index); + av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d.%d\n", + ist->file_index, ist->st->index); if (exit_on_error) exit_program(1); av_free_packet(&pkt); @@ -2480,58 +2488,13 @@ static int transcode(OutputFile *output_files, return ret; } -static int opt_video_rc_override_string(const char *opt, const char *arg) -{ - video_rc_override_string = arg; - return 0; -} - -static int opt_me_threshold(const char *opt, const char *arg) -{ - me_threshold = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); - return 0; -} - static int opt_verbose(const char *opt, const char *arg) { - verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10); - return 0; -} - -static int opt_frame_rate(const char *opt, const char *arg) -{ - if (av_parse_video_rate(&frame_rate, arg) < 0) { - fprintf(stderr, "Incorrect value for %s: %s\n", opt, arg); - exit_program(1); - } - return 0; -} - -static int opt_frame_size(const char *opt, const char *arg) -{ - if (av_parse_video_size(&frame_width, &frame_height, arg) < 0) { - fprintf(stderr, "Incorrect frame size\n"); - return AVERROR(EINVAL); - } - return 0; -} - -static int opt_frame_pix_fmt(const char *opt, const char *arg) -{ - if (strcmp(arg, "list")) { - frame_pix_fmt = av_get_pix_fmt(arg); - if (frame_pix_fmt == PIX_FMT_NONE) { - fprintf(stderr, "Unknown pixel format requested: %s\n", arg); - return AVERROR(EINVAL); - } - } else { - show_pix_fmts(); - exit_program(0); - } + av_log(NULL, AV_LOG_WARNING, "-%s is deprecated, use -loglevel\n", opt); return 0; } -static int opt_frame_aspect_ratio(const char *opt, const char *arg) +static double parse_frame_aspect_ratio(const char *arg) { int x = 0, y = 0; double ar = 0; @@ -2549,57 +2512,10 @@ static int opt_frame_aspect_ratio(const char *opt, const char *arg) ar = strtod(arg, NULL); if (!ar) { - fprintf(stderr, "Incorrect aspect ratio specification.\n"); - return AVERROR(EINVAL); - } - frame_aspect_ratio = ar; - return 0; -} - -static int opt_qscale(const char *opt, const char *arg) -{ - video_qscale = parse_number_or_die(opt, arg, OPT_FLOAT, 0, 255); - if (video_qscale == 0) { - fprintf(stderr, "qscale must be > 0.0 and <= 255\n"); - return AVERROR(EINVAL); - } - return 0; -} - -static int opt_top_field_first(const char *opt, const char *arg) -{ - top_field_first = parse_number_or_die(opt, arg, OPT_INT, 0, 1); - return 0; -} - -static int opt_audio_sample_fmt(const char *opt, const char *arg) -{ - if (strcmp(arg, "list")) { - audio_sample_fmt = av_get_sample_fmt(arg); - if (audio_sample_fmt == AV_SAMPLE_FMT_NONE) { - av_log(NULL, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg); - return AVERROR(EINVAL); - } - } else { - int i; - char fmt_str[128]; - for (i = -1; i < AV_SAMPLE_FMT_NB; i++) - printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i)); - exit_program(0); + av_log(NULL, AV_LOG_FATAL, "Incorrect aspect ratio specification.\n"); + exit_program(1); } - return 0; -} - -static int opt_audio_rate(const char *opt, const char *arg) -{ - audio_sample_rate = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); - return 0; -} - -static int opt_audio_channels(const char *opt, const char *arg) -{ - audio_channels = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); - return 0; + return ar; } static int opt_audio_codec(OptionsContext *o, const char *opt, const char *arg) @@ -2641,7 +2557,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) *sync = 0; sync_file_idx = strtol(sync + 1, &sync, 0); if (sync_file_idx >= nb_input_files || sync_file_idx < 0) { - av_log(NULL, AV_LOG_ERROR, "Invalid sync file index: %d.\n", sync_file_idx); + av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx); exit_program(1); } if (*sync) @@ -2653,7 +2569,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) break; } if (i == input_files[sync_file_idx].nb_streams) { - av_log(NULL, AV_LOG_ERROR, "Sync stream specification in map %s does not " + av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not " "match any streams.\n", arg); exit_program(1); } @@ -2662,7 +2578,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) file_idx = strtol(map, &p, 0); if (file_idx >= nb_input_files || file_idx < 0) { - av_log(NULL, AV_LOG_ERROR, "Invalid input file index: %d.\n", file_idx); + av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx); exit_program(1); } if (negative) @@ -2696,7 +2612,7 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) } if (!m) { - av_log(NULL, AV_LOG_ERROR, "Stream map '%s' matches no streams.\n", arg); + av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n", arg); exit_program(1); } @@ -2718,7 +2634,7 @@ static void parse_meta_type(char *arg, char *type, int *index) *index = strtol(++arg, NULL, 0); break; default: - fprintf(stderr, "Invalid metadata type %c.\n", *arg); + av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg); exit_program(1); } } else @@ -2764,11 +2680,11 @@ static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, i avcodec_find_encoder_by_name(name) : avcodec_find_decoder_by_name(name); if(!codec) { - av_log(NULL, AV_LOG_ERROR, "Unknown %s '%s'\n", codec_string, name); + av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name); exit_program(1); } if(codec->type != type) { - av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name); + av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name); exit_program(1); } return codec->id; @@ -2826,7 +2742,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) switch (dec->codec_type) { case AVMEDIA_TYPE_AUDIO: - if(audio_disable) + if (o->audio_disable) st->discard= AVDISCARD_ALL; break; case AVMEDIA_TYPE_VIDEO: @@ -2837,19 +2753,15 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) dec->height >>= dec->lowres; dec->width >>= dec->lowres; } - if(me_threshold) - dec->debug |= FF_DEBUG_MV; if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) { - if (verbose >= 0) - fprintf(stderr,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n", - i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num, - - (float)rfps / rfps_base, rfps, rfps_base); + av_log(NULL, AV_LOG_INFO,"\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\n", + i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num, + (float)rfps / rfps_base, rfps, rfps_base); } - if(video_disable) + if (o->video_disable) st->discard= AVDISCARD_ALL; else if(video_discard) st->discard= video_discard; @@ -2857,7 +2769,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) case AVMEDIA_TYPE_DATA: break; case AVMEDIA_TYPE_SUBTITLE: - if(subtitle_disable) + if (o->subtitle_disable) st->discard = AVDISCARD_ALL; break; case AVMEDIA_TYPE_ATTACHMENT: @@ -2881,7 +2793,7 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena if (o->format) { if (!(file_iformat = av_find_input_format(o->format))) { - fprintf(stderr, "Unknown input format: '%s'\n", o->format); + av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format); exit_program(1); } } @@ -2898,24 +2810,22 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena print_error(filename, AVERROR(ENOMEM)); exit_program(1); } - if (audio_sample_rate) { - snprintf(buf, sizeof(buf), "%d", audio_sample_rate); + if (o->nb_audio_sample_rate) { + snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i); av_dict_set(&format_opts, "sample_rate", buf, 0); } - if (audio_channels) { - snprintf(buf, sizeof(buf), "%d", audio_channels); + if (o->nb_audio_channels) { + snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i); av_dict_set(&format_opts, "channels", buf, 0); } - if (frame_rate.num) { - snprintf(buf, sizeof(buf), "%d/%d", frame_rate.num, frame_rate.den); - av_dict_set(&format_opts, "framerate", buf, 0); + if (o->nb_frame_rates) { + av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0); } - if (frame_width && frame_height) { - snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height); - av_dict_set(&format_opts, "video_size", buf, 0); + if (o->nb_frame_sizes) { + av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0); } - if (frame_pix_fmt != PIX_FMT_NONE) - av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0); + if (o->nb_frame_pix_fmts) + av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0); ic->flags |= AVFMT_FLAG_NONBLOCK; @@ -2927,30 +2837,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena } assert_avoptions(format_opts); - if(opt_programid) { - int i, j; - int found=0; - for(i=0; inb_streams; i++){ - ic->streams[i]->discard= AVDISCARD_ALL; - } - for(i=0; inb_programs; i++){ - AVProgram *p= ic->programs[i]; - if(p->id != opt_programid){ - p->discard = AVDISCARD_ALL; - }else{ - found=1; - for(j=0; jnb_stream_indexes; j++){ - ic->streams[p->stream_index[j]]->discard= AVDISCARD_DEFAULT; - } - } - } - if(!found){ - fprintf(stderr, "Specified program id not found\n"); - exit_program(1); - } - opt_programid=0; - } - /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) choose_codec(o, ic, ic->streams[i], ic->streams[i]->codec->codec_type); @@ -2962,8 +2848,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena /* If not enough info to get the stream parameters, we decode the first frames to get it. (used in mpeg case for example) */ ret = avformat_find_stream_info(ic, opts); - if (ret < 0 && verbose >= 0) { - fprintf(stderr, "%s: could not find codec parameters\n", filename); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename); av_close_input_file(ic); exit_program(1); } @@ -2977,8 +2863,8 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena if (o->start_time != 0) { ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD); if (ret < 0) { - fprintf(stderr, "%s: could not seek to position %0.3f\n", - filename, (double)timestamp / AV_TIME_BASE); + av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n", + filename, (double)timestamp / AV_TIME_BASE); } } @@ -2986,22 +2872,14 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena add_input_streams(o, ic); /* dump the file content */ - if (verbose >= 0) - av_dump_format(ic, nb_input_files, filename, 0); + av_dump_format(ic, nb_input_files, filename, 0); input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); input_files[nb_input_files - 1].ctx = ic; input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp); input_files[nb_input_files - 1].nb_streams = ic->nb_streams; - - frame_rate = (AVRational){0, 0}; - frame_pix_fmt = PIX_FMT_NONE; - frame_height = 0; - frame_width = 0; - audio_sample_rate = 0; - audio_channels = 0; - audio_sample_fmt = AV_SAMPLE_FMT_NONE; + input_files[nb_input_files - 1].rate_emu = o->rate_emu; for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); @@ -3037,14 +2915,15 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type) { OutputStream *ost; - AVStream *st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); + AVStream *st = av_new_stream(oc, oc->nb_streams < o->nb_streamid_map ? o->streamid_map[oc->nb_streams] : 0); int idx = oc->nb_streams - 1; int64_t max_frames = INT64_MAX; char *bsf = NULL, *next, *codec_tag = NULL; AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL; + double qscale = -1; if (!st) { - av_log(NULL, AV_LOG_ERROR, "Could not alloc stream.\n"); + av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n"); exit_program(1); } @@ -3071,7 +2950,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e if (next = strchr(bsf, ',')) *next++ = 0; if (!(bsfc = av_bitstream_filter_init(bsf))) { - av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter %s\n", bsf); + av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf); exit_program(1); } if (bsfc_prev) @@ -3091,10 +2970,33 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e st->codec->codec_tag = tag; } + MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); + if (qscale >= 0 || same_quant) { + st->codec->flags |= CODEC_FLAG_QSCALE; + st->codec->global_quality = FF_QP2LAMBDA * qscale; + } + ost->sws_flags = av_get_int(sws_opts, "sws_flags", NULL); return ost; } +static void parse_matrix_coeffs(uint16_t *dest, const char *str) +{ + int i; + const char *p = str; + for(i = 0;; i++) { + dest[i] = atoi(p); + if(i == 63) + break; + p = strchr(p, ','); + if(!p) { + av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i); + exit_program(1); + } + p++; + } +} + static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) { AVStream *st; @@ -3103,52 +3005,65 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO); st = ost->st; - if (!st->stream_copy) { - ost->frame_aspect_ratio = frame_aspect_ratio; - frame_aspect_ratio = 0; -#if CONFIG_AVFILTER - ost->avfilter= vfilters; - vfilters = NULL; -#endif - } - video_enc = st->codec; if(oc->oformat->flags & AVFMT_GLOBALHEADER) { video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; } - if (st->stream_copy) { - video_enc->sample_aspect_ratio = - st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); - } else { - const char *p; - int i; + if (!st->stream_copy) { + const char *p = NULL; + char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; + char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; + char *intra_matrix = NULL, *inter_matrix = NULL, *filters = NULL; + int i, force_fps = 0, top_field_first = -1; + + MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); + if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) { + av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate); + exit_program(1); + } - if (frame_rate.num) - ost->frame_rate = frame_rate; + MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st); + if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) { + av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size); + exit_program(1); + } - video_enc->width = frame_width; - video_enc->height = frame_height; - video_enc->pix_fmt = frame_pix_fmt; - st->sample_aspect_ratio = video_enc->sample_aspect_ratio; + MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st); + if (frame_aspect_ratio) + ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio); - if (video_qscale || same_quant) { - video_enc->flags |= CODEC_FLAG_QSCALE; - video_enc->global_quality = FF_QP2LAMBDA * video_qscale; + MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st); + if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) { + av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt); + exit_program(1); } + st->sample_aspect_ratio = video_enc->sample_aspect_ratio; - if(intra_matrix) - video_enc->intra_matrix = intra_matrix; - if(inter_matrix) - video_enc->inter_matrix = inter_matrix; + MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st); + if (intra_matrix) { + if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) { + av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n"); + exit_program(1); + } + parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix); + } + MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st); + if (inter_matrix) { + if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) { + av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n"); + exit_program(1); + } + parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix); + } - p= video_rc_override_string; + MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st); for(i=0; p; i++){ int start, end, q; int e=sscanf(p, "%d,%d,%d", &start, &end, &q); if(e!=3){ - fprintf(stderr, "error parsing rc_override\n"); + av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n"); exit_program(1); } video_enc->rc_override= @@ -3170,12 +3085,8 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) video_enc->rc_override_count=i; if (!video_enc->rc_initial_buffer_occupancy) video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4; - video_enc->me_threshold= me_threshold; video_enc->intra_dc_precision= intra_dc_precision - 8; - if (do_psnr) - video_enc->flags|= CODEC_FLAG_PSNR; - /* two pass mode */ if (do_pass) { if (do_pass == 1) { @@ -3185,14 +3096,23 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) } } + MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st); if (forced_key_frames) parse_forced_key_frames(forced_key_frames, ost, video_enc); + + MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st); + ost->force_fps = force_fps; + + MATCH_PER_STREAM_OPT(top_field_first, i, top_field_first, oc, st); + ost->top_field_first = top_field_first; + +#if CONFIG_AVFILTER + MATCH_PER_STREAM_OPT(filters, str, filters, oc, st); + if (filters) + ost->avfilter = av_strdup(filters); +#endif } - /* reset some key parameters */ - video_disable = 0; - av_freep(&forced_key_frames); - frame_pix_fmt = PIX_FMT_NONE; return ost; } @@ -3212,20 +3132,19 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc) audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; } if (!st->stream_copy) { - if (audio_qscale > QSCALE_NONE) { - audio_enc->flags |= CODEC_FLAG_QSCALE; - audio_enc->global_quality = FF_QP2LAMBDA * audio_qscale; + char *sample_fmt = NULL; + + MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st); + + MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st); + if (sample_fmt && + (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) { + av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt); + exit_program(1); } - if (audio_channels) - audio_enc->channels = audio_channels; - if (audio_sample_fmt != AV_SAMPLE_FMT_NONE) - audio_enc->sample_fmt = audio_sample_fmt; - if (audio_sample_rate) - audio_enc->sample_rate = audio_sample_rate; - } - /* reset some key parameters */ - audio_disable = 0; + MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st); + } return ost; } @@ -3240,7 +3159,7 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc) st = ost->st; data_enc = st->codec; if (!st->stream_copy) { - fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n"); + av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n"); exit_program(1); } @@ -3248,7 +3167,6 @@ static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc) data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; } - data_disable = 0; return ost; } @@ -3268,12 +3186,11 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc) subtitle_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; } - subtitle_disable = 0; return ost; } /* arg format is "output-stream-index:streamid-value". */ -static int opt_streamid(const char *opt, const char *arg) +static int opt_streamid(OptionsContext *o, const char *opt, const char *arg) { int idx; char *p; @@ -3282,15 +3199,15 @@ static int opt_streamid(const char *opt, const char *arg) av_strlcpy(idx_str, arg, sizeof(idx_str)); p = strchr(idx_str, ':'); if (!p) { - fprintf(stderr, - "Invalid value '%s' for option '%s', required syntax is 'index:value'\n", - arg, opt); + av_log(NULL, AV_LOG_FATAL, + "Invalid value '%s' for option '%s', required syntax is 'index:value'\n", + arg, opt); exit_program(1); } *p++ = '\0'; idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, INT_MAX); - streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1); - streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); + o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1); + o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); return 0; } @@ -3388,14 +3305,14 @@ static void opt_output_file(void *optctx, const char *filename) if (o->format) { file_oformat = av_guess_format(o->format, NULL, NULL); if (!file_oformat) { - fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", o->format); + av_log(NULL, AV_LOG_FATAL, "Requested output format '%s' is not a suitable output format\n", o->format); exit_program(1); } } else { file_oformat = av_guess_format(NULL, filename, NULL); if (!file_oformat) { - fprintf(stderr, "Unable to find a suitable output format for '%s'\n", - filename); + av_log(NULL, AV_LOG_FATAL, "Unable to find a suitable output format for '%s'\n", + filename); exit_program(1); } } @@ -3423,7 +3340,7 @@ static void opt_output_file(void *optctx, const char *filename) } /* video: highest resolution */ - if (!video_disable && oc->oformat->video_codec != CODEC_ID_NONE) { + if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) { int area = 0, idx = -1; for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; @@ -3437,7 +3354,7 @@ static void opt_output_file(void *optctx, const char *filename) } /* audio: most channels */ - if (!audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) { + if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) { int channels = 0, idx = -1; for (i = 0; i < nb_input_streams; i++) { ist = &input_streams[i]; @@ -3451,7 +3368,7 @@ static void opt_output_file(void *optctx, const char *filename) } /* subtitles: pick first */ - if (!subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) { + if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) { for (i = 0; i < nb_input_streams; i++) if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { NEW_STREAM(subtitle, i); @@ -3473,7 +3390,7 @@ static void opt_output_file(void *optctx, const char *filename) case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break; case AVMEDIA_TYPE_DATA: ost = new_data_stream(o, oc); break; default: - av_log(NULL, AV_LOG_ERROR, "Cannot map stream #%d.%d - unsupported type.\n", + av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\n", map->file_index, map->stream_index); exit_program(1); } @@ -3545,14 +3462,14 @@ static void opt_output_file(void *optctx, const char *filename) break; } } else { - av_log(NULL, AV_LOG_ERROR, "Invalid input file index %d in chapter mapping.\n", + av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n", o->chapters_input_file); exit_program(1); } } if (o->chapters_input_file >= 0) copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1], - o->metadata_chapters_manual); + !o->metadata_chapters_manual); /* copy metadata */ for (i = 0; i < o->nb_meta_data_maps; i++) { @@ -3562,7 +3479,7 @@ static void opt_output_file(void *optctx, const char *filename) #define METADATA_CHECK_INDEX(index, nb_elems, desc)\ if ((index) < 0 || (index) >= (nb_elems)) {\ - av_log(NULL, AV_LOG_ERROR, "Invalid %s index %d while processing metadata maps\n",\ + av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\n",\ (desc), (index));\ exit_program(1);\ } @@ -3618,7 +3535,7 @@ static void opt_output_file(void *optctx, const char *filename) val = strchr(o->metadata[i].u.str, '='); if (!val) { - av_log(NULL, AV_LOG_ERROR, "No '=' character in metadata string %s.\n", + av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n", o->metadata[i].u.str); exit_program(1); } @@ -3631,37 +3548,26 @@ static void opt_output_file(void *optctx, const char *filename) break; case 's': if (index < 0 || index >= oc->nb_streams) { - av_log(NULL, AV_LOG_ERROR, "Invalid stream index %d in metadata specifier.\n", index); + av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\n", index); exit_program(1); } - m = &oc->streams[i]->metadata; + m = &oc->streams[index]->metadata; break; case 'c': if (index < 0 || index >= oc->nb_chapters) { - av_log(NULL, AV_LOG_ERROR, "Invalid chapter index %d in metadata specifier.\n", index); + av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index); exit_program(1); } - m = &oc->chapters[i]->metadata; + m = &oc->chapters[index]->metadata; break; default: - av_log(NULL, AV_LOG_ERROR, "Invalid metadata specifier %s.\n", o->metadata[i].specifier); + av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier); exit_program(1); } av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0); } - frame_rate = (AVRational){0, 0}; - frame_width = 0; - frame_height = 0; - audio_sample_rate = 0; - audio_channels = 0; - audio_sample_fmt = AV_SAMPLE_FMT_NONE; - - av_freep(&streamid_map); - nb_streamid_map = 0; - - av_freep(&forced_key_frames); reset_options(o); } @@ -3708,33 +3614,9 @@ static int64_t getmaxrss(void) #endif } -static void parse_matrix_coeffs(uint16_t *dest, const char *str) -{ - int i; - const char *p = str; - for(i = 0;; i++) { - dest[i] = atoi(p); - if(i == 63) - break; - p = strchr(p, ','); - if(!p) { - fprintf(stderr, "Syntax error in matrix \"%s\" at coeff %d\n", str, i); - exit_program(1); - } - p++; - } -} - -static void opt_inter_matrix(const char *arg) -{ - inter_matrix = av_mallocz(sizeof(uint16_t) * 64); - parse_matrix_coeffs(inter_matrix, arg); -} - -static void opt_intra_matrix(const char *arg) +static int opt_audio_qscale(OptionsContext *o, const char *opt, const char *arg) { - intra_matrix = av_mallocz(sizeof(uint16_t) * 64); - parse_matrix_coeffs(intra_matrix, arg); + return parse_option(o, "q:a", arg, options); } static void show_usage(void) @@ -3829,44 +3711,35 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) norm = FILM; arg += 5; } else { - int fr; - /* Calculate FR via float to avoid int overflow */ - fr = (int)(frame_rate.num * 1000.0 / frame_rate.den); - if(fr == 25000) { - norm = PAL; - } else if((fr == 29970) || (fr == 23976)) { - norm = NTSC; - } else { - /* Try to determine PAL/NTSC by peeking in the input files */ - if(nb_input_files) { - int i, j; - for (j = 0; j < nb_input_files; j++) { - for (i = 0; i < input_files[j].nb_streams; i++) { - AVCodecContext *c = input_files[j].ctx->streams[i]->codec; - if(c->codec_type != AVMEDIA_TYPE_VIDEO) - continue; - fr = c->time_base.den * 1000 / c->time_base.num; - if(fr == 25000) { - norm = PAL; - break; - } else if((fr == 29970) || (fr == 23976)) { - norm = NTSC; - break; - } - } - if(norm != UNKNOWN) + /* Try to determine PAL/NTSC by peeking in the input files */ + if(nb_input_files) { + int i, j, fr; + for (j = 0; j < nb_input_files; j++) { + for (i = 0; i < input_files[j].nb_streams; i++) { + AVCodecContext *c = input_files[j].ctx->streams[i]->codec; + if(c->codec_type != AVMEDIA_TYPE_VIDEO) + continue; + fr = c->time_base.den * 1000 / c->time_base.num; + if(fr == 25000) { + norm = PAL; break; + } else if((fr == 29970) || (fr == 23976)) { + norm = NTSC; + break; + } } + if(norm != UNKNOWN) + break; } } - if(verbose > 0 && norm != UNKNOWN) - fprintf(stderr, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC"); + if (norm != UNKNOWN) + av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC"); } if(norm == UNKNOWN) { - fprintf(stderr, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n"); - fprintf(stderr, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n"); - fprintf(stderr, "or set a framerate with \"-r xxx\".\n"); + av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n"); + av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n"); + av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n"); exit_program(1); } @@ -3875,8 +3748,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_audio_codec(o, "c:a", "mp2"); parse_option(o, "f", "vcd", options); - opt_frame_size("s", norm == PAL ? "352x288" : "352x240"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options); + parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "1150000"); @@ -3885,8 +3758,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_default("bufsize", "327680"); // 40*1024*8; opt_default("b:a", "224000"); - audio_sample_rate = 44100; - audio_channels = 2; + parse_option(o, "ar", "44100", options); + parse_option(o, "ac", "2", options); opt_default("packetsize", "2324"); opt_default("muxrate", "1411200"); // 2352 * 75 * 8; @@ -3903,8 +3776,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_audio_codec(o, "c:a", "mp2"); parse_option(o, "f", "svcd", options); - opt_frame_size("s", norm == PAL ? "480x576" : "480x480"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options); + parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "2040000"); @@ -3915,7 +3788,7 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_default("b:a", "224000"); - audio_sample_rate = 44100; + parse_option(o, "ar", "44100", options); opt_default("packetsize", "2324"); @@ -3925,8 +3798,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_audio_codec(o, "c:a", "ac3"); parse_option(o, "f", "dvd", options); - opt_frame_size("vcodec", norm == PAL ? "720x576" : "720x480"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options); + parse_option(o, "r", frame_rates[norm], options); opt_default("g", norm == PAL ? "15" : "18"); opt_default("b", "6000000"); @@ -3938,22 +3811,22 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) opt_default("muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8 opt_default("b:a", "448000"); - audio_sample_rate = 48000; + parse_option(o, "ar", "48000", options); } else if(!strncmp(arg, "dv", 2)) { parse_option(o, "f", "dv", options); - opt_frame_size("s", norm == PAL ? "720x576" : "720x480"); - opt_frame_pix_fmt("pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : - norm == PAL ? "yuv420p" : "yuv411p"); - opt_frame_rate("r", frame_rates[norm]); + parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options); + parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" : + norm == PAL ? "yuv420p" : "yuv411p", options); + parse_option(o, "r", frame_rates[norm], options); - audio_sample_rate = 48000; - audio_channels = 2; + parse_option(o, "ar", "48000", options); + parse_option(o, "ac", "2", options); } else { - fprintf(stderr, "Unknown target: %s\n", arg); + av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg); return AVERROR(EINVAL); } return 0; @@ -4007,6 +3880,11 @@ static int opt_subtitle_tag(OptionsContext *o, const char *opt, const char *arg) return parse_option(o, "tag:s", arg, options); } +static int opt_video_filters(OptionsContext *o, const char *opt, const char *arg) +{ + return parse_option(o, "filter:v", arg, options); +} + #define OFFSET(x) offsetof(OptionsContext, x) static const OptionDef options[] = { /* main options */ @@ -4035,7 +3913,7 @@ static const OptionDef options[] = { { "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump}, "when dumping packets, also dump the payload" }, { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET, {.off = OFFSET(rate_emu)}, "read input at native frame rate", "" }, - { "v", HAS_ARG, {(void*)opt_verbose}, "set the verbosity level", "number" }, + { "v", HAS_ARG, {(void*)opt_verbose}, "deprecated, use -loglevel instead", "number" }, { "target", HAS_ARG | OPT_FUNC2, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" }, { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" }, { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" }, @@ -4044,59 +3922,60 @@ static const OptionDef options[] = { { "copytb", OPT_BOOL | OPT_EXPERT, {(void*)©_tb}, "copy input stream time base when stream copying" }, { "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, // { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "threshold" }, - { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" }, { "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" }, { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)©_initial_nonkeyframes}, "copy initial non-keyframes" }, { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, {.off = OFFSET(max_frames)}, "set the number of frames to record", "number" }, { "tag", OPT_STRING | HAS_ARG | OPT_SPEC, {.off = OFFSET(codec_tags)}, "force codec tag/fourcc", "fourcc/tag" }, + { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" }, + { "qscale", HAS_ARG | OPT_EXPERT | OPT_DOUBLE | OPT_SPEC, {.off = OFFSET(qscale)}, "use fixed quality scale (VBR)", "q" }, +#if CONFIG_AVFILTER + { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(filters)}, "set stream filterchain", "filter_list" }, +#endif /* video options */ { "vframes", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_frames}, "set the number of video frames to record", "number" }, - { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, - { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, - { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, - { "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" }, - { "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" }, + { "r", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_rates)}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, + { "s", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_sizes)}, "set frame size (WxH or abbreviation)", "size" }, + { "aspect", HAS_ARG | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_aspect_ratios)}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, + { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(frame_pix_fmts)}, "set pixel format", "format" }, + { "vn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET, {.off = OFFSET(video_disable)}, "disable video" }, { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, - { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" }, - { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, + { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(rc_overrides)}, "rate control override for specific intervals", "override" }, { "vcodec", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" }, - { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimation threshold", "threshold" }, { "same_quant", OPT_BOOL | OPT_VIDEO, {(void*)&same_quant}, "use same quantizer as source (implies VBR)" }, { "pass", HAS_ARG | OPT_VIDEO, {(void*)opt_pass}, "select the pass number (1 or 2)", "n" }, { "passlogfile", HAS_ARG | OPT_STRING | OPT_VIDEO, {(void*)&pass_logfilename_prefix}, "select two pass log file name prefix", "prefix" }, { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace}, "deinterlace pictures" }, - { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" }, { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" }, { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" }, #if CONFIG_AVFILTER - { "vf", OPT_STRING | HAS_ARG, {(void*)&vfilters}, "video filters", "filter list" }, + { "vf", HAS_ARG | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_filters}, "video filters", "filter list" }, #endif - { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" }, - { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" }, - { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, + { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(intra_matrices)}, "specify intra matrix coeffs", "matrix" }, + { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_STRING | OPT_SPEC, {.off = OFFSET(inter_matrices)}, "specify inter matrix coeffs", "matrix" }, + { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_INT| OPT_SPEC, {.off = OFFSET(top_field_first)}, "top=1/bottom=0/auto=-1 field first", "" }, { "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" }, { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_FUNC2, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" }, { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, - { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&force_fps}, "force the selected framerate, disable the best supported framerate selection" }, - { "streamid", HAS_ARG | OPT_EXPERT, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, - { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void *)&forced_key_frames}, "force key frames at specified timestamps", "timestamps" }, + { "force_fps", OPT_BOOL | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(force_fps)}, "force the selected framerate, disable the best supported framerate selection" }, + { "streamid", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_streamid}, "set the value of an outfile streamid", "streamIndex:value" }, + { "force_key_frames", OPT_STRING | HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_SPEC, {.off = OFFSET(forced_key_frames)}, "force key frames at specified timestamps", "timestamps" }, /* audio options */ { "aframes", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_frames}, "set the number of audio frames to record", "number" }, - { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", }, - { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, - { "ac", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_channels}, "set number of audio channels", "channels" }, - { "an", OPT_BOOL | OPT_AUDIO, {(void*)&audio_disable}, "disable audio" }, + { "aq", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_qscale}, "set audio quality (codec-specific)", "quality", }, + { "ar", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_sample_rate)}, "set audio sampling rate (in Hz)", "rate" }, + { "ac", HAS_ARG | OPT_AUDIO | OPT_INT | OPT_SPEC, {.off = OFFSET(audio_channels)}, "set number of audio channels", "channels" }, + { "an", OPT_BOOL | OPT_AUDIO | OPT_OFFSET, {.off = OFFSET(audio_disable)}, "disable audio" }, { "acodec", HAS_ARG | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_codec}, "force audio codec ('copy' to copy stream)", "codec" }, { "atag", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_FUNC2, {(void*)opt_audio_tag}, "force audio tag/fourcc", "fourcc/tag" }, { "vol", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&audio_volume}, "change audio volume (256=normal)" , "volume" }, // - { "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" }, + { "sample_fmt", HAS_ARG | OPT_EXPERT | OPT_AUDIO | OPT_SPEC | OPT_STRING, {.off = OFFSET(sample_fmts)}, "set sample format", "format" }, /* subtitle options */ - { "sn", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_disable}, "disable subtitle" }, + { "sn", OPT_BOOL | OPT_SUBTITLE | OPT_OFFSET, {.off = OFFSET(subtitle_disable)}, "disable subtitle" }, { "scodec", HAS_ARG | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" }, { "stag", HAS_ARG | OPT_EXPERT | OPT_SUBTITLE | OPT_FUNC2, {(void*)opt_subtitle_tag}, "force subtitle tag/fourcc", "fourcc/tag" }, @@ -4124,6 +4003,7 @@ int main(int argc, char **argv) reset_options(&o); av_log_set_flags(AV_LOG_SKIP_REPEATED); + parse_loglevel(argc, argv, options); avcodec_register_all(); #if CONFIG_AVDEVICE @@ -4143,7 +4023,7 @@ int main(int argc, char **argv) if(nb_output_files <= 0 && nb_input_files == 0) { show_usage(); - fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name); + av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name); exit_program(1); } @@ -4154,7 +4034,7 @@ int main(int argc, char **argv) } if (nb_input_files == 0) { - fprintf(stderr, "At least one input file must be specified\n"); + av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n"); exit_program(1); }