How to avoid a growing delay with ffmpeg between sound and raw video data ?

老子叫甜甜 提交于 2019-12-10 18:48:37

问题


Hello everybody and thank you for reading !

Here is my problem : I have a program piping raw video frames to the standard output. This program is using OpenCV to capture and process the video and outputs directly the processed frames. The loop is synced to the framerate I chose. I'm using ffmpeg to read from the standard input and everything works fine for the video. But now that I added the sound I have a big problem : a growing delay is occuring and I really need to get rid of it. So here is my idea, but I really need your help :

I have to find a way to include a timestamp information to the raw video. To be understandable by ffmpeg, it needs to be a known raw video compatible container. And then I will need to use the container API and pipe it to the standard output in my program. I really do not know what to use in the jungle of video formats and codecs, and I don't event know how to enable timestamp synchronizing in ffmpeg...

If anyone has an idea, i am really interested here. For information, here is the command line i use to pipe the raw video :

./myprogram | ffmpeg -y -f alsa -i pulse -ac 2  -f rawvideo -vcodec rawvideo -r 24 -s 640x480 -pix_fmt bgr24 -i - -vcodec libx264 -pix_fmt yuv420p -r 24 -f flv -ar 44100 out.flv;

Thand you very much,

Roland


回答1:


The delay between video and audio is an old problem in the multimedia space. There is no silver bullet to solve it, but you may try to use different codecs (especially newer ones, and not from microsoft). You may find lower delays, and, for decent video lengths (1 hour), nothing bothersome.




回答2:


The easy way out is to process the audio & video files in segments, say cut 30mins of video and audio. Since streams are desync, you can control the it with ffmpeg, see guide here or here, the nice thing is you don't need two files (streams) as ffmpeg can work with source from the SAME file.

Once you have figured out the delay, repeat for the next segment and so on.

Sometimes the audio may be longer than 30 mins, say 33mins. Then I'd use 'Audacity' to squeeze the length back to 30mins before merging.



来源:https://stackoverflow.com/questions/8106846/how-to-avoid-a-growing-delay-with-ffmpeg-between-sound-and-raw-video-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!