[FFmpeg-devel] rawvideo/avi bug?

Martin Gentry mgentry
Tue Jul 24 22:08:09 CEST 2007


Hopefully this is appropriate for the devel list instead of the users list,
I'm assuming devel is appropriate if I'm going to be attempting to submit a
patch (if needed).

There appears to be a bug with raw video AVI support.

I discovered that when going from this rawvideo avi to rawvideo avi the
image gets flipped vertically (maybe excluding a -vcodec copy?).  The
original source video I'm using plays fine in Windows Media Player.  After
one pass through FFmpeg to convert to a rawvideo bgr24 avi the video plays
back upside down.  Passing that upside down video through FFmpeg again turns
it right-side up again.  (See full command lines and output below.)

After some degree of debugging and looking at FFmpeg's source code for the
first time the issue seems to be the handling of the height in the bitmap
header portion of the input.  The source video contains a positive height
and so the pixel data is arranged bottom to top.  The code in rawdec.c just
always flips video if the codec_tag is 0, bits_per_sample is non-zero and
linesize[2] is 0, with a positive height value this is correct.  However
along the way to being re-encoded as bgr24 raw video the frame data ends up
right side up and thus the height in the bitmap header in the output avi
should be negative.  I temporarily just naively modified avienc.c to just
always write a negative height and the output then plays back correctly
after the first time through FFmpeg but the file cannot then be used as
input into FFmpeg.  Given negative heights render the input invalid from the
code's point of view, the rawdec.c code is fine since it'll only get that
far if the pixel data actually does need to be flipped.

Anyway, at this point I don't have enough familiarity with the code to just
dive into the correct place to fix this (assuming people even agree that
it's a bug).

I'm more than willing to submit a patch assuming I can figure out what to
fix, but if anyone has some way to point me in the correct direction that
would certainly save me some time.  In particular, is it proper to use
AVCodecContext.coded_height for all this and set it appropriately (pos or
neg)?  Is there already something that should be taking care of this that
I'm just not aware of?  Am I just plain wrong about what the problem is?

Thanks,
-martin


------
Starting with input.avi that plays correctly in WMP ...

$ ffmpeg -i input.avi -t 30 -acodec copy -vcodec rawvideo -pix_fmt bgr24
-vhook ./libenscramblevhook.so bgr24-1.avi
FFmpeg version SVN-r9791, Copyright (c) 2000-2007 Fabrice Bellard, et al.
  configuration: --disable-shared --enable-static --enable-libogg
--enable-libvorbis
  libavutil version: 49.4.1
  libavcodec version: 51.40.4
  libavformat version: 51.12.1
  built on Jul 24 2007 14:34:51, gcc: 4.1.2 20060928 (prerelease) (Ubuntu
4.1.1-13ubuntu5)
Input #0, avi, from ' input.avi':
  Duration: 00:01:59.1, start: 0.000000, bitrate: 48237 kb/s
  Stream #0.0: Video: rawvideo, rgb555, 480x260, 23.98 fps(r)
  Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, 352 kb/s
Output #0, avi, to ' bgr24-1.avi':
  Stream #0.0: Video: rawvideo, bgr24, 480x260, q=2-31, 200 kb/s, 23.98fps(c)
  Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, 352 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame=  720 fps= 30 q=0.0 Lsize=  264822kB time=30.0 bitrate=72307.2kbits/s

video:263250kB audio:1292kB global headers:0kB muxing overhead 0.105631%

Resulting bgr24-1.avi plays back upside down in WMP.

$ ffmpeg -i bgr24-1.avi -t 30 -acodec copy -vcodec rawvideo -pix_fmt bgr24
-vhook ./libenscramblevhook.so bgr24-2.avi
FFmpeg version SVN-r9791, Copyright (c) 2000-2007 Fabrice Bellard, et al.
  configuration: --disable-shared --enable-static --enable-libogg
--enable-libvorbis
  libavutil version: 49.4.1
  libavcodec version: 51.40.4
  libavformat version: 51.12.1
  built on Jul 24 2007 14:34:51, gcc: 4.1.2 20060928 (prerelease) (Ubuntu
4.1.1-13ubuntu5)
Input #0, avi, from ' bgr24-1.avi':
  Duration: 00:00:30.0, start: 0.000000, bitrate: 72242 kb/s
  Stream #0.0: Video: rawvideo, bgr24, 480x260, 23.98 fps(r)
  Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, 352 kb/s
Output #0, avi, to ' bgr24-2.avi':
  Stream #0.0: Video: rawvideo, bgr24, 480x260, q=2-31, 200 kb/s, 23.98fps(c)
  Stream #0.1: Audio: pcm_s16le, 22050 Hz, mono, 352 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame=  720 fps= 28 q=0.0 Lsize=  264822kB time=30.0 bitrate=72307.2kbits/s

video:263250kB audio:1292kB global headers:0kB muxing overhead 0.105631%

Resulting bgr24-2.avi plays back correctly in WMP.




More information about the ffmpeg-devel mailing list