1

I wanted to create some timelapse footage with my NOIR pi and IR light source with my pi 2 B+. I am able to capture the photos fine. My problem is that when is use os.system("avconv........") to convert the photos to video I keep getting a syntax error.

When I paste the same line (minus the os.system and "") it works absolutely fine. I have import os and import sys at the top of my script so it isn't that it can't call os.system (I don't think).

I have also tried subprocess.callw but have the same issue. Both attempts are below. I'm less familiar with subprocess.call so am even more uncertain as to whether it's correct.

subprocess.call(["/usr/bin/avconv","-r","24","-i","/home/pi/Timelapse/image%05d.jpg","-b","3000k","-r","24","-c:v","mpeg4",TimelapseVideo.mp4])

os.system('avconv -y -r %s -i /home/pi/Timelapse/image%s.jpg -r %s -vcodec libx264 -q:v 3 -vf crop=4256:2832,scale=iw:iw /home/pi/Timelapse/timelapse.mp4" %(FPS_IN,'{:05d}',FPS_OUT))

I'm fairly new to python, I only started playing with it a few weeks ago when I got the pi, steep learning curve. Any advice would be fantastic :)

2

In the first case you need to quote TimelapseVideo.mp4

subprocess.call(["/usr/bin/avconv","-r","24","-i","/home/pi/Timelapse/image%05d.jpg","-b","3000k","-r","24","-c:v","mpeg4","TimelapseVideo.mp4"])

In the second case you are mixing single and double quotes. I suggesting suing format strings instead of the format operator %.

os.system('avconv -y -r {0} -i /home/pi/Timelapse/image{{:05d}}.jpg -r {1} -vcodec libx264 -q:v 3 -vf crop=4256:2832,scale=iw:iw /home/pi/Timelapse/timelapse.mp4'.format( FPS_IN,FPS_OUT)

Note that {{ and }} are needed if you want a curly brace in a format string.

| improve this answer | |
  • Thanks for the help. I am still getting errors with both lines. I feel like it must be something in the avconv bit but I have no idea what. sudo python SleepingTimeLapse.py File "SleepingTimeLapse.py", line 60 os.system('avconv -y -r {0} -i /home/pi/Timelapse.image{{:05d}}.jpg -r {1} -vcodec libx264 -crf 20 -g 15 timelapsevideo.mp4 /home/pi/timelapse.mp4' .(FPS_IN,FPS_OUT)) ^ SyntaxError: invalid syntax – Robin Feb 25 '16 at 18:26
  • You are missingformat after the string. – Craig Feb 25 '16 at 18:35

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.