Support for slices in d3d11h264dec?

In short, d3d11h264dec doesn’t seem to handle multiple slices per frame by default, how do I remedy this?

I have a Maevex 6052 encoder appliance that produces an H.264 stream of an HDMI input. The output stream is sent over RTSP where I decode it using GStreamer to display it locally. Notably, the encoder is configured to be “Optimized for low latency”, which appears to divide outgoing frames into 4 slices.

When decoding, only the top of the image appears to be decoded correctly, where the bottom 3/4ths is a big blur that appears to just repeat the last successfully decoded line of pixels. The top portion plays normally. Errors appear in the log indicating the slice error:

...
0:00:03.747752100 22856 000001203CC3E180 INFO            videodecoder gstvideodecoder.c:1631:gst_video_decoder_sink_event_default:<d3d11h264dec0> upstream tags: taglist, video-codec=(string)"H.264\ \(High\ Profile\)", minimum-bitrate=(uint)59041, maximum-bitrate=(uint)3019281, bitrate=(uint)8594073;
0:00:03.762124100 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 2040
0:00:03.762317000 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
0:00:03.762531900 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 4080
0:00:03.762687800 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
0:00:03.762814800 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 6120
0:00:03.762992800 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
0:00:03.763102400 22856 000001203CC3E180 WARN       codecparsers_h264 gsth264parser.c:1116:gst_h264_parser_parse_user_data_unregistered: No more remaining payload data to store
0:00:03.763213700 22856 000001203CC3E180 WARN               h264parse gsth264parse.c:642:gst_h264_parse_process_sei:<h264parse0> failed to parse one or more SEI message
0:00:03.778765600 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 2040
0:00:03.778999900 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
0:00:03.779136600 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 4080
0:00:03.779257000 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
0:00:03.779384900 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 6120
0:00:03.779505200 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
0:00:03.779673100 22856 000001203CC3E180 WARN       codecparsers_h264 gsth264parser.c:1116:gst_h264_parser_parse_user_data_unregistered: No more remaining payload data to store
0:00:03.779826700 22856 000001203CC3E180 WARN               h264parse gsth264parse.c:642:gst_h264_parse_process_sei:<h264parse0> failed to parse one or more SEI message
0:00:03.796004200 22856 000001203CC3E180 ERROR            h264decoder gsth264decoder.c:751:gst_h264_decoder_preprocess_slice:<d3d11h264dec0> Invalid stream, first_mb_in_slice 2040
0:00:03.797273500 22856 000001203CC3E180 WARN            videodecoder gstvideodecoder.c:4787:_gst_video_decoder_error:<d3d11h264dec0> error: Failed to decode data
...

I’m running Windows 10 with GStreamer MSVC x64 1.24.7. Some other decoders appear to have the same issue (nvh264dec), or they work, but with higher latency or system utilization, so I’d prefer to use d3d11. Here’s the pipeline used.

gst-launch-1.0.exe rtspsrc location="rtsp://192.168.42.101:3049/S1" latency=10 ! rtph264depay ! queue ! h264parse ! d3d11h264dec ! d3d11videosink

I tried saving the stream to file after h264parse, but when replaying the file (starting with h264parse), it decodes fine, so not sure what’s going on there…

# Save
gst-launch-1.0.exe rtspsrc location="rtsp://192.168.42.101:3049/S1" latency=10 ! rtph264depay ! h264parse config-interval=1 ! video/x-h264,stream-format=byte-stream, alignment=au ! tee name=t ! queue ! filesink location= test.h264 t. ! queue ! d3d11h264dec ! d3d11videosink

# Play from file
gst-launch-1.0.exe filesrc location= test.h264 ! 'video/x-h264, stream-format=byte-stream, alignment=au' ! h264parse ! d3d11h264dec ! d3d11videosink

Best to save the stream with wireshark or tcpdump. We will then be able to do that verification needed, multiple slice support should work with D3D11/12 DXVA based decoders.

The traces about the first slice not being at macroblock 0 like it should is a bit suspicious. I know it might be hitting a bug in h264parse, for which we had a fix in 1.24, but had to be reverted due to severe regressions. If this is it, h264parse ends up splitting slices erroneously into AU.

Wireshark capture is linked below, let me know if you have issues accessing, or if there’s something else I can provide.

Matrox_Low-latency_Cap.pcapng.gz

File was captured while running the same GStreamer pipeline (the first one, under log).

I don’t have a window machine, but this can be reproduce on Linux. I’ve used wireshark to convert from pcapng to old pcap format.

GST_DEBUG=2 gst-launch-1.0 filesrc location=test.pcap ! pcapparse dst-port=64472 caps="application/x-rtp, clock-rate=(int)90000, encoding-name=(string)H264, media=(string)video" ! rtpjitterbuffer ! rtph264depay ! h264parse ! video/x-h264,alignment=au ! vah264dec ! glimagesink

What stood out is this error:

0:00:06.729493495 1740023 0x7f3e58000b90 WARN               h264parse gsth264parse.c:642:gst_h264_parse_process_sei:<h264parse0> failed to parse one or more SEI message

I for some reason didn’t notice it. But perhaps that least to the first slices of every frame being dropped ?

Another interesting information is that if you save the raw H.264 data, and play it back its all good:

GST_DEBUG=2 gst-launch-1.0 filesrc location=test.pcap ! pcapparse dst-port=64472 caps="application/x-rtp, clock-rate=(int)90000, encoding-name=(string)H264, media=(string)video" ! rtpjitterbuffer ! rtph264depay !  video/x-h264,stream-format=byte-stream ! filesink location=data.h264

gst-play-1.0 data.h264

That clearly points to a GStreamer bug.

I had no idea GStreamer supported pcap replays, this is handy to know!

I also noticed the SEI parse failures, but I assumed it was SEI info the encoder appliance was adding, not necessarily a parse error.

Let me know if I can provide additional information or test something on my end.