webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

SampleBuilder can't handle H264

Open Sean-Der opened this issue 4 years ago • 12 comments

We just got a report in Slack from a user that wasn't able to use rtp-to-webrtc with H264.

I am not sure what the issues are, investigating now.

Sean-Der avatar Jan 29 '21 19:01 Sean-Der

It seems like the SampleBuilder is condensing the SPS/PPS/IDR into one RTP packet and that is breaking things.

GStreamer sends them as three distinict packets, with one timestamp. We then emit a Sample with them all in one Payload. That one Payload gets turned into one RTP packet.

Sean-Der avatar Jan 30 '21 07:01 Sean-Der

Definitely, there‘s an issue with H264. My test case(examples/rtp-to-webrtc) is under Pion webrtc version 3.0.4.

Here‘s one piece of my code.

videoTrack, err := webrtc.NewTrackLocalStaticRTP(webrtc.RTPCodecCapability{ MimeType: webrtc.MimeTypeH264, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f", }, "video", "pion")

Environment: Windowns 10, Internal network with IP camera using UDP to push media streams(standard RTP packet).

  1. IP camera:HIK VISION(海康威视). Push RTP packet to the the specific port, work well in both web page and VLC player.

  2. Another IP camera: I have no idea about it's manufacturer. Work well only in VLC player, it seems there's something wrong in web page.

  3. Use ffmpeg command line ffmpeg -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f rtp udp://192.168.1.88:3232 to push screen record. The result just like the test case 2 above.

It's weird when I use rtsp(H264) with this repo(https://github.com/deepch/RTSPtoWebRTC), all my IP camera work well in web page.

Could you please give a clue about my problems?

Thanks a lot!

WhalenChan avatar Mar 12 '21 08:03 WhalenChan

Hey @WhalenChan. Your issue isn't related to the SampleBuilder, but happy to help!

My guess is that you aren't attaching a SPS/PPS to every IDR. You can see here the work that is involved.

Can you try rtsp-bench it is a much more naieve version and might be all you need.

Would you mind moving this conversation to Slack or the GitHub Discussions? Just so we can keep this issue related to original issue.

thanks!

Sean-Der avatar Mar 12 '21 16:03 Sean-Der

@Sean-Der I got it, thanks for your help!

WhalenChan avatar Mar 13 '21 02:03 WhalenChan

did you get it to work? do you have an ffmpeg command line or patch to pion to make it work? we need to stream both from ffmpeg and hik cameras.

maddanio avatar Apr 27 '21 12:04 maddanio

what I gather from the sdp that ffmpeg spits out is it always uses packetization mode 1 (non-interleaved single nalu, with large nalus being fragmented into fu-a)

maddanio avatar Apr 27 '21 13:04 maddanio

btw: does pion have to actually do anything to the packets? I would have thought it can just forward them untouched. thats what we do in our own rtsp proxy implementation, though not sure if that works for webrtc?

maddanio avatar Apr 27 '21 13:04 maddanio

ok, I managed to solve it by adding some package processing stolen from here

maddanio avatar Apr 29 '21 10:04 maddanio

Definitely, there‘s an issue with H264. My test case(examples/rtp-to-webrtc) is under Pion webrtc version 3.0.4.

Here‘s one piece of my code.

videoTrack, err := webrtc.NewTrackLocalStaticRTP(webrtc.RTPCodecCapability{ MimeType: webrtc.MimeTypeH264, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f", }, "video", "pion")

Environment: Windowns 10, Internal network with IP camera using UDP to push media streams(standard RTP packet).

  1. IP camera:HIK VISION(海康威视). Push RTP packet to the the specific port, work well in both web page and VLC player.
  2. Another IP camera: I have no idea about it's manufacturer. Work well only in VLC player, it seems there's something wrong in web page.
  3. Use ffmpeg command line ffmpeg -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f rtp udp://192.168.1.88:3232 to push screen record. The result just like the test case 2 above.

It's weird when I use rtsp(H264) with this repo(https://github.com/deepch/RTSPtoWebRTC), all my IP camera work well in web page.

Could you please give a clue about my problems?

Thanks a lot!

Definitely, there‘s an issue with H264. My test case(examples/rtp-to-webrtc) is under Pion webrtc version 3.0.4.

Here‘s one piece of my code.

videoTrack, err := webrtc.NewTrackLocalStaticRTP(webrtc.RTPCodecCapability{ MimeType: webrtc.MimeTypeH264, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f", }, "video", "pion")

Environment: Windowns 10, Internal network with IP camera using UDP to push media streams(standard RTP packet).

  1. IP camera:HIK VISION(海康威视). Push RTP packet to the the specific port, work well in both web page and VLC player.
  2. Another IP camera: I have no idea about it's manufacturer. Work well only in VLC player, it seems there's something wrong in web page.
  3. Use ffmpeg command line ffmpeg -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f rtp udp://192.168.1.88:3232 to push screen record. The result just like the test case 2 above.

It's weird when I use rtsp(H264) with this repo(https://github.com/deepch/RTSPtoWebRTC), all my IP camera work well in web page.

Could you please give a clue about my problems?

Thanks a lot!

ffmpeg -re -f lavfi -i testsrc=size=640x480:rate=30 -pix_fmt yuv420p -c:v libx264 -bsf:v h264_mp4toannexb -cpu-used 5 -deadline 1 -g 10 -error-resilient 1 -auto-alt-ref 1 -f rtp rtp://127.0.0.1:5004?pkt_size=1200

Use this ffmpeg command , work well in both web page and VLC player.

liceim avatar Sep 25 '21 06:09 liceim

That is exactly the example i based my version on. I added signaling via websocket and had to modify the h264 nalus by adding start codes.

maddanio avatar Sep 25 '21 09:09 maddanio

Hello,I made many tests.And I find that web can play normal if we remove -preset ultrafast. ffmpeg -re -f lavfi -i testsrc=size=640x480:rate=30 -pix_fmt yuv420p -c:v libx264 -g 10 -preset ultrafast -tune zerolatency -f rtp rtp://127.0.0.1:5004?pkt_size=1200 In this way,just VLC can play,not the web. ffmpeg -re -f lavfi -i testsrc=size=640x480:rate=30 -pix_fmt yuv420p -c:v libx264 -g 10 -tune zerolatency -f rtp rtp://127.0.0.1:5004?pkt_size=1200 And in this way,both VLC and web can play. WHY IS THAT? I can't understand,but we can think about it.

xiaodeedaijia avatar Feb 23 '22 13:02 xiaodeedaijia