FFmpegWrapper

FFmpegWrapper is a small wrapper for the ffmpeg encoder. You can append Codec, Filters and other OptionStores to the FFmpeg class and then run the resulting command.

>>> from ffmpegwrapper import FFmpeg, Input, Output, VideoCodec, VideoFilter
>>> videofilter = VideoFilter().crop(300, 200)
>>> codec = VideoCodec('webm')
>>> input_video = Input('old')
>>> output_video = Output('new', videofilter, codec)
>>> FFmpeg('ffmpeg', input_video, output_video)
<FFmpeg ['ffmpeg', '-i', 'old', '-vf', 'crop=300:200', '-vcodec', 'webm', 'new']>

Stores and Options

There are two kinds of classes in FFmpegwrapper. The Stores and Options. A Store is a object where you can append an Option or even Stores which then have their own Options. A Option represent one or more arguments for FFmpeg. A Store is more likea bigger block of Options for a specific need. For example: Everything that describe the Output can be appended to the Output class.

API

class ffmpegwrapper.FFmpeg(binary='ffmpeg', *args)

This class represent the FFmpeg command.

It behaves like a list. If you iterate over the object it will yield small parts from the ffmpeg command with it arguments. The arguments for the command are in the Option classes. They can be appended directly or through one or more Stores.

Parameters:
  • binary – The binary subprocess should execute at the run()
  • args – A list of Stores that should be appended
run()

Executes the command of this object. Return a FFmpegProcess object which have already the FFmpegProcess.run() invoked.

Returns:FFmpegProcess object with run() invoked
class ffmpegwrapper.ffmpeg.FFmpegProcess(command)

Class to exectute FFmpeg.

Parameters:command – a sequence of the binary and it arguments
readlines(keepends=False)

Yield lines from the queue that were collected from the command. You can specify if you want to keep newlines at the ends. Default is to drop them.

Parameters:keepends – keep the newlines at the end. Default=False
run(daemon=True)

Executes the command. A thread will be started to collect the outputs (stderr and stdout) from that command. The outputs will be written to the queue.

Returns:self

Input/Output

class ffmpegwrapper.Input(file, *args)

Store for a input file.

Parameters:
  • file – Path to the input file
  • args – A list of Stores that should be appended
class ffmpegwrapper.Output(file, *args)

Store for a output file.

Parameters:
  • file – Path in which the file should be saved
  • args – A list of Stores that should be appended
overwrite()

Overwrite the file if it already exist

Codecs

class ffmpegwrapper.VideoCodec(name, *args)

This represent an video codec.

You can append this class to an Output object to tell which FFmpeg which codec you want.

aspect(x, y)
bitrate(bitrate)
bitrate_tolerance(tolerance)
buffer_size(size)
fps(fps)
frames(number)
language(lang)
max_bitrate(rate)
min_bitrate(rate)
pass_number(number)
preset(preset)
same_quality()
size(x, y)
class ffmpegwrapper.AudioCodec(name, *args)

This represent an audio codec.

You can append this class to an Output object to tell which FFmpeg which codec you want.

bitrate(rate)
channels(number)
frames(number)
frequence(freq)
language(lang)
preset(preset)

Load default presets from a preset file

quality(number)

Filters

class ffmpegwrapper.VideoFilter(*args)

FilterStore for Videofilters.

See also

FFmpeg documentation, Videofilter
Documentation of all filters and which effect they have.
blackframe(amount, threshold)
copy()
crop(out_w, out_h=None, x=None, y=None)
cropdetect(limit=None, round=None, reset=None)
drawbox(x, y, width, height, color)
drawtext(**kwargs)
fade(type, start, number)
fieldorder(type)
fifo()
format(*args)
freior(name, *args)
gradfun(strength='', radius='')
hflip()
hqdn3d(luma_sp=None, chroma_sp=None, luma_tmp=None, chroma_tmp=None)
mp(**kwargs)
negate()
noformat(*args)
null()
overlay(x, y)
pad(width, height, x, y, color)
scale(width=-1, height=-1)
select(expression)
setdar(x, y)
setpts(expression)
setsar(x, y)
slicify(height=16)
transpose(type)
unsharp(*args)
vflip()
yadif(mode=0, parity=-1)
class ffmpegwrapper.AudioFilter(*args)

FilterStore for Audifilters.

See also

FFmpeg documentation, Audiofilter
Documentation of all filters and which effect they have.
null()

does nothing

Stores and Options

class ffmpegwrapper.options.Option(*args, **kwargs)
class ffmpegwrapper.options.OptionStore(*args)

License

Table Of Contents

This Page