1

I am trying to sync the raspberry pi camera (revision 1.3) to an external microphone. The sync is fine for the first 5 minutes or so, but around the 20 minute mark, the difference becomes really noticeable.

I believe the issue might be because the camera is not actually recording at 25 fps, but I'm not sure why the difference in sync worsens as the video duration increases.

How would I go about fixing this?

with picamera.PiCamera() as camera:
camera.annotate_background = True
camera.framerate = 25
camera.resolution = (1280,720)
videofilename = file_timestamp + "_" + species + "_mytest.h264"
audiofilename = file_timestamp + "_" + species + "_mytest.wav"
mergefilename = file_timestamp + "_" + species + "_mytest.mov"
syncfilename = "sync_" + mergefilename

start = dt.datetime.now() 
command = "~/alsa-utils/bin/arecord -Dhw:sndrpiwsp -d %s -c 2 -f s16_LE -r 8000 %s" % (length, audiofilename)
camera.start_preview()
camera.start_recording(videofilename)
video_start_time = dt.datetime.utcnow() #
print str(video_start_time) + ' -- started video recording!'
psub = subprocess.Popen(command , shell=True, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True)
while psub.poll() is None:
    line = psub.stderr.readline()
    if line[0:14] == 'Recording WAVE':
        #audio_start_time = dt.datetime.utcnow()
        print str(audio_start_time) + ' -- started audio recording!'
    if line[0:12] == 'Writing WAVE':
        audio_accurate_start_time = dt.datetime.utcnow()
        print str(audio_accurate_start_time) + ' -- started writing audio!'
audio_accurate_start_delay = audio_accurate_start_time - video_start_time #version numbering (v.2)
the_accurate_delay = float(str(audio_accurate_start_delay)[5:14])`merge = "avconv -i %s -i %s -c copy %s" % (videofilename, audiofilename, mergefilename)

sync = "avconv -itsoffset %s -i %s -i %s -map 0:1 -map 1:0 -c:v copy -c:a copy %s" % (the_accurate_delay, mergefilename, mergefilename, syncfilename)`

1 Answer 1

0

If the audio is getting ahead of the video, try lowering the resolution of the camera to something smaller like 800x600. If that works its probably gpu bottlenecked; you could try to allocate more ram to the GPU & then set it back at 1280x720

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.