#9089 closed defect (fixed)

Modify the system time, resulting in unable to save screen recording

Reported by: HouLei Owned by:
Priority: normal Component: avdevice
Version: git-master Keywords: x11grab
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

  1. Linux X11 system execution instruction: ffmpeg - F x11grab - fragment 25 - video_ size 1920*1080 -i :0.0 out.mp4
  1. Modify Linux system time
  1. Stop screen recording

Problem: unable to save screen recording file

Analysis: screen recording relies on the system time for audio and video synchronization, and adjusting the time will affect the synchronization operation.

Change History (6)

comment:1 by Carl Eugen Hoyos, 12 months ago

Component: ffmpegundetermined
Keywords: system time ffmpeg removed
Priority: importantnormal

If you want to report a bug that should be fixed in the FFmpeg codebase please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output.

comment:2 by Marton Balint, 12 months ago

Why is x11grab using av_gettime() instead of av_gettime_relative()? Because that seems to be the main issue here.

in reply to:  1 comment:3 by HouLei, 11 months ago

Replying to cehoyos:

If you want to report a bug that should be fixed in the FFmpeg codebase please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output.

commit 029e3c1c70b31ede9f17dda4b3a4fc8e35cada70 (HEAD -> master, origin/master, origin/HEAD)

houlei@houlei-PC:~/project/ffmpeg-source/ffmpeg-test$ ffmpeg -f x11grab -framerate 25 -video_size 1920*1080 -i :0.0 out.mp4
ffmpeg version N-101185-g029e3c1c70 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 8 (Uos 8.3.0.5-1+dde)
  configuration: 
  libavutil      56. 65.100 / 56. 65.100
  libavcodec     58.124.100 / 58.124.100
  libavformat    58. 67.100 / 58. 67.100
  libavdevice    58. 12.100 / 58. 12.100
  libavfilter     7.107.100 /  7.107.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
[x11grab @ 0x3aac380] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0':
  Duration: N/A, start: 1613791133.078335, bitrate: 1658880 kb/s
  Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 1658880 kb/s, 25 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf58.67.100
  Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(tv, progressive), 1920x1080, q=2-31, 200 kb/s, 25 fps, 12800 tbn
    Metadata:
      encoder         : Lavc58.124.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame=  301 fps= 25 q=24.8 size=    1536kB time=00:00:12.00 bitrate=1048.6kbits/s speed=   1x   

When using ffmpeg to record screen, set the operating system time and set the system time backward. Stop screen recording, unable to save video.

static int64_t wait_frame(AVFormatContext *s, AVPacket *pkt)
{
    XCBGrabContext *c = s->priv_data;
    int64_t curtime, delay;

    c->time_frame += c->frame_duration;

    for (;;) {
        curtime = av_gettime();
        delay   = c->time_frame - curtime;
        if (delay <= 0)
            break;
        av_usleep(delay);   
//Here is the reason for the problem: because the user changes the operating system time, the delay time is too long, so the screen recording cannot be stopped.
    }

    return curtime;
}
Last edited 11 months ago by Carl Eugen Hoyos (previous) (diff)

in reply to:  2 comment:4 by HouLei, 11 months ago

Replying to cus:

Why is x11grab using av_gettime() instead of av_gettime_relative()? Because that seems to be the main issue here.

The cause of the problem has been found, just like cehoyos' reply.

comment:5 by HouLei, 11 months ago

Status: newopen

comment:6 by Carl Eugen Hoyos, 11 months ago

Component: undeterminedavdevice
Keywords: x11grab added
Resolution: fixed
Status: openclosed

Maybe fixed by Marton in 2d32aed85c4874a2596202b6f0c08e6ce49e3bca

Note: See TracTickets for help on using tickets.