In Windows one line with spaces should work, but in Linux we have to pass the arguments as list.

  • We can build the command as a list:

     command = ['ffmpeg', '-i', 'head1.png', '-i', 'hdmiSpitting.mov', '-filter_complex', '[0:v][1:v]overlay=0:0', '-pix_fmt', 'yuv420p', '-c:a', 'copy', 'output3.mov']
    
  • We may also use shlex.split:

     import shlex
     command = shlex.split('ffmpeg -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov')
    

Adding -y argument:
If the output file output3.mov already exists, FFmpeg prints a message:
File 'output3.mov' already exists. Overwrite? [y/N]
And waits for the user to press y.
In some development environments we can't see the message.
Add -y for overwriting the output if already exists (without asking):

command = shlex.split('ffmpeg -y -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov')

Path issues:
There are cases when ffmpeg executable is not in the execution path.
Using full path may be necessary.
Example for Windows (assuming ffmpeg.exe is in c:\FFmpeg\bin):

command = shlex.split('c:\\FFmpeg\\bin\\ffmpeg.exe -y -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov')

In Linux, the default path is /usr/bin/ffmpeg.


Using shell=True is not recommended and considered "unsafe".
For details see Security Considerations.
The default is False, so we may use subprocess.call(command).

Note: subprocess.run supposes to replace subprocess.call.
See this post for details.


Creating log file by adding -report argument:
In some development environments we can't see FFmpeg messages, which are printed to the console (written to stderr).
Adding -report argument creates a log file with name like ffmpeg-20220624-114156.log.
The log file may tell us what went wrong when we can't see the console.

Example:

import subprocess
import shlex
subprocess.run(shlex.split('ffmpeg -y -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov -report'))
Answer from Rotem on Stack Overflow
🌐
Medium
artwilton.medium.com › running-ffmpeg-commands-from-a-python-script-676eaf2b2739
Running FFmpeg commands from a Python Script | by Arthur Wilton | Medium
May 4, 2021 - Finally I created a function called runFFmpeg that takes in a list of commands and runs those commands with subprocess. I added in an extra message that gets printed when FFmpeg runs successfully, or when it errors out. This is a great feature of subprocess in that it lets you check the exit status of your shell command.
Top answer
1 of 3
11

In Windows one line with spaces should work, but in Linux we have to pass the arguments as list.

  • We can build the command as a list:

     command = ['ffmpeg', '-i', 'head1.png', '-i', 'hdmiSpitting.mov', '-filter_complex', '[0:v][1:v]overlay=0:0', '-pix_fmt', 'yuv420p', '-c:a', 'copy', 'output3.mov']
    
  • We may also use shlex.split:

     import shlex
     command = shlex.split('ffmpeg -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov')
    

Adding -y argument:
If the output file output3.mov already exists, FFmpeg prints a message:
File 'output3.mov' already exists. Overwrite? [y/N]
And waits for the user to press y.
In some development environments we can't see the message.
Add -y for overwriting the output if already exists (without asking):

command = shlex.split('ffmpeg -y -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov')

Path issues:
There are cases when ffmpeg executable is not in the execution path.
Using full path may be necessary.
Example for Windows (assuming ffmpeg.exe is in c:\FFmpeg\bin):

command = shlex.split('c:\\FFmpeg\\bin\\ffmpeg.exe -y -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov')

In Linux, the default path is /usr/bin/ffmpeg.


Using shell=True is not recommended and considered "unsafe".
For details see Security Considerations.
The default is False, so we may use subprocess.call(command).

Note: subprocess.run supposes to replace subprocess.call.
See this post for details.


Creating log file by adding -report argument:
In some development environments we can't see FFmpeg messages, which are printed to the console (written to stderr).
Adding -report argument creates a log file with name like ffmpeg-20220624-114156.log.
The log file may tell us what went wrong when we can't see the console.

Example:

import subprocess
import shlex
subprocess.run(shlex.split('ffmpeg -y -i head1.png -i hdmiSpitting.mov -filter_complex "[0:v][1:v] overlay=0:0" -pix_fmt yuv420p -c:a copy output3.mov -report'))
2 of 3
3

I ended up using os.system() instead of subprocess and got the results I wanted before returning to see answers on this question. The answer from Rotem is incredibly useful and does solve my issue as well, with the added information of -y parameter.

I'll paste my entire code here, as it may be useful to someone in the future.

import os

os.chdir('/Users/Todd/Desktop/ffmpeg')
background = "01Background/Untitled_Artwork7.png"
backgear = "02Backgear/Surfboard-01.png"
head = "03Head/Goldhead_Goldshell1.png"
eye = "04eye/Keye-01.png"
outfit = "05Outfit/Summershirt-01.png"
headgear = "06Headgear/PopejoyHair_Goldshell1.png"
mouth = "hdmiSpitting.mov"
frontgear = "08Frontgear/TreePot-01.png"


# takes a list of 3 or more files and creates ffmpeg command to overlay them in order
# the first element in the list will be the lowest Z element (farthest back)
def generateCommand(files = []):
    command = "ffmpeg"
    i = 0
    count = 0
    alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"]
    for file in files:
        command += " -i " + file
        count += 1
    command += " -filter_complex \"[0][1]overlay[a];["
    while i < count-3: 
        command += alphabet[i] + "][" + str(i+2) + "]overlay[" + alphabet[i+1] + "];["
        i += 1
    command += alphabet[i] + "][" + str(i+2) + "]overlay\""
    command += " -pix_fmt yuv420p -c:a copy output3.mov"
    return command

# Takes two files and overlays file1 over file2
# This is a separate function because of the different command syntax for less than 3 files
def overlayTwoLayers(file1, file2):
    command = "ffmpeg -i " + file1 + " -i " + file2 + " -filter_complex \"[0:v][1:v] overlay=0:0\" -pix_fmt yuv420p -c:a copy output3.mov"
    os.system(command)

# Call this function with a list of files you want to be compiled
def generateImage(files):
    command = generateCommand(files)
    os.system(command)

files = []
files.append(background)
files.append(backgear)
files.append(head)
files.append(eye)
files.append(outfit)
files.append(headgear)
files.append(mouth)
files.append(frontgear)

generateImage(files)


print("done")
Discussions

ffmpeg in python script - Stack Overflow
I would like to run the following command in a python script, I also want to make it loop over several videos in a folder. This is the command I want to run. ffmpeg -i mymovie.avi -f image2 -vf fp... More on stackoverflow.com
🌐 stackoverflow.com
Running cmd in python - Stack Overflow
I know this question is old, but now there is an excellent wrapper for ffmpeg in Python : ffmpeg-python. More on stackoverflow.com
🌐 stackoverflow.com
July 24, 2017
How to Run FFmpeg in a Python Step Without Local Installation and No Access to Apt-Get or Pip? - Help - Pipedream
This topic was automatically generated from Slack. You can find the original thread here. I’ve been banging my head on this for hours and searching the slack isn’t helpful at all… I’m trying to run ffmpeg inside a python step and I dont have it install locally…many suggestions have ... More on pipedream.com
🌐 pipedream.com
0
October 29, 2024
Is there any python implementation of FFmpeg?
There's Vapour Synth ... libs for Python. Not quite sure how it compares to ffmpeg though · A genius built the backbone of video—then vanished - Part 2 ... Having trouble converting a .WMV file into a .MP4 file. ... Two videos (filmed on same device minutes apart) refuses to mux. How to copy Transcode info onto another using FFmpeg? ... Linux vs Windows code: Learnt the coding on my old linux and now trying to adapt it to my speedy windows ... How I run FFmpeg inside ... More on reddit.com
🌐 r/ffmpeg
12
0
February 19, 2024
🌐
FFmpeg Python
kkroening.github.io › ffmpeg-python
ffmpeg-python: Python bindings for FFmpeg — ffmpeg-python documentation
Build command-line for invoking ffmpeg. The run() function uses this to build the commnad line arguments and should work in most cases, but calling this function directly is useful for debugging or if you need to invoke ffmpeg manually for whatever reason.
🌐
Bannerbear
bannerbear.com › blog › how-to-use-ffmpeg-in-python-with-examples
How to Use FFMpeg in Python (with Examples) - Bannerbear
import ffmpeg start_time = '00:00:10' # Start time for trimming (HH:MM:SS) end_time = '00:00:20' # End time for trimming (HH:MM:SS) ( ffmpeg.input("input.mp4", ss=start_time, to=end_time) .output("trimmed_output.mp4") .run() ) Here’s a screenshot of the input video at the 00:00:10 timestamp: ... Another thing you can do with FFmpeg by adding parameters to the functions is to extract frames from the input video.
🌐
GitHub
github.com › kkroening › ffmpeg-python
GitHub - kkroening/ffmpeg-python: Python bindings for FFmpeg - with complex filtering support · GitHub
This dilemma is intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the way while users may refer to the official ffmpeg documentation as to why certain filters drop audio. As usual, take a look at the examples (Audio/video pipeline in particular). How can I find out the used command line arguments? You can run stream.get_args() before stream.run() to retrieve the command line arguments that will be passed to ffmpeg.
Starred by 11K users
Forked by 941 users
Languages   Python
🌐
Gumlet
gumlet.com › learn › ffmpeg-python
How to Use FFmpeg with Python in 2026? - Gumlet
January 22, 2026 - This example demonstrates how ffmpeg-python builds the FFmpeg command behind the scenes and runs it, providing a simpler and more Pythonic interface. ... Simplified syntax: Libraries like moviepy and ffmpeg-python provide a user-friendly syntax for performing complex multimedia tasks without needing deep knowledge of FFmpeg’s command-line interface. Wide range of functionality: These libraries allow you to perform advanced video and audio manipulations, from trimming and merging to adding transitions and effects.
🌐
PyPI
pypi.org › project › ffmpeg-python
ffmpeg-python · PyPI
Download URL: ffmpeg_python-0.2.0-py3-none-any.whl
      » pip install ffmpeg-python
    
Published   Jul 06, 2019
Version   0.2.0
Find elsewhere
🌐
PyPI
pypi.org › project › python-ffmpeg
python-ffmpeg
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Medium
pjcarroll.medium.com › python-and-ffmpeg-2de5d29a4e2c
Python and ffmpeg. Say goodbye to directory woes | by PJ Carroll | Medium
December 26, 2020 - not is the python way of doing the opposite of a binary command. The full ffmpeg command looks like this: if(not os.path.isfile(outfile)): stream = ffmpeg.input(infile) stream = ffmpeg.output(stream, outfile) ffmpeg.run(stream) Job done.
🌐
Unixmen
unixmen.com › home › linux tutorials › hacking ffmpeg with python – part one
Hacking FFmpeg With Python - Part One
It is written mostly in C programming language and the best part is that FFmpeg is open source. Through this tutorial you are going to learn how to use the python programming language for interacting with this open source tool in order to automate some simple tasks. The python version being used through this article is Python 2.7.x so make sure to install it on your own linux machine before going any further as a different version may give you all kind of errors when running the code in the python interactive shell.
🌐
Medium
medium.com › @aleksej.gudkov › ffmpeg-python-example-a-guide-to-using-ffmpeg-with-python-020cdb7733e7
FFmpeg Python Example: A Guide to Using FFmpeg with Python | by UATeam | Medium
November 12, 2025 - For Windows: Download the FFmpeg executable from the FFmpeg website and add it to your system’s PATH. FFmpeg Python Library Install ffmpeg-python, a Python wrapper for FFmpeg:
🌐
Python Programming
pythonprogramming.altervista.org › ffmpeg-used-with-python
Ffmpeg - python programming - Altervista
@echo off<br>rem set /p file=Which file you want to make mono?<br>set /p fps=Number of frame per second?<br>ffmpeg -i %1 -map_channel 0.1.0 -c:v copy %1_mono.mp4<br>ffmpeg -i %1_mono.mp4 -filter:v fps=fps=%fps% %file%low_fps.mp4<br>pause ... import os from tkinter import filedialog filename = filedialog.askopenfilename() command = f"ffmpeg -i {filename} -q:a 0 -map a sample.mp3" os.system(command)
🌐
Medium
gradient-drift.medium.com › how-to-use-ffmpeg-on-python-2ba3fa360ba7
How to Use FFmpeg on Python?. I often read the python weekly… | by Gradient Drift | Medium
January 5, 2020 - In the latest newsletter I find this project ffmpeg-python on Github. It’s pretty convenient for me(maybe also for you) In case you don’t actually know what FFmpeg is, I give the introduction from Wikipedia below:
🌐
Readthedocs
ffmpy.readthedocs.io › 1.0.0
ffmpy — ffmpy 1.0.0 documentation
from ffmpy import FFmpeg ff = FFmpeg( inputs={'input.mp4': None}, outputs={'output.avi': None} ) ff.run()
🌐
Delft Stack
delftstack.com › home › howto › python › ffmpeg python
FFmpeg in Python Script | Delft Stack
October 10, 2023 - import ffmpeg video = ffmpeg.input("Pencil.mp4") video = ffmpeg.vflip(video) video = ffmpeg.output(video, "vertical.mp4") ffmpeg.run(video) FFmpeg is a handy tool for performing different operations on multimedia files. It can quickly trim the video, change file format, extract audio, create GIFs, and more. By this point, you should have clearly understood how to use FFmpeg commands in Python script.
🌐
Pipedream
pipedream.com › help
How to Run FFmpeg in a Python Step Without Local Installation and No Access to Apt-Get or Pip? - Help - Pipedream
October 29, 2024 - This topic was automatically generated from Slack. You can find the original thread here. I’ve been banging my head on this for hours and searching the slack isn’t helpful at all… I’m trying to run ffmpeg inside a python step and I dont have it install locally…many suggestions have suggested to apt-get install it or pip install but the process cannot find neither pip nor apt-get…anyone have any ideas?
🌐
GitHub
gist.github.com › derekkwok › 4077509
Simple python script to encode videos using ffmpeg · GitHub
August 10, 2020 - Simple python script to encode videos using ffmpeg - encode.py
🌐
Reddit
reddit.com › r/ffmpeg › is there any python implementation of ffmpeg?
Is there any python implementation of FFmpeg? : r/ffmpeg
February 19, 2024 - There's Vapour Synth https://github.com/vapoursynth/vapoursynth which aims to be an easy to use video processing libs for Python. Not quite sure how it compares to ffmpeg though · A genius built the backbone of video—then vanished - Part 2 ... Having trouble converting a .WMV file into a .MP4 file. ... Two videos (filmed on same device minutes apart) refuses to mux. How to copy Transcode info onto another using FFmpeg? ... Linux vs Windows code: Learnt the coding on my old linux and now trying to adapt it to my speedy windows ... How I run FFmpeg inside n8n Code node on a self-hosted VPS (no extra installs beyond what's in Docker)