[FFmpeg-user] ffmpeg latency and lag combining audio and video on Raspberry Pi

Neik neik at rikai.com
Fri Jun 12 14:32:19 CEST 2015


I am trying to stream combined audio and video from a Raspberry Pi.

To capture video alone I use:

raspivid -o - -t 0 -n -w 1280 -h 720 -fps 25 | ffmpeg -thread_queue_size 
1024 -y -f h264 -framerate 25 -i - -vcodec copy -f mpegts 
udp://44.0.0.95:1234

It takes 6 seconds for the streaming status line to appear. The video 
then lags reality by about 2.3 seconds

Why does this delay occur? How can I reduce it to zero?

To combine video and audio I use:

raspivid -o - -t 0 -n -w 1280 -h 720 -fps 25 | ffmpeg -thread_queue_size 
1024 -y -f h264 -framerate 25 -i - -thread_queue_size 512 -f alsa -ac 1 
-i hw:1 -vcodec copy -acodec mp3 -f mpegts udp://44.0.0.95:1234

The output is

***
Input #0, h264, from 'pipe:':
   Duration: N/A, bitrate: N/A
     Stream #0:0: Video: h264 (High), yuv420p, 1280x720, 25 fps, 25 tbr, 
1200k tbn, 50 tbc
Guessed Channel Layout for  Input Stream #1.0 : mono
Input #1, alsa, from 'hw:1':
   Duration: N/A, start: 1434111331.928930, bitrate: 768 kb/s
     Stream #1:0: Audio: pcm_s16le, 48000 Hz, 1 channels, s16, 768 kb/s
Output #0, mpegts, to 'udp://44.0.0.95:1234':
   Metadata:
     encoder         : Lavf56.36.100
     Stream #0:0: Video: h264, yuv420p, 1280x720, q=2-31, 25 fps, 25 tbr, 
90k tbn, 25 tbc
*** IT TAKES 5.5 seconds to get to the line above, where it then pauses 
for another 6.2 seconds before printing the following
     Stream #0:1: Audio: mp3 (libmp3lame), 48000 Hz, mono, s16p
     Metadata:
       encoder         : Lavc56.41.100 libmp3lame
Stream mapping:
   Stream #0:0 -> #0:0 (copy)
   Stream #1:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
frame=  678 fps= 25 q=-1.0 Lsize=   23528kB time=00:00:27.21 
bitrate=7081.5kbits/s
video:21531kB audio:213kB subtitle:0kB other streams:0kB global 
headers:0kB muxing overhead: 8.205520%
***

The resulting stream has the audio delayed by about 2 seconds and the 
video by a total of 10.4 seconds.

I feel I must be able to improve on this!

I am collecting and viewing the stream using VLC under windows. Using 
ffplay yields similar results.

The load on the RPi is about 25% of one core.





More information about the ffmpeg-user mailing list