#undef NDEBUG
#include <assert.h>
-#if !defined(INFINITY) && defined(HUGE_VAL)
-#define INFINITY HUGE_VAL
-#endif
-
#undef exit
static const char program_name[] = "FFmpeg";
static int pgmyuv_compatibility_hack=0;
static float dts_delta_threshold = 10;
-static int sws_flags = SWS_BICUBIC;
+static unsigned int sws_flags = SWS_BICUBIC;
static const char **opt_names;
static int opt_name_count;
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"
/* now encode as many frames as possible */
if (enc->frame_size > 1) {
/* output resampled raw samples */
+ av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out + 1);
av_fifo_write(&ost->fifo, buftmp, size_out);
frame_bytes = enc->frame_size * 2 * enc->channels;
AVPacket pkt;
av_init_packet(&pkt);
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
+
ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
(short *)audio_buf);
audio_size += ret;
size_out = size_out >> 1;
break;
}
+ //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
ret = avcodec_encode_audio(enc, audio_out, size_out,
(short *)buftmp);
audio_size += ret;
//FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
if (vdelta < -1.1)
nb_frames = 0;
+ else if (video_sync_method == 2)
+ ost->sync_opts= lrintf(get_sync_ipts(ost) / av_q2d(enc->time_base));
else if (vdelta > 1.1)
nb_frames = lrintf(vdelta);
//fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, ost->sync_ipts, nb_frames);
}
static double psnr(double d){
- if(d==0) return INFINITY;
return -10.0*log(d)/log(10.0);
}
enc = ost->st->codec;
if (vid && enc->codec_type == CODEC_TYPE_VIDEO) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ",
- enc->coded_frame->quality/(float)FF_QP2LAMBDA);
+ enc->coded_frame && !ost->st->stream_copy ?
+ enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
}
if (!vid && enc->codec_type == CODEC_TYPE_VIDEO) {
float t = (av_gettime()-timer_start) / 1000000.0;
frame_number = ost->frame_number;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ",
frame_number, (t>1)?(int)(frame_number/t+0.5) : 0,
- enc->coded_frame ? enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
+ enc->coded_frame && !ost->st->stream_copy ?
+ enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1);
if(is_last_report)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
if(qp_hist && enc->coded_frame){
AVSubtitle subtitle, *subtitle_to_free;
int got_subtitle;
- if(!pkt){
- ist->pts= ist->next_pts; // needed for last packet if vsync=0
- } else if (pkt->dts != AV_NOPTS_VALUE) { //FIXME seems redundant, as libavformat does this too
- ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
- } else {
-// assert(ist->pts == ist->next_pts);
- }
+ if(ist->next_pts == AV_NOPTS_VALUE)
+ ist->next_pts= ist->pts;
if (pkt == NULL) {
/* EOF handling */
goto handle_eof;
}
+ if(pkt->dts != AV_NOPTS_VALUE)
+ ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+
len = pkt->size;
ptr = pkt->data;
while (len > 0) {
handle_eof:
+ ist->pts= ist->next_pts;
+
+ if(len && len != pkt->size && verbose>0)
+ fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index);
+
/* decode the packet if needed */
data_buf = NULL; /* fail safe */
data_size = 0;
av_strlcpy(ost->st->language, ist->st->language,
sizeof(ost->st->language));
+ ost->st->disposition = ist->st->disposition;
+
if (ost->st->stream_copy) {
/* if stream_copy is selected, no need to decode or encode */
codec->codec_id = icodec->codec_id;
} else {
switch(codec->codec_type) {
case CODEC_TYPE_AUDIO:
- if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
+ if (av_fifo_init(&ost->fifo, 1024))
goto fail;
ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
icodec->request_channels = codec->channels;
ist = ist_table[i];
is = input_files[ist->file_index];
ist->pts = 0;
- ist->next_pts=0;
- if( input_files_ts_offset[ist->file_index] != -is->start_time
- && !(is->start_time == AV_NOPTS_VALUE && input_files_ts_offset[ist->file_index]==0))
- ist->next_pts= AV_NOPTS_VALUE;
+ ist->next_pts = AV_NOPTS_VALUE;
ist->is_start = 1;
}
}
}
-#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER)
extern int ffm_nopts;
-#endif
static int opt_default(const char *opt, const char *arg){
int type;
static void opt_verbose(const char *arg)
{
verbose = atoi(arg);
- av_log_set_level(atoi(arg));
+ av_log_set_level(verbose);
}
static void opt_frame_rate(const char *arg)
int x = 0, y = 0;
double ar = 0;
const char *p;
+ char *end;
p = strchr(arg, ':');
if (p) {
- x = strtol(arg, (char **)&arg, 10);
- if (arg == p)
- y = strtol(arg+1, (char **)&arg, 10);
+ x = strtol(arg, &end, 10);
+ if (end == p)
+ y = strtol(end+1, &end, 10);
if (x > 0 && y > 0)
ar = (double)x / (double)y;
} else
- ar = strtod(arg, (char **)&arg);
+ ar = strtod(arg, NULL);
if (!ar) {
fprintf(stderr, "Incorrect aspect ratio specification.\n");
static void opt_map(const char *arg)
{
AVStreamMap *m;
- const char *p;
+ char *p;
- p = arg;
m = &stream_maps[nb_stream_maps++];
- m->file_index = strtol(arg, (char **)&p, 0);
+ m->file_index = strtol(arg, &p, 0);
if (*p)
p++;
- m->stream_index = strtol(p, (char **)&p, 0);
+ m->stream_index = strtol(p, &p, 0);
if (*p) {
p++;
- m->sync_file_index = strtol(p, (char **)&p, 0);
+ m->sync_file_index = strtol(p, &p, 0);
if (*p)
p++;
- m->sync_stream_index = strtol(p, (char **)&p, 0);
+ m->sync_stream_index = strtol(p, &p, 0);
} else {
m->sync_file_index = m->file_index;
m->sync_stream_index = m->stream_index;
static void opt_map_meta_data(const char *arg)
{
AVMetaDataMap *m;
- const char *p;
+ char *p;
- p = arg;
m = &meta_data_maps[nb_meta_data_maps++];
- m->out_file = strtol(arg, (char **)&p, 0);
+ m->out_file = strtol(arg, &p, 0);
if (*p)
p++;
- m->in_file = strtol(p, (char **)&p, 0);
+ m->in_file = strtol(p, &p, 0);
}
-static int64_t parse_time_or_die(const char *timestr, int is_duration)
+static int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
{
int64_t us = parse_date(timestr, is_duration);
if (us == INT64_MIN) {
- fprintf(stderr, "Invalid %s specification: %s\n",
- is_duration ? "duration" : "date", timestr);
+ fprintf(stderr, "Invalid %s specification for %s: %s\n",
+ is_duration ? "duration" : "date", context, timestr);
exit(1);
}
return us;
static void opt_recording_time(const char *arg)
{
- recording_time = parse_time_or_die(arg, 1);
+ recording_time = parse_time_or_die("t", arg, 1);
}
static void opt_start_time(const char *arg)
{
- start_time = parse_time_or_die(arg, 1);
+ start_time = parse_time_or_die("ss", arg, 1);
}
static void opt_rec_timestamp(const char *arg)
{
- rec_timestamp = parse_time_or_die(arg, 0) / 1000000;
+ rec_timestamp = parse_time_or_die("timestamp", arg, 0) / 1000000;
}
static void opt_input_ts_offset(const char *arg)
{
- input_ts_offset = parse_time_or_die(arg, 1);
+ input_ts_offset = parse_time_or_die("itsoffset", arg, 1);
}
static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
{
- char *codec_string = encoder ? "encoder" : "decoder";
+ const char *codec_string = encoder ? "encoder" : "decoder";
AVCodec *codec;
if(!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) {
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;
{ "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" },
{ "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
{ "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
- { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" },
+ { "v", HAS_ARG, {(void*)opt_verbose}, "set the logging verbosity level", "number" },
{ "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
{ "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
{ "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },
{ "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, },