int64_t video_pts_offset = 0, audio_pts_offset = 0;
int64_t next_video_pts = 0, next_audio_pts = 0;
+AVRational prev_video_timebase{0, 0};
+AVRational prev_audio_timebase{0, 0};
+
void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, AudioEncoder *audio_encoder,
int64_t video_pts, AVRational video_timebase,
int64_t audio_pts, AVRational audio_timebase,
FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format)
{
+ // Our splicing wants consistent timebases...
+ if (video_pts >= 0) {
+ if (prev_video_timebase.den == 0) {
+ prev_video_timebase = video_timebase;
+ }
+ video_pts = av_rescale_q(video_pts, video_timebase, prev_video_timebase);
+ video_timebase = prev_video_timebase;
+ }
+ if (audio_pts >= 0) {
+ if (prev_audio_timebase.den == 0) {
+ prev_audio_timebase = audio_timebase;
+ }
+ audio_pts = av_rescale_q(audio_pts, audio_timebase, prev_audio_timebase);
+ audio_timebase = prev_audio_timebase;
+ }
+
if (video_pts >= 0)
video_pts += video_pts_offset;
if (audio_pts >= 0)
ReceivedTimestamps ts;
ts.ts.push_back(steady_clock::now());
- next_video_pts = video_pts + av_rescale_q(1, AVRational{ 1001, 60000 }, video_timebase);
+ //next_video_pts = video_pts + av_rescale_q(1, AVRational{ 1001, 60000 }, video_timebase);
+
+ // I hate Matroska timestamps and their inaccuracy...
+ next_video_pts = video_pts + av_rescale_q(1, AVRational{ 500, 60000 }, video_timebase);
+
video_pts = av_rescale_q(video_pts, video_timebase, AVRational{ 1, TIMEBASE });
int64_t frame_duration = int64_t(TIMEBASE) * video_format.frame_rate_den / video_format.frame_rate_nom;
if (team1 != "nocef") {
} else {
assert(false);
}
- next_audio_pts = audio_pts + av_rescale_q(num_samples / 2, AVRational{ 1, OUTPUT_FREQUENCY }, audio_timebase);
+ //next_audio_pts = audio_pts + av_rescale_q(num_samples / 2, AVRational{ 1, OUTPUT_FREQUENCY }, audio_timebase);
+ // Matroska hack...
+ next_audio_pts = audio_pts + av_rescale_q(num_samples / 4, AVRational{ 1, OUTPUT_FREQUENCY }, audio_timebase);
audio_pts = av_rescale_q(audio_pts, audio_timebase, AVRational{ 1, TIMEBASE });
audio_encoder->encode_audio(float_samples, audio_pts);
}