Commit 50c3dd32 authored by Michael Niedermayer's avatar Michael Niedermayer

pass timestamps correctly for -sync 0

use zero sized frames in avi to handle duplicate frames

Originally committed as revision 3225 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent caacc47f
......@@ -618,17 +618,17 @@ static void do_video_out(AVFormatContext *s,
else if (vdelta > 1.1)
nb_frames = 2;
//fprintf(stderr, "vdelta:%f, ost->sync_opts:%lld, ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, ost->sync_ipts, nb_frames);
}
if (nb_frames == 0){
++nb_frames_drop;
if (verbose>2)
fprintf(stderr, "*** drop!\n");
}else if (nb_frames == 2) {
++nb_frames_dup;
if (verbose>2)
fprintf(stderr, "*** dup!\n");
}
ost->sync_opts+= nb_frames;
if (nb_frames == 0){
++nb_frames_drop;
if (verbose>2)
fprintf(stderr, "*** drop!\n");
}else if (nb_frames == 2) {
++nb_frames_dup;
if (verbose>2)
fprintf(stderr, "*** dup!\n");
}
}else
ost->sync_opts= lrintf(ost->sync_ipts * enc->frame_rate / enc->frame_rate_base);
if (nb_frames <= 0)
return;
......@@ -811,7 +811,9 @@ static void do_video_out(AVFormatContext *s,
big_picture.quality = ost->st->quality;
if(!me_threshold)
big_picture.pict_type = 0;
big_picture.pts = AV_NOPTS_VALUE; //FIXME
// big_picture.pts = AV_NOPTS_VALUE;
big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->frame_rate_base, enc->frame_rate);
//av_log(NULL, AV_LOG_DEBUG, "%lld -> encoder\n", ost->sync_opts);
ret = avcodec_encode_video(enc,
video_buffer, VIDEO_BUFFER_SIZE,
&big_picture);
......@@ -821,6 +823,10 @@ static void do_video_out(AVFormatContext *s,
pkt.size= ret;
if(enc->coded_frame)
pkt.pts= enc->coded_frame->pts;
/*av_log(NULL, AV_LOG_DEBUG, "encoder -> %lld/%lld\n",
pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->frame_rate, AV_TIME_BASE*(int64_t)enc->frame_rate_base) : -1,
pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->frame_rate, AV_TIME_BASE*(int64_t)enc->frame_rate_base) : -1);*/
if(enc->coded_frame && enc->coded_frame->key_frame)
pkt.flags |= PKT_FLAG_KEY;
av_interleaved_write_frame(s, &pkt);
......@@ -834,6 +840,7 @@ static void do_video_out(AVFormatContext *s,
}
}
}
ost->sync_opts++;
ost->frame_number++;
}
the_end:
......
......@@ -43,6 +43,7 @@ typedef struct {
offset_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS];
int audio_strm_length[MAX_STREAMS];
int riff_id;
int packet_count[MAX_STREAMS];
AVIIndex indexes[MAX_STREAMS];
} AVIContext;
......@@ -382,6 +383,7 @@ static int avi_write_header(AVFormatContext *s)
put_le32(pb, stream->frame_rate_base); /* scale */
put_le32(pb, stream->frame_rate); /* rate */
av_set_pts_info(s->streams[i], 64, stream->frame_rate_base, stream->frame_rate);
put_le32(pb, 0); /* start */
avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
......@@ -404,6 +406,7 @@ static int avi_write_header(AVFormatContext *s)
parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
put_le32(pb, au_scale); /* scale */
put_le32(pb, au_byterate); /* rate */
// av_set_pts_info(&s->streams[i], 64, au_scale, au_byterate);
put_le32(pb, 0); /* start */
avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
put_le32(pb, 0); /* length, XXX: filled later */
......@@ -615,10 +618,23 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
ByteIOContext *pb = &s->pb;
unsigned char tag[5];
unsigned int flags=0;
AVCodecContext *enc;
const int stream_index= pkt->stream_index;
AVCodecContext *enc= &s->streams[stream_index]->codec;;
int size= pkt->size;
// av_log(s, AV_LOG_DEBUG, "%lld %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index);
while(enc->codec_type == CODEC_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avi->packet_count[stream_index]){
AVPacket empty_packet;
av_init_packet(&empty_packet);
empty_packet.size= 0;
empty_packet.data= NULL;
empty_packet.stream_index= stream_index;
avi_write_packet(s, &empty_packet);
// av_log(s, AV_LOG_DEBUG, "dup %lld %d\n", pkt->dts, avi->packet_count[stream_index]);
}
avi->packet_count[stream_index]++;
if (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE) {
avi_write_ix(s);
end_tag(pb, avi->movi_list);
......@@ -630,7 +646,6 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi");
}
enc = &s->streams[stream_index]->codec;
avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
if(pkt->flags&PKT_FLAG_KEY)
flags = 0x10;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment