Repository navigation
Add transform_mp4_cut to build the upload of a part of a video - #985
Merged
Merged
Conversation
transform_mp4_cut() is transform_mp4() for a part of a video. It keeps the samples from the last sync sample presented by the start of the part to the first sync sample from which every frame is presented after its end, so every frame of the part decodes, nothing is encoded again, and the source is read for those samples only. The leading frames of an open GOP are decoded after its sync sample but presented before it, so the cut runs on past a sync sample whose leading frames are presented by the end. The part starts at time 0 of the new video: the sample generator is made for the decoding time of the start of the cut, which is the time of the frames in the new video, so the CAMM samples it adds are timed on them. The creation time of the new video is moved to the start of the cut, in whole seconds. In an open GOP, the frames decoded after the first sync sample but presented before it reference the GOP before, which is not kept, so they are left out. Other video tracks, such as the second lens of a 360 camera, are cut at the same time, or MP4CutError is raised; each ends at a sync sample of its own. The duration of each track and its single edit span the frames it presents, from the earliest to the end of the latest. MP4CutError is also raised for a part where a video track presents no frame, or with no time (NaN). MP4Header holds the ftyp and moov boxes, read once for all the parts of a video. Nothing calls it yet: uploading a video in parts comes in a follow-up.
caglarpir
force-pushed
the
cut-video-at-sync-samples
branch
from
December 1, 2026 15:32
a25dbb5 to
9ad2bc8
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.
transform_mp4_cut()builds whattransform_mp4()builds, for a part of a video. It is for uploading a video whose GPS track has gaps as one sequence per part (#988).MP4CutErroris raised. Each ends at a sync sample of its own, andMP4Cut.endis the end of the one that runs the longest.MP4CutErroris raised for a part where a video track presents no frame, or with no time (NaN).MP4Headerholds the ftyp and moov boxes, read once for all the parts of a video.Checked on H.264 with B-frames, HEVC with negative composition offsets, open-GOP HEVC and H.264, all-intra and single-GOP H.264, stream-copy cuts, two video tracks, a 261 s phone video and a 3.2 GB dual-lens 360 video:
mmco: unref short failure, but its frames still decode bit-exact.