S
S
sstotenkopf2017-03-06 22:16:53
fmpeg
sstotenkopf, 2017-03-06 22:16:53

How to sync audio and video for streaming with ffmpeg?

Hello, I have a task to stream video through ffmpeg, for this task I used raspberry pi zero with raspbian OS and a program that allows you to get video from the native raspivid camera, in general, I managed to stream video in this way:

sudo raspivid -n -vf -hf -ex auto -w 1024 -h 768 -fps 25 -t 0 -b 2000000 -o - | 
ffmpeg -y -f h264 -i - -vcodec copy -f flv rtmp://myip/myapp/mystream

But you need to send a stream with sound, I tried to use alsa in ffmpeg, but too much cpu is consumed and a warning alsa buffer xrun occurs. Solved the problem using arecord:
raspivid -t 0 -w 1024 -h 768 -fps 25 -vf -hf -b 1000000 -v -o temp.v & 
arecord -f cd -D plughw:0 | 
ffmpeg -i temp.v -itsoffset 13.5 -i - -c:v copy -c:a libmp3lame -b:a 64k -f flv rtmp://myip/myapp/mystream
Using the method of scientific poke, I picked up the parameter itsoffset, sound and video go synchronously. But if the Internet speed sags (3g modem), the stream disappears for a while, then the sound and video are completely out of sync and then go asynchronously. Unfortunately, I have no experience with ffmpeg and I don’t know how to fix it, I tried to solve it by choosing async and vsync parameters, it didn’t help. How can this problem be solved? Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question