Convert Frame Number into Video PTS
| 2604 | |
| 2605 | // Convert Frame Number into Video PTS |
| 2606 | int64_t FFmpegReader::ConvertFrameToAudioPTS(int64_t frame_number) { |
| 2607 | const double fps_value = (info.fps.num > 0 && info.fps.den > 0) ? info.fps.ToDouble() : 30.0; |
| 2608 | const double audio_timebase_value = |
| 2609 | (info.audio_timebase.num > 0 && info.audio_timebase.den > 0) |
| 2610 | ? info.audio_timebase.ToDouble() |
| 2611 | : (1.0 / 48000.0); |
| 2612 | |
| 2613 | // Get timestamp of this frame (in seconds) |
| 2614 | double seconds = (double(frame_number - 1) / fps_value) + pts_offset_seconds; |
| 2615 | |
| 2616 | // Calculate the # of audio packets in this timestamp |
| 2617 | int64_t audio_pts = round(seconds / audio_timebase_value); |
| 2618 | |
| 2619 | // Apply PTS offset (opposite) |
| 2620 | return audio_pts; |
| 2621 | } |
| 2622 | |
| 2623 | // Calculate Starting video frame and sample # for an audio PTS |
| 2624 | AudioLocation FFmpegReader::GetAudioPTSLocation(int64_t pts) { |