Search code examples
python-3.xwindowsvideostack-overflowvideo-compression

What is the problem with this python 3 script


I made a script for compressing videos

import ffmpeg
import subprocess

result = subprocess.run("C:\\ffmpeg\\bin\\ffmpeg.exe"['ffmpeg -i output.mp4 -b 800k output.mp4'])
print(result)

When I run this an error will come like this-

    result = subprocess.run("C:\\ffmpeg\\bin\\ffmpeg.exe"['ffmpeg -i output.mp4 -b 800k output.mp4'])
TypeError: string indices must be integers

What is the solution?


Solution

  • This appears to be malformed:

    subprocess.run("C:\\ffmpeg\\bin\\ffmpeg.exe"['ffmpeg -i output.mp4 -b 800k output.mp4'])
    

    I'm pretty sure you just want this:

    result = subprocess.run(["C:\\ffmpeg\\bin\\ffmpeg.exe", "-i", "output.mp4", "-b", "800k",  "output.mp4"])
    

    Or perhaps just this:

    result = subprocess.run("C:\\ffmpeg\\bin\\ffmpeg.exe -i output.mp4 -b 800k output.mp4")
    

    Also, not sure if it's a good idea to have your input file and output file, output.mp4 be the same.