Recording sound and video on raspi.


3 posts
by pipuppy » Fri Feb 17, 2017 3:02 pm
Hi,

Hopefully this question is in the most suitable section of the forum this time around?

I have a number of raspis (2 and 3's) plus a camera module and came up with the idea of making a sort of camcorder. Since the raspi does not support audio input I would have to add one of the supported USB soundcards for audio capture. The resulting sound/video would then be recorded to the SD card.

Looking at similar projects on the Internet I note that recording both sound and video at the same time is possible on the raspi but problematic. My understanding is that it will only work for short video clips of a few seconds due to a design issue with the raspi camera not being able to support precise 25 Hz frame rates? The problem is described here...

http://raspberrypi.stackexchange.com/qu ... crophoneph

If I understand correctly the video-and-sound will go further out-of-sync as the recording time gets longer. Does anyone know if its possible to work around this issue in some way so that recordings of 30 mins or longer at 25 or 30 FPS would be possible without loss of sync between the sound and video?

Regards,

Pipuppy
Posts: 54
Joined: Fri Aug 24, 2012 12:51 pm
by 6by9 » Fri Feb 17, 2017 3:54 pm
Your link is broken. I'm assuming you meant http://raspberrypi.stackexchange.com/qu ... microphone
I love out of date information :roll: If they'd read that whole thread then they would see that the capture times were corrected to be <0.01% out.

No capture device is always spot on the specified capture rate, be it 48kHz for audio, or 25fps for video, unless you have an external very accurate clock and control loops adjusting the capture rate (eg television studios). Oscillators always have a tolerance.
Every buffer produced by the camera has a timestamp on it (particularly via V4L2). That is the normal approach for synchronising multiple sources as you just timestamp all data off the common clock.
Don't use raspivid piped into another app as that discards all timestamp information, something like GStreamer capturing data via V4L2 (use v4l2src) should do the trick. You may want to get a more recent version of GStreamer than is in the repo - V1.4 was reportedly not liking the H264 stream the Pi produced.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3939
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
by pipuppy » Sat Feb 18, 2017 11:42 am
Hi 6by9 and many thanks for taking the time to respond.

Firstly, sorry for my "dead link" which resulted from my cut-n-pasting from another posting.

I read your detailed reply and it has taught me a great deal, I allways wondered how video/audio was put in sync in the digital world. After reading your comments I understand that time stamped data would be ideal for my proposed project which would include audio/video/sensor data but sadly I suspect my current level of understanding prevents me from implementing this right away. Clearly something I will have to research and experiment with.

As a short term "get me going" fix I will fall back to using picam....

https://github.com/iizukanao/picam

Are any future updates planned for the raspi camera which would include some form of software to intergrate audio/video to a single file?

Thanks again for your response.

Regards,

pipuppy
Posts: 54
Joined: Fri Aug 24, 2012 12:51 pm