MCPcopy
hub / github.com/midrender/revideo / getNextFrame

Method getNextFrame

packages/2d/src/lib/utils/video/parser/parser.ts:124–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122 }
123
124 public async getNextFrame() {
125 // Start the first segment
126 if (!this.sampler) {
127 // Skip segments until the start time
128 let startTimeWithinSegment = this.startTime;
129 while (this.nextSegment < this.edits.length) {
130 const segmentDurationInSeconds = this.getSecondDurationOfSegment(
131 this.edits[this.nextSegment],
132 );
133 if (startTimeWithinSegment < segmentDurationInSeconds) {
134 break;
135 }
136
137 startTimeWithinSegment -= segmentDurationInSeconds;
138 this.nextSegment++;
139 }
140
141 // The timestamp is outside of the video
142 if (this.nextSegment >= this.edits.length) {
143 throw new Error(
144 `Timestamp ${this.startTime} is outside of the video, max timestamp is ${this.getDuration()}`,
145 );
146 }
147
148 const segment = new Segment(
149 this.uri,
150 this.file,
151 this.edits,
152 this.nextSegment,
153 startTimeWithinSegment,
154 );
155 await segment.start(this.decoderConfig!);
156
157 this.sampler = new FrameSampler(
158 segment,
159 this.edits[this.nextSegment].fps,
160 this.targetFps,
161 0,
162 );
163 this.nextSegment++;
164 }
165
166 // Try to get the next frame
167 let frame = await this.sampler.getNextFrame();
168
169 // If there are no more frames in the current segment, start the next segment
170 while (!frame && this.nextSegment < this.edits.length) {
171 this.sampler.getSegment().close();
172 this.sampler.getLastFrame()?.close();
173 const segment = new Segment(
174 this.uri,
175 this.file,
176 this.edits,
177 this.nextSegment,
178 0,
179 );
180 await segment.start(this.decoderConfig!);
181

Callers

nothing calls this directly

Calls 7

getDurationMethod · 0.95
startMethod · 0.95
getSegmentMethod · 0.80
getSumMethod · 0.80
closeMethod · 0.45
getLastFrameMethod · 0.45

Tested by

no test coverage detected