I would like to understand how to read the following ffmpeg instruction

Your ffmpeg command is semi-obfuscated by scripting so the actual command is not known, but here's an explanation of each option:

  • -i indicates the input.
  • -r 1 sets output frame rate to 1. This is not needed if you want to output a single image or if you want to output all images. In this example it is used to output one frame per second which would skip many frames.
  • -s qvga sets output width x height to "qvga" which is an alias for 320x240.
  • -t 1 sets the output duration to 1 second. This is not needed if you want to output a single image or if you want to output all images. It is often added by rookie users trying to output a single image but -frames:v 1 should be used instead.
  • -f image2 An often superfluous option used to set the output format or muxer. It is used if your output name is ambiguous (perhaps due to scripting). Otherwise, ffmpeg will automatically choose the proper muxer for image outputs.

how can l adapt it to get all the frames of a given video ?

The simplest, unscripted command to get all of the frames is:

ffmpeg -i input %04d.png

This will output 0001.png, 0002.png, 0003.png, etc. If you want more than a numerical sequence you can use something like output_%05d.png which would result in output_00001.png.

For more info see FFmpeg Documentation: Image Muxer.

Answer from llogan on askubuntu.com
Top answer
1 of 2
1

I would like to understand how to read the following ffmpeg instruction

Your ffmpeg command is semi-obfuscated by scripting so the actual command is not known, but here's an explanation of each option:

  • -i indicates the input.
  • -r 1 sets output frame rate to 1. This is not needed if you want to output a single image or if you want to output all images. In this example it is used to output one frame per second which would skip many frames.
  • -s qvga sets output width x height to "qvga" which is an alias for 320x240.
  • -t 1 sets the output duration to 1 second. This is not needed if you want to output a single image or if you want to output all images. It is often added by rookie users trying to output a single image but -frames:v 1 should be used instead.
  • -f image2 An often superfluous option used to set the output format or muxer. It is used if your output name is ambiguous (perhaps due to scripting). Otherwise, ffmpeg will automatically choose the proper muxer for image outputs.

how can l adapt it to get all the frames of a given video ?

The simplest, unscripted command to get all of the frames is:

ffmpeg -i input %04d.png

This will output 0001.png, 0002.png, 0003.png, etc. If you want more than a numerical sequence you can use something like output_%05d.png which would result in output_00001.png.

For more info see FFmpeg Documentation: Image Muxer.

2 of 2
1
import subprocess
L=subprocess.call('ffmpeg -i %s -r 1 -s qvga -t 1 -f image2 %s' % (videoName,frameName), shell=True)

Information:

  1. import subprocess: The subprocess module enables you to start new applications from your Python program.

  2. L=subprocess.call(...): Assign the output of the call() method to variable L.

  3. ffmpeg -i %s -r 1 -s qvga -t 1 -f image2 %s' % (videoName,frameName), shell=True: Command to run here ffmpeg

  4. -i %s: input file name gotten from videoName variable --> input file url

  5. -r 1: frame rate.

  6. -s qvga: frame size.

  7. -f image2: Force input or output file format

  8. -t 1: When used as an output option (before an output url), stop writing the output after its duration reaches duration.

  9. % (videoName,frameName): Python string formatting that will replace %s sequences in the previous string with the items in the tuple.

  10. shell=True: Make use of specific shell features like word splitting or parameter expansion

Usage:

#!/usr/bin/env python

import subprocess 
L=subprocess.call('ffmpeg -r 5 -i out.ogv fmprg_%04d.png', shell=True)
L()
  • Make executable: chmod u+x filename.sh,
  • Run with: ./filename.sh

Information:

fmprg_%04d.png: Creates images with 0000, 0001, 0002, 0004, ... between fmprg_ and .png.

Read:

man ffmpeg

https://pythonspot.com/en/tag/subprocess/

Discussions

Help me understand subprocess (vs OS, application is FFmpeg/FFprobe)
Pretty sure ffmpeg outputs to stderr (for god knows what reason). You'll need something more like this: process = subprocess.Popen( ['ffmpeg', '--help'], stderr=subprocess.PIPE, text=True, ) print(process.stderr.read()) (There may be a more elegant way to do it; I've never familiarized myself with subprocess.run.) More on reddit.com
🌐 r/learnpython
4
0
August 13, 2023
ffmpeg python subprocess error only on ubuntu - Stack Overflow
Im working on an application that is splitting videos from youtube into images. I work on a macbook pro for development, but our app servers run on an ubuntu 12.04 server. The current code on our s... More on stackoverflow.com
🌐 stackoverflow.com
April 17, 2017
FFMPEG and Pythons subprocess - Stack Overflow
I'm trying to write a gui for FFMPEG. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conver... More on stackoverflow.com
🌐 stackoverflow.com
Using ffmpeg in a subprocess
I’m using ffprobe from ffmpeg to get information about user-selected image dimensions. I’m doing this inside of a subprocess, but after my deployed app failed to work I realized I need to detect the right Python executable to use. I found this article helpful for better understanding what ... More on discuss.streamlit.io
🌐 discuss.streamlit.io
0
0
December 22, 2022
🌐
Unixmen
unixmen.com › home › uncategorized › hack ffmpeg with python, part two
Hacking FFmpeg With Python, Part Two
So make sure you write it in the python interactive shell as we are going to make use of it. So far we have written some code in our interactive shell. Making use of the function which deals with parsing the information returned from ffprobe is really easy. Before making use of the above function it is needed to spawn a new process as shown below: cmds = ['/usr/local/bin/ffprobe', '-show_format', 'test.mp4'] format_p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
🌐
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")
🌐
Reddit
reddit.com › r/learnpython › help me understand subprocess (vs os, application is ffmpeg/ffprobe)
r/learnpython on Reddit: Help me understand subprocess (vs OS, application is FFmpeg/FFprobe)
August 13, 2023 -

I forgot to save some of my Jupyter notebook last night, so code that is psudo or actual runs will be marked

Some notes/context:

  • Development environment is Windows/Jupyter running whatever latest/stable Python (3.7?, no idea).

  • FFmpeg/FFprobe is open source video processing and querying software that runs on the host machine

  • This task is to ping FFMpeg on the host machine, and store the output as a variable for Python

I have this running using OS no problem (no pseudo, actually runs):

# importing os module 
import os

# Command to execute
cmd = 'ffmpeg -r 24 -i test1.mkv -r 24 -i test2.mkv -lavfi libvmaf="n_threads=20:n_subsample=10" -f null -'

#Using os.system() method
os.system(cmd)

Psudo output:

[Parsed_libvmaf_0 @ 00000148cfab6a80] VMAF score: 96.393400

Great!

But I need to store this as a variable in Python, which I believe is not possible with the OS.System method

But I just can't seem to figure out how to get subprocess to either work, or return the output (actual code):

# importing sibprocess module
import subprocess

# Command to execute
cmd = 'ffmpeg -r 24 -i test.mkv -r 24 -i testsrtlaopus111.mkv -lavfi libvmaf="n_threads=20:n_subsample=10" -f null -'

# Using os.system() method
returned_value = subprocess.check_output(cmd, shell=True)  

# Runs the cmd, returns output 
print('returned value:', returned_value)

Which runs, I can see the ffmpeg command running in terminal, but once the command in terminal finishes processing, the python returns:

returned value: b''

Instead of the desired output:

[Parsed_libvmaf_0 @ 00000148cfab6a80] VMAF score: 96.393400

What am I doing wrong here?

Find elsewhere
🌐
Electric-blue-industries
electric-blue-industries.com › 2020 › 02 › 07 › python環境からffmpegを使う
Python環境からffmpegを使う – Electric Blue Industries Ltd.
import subprocess input_video_name = 'hogehoge.mp4' output_image_name = 'fugafuga'+'d.m4a' command = 'ffmpeg -i '+input_video+' -acodec copy -map 0:1 -vn '+output_audio subprocess.call(command, shell=True)
🌐
Stack Overflow
stackoverflow.com › questions › 43460309 › ffmpeg-python-subprocess-error-only-on-ubuntu
ffmpeg python subprocess error only on ubuntu - Stack Overflow
April 17, 2017 - import subprocess command = "for i in {0..3} ; do ffmpeg -accurate_seek -ss `echo $i*60.0 | bc` -i test.mkv -frames:v 1 images/test_img_$i.jpg ; done" process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr = subprocess.STDOUT, shell=True) output = process.communicate() print output[0].replace('\\n' , '\n') The thing is, when i run this on my OSX terminal, it works fine, but there is some issue with doing it in ubuntu.
🌐
Google Groups
groups.google.com › g › python-tornado › c › 6ExxyBetLoo
Ffmpeg via subprocess api
-------------------------------------------------cmd = ["/usr/bin/ffmpeg", "-threads", "2", "-f", "lavfi", "-i", "anullsrc=r16000:cl=stereo", "-re", "-i", "/dev/video0", "-c:a", "aac", "-strict", "experimental", "-b:a", "128k", "-ar", "44100", "-s", "640x480", "-vcodec", "libx264", "-x264-params", "keyint=120:scenecut=0", "-vb", "200k", "-pix_fmt", "yuv420p", "-f", "flv", "rtmp://a.rtmp.youtube.com/live2/<key>"] self.__streaming_process = Subprocess(cmd, stdout=Subprocess.STREAM) self.__streaming_process.set_exit_callback(self.__ffmpeg_closed) IOLoop.instance().add_timeout(time.time() + 10, self.do_fulfill_stop_streaming) while True: line = await self.__streaming_process.stdout.read_until(b"\n") if not line: self.logger.debug("nothing to show") await asyncio.sleep(.2) else: print(line) pass
🌐
Stack Overflow
devres.zoomquiet.top › data › 20181202005312 › index.html
FFMPEG and Pythons subprocess - Stack Overflow
while 1: print convert.ffmpeg.stdout.readline() print convert.ffmpeg.stderr.readline() Disclaimer: I haven't tested this in Python, but I made a comparable application using Java. ... He is already redirecting stderr to stdout. – Christian Oudard Sep 21 '09 at 17:04 · Gorgapor, are you sure he is? – Matthew Talbert Sep 21 '09 at 17:15 · Yes, the stderr is redirected in the code snippit on the line with subprocess.Popen -- of course it can be cut off if you don't use the scroll bar under the code snippit...
🌐
Gumlet
gumlet.com › learn › ffmpeg-python
How to Use FFmpeg with Python in 2026? - Gumlet
January 22, 2026 - One of the most flexible ways to interact with FFmpeg in Python is by using the subprocess module, which allows you to execute FFmpeg commands as if you were running them in a terminal.
🌐
Superkogito
superkogito.github.io › blog › 2020 › 03 › 19 › ffmpeg_pipe.html
How to pipe an FFmpeg output and pass it to a Python variable?
March 19, 2020 - FFmpeg shell commands can be executed in python with the help of the subprocess package and the resulting output can read from the subprocess pipe.
🌐
Streamlit
discuss.streamlit.io › community cloud
Using ffmpeg in a subprocess - Community Cloud - Streamlit
December 22, 2022 - I’m using ffprobe from ffmpeg to get information about user-selected image dimensions. I’m doing this inside of a subprocess, but after my deployed app failed to work I realized I need to detect the right Python executable to use. I found this article helpful for better understanding what ...
🌐
FFmpeg Python
kkroening.github.io › ffmpeg-python
ffmpeg-python: Python bindings for FFmpeg — ffmpeg-python documentation
Asynchronously invoke ffmpeg for the supplied node graph. ... A subprocess Popen object representing the child process.
🌐
Google Groups
groups.google.com › g › comp.lang.python › c › BHqc-18WIp4
using ffmpeg command line with python's subprocess module
-name '*.wav' -printf "file '%p'\n") -c copy output.wav In bash, the <(...) notation is like piping: it executes the command inside the parentheses and uses that as standard input to ffmpeg. So if you work out what the commands are doing (it looks like they emit a line saying "file '...'" for each .wav file in the current directory, possibly including subdirectories) and replicate that in Python, you should be able to make it cross-platform.
Top answer
1 of 1
2

This works fine on my machine (Win10, Blender 2.79, ffmpeg 3.2):

import bpy
import json
import subprocess

def find_video_metadata(video_path: str) -> (int, int):
    """Find the resolution of the input video file."""

    ffpath = r"C:\cygwin64\home\Sybren\ffmpeg\bin\ffprobe.exe"

    args = [ffpath] + "-v quiet -print_format json -show_streams".split() + [video_path]

    # run the ffprobe process, decode stdout into utf-8 & convert to JSON
    ffout = subprocess.check_output(args).decode('utf-8')
    ffinfo = json.loads(ffout)

    # prints all the metadata available:
    import pprint
    pp = pprint.PrettyPrinter(indent=2)
    pp.pprint(ffinfo)

    # for example, find height and width
    height = ffinfo['streams'][0]['height']
    width = ffinfo['streams'][0]['width']

    print(height, width)
    return height, width

fname = r"A:\RIP\prooi\title03.mkv"
print(find_video_metadata(fname))

I've changed a few things:

  • Not used shlex to parse the string we construct ourselves. Since you didn't quote the filenames containing the space, my bet is that shlex couldn't split it properly. By avoiding this altogether and constructing the argument list explicitly, it just works.
  • Using 'raw' strings using the r"" prefix avoids having to double every backslash.
  • I like using different names for different things. I split the doubly-used ffprobeOutput name into ffout (which is a bytes object) and ffinfo (which is a dict).
  • Not overriding the built-in name file.
  • Using PEP8 for naming (so no camel case for function names and local variable names).
  • I added type declarations to the function.
  • Turned the comment into a docstring, and removed the "function to" bit of it; the "def" keyword already indicates that it's a function, so there is no need to repeat that.
🌐
GitHub
github.com › Ch00k › ffmpy › issues › 34
Cannot read subprocess.PIPE from ffmpeg.run() · Issue #34 · Ch00k/ffmpy
May 11, 2019 - ff = ffmpy.FFmpeg( inputs={'song.mp3': '-y'}, outputs={'converted.wav': '-frames:a 441000 ' '-sample_fmt s16 '} ) ff.run(stdout=subprocess.PIPE) ... with subprocess.Popen(["python", "ffmpy_test.py"], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: for line in p.stdout: logger.info(line)
Published   May 11, 2019
Author   aspen1135
🌐
PyPI
pypi.org › project › better-ffmpeg-progress
better-ffmpeg-progress · PyPI
Create an instance of the FfmpegProcess class and supply a list of arguments like you would to subprocess.run() or subprocess.Popen().
      » pip install better-ffmpeg-progress
    
Published   Apr 19, 2026
Version   4.1.0