I’m using ffprobe
from ffmpeg
to get information about user-selected image dimensions. I’m doing this inside of a subprocess, but after my deployed app failed to work I realized I need to detect the right Python executable to use. I found this article helpful for better understanding what the issue is, but I’m having trouble actually resolving it. I don’t really know Python very well.
Here’s what the code looks like now (this works locally):
selected_image_height = subprocess.run(f'ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=s=x:p=0 {selected_image}', stdout=subprocess.PIPE)
Here’s an example of something I’ve tried based on the help article that doesn’t work:
selected_image_height = subprocess.run([f'{sys.executable}','ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 {selected_image}'], stdout=subprocess.PIPE)
I’ve tried a bunch of other things, but I feel like I’m missing something really fundamental because I don’t know Python well enough. I also realize this is probably really ugly code, sorry!
- Code: GitHub - mrisdal/canto-podcast-creator: A Streamlit app that I use to create videos for my Cantonese language learning Instagram
- Deployed app: https://mrisdal-canto-podcast-creator-create-podcast-oselu7.streamlit.app/
Some additional information in case it’s helpful. I’m using this custom image selector module to let the user pick from a set of images that live together in a folder.
background_input_path = "./input/backgrounds/"
backgrounds = []
for path in os.listdir(background_input_path):
# Check if current path is a file and add it to a list
# All the files here should be images. They don't need to be the same size, but ideally they're square
if os.path.isfile(os.path.join(background_input_path, path)):
backgrounds.append(background_input_path + path)
# Image selector widget
selected_image = image_select("Background choices", backgrounds)
ETA: Adding ffmpeg
to packages.txt
did not change the error. I still see:
FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 ./input/backgrounds/background_5.jpg'
ETA #2: I ended up “fixing” it by just removing this step and instead processing the images so that they’re all 512x512 so that I can make more assumptions later on. Would still be interested to learn more about how to use subprocesses on Streamlit Cloud, but my app is working again for now.