36 Data(
const LoopOffset &offset, AVFrameUPtr f,
const CodecContext &codecContext,
37 const PlaybackEngineObjectID &sourceID)
44 if (frame->pts != AV_NOPTS_VALUE)
45 startTime = codecContext.toTrackPosition(AVStreamPosition(frame->pts));
47 startTime = codecContext.toTrackPosition(
48 AVStreamPosition(frame->best_effort_timestamp));
50 if (
auto frameDuration = getAVFrameDuration(*frame)) {
51 duration = codecContext.toTrackDuration(AVStreamDuration(frameDuration));
54 if (codecContext.context()->codec_type == AVMEDIA_TYPE_AUDIO) {
55 if (frame->sample_rate)
56 duration = TrackDuration(qint64(1000000) * frame->nb_samples
57 / frame->sample_rate);
59 duration = TrackDuration(0);
62 const auto &avgFrameRate = codecContext.stream()->avg_frame_rate;
63 duration = TrackDuration(
64 mul(qint64(1000000), { avgFrameRate.den, avgFrameRate.num })