MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / GetFrame

Method GetFrame

src/ChunkReader.cpp:184–242  ·  view source on GitHub ↗

Get an openshot::Frame object for a specific frame number of this reader.

Source from the content-addressed store, hash-verified

182
183// Get an openshot::Frame object for a specific frame number of this reader.
184std::shared_ptr<Frame> ChunkReader::GetFrame(int64_t requested_frame)
185{
186 // Determine what chunk contains this frame
187 ChunkLocation location = find_chunk_frame(requested_frame);
188
189 // New Chunk (Close the old reader, and open the new one)
190 if (previous_location.number != location.number)
191 {
192 // Determine version of chunk
193 std::string folder_name = "";
194 switch (version)
195 {
196 case THUMBNAIL:
197 folder_name = "thumb";
198 break;
199 case PREVIEW:
200 folder_name = "preview";
201 break;
202 case FINAL:
203 folder_name = "final";
204 break;
205 }
206
207 // Load path of chunk video
208 std::string chunk_video_path = get_chunk_path(location.number, folder_name, ".webm");
209
210 // Close existing reader (if needed)
211 if (local_reader)
212 {
213 // Close and delete old reader
214 local_reader->Close();
215 delete local_reader;
216 }
217
218 try
219 {
220 // Load new FFmpegReader
221 local_reader = new FFmpegReader(chunk_video_path);
222 local_reader->Open(); // open reader
223
224 } catch (const InvalidFile& e)
225 {
226 // Invalid Chunk (possibly it is not found)
227 throw ChunkNotFound(path, requested_frame, location.number, location.frame);
228 }
229
230 // Set the new location
231 previous_location = location;
232 }
233
234 // Get the frame (from the current reader)
235 last_frame = local_reader->GetFrame(location.frame);
236
237 // Update the frame number property
238 last_frame->number = requested_frame;
239
240 // Return the frame
241 return last_frame;

Callers

nothing calls this directly

Calls 3

ChunkNotFoundClass · 0.85
CloseMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected