BGR24-YUV420-BGR24 conversion on raw video

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

BGR24-YUV420-BGR24 conversion on raw video

Timo S
Hello.

I am tring to find an explanation on this peculiarity:

1) Introduce a raw BGR24 avi video and transcode it to YUV420 using ffmpeg -i rawinput.avi -vcodec rawvideo -pix_fmt yuv420p output.yuv
2) Transcode it back to BGR24 avi using ffmpeg -s 848x480 -i output.yuv -vcodec rawvideo -pix_fmt bgr24 raw_decoded.avi
3) Compare PSNR, AbsDiff and UIQ results on the original rawinput.avi and raw_decoded.avi

Results: Comparative PSNR, AbsDiff and UIQ measurements on Y-components indicate that the raw_decoded.avi has changed (ie PSNR-Y way less than 100 dB). Change definitely should be expected on U and V components but I did not expect any change on Y component.

Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: BGR24-YUV420-BGR24 conversion on raw video

Timo S
ffmpeg -s 848x480 -i D:\sintel_7.yuv -vcodec rawvideo -pix_fmt bgr
24 sintel_7_rawYUVDecoded.avi
ffmpeg version N-41074-g9c27f29 Copyright (c) 2000-2012 the FFmpeg developers
  built on May 27 2012 13:25:48 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --e
nable-zlib
  libavutil      51. 55.100 / 51. 55.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.101 / 54.  6.101
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[rawvideo @ 00000000003af340] Estimating duration from bitrate, this may be inac
curate
Input #0, rawvideo, from 'D:\sintel_7.yuv':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 848x480, 25 tbr,
25 tbn, 25 tbc
[buffer @ 0000000001f94f40] w:848 h:480 pixfmt:yuv420p tb:1/25 sar:0/1 sws_param
:flags=2
[buffersink @ 0000000001f95e20] No opaque field provided
[format @ 0000000001f82b00] auto-inserting filter 'auto-inserted scaler 0' betwe
en the filter 'src' and the filter 'format'
[scale @ 0000000001f83420] w:848 h:480 fmt:yuv420p sar:0/1 -> w:848 h:480 fmt:bg
r24 sar:0/1 flags:0x4
Output #0, avi, to 'sintel_7_rawYUVDecoded.avi':
  Metadata:
    ISFT            : Lavf54.6.101
    Stream #0:0: Video: rawvideo, bgr24, 848x480, q=2-31, 200 kb/s, 25 tbn, 25 t
bc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> rawvideo)
Press [q] to stop, [?] for help
Truncating packet of size 610560 to 1
frame=   98 fps=0.0 q=0.0 Lsize=  116873kB time=00:00:03.92 bitrate=244240.4kbit
s/s
video:116865kB audio:0kB global headers:0kB muxing overhead 0.006713%

C:\Users\Timo>ffmpeg -s 848x480 -i D:\sintel_7.yuv -vcodec rawvideo -pix_fmt bgr
24 d:\sintel_7_rawYUVDecoded.avi
ffmpeg version N-41074-g9c27f29 Copyright (c) 2000-2012 the FFmpeg developers
  built on May 27 2012 13:25:48 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --e
nable-zlib
  libavutil      51. 55.100 / 51. 55.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.101 / 54.  6.101
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[rawvideo @ 00000000003df380] Estimating duration from bitrate, this may be inac
curate
Input #0, rawvideo, from 'D:\sintel_7.yuv':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 848x480, 25 tbr,
25 tbn, 25 tbc
[buffer @ 0000000000344f80] w:848 h:480 pixfmt:yuv420p tb:1/25 sar:0/1 sws_param
:flags=2
[buffersink @ 0000000000345e60] No opaque field provided
[format @ 0000000000332b20] auto-inserting filter 'auto-inserted scaler 0' betwe
en the filter 'src' and the filter 'format'
[scale @ 0000000000333440] w:848 h:480 fmt:yuv420p sar:0/1 -> w:848 h:480 fmt:bg
r24 sar:0/1 flags:0x4
Output #0, avi, to 'd:\sintel_7_rawYUVDecoded.avi':
  Metadata:
    ISFT            : Lavf54.6.101
    Stream #0:0: Video: rawvideo, bgr24, 848x480, q=2-31, 200 kb/s, 25 tbn, 25 t
bc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> rawvideo)
Press [q] to stop, [?] for help
Truncating packet of size 610560 to 1
frame=   98 fps=0.0 q=0.0 Lsize=  116873kB time=00:00:03.92 bitrate=244240.4kbit
s/s
video:116865kB audio:0kB global headers:0kB muxing overhead 0.006713%
Reply | Threaded
Open this post in threaded view
|

Re: BGR24-YUV420-BGR24 conversion on raw video

Mark Himsley-2
In reply to this post by Timo S
On 18 Sep 2012 19:10, "Timo S" <[hidden email]> wrote:

>
> Hello.
>
> I am tring to find an explanation on this peculiarity:
>
> 1) Introduce a raw BGR24 avi video and transcode it to YUV420 using ffmpeg
> -i rawinput.avi -vcodec rawvideo -pix_fmt yuv420p output.yuv
> 2) Transcode it back to BGR24 avi using ffmpeg -s 848x480 -i output.yuv
> -vcodec rawvideo -pix_fmt bgr24 raw_decoded.avi
> 3) Compare PSNR, AbsDiff and UIQ results on the original rawinput.avi and
> raw_decoded.avi
>
> Results: Comparative PSNR, AbsDiff and UIQ measurements on Y-components
> indicate that the raw_decoded.avi has changed (ie PSNR-Y way less than 100
> dB). Change definitely should be expected on U and V components but I did
> not expect any change on Y component.
>
> Any ideas?

In BGR24 each component has values in the range 0-255

They will be mapped to YUV where Y is in the range 16-235. Therefore some
levels are lost as there is not a direct one-to-one mapping.

Those YUV levels will then be mapped back to 0-255 when you return to
BGR24. Again, there is no one-to-one mapping so more loss of levels (and
dithering) so worse PSNR.

--
Mark
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: BGR24-YUV420-BGR24 conversion on raw video

Timo S
Thanks Mark! :)

So, the good old BT.709...

Is there any way to force the conversion to full 0-255 range? I wouldn't want to be bound by ancient TV technology...

It's kinda hard to test concept codecs like the H.265 (which uses raw yuv as test videos) if the comparison uses raw bgr24 avi for test material. The metrics would be utterly useless. Of course PSNR is never conclusive if comparing codecs and therefore I use also AbsDiff and UIQ. Possibly SSIM, if we are successful in implementing that.

Offtopic: H.265 test encoder is seriously buggy. It was even missing an include line on the source code, so it wouldn't build. Luckily one guy here knows his C++.
Reply | Threaded
Open this post in threaded view
|

Re: BGR24-YUV420-BGR24 conversion on raw video

Tim Nicholson-2
On 19/09/12 06:34, Timo S wrote:
> Thanks Mark! :)
>
> So, the good old BT.709...
>

Actually 601....


> Is there any way to force the conversion to full 0-255 range? I wouldn't
> want to be bound by ancient TV technology...
>

The ffmpeg libs support a number of different colourspaces for
conversion between RGB and YUV. Not sure if full range is one of them.
Unfortunately whilst third party users make use of this, ffmpeg itself
defaults to always using "SWS_CS_DEFAULT" which is set to 601.

As they say, I'm sure a patch would be welcome....

> It's kinda hard to test concept codecs like the H.265 (which uses raw yuv as
> test videos) if the comparison uses raw bgr24 avi for test material. The
> metrics would be utterly useless. Of course PSNR is never conclusive if
> comparing codecs and therefore I use also AbsDiff and UIQ. Possibly SSIM, if
> we are successful in implementing that.
>
> Offtopic: H.265 test encoder is seriously buggy. It was even missing an
> include line on the source code, so it wouldn't build. Luckily one guy here
> knows his C++.
>

So the test encoder is C++ only then....

>
> [...]


--
Tim


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user