Skip to content

Conversation

@ha-ves
Copy link
Contributor

@ha-ves ha-ves commented May 2, 2025

I read a bit RFC 7798 Section 4.4

Summary:

  • The NAL parser forgot to set zeroes back to 0,
  • The aggregator forgot to return aggregated NALs,
  • Use a semantically readable fragmentation NAL (FU) handling

fixes #1392
forwards sipsorcery-org/SIPSorceryMedia.FFmpeg#97

put some log comments
@sipsorcery
Copy link
Member

@ha-ves this PR does not build for me.

The name '_pktCounter' does not exist in the current context

@sipsorcery
Copy link
Member

Also how have you been testing H265? I've attempted to use the WebRTCFFmpegGetStarted with this PR and the corresponding SIPSorceryMedia.FFmpeg one but the codec does not get recognised.

System.NotImplementedException: Codec Unknown is not supported by the FFmpeg video encoder.

@ha-ves
Copy link
Contributor Author

ha-ves commented May 3, 2025

@sipsorcery Sorry, leftover stats logging.

All examples and tests with browser peers are pending since they don't support HEVC/H.265, so there will be no correctly negotiated format.

I was testing in WPF. I could add it as an example with this PR, I'll have to clean it up a bit.
The test in summary:

var it = new FFmpegFileSource("max_intro.mp4", true, null);

var ti = new FFmpegVideoEndPoint();

///...
// assign endpoint event to copy to wiretablebitmap backbuffer, etc.
///...

it.RestrictFormats(f => f.Codec == VideoCodecsEnum.H265);
it.SetVideoSourceFormat(it.GetVideoSourceFormats().First());

/// ...
// create 2 PC,
// assign events, add tracks, signaling, etc.,
/// ...

while (pcrmt.connectionState != RTCPeerConnectionState.connected
    || pclcl.connectionState != RTCPeerConnectionState.connected)
    Thread.Sleep(1000);

it.StartVideo();

@jimm98y
Copy link
Contributor

jimm98y commented May 9, 2025

"All examples and tests with browser peers are pending since they don't support HEVC/H.265"
Actually, Safari on iOS/MacOS has supported H265 in WebRTC for a few months already and now the latest Chrome 136 also supports H265 in WebRTC. The requirement for it to work is to have a HW HEVC decoder, it does not work with software decoding. Most GPUs today should support it.

@sipsorcery
Copy link
Member

As @jimm98y says Chrome has announced support from version 136. I was on v135 but a pending update got me to v136. I then did try and test H265 again but it seems my GPU does not have a H265 codec.

My iPhone does advertise H265 but it's a bit tricky to test on with my network set up.

Given H265 support is still brand new in most cases I think it's safe enough to merge this PR. That will make it easier to test and add additional fixes if needs be.

@sipsorcery sipsorcery merged commit 1df3a79 into sipsorcery-org:master May 10, 2025
@ha-ves ha-ves deleted the hevc-rtp branch May 10, 2025 15:19
Comment on lines +212 to +216
if (nals.Where(x => x.NAL.Length < RTPSession.RTP_MAX_PAYLOAD).Count() > 1)
{
//logger.LogTrace("(ou) Trying aggregating {nals} nals", nals.Count());
nals = H265Packetiser.CreateAggregated(nals, RTPSession.RTP_MAX_PAYLOAD);
}
Copy link
Contributor

@paulomorgado paulomorgado May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any will only cause the nals sequence to be iterated until the first is found, while Count will cause the nals sequence to be completely iterated.

Both incur in delegate allocation (although in the latest SDKs this may be a static delegate instance) and invocation.

I would prefer something like:

                foreach (var nal in nals)
                {
                    if (nal.NAL.Length< RTPSession.RTP_MAX_PAYLOAD)
                    {
                        nals = H265Packetiser.CreateAggregated(nals, RTPSession.RTP_MAX_PAYLOAD);
                        break;
                    }
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HEVC/H.265 NAL Unit type depacketization is wrong?

4 participants