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
🌐
FFmpeg Python
kkroening.github.io › ffmpeg-python
ffmpeg-python: Python bindings for FFmpeg — ffmpeg-python documentation
These parameters allow the x and y expressions to refer each other, so you can for example specify y=x/dar. ... Apply custom filter. filter_ is normally used by higher-level filter functions such as hflip, but if a filter implementation is missing from ffmpeg-python, you can call filter_ directly to have ffmpeg-python pass the filter name and arguments to ffmpeg verbatim.
🌐
Bannerbear
bannerbear.com › blog › how-to-use-ffmpeg-in-python-with-examples
How to Use FFMpeg in Python (with Examples) - Bannerbear
Then, make an HTTP request in your Python code to call the Bannerbear API and trigger the video generation process. You will get the URL of the resulting video in the response and here’s a screenshot of the video: ... You can refer to this tutorial and the API Reference to learn how to do it in detail. The ffmpeg-library enables you to use FFmpeg in Python to manipulate various media files for different purposes like building comprehensive multimedia applications, preprocessing media files for machine learning projects, etc.
Discussions

How can I run an ffmpeg command in a python script? - Stack Overflow
I want to overlay a transparent video over top of an image using ffmpeg and python I am able to do this successfully through terminal, but I cannot get ffmpeg commands to work in python. The follow... More on stackoverflow.com
🌐 stackoverflow.com
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
My guess would be that the location ... to the ffmpeg binary in subprocess.call, or update the setting for Path. 2013-05-25T10:40:11.057Z+00:00 ... 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
python - subprocess call ffmpeg (command line) - Stack Overflow
I have been incorporating subprocess calls in my program. I have had no issues with subprocess calls for other commands, but I am having trouble getting the command line input ffmpeg -r 10 -i fram... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › kkroening › ffmpeg-python
GitHub - kkroening/ffmpeg-python: Python bindings for FFmpeg - with complex filtering support · GitHub
See the Examples README for additional examples. Don't see the filter you're looking for? While ffmpeg-python includes shorthand notation for some of the most commonly used filters (such as concat), all filters can be referenced via the .filter operator:
Starred by 11K users
Forked by 940 users
Languages   Python
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")
🌐
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 - The first thing I do is import the subprocess module which allows me to run shell commands from Python. More info about subprocess can be found here. Then I setup a variable to define where the ffmpeg binary is located. ... I created a function grabUserInput() which prompts a user for input, stores that input in a dictionary, and returns that dictionary to be used in another function. Within that function I defined a nested function called filterInput() which is responsible for formatting the input message the user will see and setting a default value so the user can simply hit enter if they don’t wish to change the default value.
🌐
Gumlet
gumlet.com › learn › ffmpeg-python
How to Use FFmpeg with Python in 2026? - Gumlet
January 22, 2026 - For example, on Ubuntu or Debian-based systems, you can run: sudo apt update sudo apt install ffmpeg For Fedora-based systems, use: sudo dnf install ffmpeg After installation, run the following command to check the installed version: ffmpeg ...
Find elsewhere
🌐
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 - FFmpeg Python Library Install ffmpeg-python, a Python wrapper for FFmpeg: ... In this example, we’ll convert a video from one format to another (e.g., MP4 to AVI) using ffmpeg-python.
🌐
PyPI
pypi.org › project › ffmpeg-python
ffmpeg-python · PyPI
Python bindings for FFmpeg - with complex filtering support
      » pip install ffmpeg-python
    
Published   Jul 06, 2019
Version   0.2.0
🌐
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
🌐
Cloudinary
cloudinary.com › home › a beginner’s guide to ffmpeg in python
A Beginner’s Guide to FFmpeg in Python | Cloudinary
January 14, 2026 - The above example writes all input video file paths to a temporary file called “input.txt” in the format required by FFmpeg’s concat demuxer (each line contains file 'filename'). Then Python’s subprocess module is used to execute the command which reads the list of files from the text ...
🌐
Unixmen
unixmen.com › home › linux tutorials › hacking ffmpeg with python – part one
Hacking FFmpeg With Python - Part One
This tutorial will guide you through the python programming language used for hacking FFmpeg in order to deal with your audio and video files.
🌐
Medium
pjcarroll.medium.com › python-and-ffmpeg-2de5d29a4e2c
Python and ffmpeg. Say goodbye to directory woes | by PJ Carroll | Medium
December 26, 2020 - We’re going to iterate through all the files in current_directory/video, run ffmpeg on it, split off the name part (see above), rename it .mp3 and put it into current_directory/audio.
🌐
Readthedocs
python-ffmpeg.readthedocs.io › en › latest › api
API Reference - python-ffmpeg
Return a list of arguments to be used when executing FFmpeg. ... Add a global option -key or -key value. ... Add an input file with specified options. By calling this method multiple times, an arbitrary number of input files can be added.
🌐
Python Programming
pythonprogramming.altervista.org › ffmpeg-used-with-python
Ffmpeg - python programming - Altervista
import os list_of_commands = [ " -i dina.wav", # input file " -vn ", # disable video if any in the file "-ar 44100", # wav audio sampling frequency " -ac 2", # audio channels " -b:a 192k", # quality of mp3, converts audio bit rate to 192kbs " output.mp3" # output file ] command = "ffmpeg" + " ".j...
🌐
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 - It can also capture and encode ... refer to its exampleor create your own scriptFor example: change the video quality, change the file type, change the bit rates...........
🌐
GitHub
github.com › kkroening › ffmpeg-python › blob › master › examples › README.md
ffmpeg-python/examples/README.md at master · kkroening/ffmpeg-python
process1 = ( ffmpeg .input(in_filename) .output('pipe:', format='rawvideo', pix_fmt='rgb24', vframes=8) .run_async(pipe_stdout=True) ) process2 = ( ffmpeg .input('pipe:', format='rawvideo', pix_fmt='rgb24', s='{}x{}'.format(width, height)) ...
Author   kkroening
🌐
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