-
Notifications
You must be signed in to change notification settings - Fork 39
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
Use ffmpeg demuxer instead of separate streams #108
Conversation
During the implementation of this, I find the Since we now directly uses the ffmpeg API, which gives us frame information, I'm thinking of providing another function, |
With raw audio formats, we can't maintain the strict 1 Opus frame per write() guarantee, so instead force the user to provide Opus audio
Again, the situation with `streamOptions` isn't really what I want, but let's progress little by little for now
Using the updated version in my script gives error "Unable to copy the codec: No suitable stream found" |
This is not finished yet, please wait |
Without an explicit input format, ffmpeg errors with "Invalid data when processing input"
Lower values lead to lower latency, but might increase overhead of repeatedly calling the function. 16KiB of output data per call seems reasonable
This is usable now, but ending the stream will cause an infinite loop to happen. I don't know where it is yet, but I suspect it's the sync loops. |
I think creating another function that does that for you sounds good. When you say that MediaUdp should detect the values from the encoder, what would that look like? The user should still be able to change the parameters of an existing udp connection, kind of like when the user selects to change the screen/application in a Go Live stream which doesn't reset the connection but could result in different stream parameters. |
Well currently if you have a movie thats like 1920x800 whats a normal movie format, most ppl will set the format to 1920x1080 what will stretch the video. And it would be kinda annoying to change for every movie file playing |
Yeah, like I said, I think it is a good idea to provide an alternative function which will use the existing video codec properties, such as video resolution. But we should also leave the existing stream function that sets user-provided options since the user may want to edit these. Right now the Discord SFU doesn't seem to check for Nitro subscription, so any user is able to send whatever resolution they want, but this may not be true in the future. |
H265 is broken, not sure if it's due to my change or not |
Ohh that makes sense. So in this scenario it's possible to change the video without having to start a new MediaUdp connection, right? |
Theoretically yes, though I don't know yet how the re-negotiation process works, let's ignore that for now. |
This will come into play later on
It turns out, the `mp4_h264toannexb` filter was helping us a great deal here, by inserting the parameter sets before each I frame. With mkv and other containers, they're only specified once in the file, so we need to synthesize it ourselves
Update after my latest additions:
Testing problematic streams from other issues:
A few notes about this implementation:
|
While spin waiting will produce the most accurate syncing, it's also very CPU intensive (briefly peaking a single core of an i3-330M), and most of the time it's not really needed anyway. Using a timeout of 1ms is better. Ideally there will be a signaling mechanism between the 2 stream, instead of each stream polling eachother, but I'm keeping this simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change alone dropped the peak CPU usage on an i3-330m from 25% to 10%, a 2.5x reduction!
Avoiding `BigInt` if possible is always good
Can confirm that several movie files are in sync after this update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Should we make this a separate issue? To remove the sleeping in AudioStream & VideoStream Or should we just do it in the PR since it fixes what the initial issue was with using |
It can be a separate issue, since it doesn't hurt to have the sleeping in here. Anyway, please wait a few days before merging. I'm waiting for a new build of libav.js which would have Yahweasel/libav.js@13cafce included in there, and remove the EDIT: Expect Sunday or Monday Yahweasel/libav.js#66 (comment) |
Seems to be comitted? |
Waiting for release, which would be 1-2 days from now |
859d396
to
5172dbe
Compare
Ready to merge! As for the follow-up changes, I'll do them in a separate PR. |
Tracking PR, there will be more changes as I continue working on this.
I've chosen to use
libav.js
as a demuxer only, so no audio decoding (as much as I'd like to have AAC decoding, there's no prebuilt up-to-date package for it, and we'd still need an external ffmpeg for hardware video encoding anyway).Checklist:
raw audioOpus in a single stream)VideoStream
andAudioStream
to use this new streamTesting