popcornmix / omxplayer

omxplayer
GNU General Public License v2.0
1.01k stars 334 forks source link

"--nativedeinterlace" has chroma upsampling error/artifacts for interlaced SD 4:2:0 mpeg2/h264/dv footage in high motion/saturated Red/Blue/Green on dark contrasts + workaround #522

Open walterav1984 opened 7 years ago

walterav1984 commented 7 years ago

Very recently the following Rpi firmware fix has been committed for improved usage of the hardware advanced deinterlacer eliminating artifacts in heavy saturated green color motion in interlaced SD 4:2:0 footage:

firmware: di_adv: Fix for green artifacts regression https://github.com/raspberrypi/firmware/commit/debe2d29bbc3df84f74672fae47f3a52fd0d40f1

Although the focus for my issue is not deinterlacing with "progressive output" but using --nativedeinterlace with "interlaced output" which is contrary to this recent firmware fix, I think they might share the same root cause which is called Chroma Upsampling Error which is prominent on interlaced 4:2:0 SD material with high saturation and motion especially in Red/Blue/Green & Orange on dark contrast areas. This recent mentioned firmware fix doesn't cause (as in regression) nor fixes the issue reported here!

Problem: SD interlaced 4:2:0 mpeg2/h264/dv video content files and or (live) streams is playedback using omxplayer on the HDMI output of the Rpi in its corresponding footage format/resolution.

omxplayer intro-clean.m2v --nativedeinterlace -I -s --loop
Input #0, matroska,webm, from 'intro-mjpeg.mkv':
  Metadata:
    ENCODER         : Lavf56.40.101
  Duration: 00:00:08.28, start: 0.040000, bitrate: 12996 kb/s
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      ENCODER         : Lavc56.60.100 mjpeg
      DURATION        : 00:00:08.280000000
Output mode 21: 720x576@50 NI:15
ntsc_freq:0 
Video codec omx-mjpeg width 720 height 576 profile -99 fps 25.000000
Subtitle count: 0, state: off, index: 1, delay: 0
Error: Unable to open font0k/  4800k A:  0.00   0.00s/  0.00s Cv:     0k Ca:     0k                            
V:PortSettingsChanged: 720x576@25.00 interlace:0 deinterlace:0 anaglyph:0 par:1.00 display:0 layer:0 alpha:255 aspectMode:0
Seek to: 00:00:0006s      0k/  4800k A: -8.14   0.00s/  0.00s Cv:     0k Ca:     0k

Using Rpi 720x576i PAL mode21/22, disable overscan, hdmi_pixel_encoding=3/4 using pixelformat 422 and 4/3 16/9 aspectratios shows Chroma Upsampling Error artifacts as in shown/recorded in this picture Red on Black contrasts. Left is correct upsampled/scaled interlace aware chroma upsampling 4:2:0 to 4:2:2 and right is incorrect. Left uses MJPEG422 as codec and right any other 4:2:0 interlaced supported codec like mpeg2/h264.

chroma-error-capture

Since real interlaced output using odd/even synced fields is possible on the Rpi since "vcgencmd hvs_update_fields X" commit: https://github.com/raspberrypi/firmware/issues/292 The only thing that Rpi is missing is interlaced aware chroma 420 upsampling 422 for interlaced SD HDMI output done by gpu/firmware?

Sample footage: The same SD 16/9 PAL 4:2:0 interlaced h264 footage from the following kodi topic can be used "Swiat wedlug Kiepskich - odc. 351.ts": http://forum.kodi.tv/showthread.php?tid=304573&pid=2505220#pid2505220

This is my test footage "intro-clean.m2v" SD 4/3 PAL 4:2:0 mpeg2 upperfield interlaced footage: https://github.com/mltframework/mlt/files/737768/intro-clean.m2v.zip https://we.tl/domVSVxnC3

Workaround: The only 4:2:2 footage the Rpi can play natively through omxplayer is MJPEG codec (correct me if I'm wrong). Other 4:2:2 capable codecs like Apple Prores, Avid DNxHD, MPEG2 IMX, XDCAM, raw yuv422 are only playable by CPU Rpi2/3 and VLC/KODI, but than I have no control over the interlacing/field sync.

Preconverting your 4:2:0 interlaced SD footage mpeg2/h264/dv to MJPEG (422 interlaced) with ffmpeg/avconv is a workaround for video files / offline only content. Using the "-vf scale=interl=1" flag makes ffmpeg aware of interlaced chroma upscaling to its output color pixel format!

ffmpeg -i intro-clean.m2v -vf scale=interl=1 -vcodec mjpeg -qscale 2 -pix_fmt yuvj422p -f matroska intro-clean-mjpeg.mkv

This will play correct with no chroma upsample artifacts. omxplayer intro-clean-mjpeg.mkv --nativedeinterlace -I -s --loop

For live TV/streaming content the only fix would be in Rpi firmware.

Hardware: Rpi 2 Blackmagic Intensity 4K hdmi in / component out to CRT monitor Sony PVM-20m4e CRT interlaced High Resolution broadcast monitor

Software: Raspbian GNU/Linux 8.0 (jessie) Linux raspberrypi 4.4.45-v7+ #954 SMP Fri Jan 27 19:06:40 GMT 2017 armv7l GNU/Linux omxplayer - Commandline multimedia player for the Raspberry Pi Build date: Thu, 19 Jan 2017 23:25:26 +0000 Version : 12b472e [master] Repository: https://github.com/popcornmix/omxplayer.git

Config.txt: disable_overscan=1 hdmi_force_mode=1 hdmi_pixel_encoding=3 hdmi_drive=2 hdmi_group=1 hdmi_mode=21 decode_MPG2=using validcode gpu_mem=256 max_usb_current=1

Background Info Similar Problem/Workaround: Professional broadcast SDI/HDMI video signal playback hardware (blackmagic Decklink/Intensity) show the exact same Color artifacts as the Rpi when outputting the same 4:2:0 footage on these SDI and HDMI a 4:2:2/4:4:4 devices using similar ffmpeg based broadcast software solutions like MLT-framework & CasparCG. The same workaround applies and have been committed this week to the github!

https://github.com/mltframework/mlt/issues/172 ##fixed in 2.2.0

https://github.com/CasparCG/Server/issues/41 ##fixed in 6.6.0

The following article is detailed, only take a look at the pictures if reading takes to much time: http://web.archive.org/web/20060719025947/http://www.hometheaterhifi.com/volume_8_2/dvd-benchmark-special-report-chroma-bug-4-2001.html

walterav1984 commented 7 years ago

How to improve this bug report, add uncompressed recordings from the HDMI output or add HD examples?