Search code examples
pythoncommandpyinstallereel

os.system doesn't work after compiling with pyinstaller


I am trying to get the duration of an online video using ffprobe

My program runs perfectly when I run it normally,
however when I try to use pyinstaller to compile the script to an exe
I click it and the os.system('ffprobe -i "{ URL Here}" -show_entries format=duration -v quiet -of csv="p=0"' > temp.txt') doesn't seem to output anything to the file , when running the non-comiled script it works perfectly and does what is supposed to do

import time
import re
import os, sys,tempfile
import eel
import ffmpy
import win32gui
import subprocess

eel.init('interface') # start the GUI

@eel.expose
def getDuration(url):
    duration = readcmd('ffprobe -i "{}" -show_entries format=duration -v quiet -of csv="p=0"'.format(url))
    # duration = subprocess.check_output(['ffprobe', '-i', url, '-show_entries', 'format=duration', '-v', 'quiet', '-of', 'csv=%s' % ("p=0")])
    return duration.rstrip()

def readcmd(cmd):
    os.system(cmd + " > temp.txt")
    data = ""
    with open('temp.txt', 'r') as file:
        data = file.read()
        file.close()
    os.remove('temp.txt')
    return data

eel.start('index.html', size=(1124, 768), mode = 'chrome') # Maybe I will implment Browser Fallback in the future

I have looked here subprocess seems not working in pyinstaller exe file I have tried running pyinstaller with
-w and without -noconsole here is how I compile : python -m eel main.py interface --noconsole --add-binary "./ffmpeg.exe;./" --add-binary "./ffprobe.exe;./"

I am using eel for gui


Solution

  • Well It turns out that I am kinda stupid, after wasting 2 days of my life to figure it out. The problem is that when I was building with pyinstaller i didn't include the dll files for
    ffmpeg which was causing it to fail. :) please don't laugh

    to solve the problem I am adding --add-data for every dll when using pyinstaller and it is now solved. or you can manually copy the dll files to the dist folder