Ffmpeg-python: How can you pipe the output to ffplay?

Created on 16 Apr 2019  路  3Comments  路  Source: kkroening/ffmpeg-python

Is there a way to pipe the output live to ffplay so it can be viewed immediately?

answered example question

Most helpful comment

One way is to run the ffmpeg process with raw video output over a pipe, and then have ffplay decode the raw video. Something like this:

import ffmpeg
import subprocess

in_filename = 'in.mp4'
width, height = 1920, 1080  # (or use ffprobe or whatever)

process1 = (
    ffmpeg
    .input(in_filename)
    # (filters/etc. go here)
    .output('pipe:', format='rawvideo', pix_fmt='rgb24')
    .run_async(pipe_stdout=True)
)
process2 = subprocess.Popen(
    [
        'ffplay',
        '-f', 'rawvideo',
        '-pix_fmt', 'rgb24',
        '-s', '{}x{}'.format(width, height),
        '-i', 'pipe:',
    ],
    stdin=process1.stdout,
)
process1.wait()
process2.wait()

FYI there's no direct support for ffplay in ffmpeg-python currently.

All 3 comments

One way is to run the ffmpeg process with raw video output over a pipe, and then have ffplay decode the raw video. Something like this:

import ffmpeg
import subprocess

in_filename = 'in.mp4'
width, height = 1920, 1080  # (or use ffprobe or whatever)

process1 = (
    ffmpeg
    .input(in_filename)
    # (filters/etc. go here)
    .output('pipe:', format='rawvideo', pix_fmt='rgb24')
    .run_async(pipe_stdout=True)
)
process2 = subprocess.Popen(
    [
        'ffplay',
        '-f', 'rawvideo',
        '-pix_fmt', 'rgb24',
        '-s', '{}x{}'.format(width, height),
        '-i', 'pipe:',
    ],
    stdin=process1.stdout,
)
process1.wait()
process2.wait()

FYI there's no direct support for ffplay in ffmpeg-python currently.

@kkroening thanks so much for this! I wanted to ask a question related to the code above:

If I implement any kind of filtering in the section you marked with: # (filters/etc. go here) I seem to be unable to live affect the args given to the filters. So if for example blur the image by calling:

.filter('gblur', sigma=blurIndex)

and I try to increment blur index in time only the first value seems to affect the video. Do you know if it's even possible to affect the filter parameters live?

Do you know if it's even possible to affect the filter parameters live?

There is no way that I know of to change ffmpeg filter graphs dynamically.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

znorris picture znorris  路  4Comments

monokal picture monokal  路  3Comments

Baa14453 picture Baa14453  路  5Comments

CNugteren picture CNugteren  路  5Comments

lalamax3d picture lalamax3d  路  3Comments