-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Switch to -f hls instead of -f segment #592
base: master
Are you sure you want to change the base?
Conversation
transcoder/src/keyframes.go
Outdated
// | ||
// Note that this handling was not possible with the -f segment muxer, since if sometimes doesn't care about the | ||
// -segment_times option and outputed segments of 0.2s. With -f segment, we needed to cut at every keyframe. | ||
if fpts < (last_frame+OptimalFragmentDuration) { |
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 might cause issues with the -ss
handling of video items.
We might need to have two lists, one for segments and one for keyframes
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.
Specially if we have keyframes at 0,5,9.8,10. We might end a segment at 10 & start the next at 9.8
With -f hls, segmentation wouldn't work if we tried to cut at every keyframes (with -hls_time 0) if keyframes are too close from one another (for example a file segmented like 0, 0.2, 0.4, 2, 5). To prevent this, we will output segments w/ more than one keyframes in those cases (using -hls_time 5). To be sure our state handling doesn't fail, the Keyframe struct was updated to only store keyframes more than 5 away from the previous one.
Not sure if this is deterministic, I don't know if switching to |
From https://x.com/JeWe37/status/1822774329152508398?s=19 it splits at the next keyframe after hls_time * [the number of segments written so far] -hls_time seems like a no go |
Possible solution I came across while reading up on something related: MP4Box should probably be able to do the required muxing to HLS, with the -bound option and forcing keyframes as you already are. The idea is then that you can make the duration so small that MP4Box will split at every keyframe, because it's desperately trying to trying to fragment more finely than it actually can. Hint from my own experience that took me a good while to figure out: Piping from ffmpeg to MP4Box is not entirely trivial. The only way I've found to do it is to use a named pipe, pipe the output from ffmpeg into that and read from it in MP4Box via
The playlist only gets written at the end, but since you aren't using it and only need correct segments anyway that shouldn't be a concern. Not entirely sure about the latency implications of this approach. |
Scratch MP4Box, this works with ffmpeg too?
Cleanly makes 90 segments. I guess the only problem is that the transmuxed stream may have too many keyframes? I suppose one could use the normal hls_time for it, then figure out the keyframes on which you actually split, and only force those keyframes, using the trick with the small hls_time for the other streams? EDIT: Given you said on twitter:
is the issue being able to not split on keyframes? If so, couldn't you just encode with encoder flags (for me |
Splitting when we re-encode is not a problem since we control both keyframes & segments. The real issue is when we transcode (aka I saw mp4box could be useful (especially w/ #542 in mind) but using another tool means having to decode (maybe even encode) each segment twice. This also means having to maintain two hwaccel handling. |
How can that be a problem then? So long as the muxed(pristine) case matches the transcoded cases all is well? Therefore so long as one can determine in advance how the muxed case will be split, one just needs to make sure the transcoded cases, where we do have full control, are split the same? What is the troublesome constraint? As for MP4Box, yea, I was thinking fmp4 already, but I don't think it really presents much additional value compared to ffmpeg for the application here. I don't see how it would cause any double encoding/deciding, it can just handle the muxing alone, see that example I gave of how to pipe between it and ffmpeg. |
I thought about it again and it could work AS LONG AS we can reliably seek/start transcoding at a specific keyframes. Right now, we seek before the keyframes we are interested in and rely on the
I'll try again later! Thanks for your help on this, I had given up! |
Another step needed for #542