Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#1175 closed defect (fixed)

mpeg2 (PS) writes bad bitrate/muxrate

Reported by: tracey_pooh Owned by: michael
Priority: critical Component: avformat
Version: git-master Keywords: mpeg2 header bug muxrate
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

example way to show the bug:

/tmp/f/ffmpeg/ffmpeg -y -i ANYVIDEO -target ntsc-dvd -frames 1 xxx.mpg;
hexdump -C -s10 -n3 xxx.mpg;

buggy:
0000000a 0c 4e 03

should be (was prior to nov2011):
0000000a 01 89 c3

the correct value, which is the 22 bits of the 3 bytes above, * 400
(gdb) p (0x0189c3 >> 2) * 400
$17 = 10080000
is the value that the "-muxrate" ffmpeg param defaults to unless overridden
and is what "-target ntsc-dvd" will also set to.
so the ffmpeg param translating into the internal storage of mpegenc.c
is off by 400.

You can see the bug a little more obviously because the "put_bits()" of 22 bits
int value in current state is 24 bits 8-)

a sample fix/patch:

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 0df0149..1e9e2ed 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -423,7 +423,10 @@ static int mpeg_mux_init(AVFormatContext *ctx)

video_bitrate += codec_rate;

}


  • if (!s->mux_rate) {

+ if (s->mux_rate) {
+ s->mux_rate /= 400; internal param is in units of 50 bytes
+ }
+ else {

/* we increase slightly the bitrate to take into account the

headers. XXX: compute it exactly */

bitrate += bitrate / 20;

Change History (4)

comment:1 Changed 4 years ago by tracey_pooh

... and sorry if "critical" is Big Alarms -- I meant to explain why I picked that.

We at Internet Archive try to help our PEG (Public Access, Education, & Government)
brothers and sisters and are transcoding for some of them (as well as video archiving).
The good folks at Seatle Community Media alerted us to the fact that none of their
programs were being "accepted" by their Televue hardware systems suddenly after
my Mar 21 ffmpeg build. It eventually led back to this bad muxrate in the pack header
causing Televue to reject the mpeg2s that we make.

Best I can tell, this muxrate is wrong for every MPEG2-PS created by ffmpeg,
so hence the "critical" selection. Apologies in advance if that was too extreme. 8-)
Rock on, ffmpeg!

comment:2 Changed 4 years ago by michael

  • Owner set to michael
  • Reproduced by developer set
  • Status changed from new to open

comment:3 Changed 4 years ago by michael

  • Keywords muxrate added
  • Resolution set to fixed
  • Status changed from open to closed

Issue fixed

This bug was introduced by:

commit 5a9ee3152b6e69166c7819f07a4992bd22052917
Author: Anton Khirnov <anton@khirnov.net>
AuthorDate?: Sun Oct 9 14:40:11 2011 +0200
Commit: Anton Khirnov <anton@khirnov.net>
CommitDate?: Mon Oct 17 08:39:53 2011 +0200

mpegenc/mpegtsenc: add muxrate private options.


Deprecate AVFormatContext.mux_rate.

AND
commit f0cb13958d8b45800f29b067ce2bc6e9f5f58740
Author: Anton Khirnov <anton@khirnov.net>
AuthorDate?: Thu Jan 12 13:31:55 2012 +0100
Commit: Anton Khirnov <anton@khirnov.net>
CommitDate?: Fri Jan 27 10:52:43 2012 +0100

lavf: remove disabled FF_API_MUXRATE cruft

Last edited 4 years ago by michael (previous) (diff)

comment:4 Changed 4 years ago by michael

It appears our releases are unaffected by this.
The buggy code was added well before the last release but luckily was not used, so i think only git-master was affected.

Note: See TracTickets for help on using tickets.