Opened 5 years ago

Closed 4 years ago

#143 closed defect (fixed)

YUV video to RGB image export color conversion issue

Reported by: peter_b Owned by:
Priority: normal Component: swscale
Version: git-master Keywords: RGB YUV color
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

When extracting images from the video (yuv422p), the color values in
the interlaced areas of the video are deviate from their original
beyond recognition.

Image comparisons and the original video can be found at:
http://download.das-werkstatt.com/pb/mthk/examples/color_problem/problem.html

Attachments (3)

yuv422p_to_rgb.patch (12.8 KB) - added by peter_b 5 years ago.
Patch to fix this (by Baptiste Coudurier)
yuvj422.jpg (18.7 KB) - added by cehoyos 5 years ago.
yuvj422jpg-N-36728-g794006f.png (4.9 KB) - added by peter_b 5 years ago.
RGB output from source: yuvj422.jpg

Download all attachments as: .zip

Change History (18)

Changed 5 years ago by peter_b

Patch to fix this (by Baptiste Coudurier)

comment:1 Changed 5 years ago by peter_b

Baptiste Coudurier posted a patch on the ffmpeg-user mailing list. I've applied this patch to git-ff1efc5 and verfified that it fixes this issue.

comment:2 Changed 5 years ago by compn

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

comment:3 Changed 5 years ago by peter_b

  • Resolution fixed deleted
  • Status changed from closed to reopened

I'm reopening this issue since the patch is currently not applied to upstream, because as Michael Niedermayer mentions in a post on the devel-mailinglist:

[quote]
the patch causes speed loss. Thats ok for 422 but the code is also
used for 420 where there is speedloss but no quality gain

iam not sure how to solve this
[quote]

comment:4 Changed 5 years ago by cehoyos

  • Status changed from reopened to open

Please post a command line, complete, uncut output (and a sample)?

comment:5 Changed 5 years ago by peter_b

It's been a while since I've had this on my table, so I can't post the exact ffmpeg-commandline I've used right now. I'll post them here as soon as I get to it.

The video sample I've used to test this, is located at:
http://download.das-werkstatt.com/pb/mthk/examples/color_problem/testvideo_color_rectangles-YUV422P.avi
(Encoding FFv1 PAL-SD resolution 720x576@25fps)

If you try to export the frames of the above video as RGB images (e.g. png, jpg) you will always get the colors interpolated between the fields.

Image samples can be found at:
http://download.das-werkstatt.com/pb/mthk/examples/color_problem/problem.html

comment:6 Changed 5 years ago by cehoyos

Please post a command line and complete, uncut output.

comment:8 Changed 5 years ago by cehoyos

  • Component changed from undetermined to swscale

comment:9 Changed 5 years ago by peter_b

I've checked the mailing list archives, and the command line used was:

ffmpeg -vframes 4 -i 'testvideo_color_rectangles-YUV422P.avi' -pix_fmt rgb24 -f image2 '%03d.bmp'

I've tried right now, and the error still persists: The colors are still wrongly interpolated.

FFmpeg version:

Git 2169f971ad9b582cc3f1e6a1430aad44d64495d3 (10 Jan 2012 06:15:18)

Uncut output:

ffmpeg version N-36659-g2169f97 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jan 10 2012 14:29:42 with gcc 4.4.5
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-avfilter --enable-pthreads --enable-bzlib --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-zlib --enable-libopenjpeg --enable-decoder=png --enable-encoder=png --enable-libdirac --enable-libschroedinger
  libavutil      51. 34.100 / 51. 34.100
  libavcodec     53. 54.100 / 53. 54.100
  libavformat    53. 29.100 / 53. 29.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 58.100 /  2. 58.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    51.  2.100 / 51.  2.100
Input #0, avi, from 'testvideo_color_rectangles-YUV422P.avi':
  Duration: 00:00:00.40, start: 0.000000, bitrate: 868 kb/s
    Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv422p, 720x576, 10 tbr, 10 tbn, 10 tbc
Incompatible pixel format 'rgb24' for codec 'bmp', auto-selecting format 'bgr24'
[buffer @ 0xa336f80] w:720 h:576 pixfmt:yuv422p tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0xa3385c0] auto-inserting filter 'auto-inserted scale 0' between the filter 'src' and the filter 'out'
[scale @ 0xa330d80] w:720 h:576 fmt:yuv422p -> w:720 h:576 fmt:bgr24 flags:0x4
[swscaler @ 0xa3311c0] No accelerated colorspace conversion found from yuv422p to bgr24.
[swscaler @ 0xa3463e0] No accelerated colorspace conversion found from yuv422p to bgr24.
[swscaler @ 0xa34ae60] No accelerated colorspace conversion found from yuv422p to bgr24.
Output #0, image2, to '%03d.bmp':
  Metadata:
    encoder         : Lavf53.29.100
    Stream #0:0: Video: bmp, bgr24, 720x576, q=2-31, 200 kb/s, 90k tbn, 10 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (ffv1 -> bmp)
Press [q] to stop, [?] for help
frame=    4 fps=  0 q=0.0 Lsize=       0kB time=00:00:00.40 bitrate=   0.0kbits/s
video:4860kB audio:0kB global headers:0kB muxing overhead -100.000000%

comment:10 Changed 5 years ago by peter_b

Additionally, Baptiste's patch cannot be applied to the current git version anymore, as the code has changed too much since the version the patch was written for (SVN revision 32669).

Changed 5 years ago by cehoyos

comment:11 Changed 5 years ago by cehoyos

  • Reproduced by developer set
  • Version changed from unspecified to git-master
$ ffmpeg -i yuvj422.jpg out.bmp
ffmpeg version N-36662-g93d49cb Copyright (c) 2000-2012 the FFmpeg developers
  built on Jan 10 2012 19:07:13 with gcc 4.5.3
  configuration: --cc='/usr/local/gcc-4.5.3/bin/gcc -m32'
  libavutil      51. 34.100 / 51. 34.100
  libavcodec     53. 54.100 / 53. 54.100
  libavformat    53. 29.100 / 53. 29.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 58.100 /  2. 58.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
Input #0, image2, from 'yuvj422.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p, 720x576, 25 tbr, 25 tbn, 25 tbc
Incompatible pixel format 'yuvj422p' for codec 'bmp', auto-selecting format 'bgr24'
[buffer @ 0x8dd8000] w:720 h:576 pixfmt:yuvj422p tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0x8dd8d20] auto-inserting filter 'auto-inserted scale 0' between the filter 'src' and the filter 'out'
[scale @ 0x8dd9240] w:720 h:576 fmt:yuvj422p -> w:720 h:576 fmt:bgr24 flags:0x4
[swscaler @ 0x8de4280] No accelerated colorspace conversion found from yuv422p to bgr24.
[swscaler @ 0x8dee060] No accelerated colorspace conversion found from yuv422p to bgr24.
[swscaler @ 0x8df2b00] No accelerated colorspace conversion found from yuv422p to bgr24.
Output #0, image2, to 'out.bmp':
  Metadata:
    encoder         : Lavf53.29.100
    Stream #0:0: Video: bmp, bgr24, 720x576, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> bmp)
Press [q] to stop, [?] for help
frame=    1 fps=  0 q=0.0 Lsize=       0kB time=00:00:00.04 bitrate=   0.0kbits/s
video:1215kB audio:0kB global headers:0kB muxing overhead -100.000000%

Changed 5 years ago by peter_b

RGB output from source: yuvj422.jpg

comment:12 follow-up: Changed 5 years ago by peter_b

I'm not sure what you're trying to tell me, but I've reproduced your conversion and attached the resulting RGB as PNG (not BMP, due to filesize issues):
yuvj422jpg-N-36728-g794006f.png

$ ffmpeg -i yuvj422.jpg out/out.png

ffmpeg version N-36728-g794006f Copyright (c) 2000-2012 the FFmpeg developers
  built on Jan 12 2012 09:16:04 with gcc 4.4.5
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-postproc --enable-swscale --enable-avfilter --enable-pthreads --enable-bzlib --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-zlib --enable-libopenjpeg --enable-decoder=png --enable-encoder=png --enable-libdirac --enable-libschroedinger
  libavutil      51. 34.100 / 51. 34.100
  libavcodec     53. 55.100 / 53. 55.100
  libavformat    53. 29.100 / 53. 29.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 58.100 /  2. 58.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0.  6.100 /  0.  6.100
  libpostproc    51.  2.100 / 51.  2.100
Input #0, image2, from 'yuvj422.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p, 720x576, 25 tbr, 25 tbn, 25 tbc
Incompatible pixel format 'yuvj422p' for codec 'png', auto-selecting format 'rgb24'
[buffer @ 0x9351e20] w:720 h:576 pixfmt:yuvj422p tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0x93487e0] auto-inserting filter 'auto-inserted scale 0' between the filter 'src' and the filter 'out'
[scale @ 0x9348d40] w:720 h:576 fmt:yuvj422p -> w:720 h:576 fmt:rgb24 flags:0x4
[swscaler @ 0x9357b60] No accelerated colorspace conversion found from yuv422p to rgb24.
[swscaler @ 0x9367800] No accelerated colorspace conversion found from yuv422p to rgb24.
[swscaler @ 0x936d2a0] No accelerated colorspace conversion found from yuv422p to rgb24.
Output #0, image2, to 'out/out.png':
  Metadata:
    encoder         : Lavf53.29.100
    Stream #0:0: Video: png, rgb24, 720x576, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> png)
Press [q] to stop, [?] for help
frame=    1 fps=  0 q=0.0 Lsize=       0kB time=00:00:00.04 bitrate=   0.0kbits/s
video:5kB audio:0kB global headers:0kB muxing overhead -100.000000%

Version 0, edited 5 years ago by peter_b (next)

comment:13 in reply to: ↑ 12 Changed 5 years ago by cehoyos

Replying to peter_b:

I'm not sure what you're trying to tell me... ;)

In August, I asked for a command line (and complete, uncut console output) and a sample.

You added a command line (and the console output) two days ago, I was able to reproduce your issue, I set the "Reproduced"-flag and I added a sample.

I did not ask for the resulting RGB file because I do not remember an issue where attaching the resulting file made reproducing the issue easier.

I hope that clears it up ;-)

comment:14 Changed 5 years ago by peter_b

Understood.
Thanks.

comment:15 Changed 4 years ago by michael

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

It appears this has been fixed by some change since it was reported, i cant reproduce it anymore

Note: See TracTickets for help on using tickets.