static int frame_leftBand = 0;
static int frame_rightBand = 0;
static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX};
-static AVRational frame_rate = (AVRational) {25,1};
+static AVRational frame_rate = (AVRational) {0,0};
static float video_qscale = 0;
static int video_qdiff = 3;
static uint16_t *intra_matrix = NULL;
static float video_rc_qmod_amp=0;
static int video_rc_qmod_freq=0;
#endif
-static char *video_rc_override_string=NULL;
-static char *video_rc_eq="tex^qComp";
+static const char *video_rc_override_string=NULL;
static int video_disable = 0;
static int video_discard = 0;
static char *video_codec_name = NULL;
static char *str_author = NULL;
static char *str_copyright = NULL;
static char *str_comment = NULL;
+static char *str_genre = NULL;
static char *str_album = NULL;
static int do_benchmark = 0;
static int do_hex_dump = 0;
static AVBitStreamFilterContext *video_bitstream_filters=NULL;
static AVBitStreamFilterContext *audio_bitstream_filters=NULL;
+static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL;
static AVBitStreamFilterContext *bitstream_filters[MAX_FILES][MAX_STREAMS];
#define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass"
&new_pkt.data, &new_pkt.size,
pkt->data, pkt->size,
pkt->flags & PKT_FLAG_KEY);
- if(a){
+ if(a>0){
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");
+ print_error("", a);
}
*pkt= new_pkt;
int size_out, frame_bytes, ret;
AVCodecContext *enc= ost->st->codec;
+ AVCodecContext *dec= ist->st->codec;
/* SC: dynamic allocation of buffers */
if (!audio_buf)
if (!audio_buf || !audio_out)
return; /* Should signal an error ! */
+ if (enc->channels != dec->channels)
+ ost->audio_resample = 1;
+
+ if (ost->audio_resample && !ost->resample) {
+ ost->resample = audio_resample_init(enc->channels, dec->channels,
+ enc->sample_rate, dec->sample_rate);
+ 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);
+ exit(1);
+ }
+ }
+
if(audio_sync_method){
double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
- av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2);
enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack
pkt.data= (uint8_t *)final_picture;
pkt.size= sizeof(AVPicture);
- if(dec->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
- pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
- if(dec->coded_frame && dec->coded_frame->key_frame)
- pkt.flags |= PKT_FLAG_KEY;
+ pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base);
+ pkt.flags |= PKT_FLAG_KEY;
write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]);
enc->coded_frame = old_frame;
if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY))
opkt.destruct= av_destruct_packet;
- write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][pkt->stream_index]);
+ write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][opkt.stream_index]);
ost->st->codec->frame_number++;
ost->frame_number++;
av_free_packet(&opkt);
case CODEC_TYPE_AUDIO:
if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
goto fail;
-
- if (codec->channels == icodec->channels &&
- codec->sample_rate == icodec->sample_rate) {
- ost->audio_resample = 0;
- } else {
- if (codec->channels != icodec->channels &&
- (icodec->codec_id == CODEC_ID_AC3 ||
- icodec->codec_id == CODEC_ID_DTS)) {
- /* Special case for 5:1 AC3 and DTS input */
- /* and mono or stereo output */
- /* Request specific number of channels */
- icodec->channels = codec->channels;
- if (codec->sample_rate == icodec->sample_rate)
- ost->audio_resample = 0;
- else {
- ost->audio_resample = 1;
- }
- } else {
- ost->audio_resample = 1;
- }
- }
- if(audio_sync_method>1)
- ost->audio_resample = 1;
-
- if(ost->audio_resample){
- ost->resample = audio_resample_init(codec->channels, icodec->channels,
- codec->sample_rate, icodec->sample_rate);
- if(!ost->resample){
- printf("Can't resample. Aborting.\n");
- abort();
- }
- }
+ ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
+ icodec->request_channels = codec->channels;
ist->decoding_needed = 1;
ost->encoding_needed = 1;
break;
av_free(ost->pict_tmp.data[0]);
if (ost->video_resample)
sws_freeContext(ost->img_resample_ctx);
- if (ost->audio_resample)
+ if (ost->resample)
audio_resample_close(ost->resample);
av_free(ost);
}
#endif
if(avctx_opts[0]->debug)
- av_log_level = AV_LOG_DEBUG;
+ av_log_set_level(AV_LOG_DEBUG);
return 0;
}
-static void opt_video_rc_eq(char *arg)
-{
- video_rc_eq = arg;
-}
-
-static void opt_video_rc_override_string(char *arg)
+static void opt_video_rc_override_string(const char *arg)
{
video_rc_override_string = arg;
}
static void opt_verbose(const char *arg)
{
verbose = atoi(arg);
- av_log_level = atoi(arg);
+ av_log_set_level(atoi(arg));
}
static void opt_frame_rate(const char *arg)
}
}
-static void opt_bitrate(const char *opt, const char *arg)
+static int opt_bitrate(const char *opt, const char *arg)
{
int codec_type = opt[0]=='a' ? CODEC_TYPE_AUDIO : CODEC_TYPE_VIDEO;
if (av_get_int(avctx_opts[codec_type], "b", NULL) < 1000)
fprintf(stderr, "WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s\n");
+
+ return 0;
}
static void opt_frame_crop_top(const char *arg)
ap->video_codec_id= CODEC_ID_PGMYUV;
for(i=0; i<opt_name_count; i++){
+ char buf[256];
const AVOption *opt;
- double d= av_get_double(avformat_opts, opt_names[i], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
- av_set_double(ic, opt_names[i], d);
+ const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_DECODING_PARAM))
+ av_set_string(ic, opt_names[i], str);
}
+
+ ic->video_codec_id = find_codec_or_die(video_codec_name , CODEC_TYPE_VIDEO , 0);
+ ic->audio_codec_id = find_codec_or_die(audio_codec_name , CODEC_TYPE_AUDIO , 0);
+ ic->subtitle_codec_id= find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 0);
+
/* open the input file with generic libav function */
err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
if (err < 0) {
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
for(j=0; j<opt_name_count; j++){
+ char buf[256];
const AVOption *opt;
- double d= av_get_double(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
- av_set_double(enc, opt_names[j], d);
+ const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM))
+ av_set_string(enc, opt_names[j], str);
}
//fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
audio_channels = enc->channels;
break;
case CODEC_TYPE_VIDEO:
for(j=0; j<opt_name_count; j++){
+ char buf[256];
const AVOption *opt;
- double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
- av_set_double(enc, opt_names[j], d);
+ const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM))
+ av_set_string(enc, opt_names[j], str);
}
frame_height = enc->height;
frame_width = enc->width;
if(subtitle_disable)
ic->streams[i]->discard = AVDISCARD_ALL;
break;
+ case CODEC_TYPE_ATTACHMENT:
case CODEC_TYPE_UNKNOWN:
break;
default:
video_channel = 0;
rate_emu = 0;
+ av_freep(&video_codec_name);
+ av_freep(&audio_codec_name);
+ av_freep(&subtitle_codec_name);
}
static void check_audio_video_sub_inputs(int *has_video_ptr, int *has_audio_ptr,
has_subtitle = 1;
break;
case CODEC_TYPE_DATA:
+ case CODEC_TYPE_ATTACHMENT:
case CODEC_TYPE_UNKNOWN:
break;
default:
st->stream_copy = 1;
video_enc->codec_type = CODEC_TYPE_VIDEO;
} else {
- char *p;
+ const char *p;
int i;
AVCodec *codec;
+ AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
if (video_codec_name)
codec = avcodec_find_encoder(codec_id);
for(i=0; i<opt_name_count; i++){
- const AVOption *opt;
- double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
- av_set_double(video_enc, opt_names[i], d);
+ char buf[256];
+ const AVOption *opt;
+ const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_string(video_enc, opt_names[i], str);
}
- video_enc->time_base.den = frame_rate.num;
- video_enc->time_base.num = frame_rate.den;
+ video_enc->time_base.den = fps.num;
+ video_enc->time_base.num = fps.den;
if(codec && codec->supported_framerates){
const AVRational *p= codec->supported_framerates;
- AVRational req= (AVRational){frame_rate.num, frame_rate.den};
const AVRational *best=NULL;
AVRational best_error= (AVRational){INT_MAX, 1};
for(; p->den!=0; p++){
- AVRational error= av_sub_q(req, *p);
+ AVRational error= av_sub_q(fps, *p);
if(error.num <0) error.num *= -1;
if(av_cmp_q(error, best_error) < 0){
best_error= error;
video_enc->inter_matrix = inter_matrix;
video_enc->max_qdiff = video_qdiff;
- video_enc->rc_eq = video_rc_eq;
video_enc->thread_count = thread_count;
p= video_rc_override_string;
for(i=0; p; i++){
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
for(i=0; i<opt_name_count; i++){
+ char buf[256];
const AVOption *opt;
- double d= av_get_double(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
- av_set_double(audio_enc, opt_names[i], d);
+ const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_string(audio_enc, opt_names[i], str);
}
if (audio_codec_name)
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_SUBTITLE);
+ bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters;
+ subtitle_bitstream_filters= NULL;
+
subtitle_enc = st->codec;
subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE;
if (subtitle_stream_copy) {
st->stream_copy = 1;
} else {
for(i=0; i<opt_name_count; i++){
- const AVOption *opt;
- double d= av_get_double(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
- av_set_double(subtitle_enc, opt_names[i], d);
+ char buf[256];
+ const AVOption *opt;
+ const char *str= av_get_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_string(subtitle_enc, opt_names[i], str);
}
subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1);
}
av_strlcpy(oc->comment, str_comment, sizeof(oc->comment));
if (str_album)
av_strlcpy(oc->album, str_album, sizeof(oc->album));
+ if (str_genre)
+ av_strlcpy(oc->genre, str_genre, sizeof(oc->genre));
}
output_files[nb_output_files++] = oc;
/* test if it already exists to avoid loosing precious files */
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
+ filename[1] == ':' ||
av_strstart(filename, "file:", NULL))) {
if (url_exist(filename)) {
int c;
oc->loop_output = loop_output;
for(i=0; i<opt_name_count; i++){
+ char buf[256];
const AVOption *opt;
- double d = av_get_double(avformat_opts, opt_names[i], &opt);
- if(!isnan(d) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
- av_set_double(oc, opt_names[i], d);
+ const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf));
+ if(str && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM))
+ av_set_string(oc, opt_names[i], str);
}
/* reset some options */
static void opt_show_formats(void)
{
- AVInputFormat *ifmt;
- AVOutputFormat *ofmt;
- URLProtocol *up;
- AVCodec *p, *p2;
+ AVInputFormat *ifmt=NULL;
+ AVOutputFormat *ofmt=NULL;
+ URLProtocol *up=NULL;
+ AVCodec *p=NULL, *p2;
+ AVBitStreamFilter *bsf=NULL;
const char *last_name;
printf("File formats:\n");
const char *name=NULL;
const char *long_name=NULL;
- for(ofmt = first_oformat; ofmt != NULL; ofmt = ofmt->next) {
+ while((ofmt= av_oformat_next(ofmt))) {
if((name == NULL || strcmp(ofmt->name, name)<0) &&
strcmp(ofmt->name, last_name)>0){
name= ofmt->name;
encode=1;
}
}
- for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) {
+ while((ifmt= av_iformat_next(ifmt))) {
if((name == NULL || strcmp(ifmt->name, name)<0) &&
strcmp(ifmt->name, last_name)>0){
name= ifmt->name;
const char *type_str;
p2=NULL;
- for(p = first_avcodec; p != NULL; p = p->next) {
+ while((p= av_codec_next(p))) {
if((p2==NULL || strcmp(p->name, p2->name)<0) &&
strcmp(p->name, last_name)>0){
p2= p;
}
printf("\n");
+ printf("Bitstream filters:\n");
+ while((bsf = av_bitstream_filter_next(bsf)))
+ printf(" %s", bsf->name);
+ printf("\n");
+
printf("Supported file protocols:\n");
- for(up = first_protocol; up != NULL; up = up->next)
+ while((up = av_protocol_next(up)))
printf(" %s:", up->name);
printf("\n");
opt_vstats_file(filename);
}
-static void opt_bsf(const char *opt, const char *arg)
+static int opt_bsf(const char *opt, const char *arg)
{
AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '='
AVBitStreamFilterContext **bsfp;
exit(1);
}
- bsfp= *opt == 'v' ? &video_bitstream_filters : &audio_bitstream_filters;
+ bsfp= *opt == 'v' ? &video_bitstream_filters :
+ *opt == 'a' ? &audio_bitstream_filters :
+ &subtitle_bitstream_filters;
while(*bsfp)
bsfp= &(*bsfp)->next;
*bsfp= bsfc;
+
+ return 0;
}
static void opt_show_license(void)
{ "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" },
{ "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" },
{ "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" },
+ { "genre", HAS_ARG | OPT_STRING, {(void*)&str_genre}, "set the genre", "string" },
{ "album", HAS_ARG | OPT_STRING, {(void*)&str_album}, "set the album", "string" },
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
"add timings for benchmarking" },
{ "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" },
{ "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantizer scale (VBR)", "q" },
- { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" },
{ "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
{ "vcodec", HAS_ARG | OPT_VIDEO, {(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 estimaton threshold", "" },
{ "absf", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" },
{ "vbsf", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" },
+ { "sbsf", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" },
{ "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
{ NULL, },