[FFmpeg-user] ffmpeg slowly get out of sync

Luo Xin luoxin123 at sina.com
Wed Nov 16 13:59:44 EET 2016


I am working on an project like live video, which uses ffmpeg to:
- capture video from v4l2 device
- capture audio from alsa device
- output hls segments

The command line and output is:
ffmpeg -thread_queue_size 64 -f alsa -ar 48000 -i hw:3 -f v4l2 -r 25 -s 
720x576 -i /dev/video2 -preset fast -vcodec h264 -b:v 1500k -b:a 64k 
-x264-params keyint=75:no-scenecut=1 -threads 4 -acodec aac -f hls 
/opt/encoder/hls/102.m3u8
ffmpeg version n3.1.3-1-gea9ca2f Copyright (c) 2000-2016 the FFmpeg 
developers
   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
   configuration: --enable-gpl --enable-libx264 --prefix=/opt/encoder
   libavutil      55. 28.100 / 55. 28.100
   libavcodec     57. 48.101 / 57. 48.101
   libavformat    57. 41.100 / 57. 41.100
   libavdevice    57.  0.101 / 57.  0.101
   libavfilter     6. 47.100 /  6. 47.100
   libswscale      4.  1.100 /  4.  1.100
   libswresample   2.  1.100 /  2.  1.100
   libpostproc    54.  0.100 / 54.  0.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:3':
   Duration: N/A, start: 1479202954.916662, bitrate: 1536 kb/s
     Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[alsa @ 0x2e55840] Thread message queue blocking; consider raising the 
thread_queue_size option (current value: 64)
[video4linux2,v4l2 @ 0x34b3300] The driver does not permit changing the 
time per frame
Input #1, video4linux2,v4l2, from '/dev/video2':
   Duration: N/A, start: 31.451263, bitrate: 165888 kb/s
     Stream #1:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 720x576, 
165888 kb/s, 25 fps, 25 tbr, 1000k tbn, 1000k tbc
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x34b6dc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 
AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0x34b6dc0] profile High 4:2:2, level 3.0, 4:2:2 8-bit
[hls @ 0x34b5100] Using AVStream.codec to pass codec parameters to 
muxers is deprecated, use AVStream.codecpar instead.
     Last message repeated 1 times
Output #0, hls, to '/opt/encoder/hls/102.m3u8':
   Metadata:
     encoder         : Lavf57.41.100
     Stream #0:0: Video: h264 (libx264), yuv422p, 720x576, q=-1--1, 1500 
kb/s, 25 fps, 90k tbn, 25 tbc
     Metadata:
       encoder         : Lavc57.48.101 libx264
     Side data:
       cpb: bitrate max/min/avg: 0/0/1500000 buffer size: 0 vbv_delay: -1
     Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 64 kb/s
     Metadata:
       encoder         : Lavc57.48.101 aac
Stream mapping:
   Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
   Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[alsa @ 0x349d7c0] Thread message queue blocking; consider raising the 
thread_queue_size option (current value: 64)

it works fine at the beginning, but it get out of sync slowly, after 5 
hour, it for sure get out of sync, and after 15 hours, the video is 
ahead of video for 2 second.

I have tried several ways try to fix it, include:
- adding -vsync 1
- adding -async 1,
- -vf "setpts=xxxx" (wrong)
Yes, I also try to use -async 25 or very large number, but I almost get 
the same result (I didn't wait for 5 hour), I also made some test on 
changing pts in code, it gives me the feel that ffmpeg can handle most 
of fail/error case, and I am in wrong way.
So I comes there ask for expert's help:
1. does "-async num" is the flexible way to fix time stamp drift?
2. how could I narrow down the reason for out of sync?
3. some updated materials I can read to dig more information?

Thanks.

Best regards,
Xin Luo



More information about the ffmpeg-user mailing list