I'm trying to build a Twitch streaming box to stream from an input device. Link to the project is:


My setup is:

I'm taking an HDMI feed from a Surface book into the HDMI - CSI-2 bridge, and connected the headphone jack of the surface to the USB sound card.

I bring the video in using raspivid and mix in the audio via ALSA and combine it all and stream using FFmpeg.

My problem is the audio and video are out of sync, and seem to drift. The audio is out by about 15-20 seconds at the start, and the video is streaming at a slower speed that the input. The stream starts about 15 seconds out, and seems to play at about three quarters speed, so after a couple of minutes it is half a minute out.

My FFmpeg command is:

raspivid -n -t 0 -w 1280 -h 720 -fps 25 -g 50 -b 250000 -o - | 
  ffmpeg -r 25.37 -thread_queue_size 512 -i - -f alsa -ar 22050 -ac 1 
  -itsoffset 15.0 -thread_queue_size 512 -i hw:1,0 -c:v copy -r 25 
  -vsync 1 -c:a mp3 -f flv <stream key>

I've experimented with -re -use_wallclock_timestamps 1 and other things to try to get a timestamp in the raspivid feed, but all with no luck.

I've also verified the same happens when saving to a file, so its not a Twitch thing.

How can I get the video to stream at the right speed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.