Commit 85b9bf56 authored by Marton Balint's avatar Marton Balint

ffplay: simplify video pts calculation

Also use frame->pts instead of a standalone variable
Signed-off-by: 's avatarMarton Balint <cus@passwd.hu>
parent 5dacf7b1
...@@ -1648,7 +1648,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t ...@@ -1648,7 +1648,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
return 0; return 0;
} }
static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial) static int get_video_frame(VideoState *is, AVFrame *frame, AVPacket *pkt, int *serial)
{ {
int got_picture; int got_picture;
...@@ -1679,22 +1679,22 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke ...@@ -1679,22 +1679,22 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke
int ret = 1; int ret = 1;
if (decoder_reorder_pts == -1) { if (decoder_reorder_pts == -1) {
*pts = av_frame_get_best_effort_timestamp(frame); frame->pts = av_frame_get_best_effort_timestamp(frame);
} else if (decoder_reorder_pts) { } else if (decoder_reorder_pts) {
*pts = frame->pkt_pts; frame->pts = frame->pkt_pts;
} else { } else {
*pts = frame->pkt_dts; frame->pts = frame->pkt_dts;
} }
if (*pts == AV_NOPTS_VALUE) { if (frame->pts == AV_NOPTS_VALUE) {
*pts = 0; frame->pts = 0;
} }
if (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) { if (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) {
SDL_LockMutex(is->pictq_mutex); SDL_LockMutex(is->pictq_mutex);
if (is->frame_last_pts != AV_NOPTS_VALUE && *pts) { if (is->frame_last_pts != AV_NOPTS_VALUE && frame->pts) {
double clockdiff = get_video_clock(is) - get_master_clock(is); double clockdiff = get_video_clock(is) - get_master_clock(is);
double dpts = av_q2d(is->video_st->time_base) * *pts; double dpts = av_q2d(is->video_st->time_base) * frame->pts;
double ptsdiff = dpts - is->frame_last_pts; double ptsdiff = dpts - is->frame_last_pts;
if (!isnan(clockdiff) && fabs(clockdiff) < AV_NOSYNC_THRESHOLD && if (!isnan(clockdiff) && fabs(clockdiff) < AV_NOSYNC_THRESHOLD &&
ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD && ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD &&
...@@ -1886,7 +1886,6 @@ static int video_thread(void *arg) ...@@ -1886,7 +1886,6 @@ static int video_thread(void *arg)
AVPacket pkt = { 0 }; AVPacket pkt = { 0 };
VideoState *is = arg; VideoState *is = arg;
AVFrame *frame = av_frame_alloc(); AVFrame *frame = av_frame_alloc();
int64_t pts_int = AV_NOPTS_VALUE, pos = -1;
double pts; double pts;
int ret; int ret;
int serial = 0; int serial = 0;
...@@ -1901,19 +1900,15 @@ static int video_thread(void *arg) ...@@ -1901,19 +1900,15 @@ static int video_thread(void *arg)
#endif #endif
for (;;) { for (;;) {
#if CONFIG_AVFILTER
AVRational tb;
#endif
while (is->paused && !is->videoq.abort_request) while (is->paused && !is->videoq.abort_request)
SDL_Delay(10); SDL_Delay(10);
avcodec_get_frame_defaults(frame); avcodec_get_frame_defaults(frame);
av_free_packet(&pkt); av_free_packet(&pkt);
ret = get_video_frame(is, frame, &pts_int, &pkt, &serial); ret = get_video_frame(is, frame, &pkt, &serial);
if (ret < 0) if (ret < 0)
goto the_end; goto the_end;
if (!ret) if (!ret)
continue; continue;
...@@ -1946,7 +1941,6 @@ static int video_thread(void *arg) ...@@ -1946,7 +1941,6 @@ static int video_thread(void *arg)
last_serial = serial; last_serial = serial;
} }
frame->pts = pts_int;
frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame); frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame);
ret = av_buffersrc_add_frame(filt_in, frame); ret = av_buffersrc_add_frame(filt_in, frame);
if (ret < 0) if (ret < 0)
...@@ -1968,23 +1962,12 @@ static int video_thread(void *arg) ...@@ -1968,23 +1962,12 @@ static int video_thread(void *arg)
if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0) if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0)
is->frame_last_filter_delay = 0; is->frame_last_filter_delay = 0;
pts_int = frame->pts; pts = frame->pts * av_q2d(filt_out->inputs[0]->time_base);
tb = filt_out->inputs[0]->time_base; ret = queue_picture(is, frame, pts, av_frame_get_pkt_pos(frame), serial);
pos = av_frame_get_pkt_pos(frame);
if (av_cmp_q(tb, is->video_st->time_base)) {
av_unused int64_t pts1 = pts_int;
pts_int = av_rescale_q(pts_int, tb, is->video_st->time_base);
av_dlog(NULL, "video_thread(): "
"tb:%d/%d pts:%"PRId64" -> tb:%d/%d pts:%"PRId64"\n",
tb.num, tb.den, pts1,
is->video_st->time_base.num, is->video_st->time_base.den, pts_int);
}
pts = pts_int * av_q2d(is->video_st->time_base);
ret = queue_picture(is, frame, pts, pos, serial);
av_frame_unref(frame); av_frame_unref(frame);
} }
#else #else
pts = pts_int * av_q2d(is->video_st->time_base); pts = frame->pts * av_q2d(is->video_st->time_base);
ret = queue_picture(is, frame, pts, pkt.pos, serial); ret = queue_picture(is, frame, pts, pkt.pos, serial);
av_frame_unref(frame); av_frame_unref(frame);
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment