Convert Frame Number into Video PTS
| 2586 | |
| 2587 | // Convert Frame Number into Video PTS |
| 2588 | int64_t FFmpegReader::ConvertFrameToVideoPTS(int64_t frame_number) { |
| 2589 | const double fps_value = (info.fps.num > 0 && info.fps.den > 0) ? info.fps.ToDouble() : 30.0; |
| 2590 | const double video_timebase_value = |
| 2591 | (info.video_timebase.num > 0 && info.video_timebase.den > 0) |
| 2592 | ? info.video_timebase.ToDouble() |
| 2593 | : (1.0 / 30.0); |
| 2594 | |
| 2595 | // Get timestamp of this frame (in seconds) |
| 2596 | double seconds = (double(frame_number - 1) / fps_value) + pts_offset_seconds; |
| 2597 | |
| 2598 | // Calculate the # of video packets in this timestamp |
| 2599 | int64_t video_pts = round(seconds / video_timebase_value); |
| 2600 | |
| 2601 | // Apply PTS offset (opposite) |
| 2602 | return video_pts; |
| 2603 | } |
| 2604 | |
| 2605 | // Convert Frame Number into Video PTS |
| 2606 | int64_t FFmpegReader::ConvertFrameToAudioPTS(int64_t frame_number) { |