From 753f08447f3a7b5859366b9274cd07ed4cd23484 Mon Sep 17 00:00:00 2001
From: Mike Scheutzow <mjs973@optonline.net>
Date: Wed, 27 Jun 2012 11:28:07 -0400
Subject: [PATCH] Fix timestamp calculation when demuxing MP3 frames in a .avi container.
The bad code was using the frame byte length to calculate a timestamp,
which is completely broken. Also set AVPacket.duration, since demux is
already calculating it. The existing avi muxer already properly handles
the muxing and index creation for MP3 audio frames. Fixes the sample
file in trac 1432.
Signed-off-by: Mike Scheutzow <mjs973@optonline.net>
---
libavformat/avidec.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index fea0694..4835750 100644
|
a
|
b
|
static int guess_ni_flag(AVFormatContext *s);
|
| 116 | 116 | (tag >> 24) & 0xff, \ |
| 117 | 117 | size) |
| 118 | 118 | |
| | 119 | /* calculate the duration of the current frame, in units of AVStream.time_base. |
| | 120 | * For video, or audio frames with variable byte length, the output value |
| | 121 | * is defined to be '1'. |
| | 122 | */ |
| 119 | 123 | static inline int get_duration(AVIStream *ast, int len){ |
| 120 | 124 | if(ast->sample_size){ |
| 121 | 125 | return len; |
| … |
… |
static int avi_read_header(AVFormatContext *s)
|
| 655 | 659 | ret = ff_get_wav_header(pb, st->codec, size); |
| 656 | 660 | if (ret < 0) |
| 657 | 661 | return ret; |
| 658 | | ast->dshow_block_align= st->codec->block_align; |
| | 662 | if (st->codec->codec_id == CODEC_ID_MP3) { |
| | 663 | /* this file assumes that a non-zero sample_size |
| | 664 | * means constant frame byte length; mp3 frames have |
| | 665 | * variable byte length */ |
| | 666 | ast->sample_size = 0; |
| | 667 | // must keep ast->dshow_block_align = 0 |
| | 668 | } else { |
| | 669 | ast->dshow_block_align= st->codec->block_align; |
| | 670 | } |
| 659 | 671 | if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){ |
| 660 | 672 | av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align); |
| 661 | 673 | ast->sample_size= st->codec->block_align; |
| … |
… |
resync:
|
| 1204 | 1216 | } else { |
| 1205 | 1217 | pkt->flags |= AV_PKT_FLAG_KEY; |
| 1206 | 1218 | } |
| 1207 | | ast->frame_offset += get_duration(ast, pkt->size); |
| | 1219 | /* pkt may contain multiple frames */ |
| | 1220 | pkt->duration = get_duration(ast, pkt->size); |
| | 1221 | ast->frame_offset += pkt->duration; |
| 1208 | 1222 | } |
| 1209 | 1223 | ast->remaining -= size; |
| 1210 | 1224 | if(!ast->remaining){ |