Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
45 views

Python Ffmpeg

Uploaded by

Sathi Natarajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Python Ffmpeg

Uploaded by

Sathi Natarajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

7/8/24, 11:22 PM python-ffmpeg

Overview

python-ffmpeg is a python binding for FFmpeg which provides sync and async APIs.

Install
To install python-ffmpeg, simply use pip:

$ pip install python-ffmpeg

Examples
Transcoding

Synchronous API

from ffmpeg import FFmpeg

def main():
ffmpeg = (
FFmpeg()
.option("y")
.input("input.mp4")
.output(
"output.mp4",
{"codec:v": "libx264"},
vf="scale=1280:-1",
preset="veryslow",
crf=24,
)
)

ffmpeg.execute()

if __name__ == "__main__":
main()

Asynchronous API

https://python-ffmpeg.readthedocs.io/en/latest/ 1/3
7/8/24, 11:22 PM python-ffmpeg

import asyncio

from ffmpeg.asyncio import FFmpeg

async def main():


ffmpeg = (
FFmpeg()
.option("y")
.input("input.mp4")
.output(
"output.mp4",
{"codec:v": "libx264"},
vf="scale=1280:-1",
preset="veryslow",
crf=24,
)
)

await ffmpeg.execute()

if __name__ == "__main__":
asyncio.run(main())

Recording

Synchronous API

from ffmpeg import FFmpeg, Progress

def main():
ffmpeg = (
FFmpeg()
.option("y")
.input(
"rtsp://username:password@127.0.0.1/cam",
rtsp_transport="tcp",
rtsp_flags="prefer_tcp",
)
.output("output.mp4", vcodec="copy")
)

@ffmpeg.on("progress")
def time_to_terminate(progress: Progress):
if progress.frame > 200:
ffmpeg.terminate()

ffmpeg.execute()

https://python-ffmpeg.readthedocs.io/en/latest/ 2/3
7/8/24, 11:22 PM python-ffmpeg

if __name__ == "__main__":
main()

Asynchronous API

import asyncio

from ffmpeg import Progress


from ffmpeg.asyncio import FFmpeg

async def main():


ffmpeg = (
FFmpeg()
.option("y")
.input(
"rtsp://username:password@127.0.0.1/cam",
rtsp_transport="tcp",
rtsp_flags="prefer_tcp",
)
.output("output.mp4", vcodec="copy")
)

@ffmpeg.on("progress")
def time_to_terminate(progress: Progress):
if progress.frame > 200:
ffmpeg.terminate()

await ffmpeg.execute()

if __name__ == "__main__":
asyncio.run(main())

https://python-ffmpeg.readthedocs.io/en/latest/ 3/3

You might also like