Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE


This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

ffmpeg poor YUV to RGB conversion

Discussions about problems encountered using ffmpeg.
Forum rules
FFmpeg is in a state of perpetual development and we do not currently have the person power to backport fixes to official releases. As such, if you wish to query or report a bug, you must try with the latest development branch revision of FFmpeg to confirm the issue still exists. The latest FFmpeg can be downloaded from here: http://www.ffmpeg.org/download.html

ffmpeg poor YUV to RGB conversion

Postby noiseshaper » Tue Sep 12, 2017 9:27 am

Hi,

I'm using ffmpeg-3.2.4-win32, static and dev versions from zeranoe page, to decode some h264 mp4 videos I have created with x264 encoder.

When I decode their frames to png using ffmpeg.exe I get poor chroma resolution, quite blocky in the static zones of the video. If I decode them to jpg, the output is OK.

Doing some tests with ffmpeg API, I've narrowed the problem to the conversion from YUV to RGB performed with sws_scale(), since the YUV output is OK.

You can see an example here (put proper google drive url, can't post proper links yet).

drive google com/file/d/0B5KI1D-N1kHpV3lGaERJRjNkcms/view

1: Original frame before compressing.

2: YUV 4:2:0 conversion before compressing

3: Video output from MPC HC + LAV decoder. This is YUV420p output after decoding.

4: Video frames decoded with ffmpeg.exe to jpeg. Output is ok, just some jpeg macroblocking is visible.

5: Video frames decoded with ffmpeg.exe to png, very blocky chroma. Using ffmpeg API avcodec_decode_video2() and sws_scale() conversion to RGB produces the same blocky chroma.

The command lines for decoding the frames to jpg and png are these:

Code: Select all
ffmpeg -i testcase.mp4 -vframes 5 -qscale:v 2 output%03d.jpg


Code: Select all
ffmpeg -i testcase.mp4 -vframes 5 output%03d.png


You can download mp4 and bat files that showcase the effect here:

drive google com/drive/folders/0B5KI1D-N1kHpcUdGd2IyM2pXMTg

Thanks in advance.
noiseshaper
 
Posts: 2
Joined: Mon Sep 11, 2017 3:42 pm

Re: ffmpeg poor YUV to RGB conversion

Postby noiseshaper » Tue Sep 12, 2017 10:11 am

Ok, I found the fix in an old ffmpeg bugtrack at trac ffmpeg org/ticket/1582

In order to do good quality YUV to RGB conversion, you have to add in ffmpeg.exe:

Code: Select all
-sws_flags full_chroma_int+accurate_rnd


Or in ffmpeg API sws_getContext() the flags:

Code: Select all
SWS_FULL_CHR_H_INT | SWS_ACCURATE_RND


With these, the RGB output is OK.

Hope this helps, thanks.
noiseshaper
 
Posts: 2
Joined: Mon Sep 11, 2017 3:42 pm


Return to ffmpeg

Who is online

Users browsing this forum: Google [Bot] and 7 guests