Reputation: 63
I'm trying to write a python script that basically captures webcam videos from the terminal. When I put the command in a string and use subprocess.call(script, True)
, I get an error, but when I literally copy/paste the same command to the terminal it works fine.
This is my python:
import subprocess
import os
if (os.path.isdir("Videos/Webcam/temp") is False):
dirmake = 'mkdir Videos/Webcam/temp'
subprocess.call(dirmake, True)
cmd = 'ffmpeg -f v4l2 -i /dev/video0 -t 00:00:10 video.webm'
subprocess.call(cmd, True)
and this is the error
`FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg -f v4l2 -i /dev/video0 -t 00:00:10 video.webm': 'ffmpeg -f v4l2 -i /dev/video0 -t 00:00:10 video.webm'`
If I just run ffmpeg -f v4l2 -i /dev/video0 -t 00:00:10 video.webm
from the terminal it works fine.
Originally the video was supposed to go in Videos/Webcam/temp but I took it out to see if the error had something to do with where I was putting the video. I'm using Ubuntu 18.04.2 LTS if that makes a difference.
Upvotes: 2
Views: 237
Reputation: 63
When using the subprocess module you will typically pass it your command as a list of strings, rather than the entire command you wish to run.
For example, rather than subprocess.call('ls -l /my/dir')
, which will give an error, you would use subprocess.call(['ls', '-l', '/my/dir'])
See more on the subprocess module here
Upvotes: 2