Last active
May 21, 2020 20:24
-
-
Save Felk/975c096083e8434a8b5823173f8b22fb to your computer and use it in GitHub Desktop.
example of lightweight ffmpeg wrapper in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline = ffmpeg.Pipeline() | |
silence, = pipeline.input(Filter("aevalsrc", 0, 1, filter_options=[ # using anullsrc corrupts the audio | |
"0", "channel_layout=stereo", "sample_rate=44100" | |
])) | |
color, = pipeline.input(Filter("color", 0, 1, filter_options=[ | |
"color=0x009999", | |
"duration=" + str(duration), | |
"rate=" + str(config.framerate), | |
"size=1920x1080", | |
])) | |
disclaimer_v, = pipeline.filter_pipeline(filters=[ | |
Scale(width=config.resolution_width, height=config.resolution_height), | |
Drawtext(textfile_path=config.disclaimer_textfile, fontfile_path=config.fontfile), | |
], in_labels=[color]) | |
disclaimer_a, = pipeline.filter(ATrim(duration=duration), in_labels=[silence]) | |
pipeline.map(disclaimer_v, disclaimer_a) | |
result = pipeline.run( | |
filepath, | |
output_args=["-t", str(duration)] + ffmpeg.get_output_args(config), | |
timeout=timedelta(seconds=20).total_seconds() | |
) | |
if result.returncode != 0: | |
raise RuntimeError("Failed to render disclaimer. ffmpeg output: {}".format(result.stderr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment