diff options
author | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2014-04-11 23:38:53 +0200 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2014-04-11 23:38:53 +0200 |
commit | c43222f436e941db3764576fc967da66f3709c35 (patch) | |
tree | fd9f38d9a917a584c65fd9d643ff7d84f8698d9e /libavformat/amr.c | |
parent | 8b122937af9ad10e9352f69c712e782fd6cfb436 (diff) | |
download | ffmpeg-c43222f436e941db3764576fc967da66f3709c35.tar.gz |
Improve amr bitrate calculation for VBR files.
Fixes ticket #3541.
Diffstat (limited to 'libavformat/amr.c')
-rw-r--r-- | libavformat/amr.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/libavformat/amr.c b/libavformat/amr.c index 47c1244b1d..6001525530 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -30,6 +30,11 @@ Only mono files are supported. #include "avformat.h" #include "internal.h" +typedef struct { + uint64_t cumulated_size; + uint64_t block_count; +} AMRContext; + static const char AMR_header[] = "#!AMR\n"; static const char AMRWB_header[] = "#!AMR-WB\n"; @@ -110,6 +115,7 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) AVCodecContext *enc = s->streams[0]->codec; int read, size = 0, toc, mode; int64_t pos = avio_tell(s->pb); + AMRContext *amr = s->priv_data; if (url_feof(s->pb)) { return AVERROR(EIO); @@ -136,8 +142,11 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) if (!size || av_new_packet(pkt, size)) return AVERROR(EIO); - /* Both AMR formats have 50 frames per second */ - s->streams[0]->codec->bit_rate = size*8*50; + if (amr->cumulated_size < UINT64_MAX - size) { + amr->cumulated_size += size; + /* Both AMR formats have 50 frames per second */ + s->streams[0]->codec->bit_rate = amr->cumulated_size / ++amr->block_count * 8 * 50; + } pkt->stream_index = 0; pkt->pos = pos; @@ -157,6 +166,7 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) AVInputFormat ff_amr_demuxer = { .name = "amr", .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR"), + .priv_data_size = sizeof(AMRContext), .read_probe = amr_probe, .read_header = amr_read_header, .read_packet = amr_read_packet, |