Quick Start

System requirements

Obviously, to work with FFMPEG you need to install it. In Ubuntu-20.04 this is:

apt-get install ffmpeg

You may also need MediaInfo to get information about video and audio streams in your files. But this is not required.

apt-get install mediainfo

Python requirements

Install fffw from PyPI:

pip install fffw

Write your first command

from fffw.encoding import *

# initialize ffmpeg wrapper with common flags
ff = FFMPEG(overwrite=True, loglevel='level+info')

# add an input file
ff < input_file('input.mp4', duration=5.0)

# scale video stream
scale = ff.video | Scale(width=1280, height=720)

# initialize an output file
output = output_file('output.mp4',
                     VideoCodec('libx264'),
                     AudioCodec('aac'))

# point scaled video stream to output file
scale > output

# tell ffmpeg about output file
ff > output

# check what we've configured
print(ff.get_cmd())

# run it
return_code, output, errors = ff.run()
if return_code != 0:
    print(output, errors)

This will print something like this (unless you really have input.mp4):

ffmpeg -loglevel level+info -y -t 5.0 -i input.mp4
-filter_complex "[0:v]scale=w=1280:h=720[vout0]"
-map "[vout0]" -c:v libx264 -map 0:a -c:a aac output.mp4
[error] input.mp4: No such file or directory

That’s all. You just opened input file, passed video stream to scale filter and then encoded results with libx264 and aac codecs to an output file.