Originally committed as revision 3225 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2004/06/15 22:49:12... | ... |
@@ -618,17 +618,17 @@ static void do_video_out(AVFormatContext *s, |
618 | 618 |
else if (vdelta > 1.1) |
619 | 619 |
nb_frames = 2; |
620 | 620 |
//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); |
621 |
- } |
|
622 |
- if (nb_frames == 0){ |
|
623 |
- ++nb_frames_drop; |
|
624 |
- if (verbose>2) |
|
625 |
- fprintf(stderr, "*** drop!\n"); |
|
626 |
- }else if (nb_frames == 2) { |
|
627 |
- ++nb_frames_dup; |
|
628 |
- if (verbose>2) |
|
629 |
- fprintf(stderr, "*** dup!\n"); |
|
630 |
- } |
|
631 |
- ost->sync_opts+= nb_frames; |
|
621 |
+ if (nb_frames == 0){ |
|
622 |
+ ++nb_frames_drop; |
|
623 |
+ if (verbose>2) |
|
624 |
+ fprintf(stderr, "*** drop!\n"); |
|
625 |
+ }else if (nb_frames == 2) { |
|
626 |
+ ++nb_frames_dup; |
|
627 |
+ if (verbose>2) |
|
628 |
+ fprintf(stderr, "*** dup!\n"); |
|
629 |
+ } |
|
630 |
+ }else |
|
631 |
+ ost->sync_opts= lrintf(ost->sync_ipts * enc->frame_rate / enc->frame_rate_base); |
|
632 | 632 |
|
633 | 633 |
if (nb_frames <= 0) |
634 | 634 |
return; |
... | ... |
@@ -811,7 +811,9 @@ static void do_video_out(AVFormatContext *s, |
811 | 811 |
big_picture.quality = ost->st->quality; |
812 | 812 |
if(!me_threshold) |
813 | 813 |
big_picture.pict_type = 0; |
814 |
- big_picture.pts = AV_NOPTS_VALUE; //FIXME |
|
814 |
+// big_picture.pts = AV_NOPTS_VALUE; |
|
815 |
+ big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->frame_rate_base, enc->frame_rate); |
|
816 |
+//av_log(NULL, AV_LOG_DEBUG, "%lld -> encoder\n", ost->sync_opts); |
|
815 | 817 |
ret = avcodec_encode_video(enc, |
816 | 818 |
video_buffer, VIDEO_BUFFER_SIZE, |
817 | 819 |
&big_picture); |
... | ... |
@@ -821,6 +823,10 @@ static void do_video_out(AVFormatContext *s, |
821 | 821 |
pkt.size= ret; |
822 | 822 |
if(enc->coded_frame) |
823 | 823 |
pkt.pts= enc->coded_frame->pts; |
824 |
+/*av_log(NULL, AV_LOG_DEBUG, "encoder -> %lld/%lld\n", |
|
825 |
+ pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->frame_rate, AV_TIME_BASE*(int64_t)enc->frame_rate_base) : -1, |
|
826 |
+ pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->frame_rate, AV_TIME_BASE*(int64_t)enc->frame_rate_base) : -1);*/ |
|
827 |
+ |
|
824 | 828 |
if(enc->coded_frame && enc->coded_frame->key_frame) |
825 | 829 |
pkt.flags |= PKT_FLAG_KEY; |
826 | 830 |
av_interleaved_write_frame(s, &pkt); |
... | ... |
@@ -834,6 +840,7 @@ static void do_video_out(AVFormatContext *s, |
834 | 834 |
} |
835 | 835 |
} |
836 | 836 |
} |
837 |
+ ost->sync_opts++; |
|
837 | 838 |
ost->frame_number++; |
838 | 839 |
} |
839 | 840 |
the_end: |
... | ... |
@@ -43,6 +43,7 @@ typedef struct { |
43 | 43 |
offset_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS]; |
44 | 44 |
int audio_strm_length[MAX_STREAMS]; |
45 | 45 |
int riff_id; |
46 |
+ int packet_count[MAX_STREAMS]; |
|
46 | 47 |
|
47 | 48 |
AVIIndex indexes[MAX_STREAMS]; |
48 | 49 |
} AVIContext; |
... | ... |
@@ -382,6 +383,7 @@ static int avi_write_header(AVFormatContext *s) |
382 | 382 |
|
383 | 383 |
put_le32(pb, stream->frame_rate_base); /* scale */ |
384 | 384 |
put_le32(pb, stream->frame_rate); /* rate */ |
385 |
+ av_set_pts_info(s->streams[i], 64, stream->frame_rate_base, stream->frame_rate); |
|
385 | 386 |
|
386 | 387 |
put_le32(pb, 0); /* start */ |
387 | 388 |
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) |
404 | 404 |
parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); |
405 | 405 |
put_le32(pb, au_scale); /* scale */ |
406 | 406 |
put_le32(pb, au_byterate); /* rate */ |
407 |
+// av_set_pts_info(&s->streams[i], 64, au_scale, au_byterate); |
|
407 | 408 |
put_le32(pb, 0); /* start */ |
408 | 409 |
avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */ |
409 | 410 |
put_le32(pb, 0); /* length, XXX: filled later */ |
... | ... |
@@ -615,10 +618,23 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) |
615 | 615 |
ByteIOContext *pb = &s->pb; |
616 | 616 |
unsigned char tag[5]; |
617 | 617 |
unsigned int flags=0; |
618 |
- AVCodecContext *enc; |
|
619 | 618 |
const int stream_index= pkt->stream_index; |
619 |
+ AVCodecContext *enc= &s->streams[stream_index]->codec;; |
|
620 | 620 |
int size= pkt->size; |
621 | 621 |
|
622 |
+// av_log(s, AV_LOG_DEBUG, "%lld %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index); |
|
623 |
+ while(enc->codec_type == CODEC_TYPE_VIDEO && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avi->packet_count[stream_index]){ |
|
624 |
+ AVPacket empty_packet; |
|
625 |
+ |
|
626 |
+ av_init_packet(&empty_packet); |
|
627 |
+ empty_packet.size= 0; |
|
628 |
+ empty_packet.data= NULL; |
|
629 |
+ empty_packet.stream_index= stream_index; |
|
630 |
+ avi_write_packet(s, &empty_packet); |
|
631 |
+// av_log(s, AV_LOG_DEBUG, "dup %lld %d\n", pkt->dts, avi->packet_count[stream_index]); |
|
632 |
+ } |
|
633 |
+ avi->packet_count[stream_index]++; |
|
634 |
+ |
|
622 | 635 |
if (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE) { |
623 | 636 |
avi_write_ix(s); |
624 | 637 |
end_tag(pb, avi->movi_list); |
... | ... |
@@ -630,7 +646,6 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) |
630 | 630 |
avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi"); |
631 | 631 |
} |
632 | 632 |
|
633 |
- enc = &s->streams[stream_index]->codec; |
|
634 | 633 |
avi_stream2fourcc(&tag[0], stream_index, enc->codec_type); |
635 | 634 |
if(pkt->flags&PKT_FLAG_KEY) |
636 | 635 |
flags = 0x10; |