After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 701340 - Interlaced H264 stream flicker
Interlaced H264 stream flicker
Status: RESOLVED FIXED
Product: gstreamer-vaapi
Classification: Other
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gstreamer-vaapi maintainer(s)
gstreamer-vaapi maintainer(s)
Depends on:
Blocks: 720305
 
 
Reported: 2013-05-31 10:24 UTC by Zhao, Halley
Modified: 2014-06-30 17:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix the bug (3.91 KB, patch)
2013-05-31 10:46 UTC, Zhao, Halley
none Details | Review

Description Zhao, Halley 2013-05-31 10:24:00 UTC
gst-launch-0.10 -v filesrc location=/root/video/H264_Main@L4.1_1920x1080_10.1Mbps_30.0fps_Interlaced_Sound_Surf.mpg ! mpegtsdemux ! vaapidecode ! vaapisink

there is obvious flicker for high resolution interlace H264 stream.
Comment 1 Zhao, Halley 2013-05-31 10:27:06 UTC
I happened to find that there is no flicker when playbin2 is used.
then I found there is 'queue' between vaapidecode and vaapisink,
next I found there is no flicker in following command line:
gst-launch-0.10 -v filesrc
location=/root/video/H264_Main@L4.1_1920x1080_10.1Mbps_30.0fps_Interlaced_Sound_Surf.mpg
! mpegtsdemux ! vaapidecode ! queue ! vaapisink

so, I guess, a frame is sent to render when its second filed isn't ready.
Comment 2 Zhao, Halley 2013-05-31 10:46:45 UTC
Created attachment 245712 [details] [review]
fix the bug

We shouldn't output an interlaced frame when the first field comes even if it is a non-ref picture, it will lead to flicker.
we can safely add this non-ref frame to dpb and handle it when dpb_add is called next time.
in this way, we need increase dpb array size by one.
Comment 3 Gwenole Beauchesne 2013-05-31 12:02:55 UTC
Hi, could you please upload the file to tinderbox? Thanks.

So far, the DPB was correctly generated for all H.264 streams I had (including interlaced) vs. the JM reference decoder. So, I will have to investigate further. The DPB should include the first field too, but it is not output yet. So, there is no need to grow the DPB size.
Comment 4 Zhao, Halley 2013-06-03 01:03:53 UTC
agree that DPB is correct;
but we shouldn't output a frame just after its first field is decoded.

two fields of a frame shares the same surface in GEN/PVR driver, so we'd wait the complete of the second filed to output a frame.

then add all non-ref pictures (even if it has the smallest poc) is the quick and easy way to fix such situation.
Comment 5 Gwenole Beauchesne 2013-06-14 11:40:41 UTC
It is technically allowed to output the first field, without waiting for the second field. However, in Wayland context, we never handled the top|bottom field flags. I had some changes to protocol/mesa but that was not merged yet. Alternative is to use VPP, but this brings overhead.

BTW, I did not find the clip, where is it? Does this happen on X11 too? Thanks.
Comment 6 Zhao, Halley 2013-06-17 07:48:29 UTC
the bug is reported on X11, not wayland.
here is the content:
http://halley-sandy.sh.intel.com/share/h264-1080-interlaced.mpg
Comment 7 Gwenole Beauchesne 2013-06-26 15:16:31 UTC
Hi, the current approach was to retain the field until we have a complete frame to output. However, this is wrong for two reasons: (i) you can have situations where you never receive the complement field, i.e. there is none or it was lost; and (ii) retaining the field longer than expected incurs additional latency, i.e. you need to parse and decode one more field, which means further waiting for the start code prefix following that one.

Besides, this specific bitstream contains SEI messages (PicTiming) that need to be supported. Those are hints that an emitted field needs to be displayed as a single field for example, thus not requiring vaapipostproc in-between.
Comment 8 Gwenole Beauchesne 2013-06-26 15:26:13 UTC
Last but not least, I have tested the clip against JM and vaapidecode: the DPB states and output times are identical. So, I am not going to change gst-vaapi behaviour. Rather, the next steps are actually to support SEI messages (PicTiming) correctly and refinements to the deinterlacing process.
Comment 9 Zhao, Halley 2013-07-01 09:51:52 UTC
some agree and disgrees
> (i) you can have situations where you never receive the complement field, i.e. there is none or it was lost; 
it isn't matter, one (incomplete) frame still gets rendered when next frame comes by dpb_bump();
> (ii) retaining the field longer than expected incurs additional
latency,
it's better than render one frame before the 2nd field is ready, current frame is rendered once upon first field (does nothing upon second field).
> Rather, the next steps are actually to support SEI messages (PicTiming) correctly and refinements to the deinterlacing process.
agree.
in order to display a frame once (whole frame) or twice (each for one field), h264 dpb requires rewrite.
Comment 10 Gwenole Beauchesne 2013-07-02 13:45:00 UTC
(In reply to comment #9)
> > (ii) retaining the field longer than expected incurs additional
> latency,
> it's better than render one frame before the 2nd field is ready, current frame
> is rendered once upon first field (does nothing upon second field).

This is a valid behaviour. For this particular clip, correct handling of SEI messages is missing.

> > Rather, the next steps are actually to support SEI messages (PicTiming) correctly and refinements to the deinterlacing process.
> agree.
> in order to display a frame once (whole frame) or twice (each for one field),
> h264 dpb requires rewrite.

You don't need a rewrite of the H.264 DPB, it's fine as is. You just need to support SEI messages and tag the picture accordingly.
Comment 11 Gwenole Beauchesne 2014-06-25 04:25:33 UTC
Changes to the DPB cannot be accepted, this implementation is strictly conforming to the specs. Another solution is to introduce the concept of delayed_picture to wait for the next field. If next picture to be output is a frame, or a field with same parity, then emit the previous delayed picture. I will work on that.

The SEI messages are a hint that could be handled later.
Comment 12 Gwenole Beauchesne 2014-06-30 17:14:21 UTC
commit f48b1e0cd6eb42d9260bb50318b44cdc2fbb8629
Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
Date:   Mon Jun 30 16:09:17 2014 +0200

    decoder: h264: fix output of second field when first field is not in DPB.
    
    Fix decoding of interlaced streams where a first field (e.g. B-slice)
    was immediately output and the current decoded field is to be paired
    with that former frame, which is no longer in DPB.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701340