MCPcopy Create free account
hub / github.com/FFMS/ffms2 / MaybeReorderFrames

Method MaybeReorderFrames

src/core/track.cpp:213–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213void FFMS_Track::MaybeReorderFrames() {
214 frame_vec &Frames = Data->Frames;
215 // First check if we need to do anything
216 bool has_b_frames = false;
217 for (size_t i = 1; i < size(); ++i) {
218 // If the timestamps are already out of order, then they actually are
219 // presentation timestamps and we don't need to do anything
220 if (Frames[i].PTS < Frames[i - 1].PTS)
221 return;
222
223 if (Frames[i].FrameType == AV_PICTURE_TYPE_B) {
224 has_b_frames = true;
225
226 // Reordering files with multiple b-frames is currently not
227 // supported
228 if (Frames[i - 1].FrameType == AV_PICTURE_TYPE_B)
229 return;
230 }
231 }
232
233 // Don't need to do anything if there are no b-frames as presentation order
234 // equals decoding order
235 if (!has_b_frames)
236 return;
237
238 // We have b-frames, but the timestamps are monotonically increasing. This
239 // means that the timestamps we have are decoding timestamps, and we want
240 // presentation time stamps. Convert DTS to PTS by swapping the timestamp
241 // of each b-frame with the frame before it. This only works for the
242 // specific case of b-frames which reference the frame immediately after
243 // them temporally, but that happens to cover the only files I've seen
244 // with b-frames and no presentation timestamps.
245 for (size_t i = 1; i < size(); ++i) {
246 if (Frames[i].FrameType == AV_PICTURE_TYPE_B)
247 std::swap(Frames[i].PTS, Frames[i - 1].PTS);
248 }
249}
250
251void FFMS_Track::RevertToDTS() {
252 frame_vec &Frames = Data->Frames;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected