I am using FFMPEG for my application. Works great when running the program through the terminal/VScode. However I wrote a .plist
script to automate my python file and now I get an error saying, sh: ffmpeg: command not found
. Tried adding the path to FFMPEG explicitly as one of the ProgramArguments
but invain.
Anyone who has tried automating a script with .plist
and facing this error?
My .plist
file that I have placed it in ~/Library/LaunchAgents/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>schedule.reel.launcher</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/Caskroom/miniconda/base/envs/venv_k2/bin/python</string>
<string>/Users/***/Kokaato/musicheroku/automate_upload/schedule_reel_creation.py</string>
</array>
<key>StandardErrorPath</key>
<string>/Users/***/Kokaato/musicheroku/automate_upload/python_script.error</string>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EDIT:
Updated code to help understand the problem better
import pandas as pd
import pafy
import os
import re
from utils import send_email
def create_reel():
df = pd.read_csv("/Users/***/Kokaato/musicheroku/automate_upload/weekly_songs.csv", header=None)
input_directory = "/Users/***/Kokaato/musicheroku/automate_upload/downloaded_songs"
output_directory = "/Users/***/Kokaato/musicheroku/automate_upload/reel_videos"
url = df.iloc[0,0]
try:
video = pafy.new(url)
except Exception as e:
send_email( _exception = e, subject= "error in pafy.new line", filename="create_video_reels.py")
best_video = video.getbest(preftype="mp4")
title = "".join(re.findall("[a-zA-Z]+", str(video.title)))
title = "".join(re.findall("[a-zA-Z]+", title))
best_video.download(
filepath=input_directory + "/{}.{}".format(title, best_video.extension)
)
try:
os.system(
"ffmpeg -i "
+ input_directory
+ "/"
+ title
+ "."
+ best_video.extension
+ " -ss 00:00:05 -to 00:00:19 -async 1 "
+ output_directory
+ "/video_reel.mp4"
)
except Exception as e:
send_email( _exception = e, subject= "Problem with ffmpeg", filename="create_video_reels.py")
# delete link from csv
df.drop(df.index[0], inplace=True)
try:
df.to_csv(path_or_buf="/Users/***/Kokaato/musicheroku/automate_upload/weekly_songs.csv", index=False, header=False)
except Exception as e:
send_email( _exception = e, subject= "Problem creating reel", filename="create_video_reels.py")