- destination->setFrame(stream_idx, next_pts);
-
- if (video_stream != nullptr) {
- // Send the frame to the stream.
- // FIXME: Vaguely less crazy pts, perhaps.
- double pts_float = fmod(duration<double>(next_frame_start.time_since_epoch()).count(), 86400.0f);
- int64_t pts = lrint(pts_float * TIMEBASE);
- video_stream->schedule_original_frame(pts, stream_idx, next_pts);
-
- // HACK: test interpolation by frame-doubling.
- int64_t next_next_pts = -1;
- {
- lock_guard<mutex> lock(frame_mu);
- auto it = upper_bound(frames[stream_idx].begin(),
- frames[stream_idx].end(),
- next_pts);
- if (it == frames[stream_idx].end() || *it >= clip.pts_out) {
- break;
- }
- next_next_pts = *it;
+ if (in_pts_lower == in_pts_upper) {
+ destination->setFrame(stream_idx, in_pts_lower, /*interpolated=*/false);
+ if (video_stream != nullptr) {
+ video_stream->schedule_original_frame(lrint(out_pts), stream_idx, in_pts_lower);
+ }
+ continue;
+ }
+
+ // Snap to input frame: If we can do so with less than 1% jitter
+ // (ie., move less than 1% of an _output_ frame), do so.
+ double in_pts_lower_as_frameno = (in_pts_lower - in_pts_origin) * output_framerate / TIMEBASE / speed;
+ double in_pts_upper_as_frameno = (in_pts_upper - in_pts_origin) * output_framerate / TIMEBASE / speed;
+ if (fabs(in_pts_lower_as_frameno - frameno) < 0.01) {
+ destination->setFrame(stream_idx, in_pts_lower, /*interpolated=*/false);
+ if (video_stream != nullptr) {
+ video_stream->schedule_original_frame(lrint(out_pts), stream_idx, in_pts_lower);