Reputation: 2625
I've got this script:
PATH = os.path.dirname(os.path.abspath(__file__))
global TEMP
for video in os.listdir(VIDEOS):
ffmpeg = PATH + "/ffmpeg/ffmpeg"
arg1 = " -v 0 -i "
arg2 = VIDEOS + "/" + video
arg3 = " -r 1 -f image2 "
arg4 = TEMP + "/" + os.path.splitext(video)[0] + "-%d.jpg"
subprocess.Popen(ffmpeg + arg1 + arg2 + arg3 + arg4).wait()
that works perfectly on Windows (using ffmpeg.exe of course), but when I try to run it on Mac I got error:
File "/Users/francesco/Desktop/untitled0.py", line 20, in Main
subprocess.Popen(ffmpeg + arg1 + arg2 + arg3 + arg4).wait()
File "subprocess.pyc", line 710, in __init__
File "subprocess.pyc", line 1327, in _execute_child
OSError: [Errno 2] No such file or directory
I've tried to print ffmpeg + arg1 + arg2 + arg3 + arg4 and paste it manually in the terminal, nothing happens, it just stuck, but if I try to copy manually all the printed arguments, it works.
Upvotes: 1
Views: 615
Reputation: 522
Had the same problem. Python 3.7 and ffmpeg, both installed with brew. Just like for you, worked in terminal, but not as a (CRON) script. Turned out that the problem was not specifying the full PATH for ffmpeg, which in my case is "/usr/local/Cellar/ffmpeg/4.1.3/bin/ffmpeg". So
[...]
import os
theCommand = "/usr/local/Cellar/ffmpeg/4.1.3/bin/ffmpeg -i /Volumes/ramDisk/audio.mp4 -i /Volumes/ramDisk/video.mp4 -c:a copy -c:v copy /Volumes/ArchiveDisk/final.mp4"
os.system(theCommand)
Upvotes: 0
Reputation: 180391
Pass a list of args and use check_call
if you want to wait until the process returns:
from subprocess import check_call
for video in os.listdir(VIDEOS):
check_call(["ffmpeg","-v", "0", "-i","{}/{}".format(VIDEOS,video), "-r", "1", "-f",
"image2","{}/-%d.jpg".format(TEMP), os.path.splitext(video)[0]])
check_call will raise a CalledProcessError for any non-zero exit status
Upvotes: 0
Reputation: 8982
The subprocess.Popen
requires list of strings, something like [ffmpeg, arg1, ...]
.
This command fails on Linux:
subprocess.Popen("ls -la").wait()
while this one succeeds:
subprocess.Popen(["ls", "-la"]).wait()
Upvotes: 2