i'm looking for a solution, either in linux or in windows, that allows me to
- record video (+audio) from my webcam & microphone, simultaneously.
- save it as a file.AVI (or mpg or whatever)
- display the video on the screen while recording it
Compression is NOT an issue in my case, and i actually prefer to capture RAW and compress it later.
So far i've done it with an ActiveX component in VB which took care of everything, and i'd like to progress with python (the VB solution is unstable, unreliable).
so far i've seen code that captures VIDEO only, or individual frames…
I've looked so far at
- OpenCV – couldn't find audio capture there
- PyGame – no simultaneous audio capture (AFAIK)
- VideoCapture – provide only single frames.
- SimpleCV – no audio
- VLC – binding to VideoLAN program into wxPthon – hopefully it will do (still investigating this option)
- kivy – just heard about it, didn't manage to get it working under windows SO FAR.
The question – is there a video & audio capture library for python?
or – what are the other options if any?
Best Answer
Answer: No. There is no single library/solution in python to do video/audio recording simultaneously. You have to implement both separately and merge the audio and video signal in a smart way to end up with a video/audio file.
I got a solution for the problem you present. My code addresses your three issues:
My solution uses
pyaudio
for audio recording,opencv
for video recording, andffmpeg
for muxing the two signals. To be able to record both simultaneously, I use multithreading. One thread records video, and a second one the audio. I have uploaded my code to github and also have included all the essential parts it here.https://github.com/JRodrigoF/AVrecordeR
Note:
opencv
is not able to control the fps at which the webcamera does the recording. It is only able to specify in the encoding of the file the desired final fps, but the webcamera usually behaves differently according to specifications and light conditions (I found). So the fps have to be controlled at the level of the code.