Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motivation to automatically remove annex-b? #608

Open
bmharper opened this issue Aug 26, 2024 · 1 comment
Open

Motivation to automatically remove annex-b? #608

bmharper opened this issue Aug 26, 2024 · 1 comment

Comments

@bmharper
Copy link

Here's a reference to the code I'm referring to:

if !d.annexBMode && bytes.Contains(nalu, []byte{0x00, 0x00, 0x00, 0x01}) {

I have two questions:

  1. Firstly, on line 233, why bytes.Contains(nalu, []byte{0x00, 0x00, 0x00, 0x01}) instead of bytes.HasPrefix? The Contains call will need to scan through the entire packet, which has a cost.
  2. What is the motivation for removing annex-b encoding, and on which cameras have you seen this?

Thanks!

@bluenviron bluenviron deleted a comment Aug 26, 2024
@bluenviron bluenviron deleted a comment Aug 26, 2024
@bmharper
Copy link
Author

I've got some more information which will help explain why I've asked this question:

I have 3 HikVision cameras, and they have confused me for a long time, but I finally figured it out:

These cameras send RTSP packets without start codes (i.e. there is no 00.00.01 or 00.00.00.01 prefix to the packets). BUT, the packets are "Annex-B" encoded, because they have "emulation prevention bytes" added. In other words, in the byte stream I find a lot of 00.00.03.01 sequences. I have verified this by trying all permutations of decoding/encoding, etc, and testing it out on ffmpeg.

So what I am saying, is that it seems clear from this example that the presence of start codes is not 1:1 correlated with Annex-B escaping. And because of this, I'm not sure that it is a good idea to automatically remove the Annex-B encoding if you detect start codes.

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

No branches or pull requests

2 participants
@bmharper and others