Skip to content

Commit 71ac1c8

Browse files
committed
Added ffmpeg for install during runs.
1 parent 1077723 commit 71ac1c8

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ jobs:
3030
if: matrix.os == 'macos-latest'
3131
run: |
3232
pip install pillow
33-
pyinstaller --onefile --name Scriptify --icon web/favicon.ico \
33+
pyinstaller --onefile --name Scriptify --icon web/favicon.ico --add-data "ffmpeg/ffmpeg_mac.zip:ffmpeg/ffmpeg_mac.zip" \
3434
--add-data "web:web" --add-data "js:js" --add-data "index.html:." --add-data "launch.html:." --add-data "style.css:." \
3535
--osx-bundle-identifier com.infinitode.scriptify --windowed main.py --version-file version_info.txt
3636
3737
- name: Build for Linux
3838
if: matrix.os == 'ubuntu-latest'
3939
run: |
40-
pyinstaller --onefile --name Scriptify --icon web/favicon.ico \
40+
pyinstaller --onefile --name Scriptify --icon web/favicon.ico --add-data "ffmpeg/ffmpeg_ubuntu.zip:ffmpeg/ffmpeg_ubuntu.zip" \
4141
--add-data "web:web" --add-data "js:js" --add-data "index.html:." --add-data "launch.html:." --add-data "style.css:." \
4242
--windowed main.py --version-file version_info.txt
4343
4444
- name: Build for Windows
4545
if: matrix.os == 'windows-latest'
4646
run: |
47-
pyinstaller --onefile --name Scriptify --icon web/favicon.ico `
47+
pyinstaller --onefile --name Scriptify --icon web/favicon.ico --add-data "ffmpeg/ffmpeg_windows.zip:ffmpeg/ffmpeg_windows.zip" `
4848
--add-data "web:web" --add-data "js:js" --add-data "index.html:." --add-data "launch.html:." --add-data "style.css:." `
4949
--windowed main.py --version-file version_info.txt
5050

ffmpeg/ffmpeg_mac.zip

25 MB
Binary file not shown.

ffmpeg/ffmpeg_ubuntu.zip

19.7 MB
Binary file not shown.

ffmpeg/ffmpeg_windows.zip

91.2 MB
Binary file not shown.

main.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import os
55
import time
66
import sys
7+
import subprocess
8+
import shutil
9+
import tempfile
710
import threading
811
import whisper # Whisper for speech-to-text processing
912
import queue
@@ -35,6 +38,53 @@
3538
os.environ["WHISPER_DOWNLOAD_DIR"] = os.path.join(base_path, "models")
3639
os.environ["WHISPER_CACHE_DIR"] = os.path.join(base_path, "models")
3740

41+
def extract_ffmpeg():
42+
"""Extracts the correct FFmpeg binary for the OS and returns its path."""
43+
temp_dir = tempfile.mkdtemp()
44+
45+
# Determine OS and archive filename
46+
if sys.platform.startswith("win"):
47+
archive_name = "ffmpeg_windows.zip"
48+
extracted_binary = "ffmpeg.exe"
49+
elif sys.platform.startswith("darwin"):
50+
archive_name = "ffmpeg_mac.zip"
51+
extracted_binary = "ffmpeg"
52+
elif sys.platform.startswith("linux"):
53+
archive_name = "ffmpeg_ubuntu.zip"
54+
extracted_binary = "ffmpeg"
55+
else:
56+
raise RuntimeError("Unsupported OS")
57+
58+
# Paths
59+
archive_path = os.path.join(os.path.dirname(__file__), "ffmpeg", archive_name)
60+
extracted_path = os.path.join(temp_dir, extracted_binary)
61+
62+
# Extract using shutil (built-in support for ZIP)
63+
try:
64+
print(f"Extracting {archive_name}...")
65+
shutil.unpack_archive(archive_path, temp_dir)
66+
67+
# Ensure correct executable permissions (Linux/macOS)
68+
if not sys.platform.startswith("win"):
69+
os.chmod(extracted_path, 0o755)
70+
71+
print(f"FFmpeg extracted to: {extracted_path}")
72+
return extracted_path
73+
74+
except Exception as e:
75+
print(f"Error extracting FFmpeg: {e}")
76+
sys.exit(1)
77+
78+
# Extract and set the FFmpeg path
79+
FFMPEG_PATH = extract_ffmpeg()
80+
81+
# Test if FFmpeg works
82+
try:
83+
subprocess.run([FFMPEG_PATH, "-version"], check=True)
84+
print("FFmpeg is working correctly.")
85+
except Exception as e:
86+
print(f"Error running FFmpeg: {e}")
87+
3888
# Create if it doesn't exist
3989
if not os.path.exists(os.environ["WHISPER_DOWNLOAD_DIR"]):
4090
os.makedirs(os.environ["WHISPER_DOWNLOAD_DIR"])

0 commit comments

Comments
 (0)