-
- vdelta = (double)(ost->st->pts.val) * s->pts_num / s->pts_den - (ost->sync_ipts - ost->sync_ipts_offset);
- if (vdelta < 100 && vdelta > -100 && ost->sync_ipts_offset) {
- if (vdelta < -AV_DELAY_MAX)
- nb_frames = 2;
- else if (vdelta > AV_DELAY_MAX)
- nb_frames = 0;
- } else {
- ost->sync_ipts_offset -= vdelta;
- if (!ost->sync_ipts_offset)
- ost->sync_ipts_offset = 0.000001; /* one microsecond */
- }
- }
-
-#if defined(AVSYNC_DEBUG)
- {
- static char *action[] = { "drop frame", "copy frame", "dup frame" };
- if (audio_sync && verbose >=0) {
- fprintf(stderr, "Input APTS %12.6f, output APTS %12.6f, ",
- (double) audio_sync->sync_ipts,
- (double) audio_sync->st->pts.val * s->pts_num / s->pts_den);
- fprintf(stderr, "Input VPTS %12.6f, output VPTS %12.6f: %s\n",
- (double) ost->sync_ipts,
- (double) ost->st->pts.val * s->pts_num / s->pts_den,
- action[nb_frames]);
- }
- }
-#endif
+ vdelta = ost->sync_ipts * enc->frame_rate / enc->frame_rate_base - ost->sync_opts;
+ //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
+ if (vdelta < -1.1)
+ nb_frames = 0;
+ else if (vdelta > 1.1)
+ nb_frames = 2;
+//fprintf(stderr, "vdelta:%f, ost->sync_opts:%lld, ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, ost->sync_ipts, nb_frames);
+ if (nb_frames == 0){
+ ++nb_frames_drop;
+ if (verbose>2)
+ fprintf(stderr, "*** drop!\n");
+ }else if (nb_frames == 2) {
+ ++nb_frames_dup;
+ if (verbose>2)
+ fprintf(stderr, "*** dup!\n");
+ }
+ }else
+ ost->sync_opts= lrintf(ost->sync_ipts * enc->frame_rate / enc->frame_rate_base);