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

Method find_intersecting_clips

src/Timeline.cpp:1138–1185  ·  view source on GitHub ↗

Find intersecting clips (or non intersecting clips)

Source from the content-addressed store, hash-verified

1136
1137// Find intersecting clips (or non intersecting clips)
1138std::vector<Clip*> Timeline::find_intersecting_clips(int64_t requested_frame, int number_of_frames, bool include)
1139{
1140 // Find matching clips
1141 std::vector<Clip*> matching_clips;
1142
1143 // Calculate time of frame
1144 const int64_t min_requested_frame = requested_frame;
1145 const int64_t max_requested_frame = requested_frame + (number_of_frames - 1);
1146
1147 // Find Clips at this time
1148 matching_clips.reserve(clips.size());
1149 const double fpsD = info.fps.ToDouble();
1150 for (auto clip : clips)
1151 {
1152 // Does clip intersect the current requested time
1153 int64_t clip_start_position = static_cast<int64_t>(std::llround(clip->Position() * fpsD)) + 1;
1154 int64_t clip_end_position = static_cast<int64_t>(std::llround((clip->Position() + clip->Duration()) * fpsD)) + 1;
1155
1156 bool does_clip_intersect =
1157 (clip_start_position <= min_requested_frame || clip_start_position <= max_requested_frame) &&
1158 (clip_end_position >= min_requested_frame || clip_end_position >= max_requested_frame);
1159
1160 // Debug output
1161 ZmqLogger::Instance()->AppendDebugMethod(
1162 "Timeline::find_intersecting_clips (Is clip near or intersecting)",
1163 "requested_frame", requested_frame,
1164 "min_requested_frame", min_requested_frame,
1165 "max_requested_frame", max_requested_frame,
1166 "clip->Position()", clip->Position(),
1167 "does_clip_intersect", does_clip_intersect);
1168
1169 // Open (or schedule for closing) this clip, based on if it's intersecting or not
1170 update_open_clips(clip, does_clip_intersect);
1171
1172 // Clip is visible
1173 if (does_clip_intersect && include)
1174 // Add the intersecting clip
1175 matching_clips.push_back(clip);
1176
1177 else if (!does_clip_intersect && !include)
1178 // Add the non-intersecting clip
1179 matching_clips.push_back(clip);
1180
1181 } // end clip loop
1182
1183 // return list
1184 return matching_clips;
1185}
1186
1187// Set the cache object used by this reader
1188void Timeline::SetCache(CacheBase* new_cache) {

Callers

nothing calls this directly

Calls 4

ToDoubleMethod · 0.80
DurationMethod · 0.80
AppendDebugMethodMethod · 0.80
PositionMethod · 0.45

Tested by

no test coverage detected