Repository navigation
Fix --field interlaced encoding: frame skipping/hang (#981), pic_struct and bff field order (#982) - #987
Merged
kirithika7 merged 3 commits intoOct 8, 2026
Conversation
Akilan-Sivakumar
force-pushed
the
fix-issue-981-982-field-interlace
branch
from
October 7, 2026 08:50
88737a1 to
6d3fd07
Compare
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.
Summary
--interlace tff|bff --fieldwas unusable from the CLI. It skipped every other input frame and never exited (#981). It also signalled every field with frame-onlypic_structvalues and encoded bff sources with the top field first (#982). This PR fixes all three problems in three separate commits:Issues and root cause
#981: every other frame skipped, CLI hangs
In
--fieldmode each input frame is split into two fields, andencoder_encodeis called once per field. The input queue countersm_picIdxReadCntandm_picReadCntwere incremented inside that same per-field loop, so they advanced twice per input frame.The CLI input queue has a single slot. The Reader took the first increment to mean "slot free" and loaded the next frame, then overwrote it with the following frame after the second increment. So every other frame was dropped: woven output frame i matched source frame 2i.
The counters then ended up out of step, and the process hung in one of two ways, depending on thread timing:
readPicture. The Reader stops at the frame limit without settingm_inputOver.readPicturereported end of input early. The encoder flushed a partial stream (the "26 fields" in the issue).AbrEncoder::destroythen blocked inpthread_cond_destroyonm_picIdxReadCntwhile the Reader was still waiting on it. This was confirmed with gdb.#982 part 1: wrong
pic_structThe SPS sets
field_seq_flag = 1, meaning every picture is a field. The--fieldbranch, however, wrotepic_struct3/4 ("top/bottom field, in that order"), which H.265 Table D.2 only allows for frames (field_seq_flag = 0). Decoders could not determine field parity.#982 part 2: bff fields in the wrong order
The CLI field split always filled the first field from row 0 (the top field), whatever the
--interlacemode. With bff, the first field is signalled as bottom but held the top rows. Decoders swapped the lines of every frame, and the fields were coded in the wrong temporal order.Fix
CLI --field mode skips every other input frame and hangs before the end of the input #981: release the input slot once per frame, after the last field:
--field: pic_struct 3/4 signalled with field_seq_flag=1, and bff fields mislabelled #982 part 1: signal
pic_struct1 (top) or 2 (bottom) from the field number. For tff the first field is top; for bff it's bottom. This matches what the existing--no-fieldinterlaced path already writes.--field: pic_struct 3/4 signalled with field_seq_flag=1, and bff fields mislabelled #982 part 2: for bff, start the first field at row 1 (odd rows = bottom field) and the second at row 0. The change applies to every plane. tff is unchanged.
Progressive encoding and the
--no-fieldinterlaced path are not affected.Testing and results
Compared against
origin/master(f2cf32d).--bframes 0,--frame-threads 1 --no-wpp, raw YUV)pic_structwith--field--fieldvs ffmpeg-split--no-fieldreference--no-fieldinterlaced--fieldtff/bff bit-identical to the referenceFixes #981
Fixes #982