1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Fix timestamps and durations if the first packets have no durations nor timestamps,

and the information needed to guess the duration only becomes known at a later packet.

Originally committed as revision 11963 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2008-02-15 20:32:32 +00:00
parent db7ae7d1b9
commit 83a9db42a3
2 changed files with 41 additions and 20 deletions

View File

@ -632,6 +632,24 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
st->start_time = pts;
}
static void update_initial_durations(AVFormatContext *s, AVStream *st, AVPacket *pkt)
{
AVPacketList *pktl= s->packet_buffer;
assert(pkt->duration && !st->cur_dts);
for(; pktl; pktl= pktl->next){
if(pktl->pkt.stream_index != pkt->stream_index)
continue;
if(pktl->pkt.pts == pktl->pkt.dts && pktl->pkt.dts == AV_NOPTS_VALUE){
pktl->pkt.pts= pktl->pkt.dts= st->cur_dts;
st->cur_dts += pkt->duration;
pktl->pkt.duration= pkt->duration;
}else
break;
}
}
static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
AVCodecParserContext *pc, AVPacket *pkt)
{
@ -647,6 +665,9 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
compute_frame_duration(&num, &den, st, pc, pkt);
if (den && num) {
pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);
if(pkt->dts == AV_NOPTS_VALUE && pkt->pts == AV_NOPTS_VALUE && st->cur_dts == 0)
update_initial_durations(s, st, pkt);
}
}

View File

@ -1075,57 +1075,57 @@ ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:165884 size:12719 flags:1
ret:-1 st:-1 ts:-0.645825 flags:1
----------------
tests/data/a-mp2.mp2
ret: 0 st: 0 dts:-102481911520608.625000 pts:-102481911520608.625000 pos:0 size:417 flags:1
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st:-1 ts:-1.000000 flags:0
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:417 size:418 flags:1
ret: 0 st: 0 dts:0.026122 pts:0.026122 pos:417 size:418 flags:1
ret: 0 st:-1 ts:1.894167 flags:1
ret: 0 st: 0 dts:1.880800 pts:1.880800 pos:30511 size:417 flags:1
ret: 0 st: 0 dts:1.880800 pts:1.880800 pos:30093 size:418 flags:1
ret: 0 st: 0 ts:0.788333 flags:0
ret: 0 st: 0 dts:0.809789 pts:0.809789 pos:13374 size:418 flags:1
ret: 0 st: 0 dts:0.809789 pts:0.809789 pos:12956 size:418 flags:1
ret: 0 st: 0 ts:-0.317500 flags:1
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st:-1 ts:2.576668 flags:0
ret: 0 st: 0 dts:2.586100 pts:2.586100 pos:41795 size:418 flags:1
ret: 0 st: 0 dts:2.586100 pts:2.586100 pos:41377 size:418 flags:1
ret: 0 st:-1 ts:1.470835 flags:1
ret: 0 st: 0 dts:1.462844 pts:1.462844 pos:23823 size:418 flags:1
ret: 0 st: 0 dts:1.462844 pts:1.462844 pos:23405 size:418 flags:1
ret: 0 st: 0 ts:0.365000 flags:0
ret: 0 st: 0 dts:0.365711 pts:0.365711 pos:6269 size:418 flags:1
ret: 0 st: 0 dts:0.365711 pts:0.365711 pos:5851 size:418 flags:1
ret: 0 st: 0 ts:-0.740833 flags:1
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st:-1 ts:2.153336 flags:0
ret: 0 st: 0 dts:2.168144 pts:2.168144 pos:35108 size:418 flags:1
ret: 0 st: 0 dts:2.168144 pts:2.168144 pos:34690 size:418 flags:1
ret: 0 st:-1 ts:1.047503 flags:1
ret: 0 st: 0 dts:1.044889 pts:1.044889 pos:17136 size:418 flags:1
ret: 0 st: 0 dts:1.044889 pts:1.044889 pos:16718 size:418 flags:1
ret: 0 st: 0 ts:-0.058333 flags:0
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st: 0 ts:2.835833 flags:1
ret: 0 st: 0 dts:2.821200 pts:2.821200 pos:45557 size:418 flags:1
ret: 0 st: 0 dts:2.821200 pts:2.821200 pos:45139 size:418 flags:1
ret: 0 st:-1 ts:1.730004 flags:0
ret: 0 st: 0 dts:1.750189 pts:1.750189 pos:28421 size:418 flags:1
ret: 0 st: 0 dts:1.750189 pts:1.750189 pos:28003 size:418 flags:1
ret: 0 st:-1 ts:0.624171 flags:1
ret: 0 st: 0 dts:0.600811 pts:0.600811 pos:10031 size:417 flags:1
ret: 0 st: 0 dts:0.600811 pts:0.600811 pos:9613 size:418 flags:1
ret: 0 st: 0 ts:-0.481667 flags:0
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st: 0 ts:2.412500 flags:1
ret: 0 st: 0 dts:2.403244 pts:2.403244 pos:38870 size:418 flags:1
ret: 0 st: 0 dts:2.403244 pts:2.403244 pos:38452 size:418 flags:1
ret: 0 st:-1 ts:1.306672 flags:0
ret: 0 st: 0 dts:1.332233 pts:1.332233 pos:21733 size:418 flags:1
ret: 0 st: 0 dts:1.332233 pts:1.332233 pos:21315 size:418 flags:1
ret: 0 st:-1 ts:0.200839 flags:1
ret: 0 st: 0 dts:0.182856 pts:0.182856 pos:3343 size:418 flags:1
ret: 0 st: 0 dts:0.182856 pts:0.182856 pos:2925 size:418 flags:1
ret: 0 st: 0 ts:-0.904989 flags:0
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st: 0 ts:1.989178 flags:1
ret: 0 st: 0 dts:1.985289 pts:1.985289 pos:32182 size:418 flags:1
ret: 0 st: 0 dts:1.985289 pts:1.985289 pos:31764 size:418 flags:1
ret: 0 st:-1 ts:0.883340 flags:0
ret: 0 st: 0 dts:0.888156 pts:0.888156 pos:14628 size:418 flags:1
ret: 0 st: 0 dts:0.888156 pts:0.888156 pos:14210 size:418 flags:1
ret: 0 st:-1 ts:-0.222493 flags:1
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
ret: 0 st: 0 ts:2.671678 flags:0
ret: 0 st: 0 dts:2.690589 pts:2.690589 pos:43467 size:418 flags:1
ret: 0 st: 0 dts:2.690589 pts:2.690589 pos:43049 size:418 flags:1
ret: 0 st: 0 ts:1.565844 flags:1
ret: 0 st: 0 dts:1.541211 pts:1.541211 pos:25077 size:418 flags:1
ret: 0 st: 0 dts:1.541211 pts:1.541211 pos:24659 size:418 flags:1
ret: 0 st:-1 ts:0.460008 flags:0
ret: 0 st: 0 dts:0.470200 pts:0.470200 pos:7941 size:418 flags:1
ret: 0 st: 0 dts:0.470200 pts:0.470200 pos:7523 size:418 flags:1
ret: 0 st:-1 ts:-0.645825 flags:1
ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1
----------------