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 - 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. Then I simply call the runFFmpeg() function to ...
🌐
FFmpeg Python
kkroening.github.io › ffmpeg-python
ffmpeg-python: Python bindings for FFmpeg — ffmpeg-python documentation
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.
Discussions

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
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
ffmpeg in python script - Stack Overflow
This question is similar to: How do I execute a program or call a system command?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. ... From a brief look at FFMPY, you could do this using ffmpy.FFmpeg... More on stackoverflow.com
🌐 stackoverflow.com
How do I call ffmpeg from a program?
If you can live with the process overhead you can just shell out. In python use subprocess it's the most flexible import subprocess # Define the FFmpeg command command = ["ffmpeg", "-i", "input.mp4", "-vf", "scale=640:-1", "output.mp4"] # Execute the command subprocess.run(command) etc More on reddit.com
🌐 r/ffmpeg
7
4
November 22, 2024
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")
🌐
GitHub
github.com › kkroening › ffmpeg-python
GitHub - kkroening/ffmpeg-python: Python bindings for FFmpeg - with complex filtering support · GitHub
Note: The actual version information displayed here may vary from one system to another; but if a message such as ffmpeg: command not found appears instead of the version information, FFmpeg is not properly installed. When in doubt, take a look at the examples to see if there's something that's close to whatever you're trying to do. ... 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
🌐
Readthedocs
ffmpy.readthedocs.io › 1.0.0
ffmpy — ffmpy 1.0.0 documentation
ffmpy is a Python wrapper for FFmpeg. It compiles FFmpeg command line from provided arguments and their respective options and executes it using Python’s subprocess.
Find elsewhere
🌐
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.
🌐
Medium
pjcarroll.medium.com › python-and-ffmpeg-2de5d29a4e2c
Python and ffmpeg. Say goodbye to directory woes | by PJ Carroll | Medium
December 26, 2020 - If you’ve used ffmpeg before you’ll be aware that it can take a while to trundle through a conversion. We should check that the output doesn’t exist first: ... not is the python way of doing the opposite of a binary command.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › using the raspberry pi › beginners
How to run this FFMPEG command with Python? - Raspberry Pi Forums
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=4 v4l2-ctl --set-ctrl=rotate=180 v4l2-ctl --overlay=1 v4l2-ctl -p 30 v4l2-ctl --set-ctrl=video_bitrate=2000000 ffmpeg -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -i /dev/zero -f h264 -framerate 30 -i /dev/video0 -vcodec copy -acodec aac -ab 128k -g 60 -f flv -r 30 rtmp://a.rtmp.youtube.com/live2/SECRET-KEY Is it possible? How do I call FFMPEG with Python? What command should I write to make it start/stop at a specific time and start again if FFMPEG fails/stops?
🌐
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)
🌐
Ask Ubuntu
askubuntu.com › questions › 64331 › python-ffmpeg-command-line-issues
11.04 - Python/FFMPEG command line issues - Ask Ubuntu
ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0 out.avi · When I run the same command in a Python script below, def call_command(command): subprocess.Popen(command.split(' ')) call_command("ffmpeg -f alsa -i default -itsoffset 00:00:00 -f video4linux2 -s 1280x720 -r 25 -i /dev/video0 out.avi")
🌐
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.
🌐
Gumlet
gumlet.com › learn › ffmpeg-python
How to Use FFmpeg with Python in 2026? - Gumlet
January 22, 2026 - Ease of Use with High-Level Libraries: While FFmpeg commands can be complex, Python simplifies their use through high-level libraries such as pydub and moviepy. These libraries provide a Pythonic interface to interact with FFmpeg’s powerful features, allowing developers to manipulate video and audio files with simple function calls ...
🌐
USAVPS
usavps.com › home › python › python tutorial: how to call ffmpeg in python?
Python Tutorial: How to Call FFmpeg in Python? - USAVPS.COM
October 20, 2024 - Here’s a basic example of how to convert a video file from one format to another: import subprocess def convert_video(input_file, output_file): command = ['ffmpeg', '-i', input_file, output_file] subprocess.run(command) # Example usage convert_video('input.mp4', 'output.avi')
🌐
PyPI
pypi.org › project › ffmpeg-python › 0.1.1
ffmpeg-python · PyPI
If you're like me and find Python to be powerful and readable, it's easy with `ffmpeg-python`: ``` import ffmpeg in_file = ffmpeg.file_input(TEST_INPUT_FILE) overlay_file = ffmpeg.file_input(TEST_OVERLAY_FILE) ffmpeg \ .concat( in_file.trim(10, 20), in_file.trim(30, 40), ) \ .overlay(overlay_file.hflip()) \ .drawbox(50, 50, 120, 120, color='red', thickness=5) \ .file_output(TEST_OUTPUT_FILE) \ .run() ``` `ffmpeg-python` takes care of running `ffmpeg` with the command-line arguments that correspond to the above filter diagram, and it's easy to what's going on and make changes as needed.
      » pip install ffmpeg-python
    
Published   May 14, 2017
Version   0.1.1
🌐
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
🌐
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
🌐
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.