Open
Conversation
It turned out that some h.264 streams are hard to segment. Instead of having periodic IDR frames, they only contain very first IDR frame, and just I frames after that. Technically, some of these I frames are equivalent of IDR ones (after them there are no inter predictions to previous frames), but aren't coded as such. Unfortunately, h.264 standard says that every compliant stream should start with IDR frame. And thus, some software (including ffmpeg used by LPMS, as well as ffplay) refuse to decode or play back streams that our segmenter produces. This in turn leads to dreaded "ZeroSegments" errors. Code in this commit is an attempt to fix this problem. It works as follows: - Fresh h264Fixer object should be created for each new segment - NALs from segment should be fed into said object via its process_nal() method - If the first Intra-coded frame of the segment is an I frame, it will get converted to the IDR frame. Then all following reference rames will have their frame_num fields changed accordingly - On detecting IDR frame Fixer will go into bypass mode, not changing anything on the stream. Therefore, it is safe to use Fixer with any stream - most of the time it will detect that the stream starts with the IDR frame and just do nothing Notes: - Please take care to call process_nal() properly, that is with at least four extra bytes in front of NAL in the supplied buffer This is because sometimes slice header will "grow" due to the changes that Fixer makes, and we want to avoid copying huge Intra-coded slices - This is not done yet, but Fixer can be easily modified to perform some additional tasks, such as making sure no extra copies of SPS/PPS are issued. To that effect, code should not write SPS/PPS immediately, but only after slice requesting particular SPS/PPS pair is observed. Then that particular SPS/PPS should be marked as "present" in the stream and not written anymore
MikeIndiaAlpha
commented
Sep 7, 2022
| for (size_t i = 0; i < numRefFramesInPicOrderCntCycle; i++){ | ||
| bs.getExpGolomb(); // offset_for_ref_frame[i] | ||
| } | ||
| return; |
Author
There was a problem hiding this comment.
I am an idiot - this "return" should get removed. Obviously, it was there with the WARN_MSG. I accidentally removed this file during formatting and had to recreate changes from older backup. Forgot about this one :-(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is long(ish) comment written in the commit itself, but a few extra things:
IMPORTANT:
This code has no effect yet (apart from some extra fields parsed out of h.264 streams). Fixer needs to be called after segmentation, and this is not done yet. We agreed that somebody from the Mist team will take care of this.
EXAMPLE (this is using tools for parsing raw h.264 stream, actual Mist code will have NALs stripped out of 0,0,1 sequences already: