#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;
/* 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;
}
static double psnr(double d){
- if(d==0) return INFINITY;
return -10.0*log(d)/log(10.0);
}
AVSubtitle subtitle, *subtitle_to_free;
int got_subtitle;
+ if(ist->next_pts == AV_NOPTS_VALUE)
+ ist->next_pts= ist->pts;
+
if (pkt == NULL) {
/* EOF handling */
ptr = NULL;
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:
- if(!pkt || ptr != pkt->data || pkt->dts == AV_NOPTS_VALUE){
- ist->pts= ist->next_pts; // needed for last packet if vsync=0 and for multi pkt
- } 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);
- }
+ 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 */
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;
}
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)
m->in_file = strtol(p, &p, 0);
}
-static int64_t parse_time_or_die(const char *timestr, int is_duration)
+static int opt_recording_time(const char *opt, const char *arg)
{
- int64_t us = parse_date(timestr, is_duration);
- if (us == INT64_MIN) {
- fprintf(stderr, "Invalid %s specification: %s\n",
- is_duration ? "duration" : "date", 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(opt, arg, 1);
+ return 0;
}
-static void opt_start_time(const char *arg)
+static int opt_start_time(const char *opt, const char *arg)
{
- start_time = parse_time_or_die(arg, 1);
+ start_time = parse_time_or_die(opt, arg, 1);
+ return 0;
}
-static void opt_rec_timestamp(const char *arg)
+static int opt_rec_timestamp(const char *opt, const char *arg)
{
- rec_timestamp = parse_time_or_die(arg, 0) / 1000000;
+ rec_timestamp = parse_time_or_die(opt, arg, 0) / 1000000;
+ return 0;
}
-static void opt_input_ts_offset(const char *arg)
+static int opt_input_ts_offset(const char *opt, const char *arg)
{
- input_ts_offset = parse_time_or_die(arg, 1);
+ input_ts_offset = parse_time_or_die(opt, arg, 1);
+ return 0;
}
static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
{ "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
{ "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" },
{ "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile:infile" },
- { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
+ { "t", OPT_FUNC2 | HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" },
{ "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, //
- { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
- { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
+ { "ss", OPT_FUNC2 | HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" },
+ { "itsoffset", OPT_FUNC2 | HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" },
{ "title", HAS_ARG | OPT_STRING, {(void*)&str_title}, "set the title", "string" },
- { "timestamp", HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" },
+ { "timestamp", OPT_FUNC2 | HAS_ARG, {(void*)&opt_rec_timestamp}, "set the timestamp", "time" },
{ "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" },
{ "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", "" },