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

Why isn't nalu slice code redundant? #227

Open
SoylentGraham opened this issue Feb 26, 2021 · 7 comments
Open

Why isn't nalu slice code redundant? #227

SoylentGraham opened this issue Feb 26, 2021 · 7 comments

Comments

@SoylentGraham
Copy link

Broadway does NALU splitting in the C code itself for cases when the data pushed in isn't split by NALU, (hence the data-read feedback)

Is there some benefit I don't see (lower memory use by filling only the small static scratch memory in C?) to having NALU splitting (slices) in decoder.js?

It inhibits correct meta being passed around. I have fixed this in my fork so input meta is synchronised with output meta, although it's a little more tricky in slice code, but it seems to me that the slice code is redundant anyway :)

@soliton4
Copy link
Collaborator

soliton4 commented Apr 1, 2021

without testing it out myself, but i believe the c code assumes its a complete nalu unless there is a 00 00 00 01 separator sequence.
so if you feed it an incomplete nalu it will decode incomplete and as a follow up error the next feed will break

if you feed it all nalus of a video file at once it will overload.
so you are probably partially right in, that you could feed more than one nalu at a time, but for practical reasons it was better to split it in the demo code, as well as in my streaming demo

@SoylentGraham
Copy link
Author

Oh, maybe I overlooked that this code buffers up and waits for a FULL nalu (or rather, it would have to wait for the next one)

The broadway code splits 001 as well as 0001 (and you can feed it more than one, that's why it returns "I read X bytes" :)

Broadway is quite resillient in some respects though, if you send half an intra frame, it'll decode half a intra frame :)
(I've been using broadway for a few years on various platforms, so found a few quirks & work arounds :)

@soliton4
Copy link
Collaborator

soliton4 commented Apr 1, 2021

00 00 01 is most likely separator between slices. it makes sense to decode them all at once

there is no way i know of to wait for a full nalu aside waiting for the next nal. i dont think the c decoder does that. so if you feed incomplete nalus you will have a degraded stream

@SoylentGraham
Copy link
Author

Ah so you are just duplicating the work C/Wasm side, you're not buffering up waiting for "complete" slices (as it's not really possible unless you feed a fake EOF nalu - I do this in my h264 implementations)

I just wanted to confirm I wasn't missing anything. :)

I've removed the redundancy in my fork, but I am splitting NALU's before feeding to broadway, as I have meta synchronised to "frames" (Nalu's, but I know Nalu isn't exclusively as single frame) correctly

https://github.com/SoylentGraham/Broadway

@soliton4
Copy link
Collaborator

soliton4 commented Apr 1, 2021

it depends on your application.
in one of my demos / apps i get the stdout from ffmpeg, which doesnt tell me the length of each nalu, in this case i have to wait for the next nalu before feeding one to broadway.

if you have an encoder or a stream where you know each nalu, you can just feed it complete nalus. no need to add extra separators there.
the nalu splitter code in broadway is optional. if you know your nalu you can just feed it as long as its complete

@SoylentGraham
Copy link
Author

no need to add extra separators there.

I'm not adding seperators, I'm pushing one EOS NALU (there's a nalu content type for end of stream) to my stream, when I know I have EOF, so I don't end up not-sending the final nalu.

@soliton4
Copy link
Collaborator

is this issue resolved?

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