You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
x11grab: fixed next frame capture time calculation
The next frame time could slip, causing the frame rate to drop until frames were dropped. Now will capture at the next correct moment instead. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
committed by
Michael Niedermayer
parent
1bbfaba196
commit
6632802aa0
@@ -526,16 +526,11 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
int64_t curtime, delay;
|
int64_t curtime, delay;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|
||||||
/* Calculate the time of the next frame */
|
|
||||||
s->time_frame += INT64_C(1000000);
|
|
||||||
|
|
||||||
/* wait based on the frame rate */
|
/* wait based on the frame rate */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
curtime = av_gettime();
|
curtime = av_gettime();
|
||||||
delay = s->time_frame * av_q2d(s->time_base) - curtime;
|
delay = s->time_frame * av_q2d(s->time_base) - curtime;
|
||||||
if (delay <= 0) {
|
if (delay <= 0) {
|
||||||
if (delay < INT64_C(-1000000) * av_q2d(s->time_base))
|
|
||||||
s->time_frame += INT64_C(1000000);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ts.tv_sec = delay / 1000000;
|
ts.tv_sec = delay / 1000000;
|
||||||
@@ -543,6 +538,11 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
nanosleep(&ts, NULL);
|
nanosleep(&ts, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calculate the time of the next frame */
|
||||||
|
do {
|
||||||
|
s->time_frame += INT64_C(1000000);
|
||||||
|
} while ((s->time_frame * av_q2d(s->time_base) - curtime) <= 0);
|
||||||
|
|
||||||
av_init_packet(pkt);
|
av_init_packet(pkt);
|
||||||
pkt->data = image->data;
|
pkt->data = image->data;
|
||||||
pkt->size = s->frame_size;
|
pkt->size = s->frame_size;
|
||||||
|
Reference in New Issue
Block a user