Opened 5 years ago

Closed 5 years ago

#52 closed defect (fixed)

mjpeg decoder is broken (at least with ga61bc91)

Reported by: ami_stuff Owned by: michael
Priority: normal Component: ffmpeg
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Please test if this bug is still valid with the HEAD, ga61bc91 generates broken output for MJPEG decoder.

http://samples.mplayerhq.hu/V-codecs/MJPEGs/pegasus_mjpeg/pegasus_mjpeg.avi

C:\>ffmpeg -i C:\pegasus_mjpeg.avi -vcodec msmpeg4v2 out3.avi
FFmpeg version git-N-28949-ga61bc91, Copyright (c) 2000-2011 the FFmpeg develope
rs

built on Apr 9 2011 00:01:59 with gcc 4.5.2
configuration: --arch=x86 --cross-prefix=i686-pc-mingw32- --target-os=mingw32

--prefix=/ffmpeg/builds/git-N-28949-ga61bc91-static --enable-memalign-hack --dis
able-shared --enable-static --enable-w32threads --disable-debug --enable-gpl --e
nable-version3 --enable-runtime-cpudetect --enable-zlib --enable-bzlib --enable-
avisynth --enable-postproc --enable-libmp3lame --enable-libx264 --enable-libvorb
is --enable-libtheora --enable-libspeex --enable-libopencore-amrnb --enable-libo
pencore-amrwb --enable-libxvid --enable-libgsm --enable-libvpx --disable-decoder
=libvpx --enable-librtmp --enable-libopenjpeg --enable-frei0r --enable-libxavs -
-cc='ccache i686-pc-mingw32-gcc'

libavutil 50. 40. 1 / 50. 40. 1
libavcodec 52.117. 0 / 52.117. 0
libavformat 52.106. 0 / 52.106. 0
libavdevice 52. 4. 0 / 52. 4. 0
libavfilter 1. 77. 1 / 1. 77. 1
libswscale 0. 13. 0 / 0. 13. 0
libpostproc 51. 2. 0 / 51. 2. 0

Input #0, avi, from 'C:\pegasus_mjpeg.avi':

Duration: 00:02:29.60, start: 0.000000, bitrate: 448 kb/s

Stream #0.0: Video: mjpeg, yuvj422p, 480x260, 20 tbr, 20 tbn, 20 tbc
Stream #0.1: Audio: mp3, 44100 Hz, stereo, s16, 319 kb/s

Incompatible pixel format 'yuvj422p' for codec 'msmpeg4v2', auto-selecting forma
t 'yuv420p'
[buffer @ 01ca2540] w:480 h:260 pixfmt:yuvj422p
[ffsink @ 01ca2760] auto-inserting filter 'auto-inserted scaler 0' between the f
ilter 'src' and the filter 'out'
[scale @ 01ca2a00] w:480 h:260 fmt:yuvj422p -> w:480 h:260 fmt:yuv420p flags:0x4

[mp2 @ 01c9a2b0] The requested thread algorithm is not supported with this threa
d library.
Output #0, avi, to 'out3.avi':

Metadata:

ISFT : Lavf52.106.0
Stream #0.0: Video: msmpeg4v2, yuv420p, 480x260, q=2-31, 200 kb/s, 20 tbn, 2

0 tbc

Stream #0.1: Audio: mp2, 44100 Hz, stereo, s16, 64 kb/s

Stream mapping:

Stream #0.0 -> #0.0
Stream #0.1 -> #0.1

Press [q] to stop encoding
[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 3 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 3 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 5 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 3 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 5 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127
[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 2 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127
[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127
[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 7 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 7 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 7 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 3 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 3 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 3 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 5 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 2 dct coefficients to -127..127

Last message repeated 1 times

[msmpeg4v2 @ 022297e0] warning, clipping 1 dct coefficients to -127..127

Last message repeated 83 times 485kB time=9.55 bitrate= 415.7kbits/s

frame= 218 fps= 78 q=31.0 Lsize= 573kB time=10.90 bitrate= 430.7kbits/s

video:459kB audio:89kB global headers:0kB muxing overhead 4.666883%

Attachments (2)

out.avi (444.9 KB) - added by ami_stuff 5 years ago.
libswscale_enable_cpu_runtime.diff (2.2 KB) - added by tateu 5 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 5 years ago by ami_stuff

g3e3ea93 05-04-2011 - ok
gee6db0d 06-04-2011 - bad

comment:2 Changed 5 years ago by cehoyos

  • Resolution set to worksforme
  • Status changed from new to closed

This works fine for me with current git HEAD, please reopen if still reproducible for you.

Changed 5 years ago by ami_stuff

comment:3 Changed 5 years ago by ami_stuff

I'm able to reproduce the problem with these builds:

http://www.bizzeh.com/ffmpeg/free/static/ffmpeg-git-N-29043-gdf149f6-x86-static-20110412.7z
http://research.m1stereo.tv/ffmpeg/snapshots/ffmpeg-20110412-6873cf9.zip
http://hawkeye.arrozcru.org/builds/32-bit/static/ffmpeg-git-9d4cb45-32-bit-static.7z

it looks probably more like libswscale bug, not decoder bug.

but the good thing is that this bug doesn't happen under m68k ;)

comment:4 Changed 5 years ago by thebombzen

I reproduced this bug. With git-N-29061-g5c00687.

comment:5 Changed 5 years ago by ami_stuff

Then libswscale is broken for win32. Someone should investigate this.

comment:6 Changed 5 years ago by ami_stuff

This seems to be fixed with git-N-29131-gf4bc923.

@thebombzen

You may try to retest your bug with the head, maybe it's fixed as well.

comment:7 Changed 5 years ago by tateu

I think it is still there. I tried a 32bit build of git-N-29157-gc967860 on Windows XP (Pentium 4) and Windows 7 (64 Bit Xeon) today. I don't think it is the decoder. ami_stuff's suggestion that it is in libswscale makes more sense. So far, I can always reproduce the problem (starting at git-53e35fd and see note about --arch below) when the source file is 32 bit RGB and the output is something other than RGB and I can sometimes reproduce the problem when the source file is 24 bit RGB and the output is something other than RGB.

If the source file is a 32 bit Avi, the following all produce green/pink video:

ffmpeg.exe -i 32Bit.avi -vcodec libx264 -fpre libx264-medium.ffpreset out_h264.mp4

fmt:bgra -> fmt:yuv420p

ffmpeg.exe -i 32Bit.avi out.mpg

fmt:bgra -> fmt:yuv420p

ffmpeg.exe -i 32Bit.avi out.jpg

fmt:bgra -> fmt:yuvj420p

--

If the source file is a 32 bit Avi, the following do NOT produce green/pink video:

ffmpeg.exe -i 32Bit.avi -vcodec huffyuv out_hfyv.avi

fmt:bgra -> fmt:bgra

ffmpeg.exe -i 32Bit.avi out.tif

fmt:bgra -> fmt:rgb24

I first noticed this problem with git-53e35fd (from around March 4th or 5th, 2011). I can NOT reproduce the problem on the slightly older git-8cf9a09.

Note about --arch:
Also, I noticed that if I compile with "--arch=x86" or "--arch=i686", then I experience the problem. If I instead compile with "--arch=x86_32", then I do NOT experience the problem. But...with "--arch=x86_32" "-vcodec mpeg4" encodes about twice as slow.

comment:8 Changed 5 years ago by cehoyos

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Could you try git bisect to find the version introducing the regression?

comment:9 Changed 5 years ago by tateu

Oh boy...git bisect...that was fun. I went through 10 32bit builds (cross compiled from Ubuntu 10.10 x64 / run on Windows 7 x64) using:

../configure --prefix=/usr/i686-mingw32 --enable-cross-compile --target-os=mingw32 --cross-prefix=i686-mingw32- --cc=i686-mingw32-gcc --arch=x86 --enable-runtime-cpudetect --enable-shared --disable-static --enable-memalign-hack --enable-gpl --enable-version3 --enable-zlib --enable-bzlib --enable-pthreads --enable-avisynth --enable-postproc --enable-avfilter

And here is the final output:

30c6fefd013a579f455c230ca9b9b0f8fc68285a is the first bad commit
commit 30c6fefd013a579f455c230ca9b9b0f8fc68285a
Author: Darren Horrocks <killallthehumans@gmail.com>
Date: Tue Apr 5 02:34:26 2011 +0200

fix runtime-cpu-detect bug in swscale

swscale doesnt ever actually do any runtime detection at all when
runtime cpu detection is enabled, it simply passes whatever is passed
to -sws_flags, which could be nothing at all making swscale default to
the C implementation.

:040000 040000 e4e9470301240f0fa3b1e5d05c19881b2e012c1a c2c332c51fe537b5159025bf6a14aeec53d32ef4 M libswscale

comment:10 Changed 5 years ago by cehoyos

Thank you!

Could you add information about the processor you are using?

comment:11 Changed 5 years ago by tateu

I just tried the latest git-N-29157-gc967860 (--arch==x86 and --arch=i686) with 30c6fefd013a579f455c230ca9b9b0f8fc68285a reverted...and the problem of converting RGB to non-RGB is gone, but...I am back to "-vcodec mpeg4" encoding about twice as slow which, I guess, makes sense since the fix was to "fix runtime-cpu-detect bug in swscale [...] default to the C implementation."

Cross compiled in VMWare (Ubuntu 10.10 x64) running on the Win7 Pro x64 machine below.

Running 32bit ffmpeg builds in Windows 7 Pro x64 on a Dual QuadCore? Xeon X5550 machine at 2.67GHz with 8GB ram.

and

Running 32bit ffmpeg builds in Windows XP Pro SP3 on a Pentium 4 machine at ???GHz (not sure) with 2GB Ram.

Last edited 5 years ago by tateu (previous) (diff)

Changed 5 years ago by tateu

comment:12 Changed 5 years ago by tateu

Ok, I think I found the problem. With --enable-runtime-cpudetect, sws_rgb2rgb_init from rgb2rgb.c was getting called with the incorrect flags and triggering rgb2rgb_init_C even though ff_getSwsFunc from swscale.c was getting called with the correct flags and triggering sws_init_swScale_MMX2().

I have attached a patch (libswscale_enable_cpu_runtime.diff) that fixes the problem for me. Basically, I moved (and modified, slightly by adding SSE2) the code from commit 30c6fefd013a579f455c230ca9b9b0f8fc68285a (swscale.c) to update_flags_cpu in utils.c.

comment:13 Changed 5 years ago by cehoyos

  • Resolution set to fixed
  • Status changed from reopened to closed

Patch applied, thank you!

Note: See TracTickets for help on using tickets.