2

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.

2
  • Use shell=True, not just True Commented May 9, 2019 at 20:47
  • I think that sub process takes a list of strings, not a single string. Commented May 9, 2019 at 20:48

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.