A python binding for FFmpeg which provides sync and async APIs
Project description
python-ffmpeg
A python binding for FFmpeg which provides sync and async APIs
Help
See documentation for more details.
Install
To install python-ffmpeg, simply use pip:
$ pip install python-ffmpeg
Examples
You can find more examples in the documentation.
Transcoding
Synchronous API
from ffmpeg import FFmpeg, Progress
def main():
ffmpeg = (
FFmpeg()
.option("y")
.input("input.mp4")
.output(
"ouptut.mp4",
{"codec:v": "libx264"},
vf="scale=1280:-1",
preset="veryslow",
crf=24,
)
)
ffmpeg.execute()
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("input.mp4")
.output(
"ouptut.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()
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())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-ffmpeg-2.0.3.tar.gz
(9.5 kB
view details)
Built Distribution
File details
Details for the file python-ffmpeg-2.0.3.tar.gz
.
File metadata
- Download URL: python-ffmpeg-2.0.3.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a3d23a0aa549b531b7cb3dbbfafde072f199a358a556860cd1efb117ebe7930 |
|
MD5 | c6a89d17a2910f49a4630cd1a2807b4b |
|
BLAKE2b-256 | 4b3ab897a22a097dceef8866b1cb6eeef133b35e191737e74dfe3968a730ec93 |
File details
Details for the file python_ffmpeg-2.0.3-py3-none-any.whl
.
File metadata
- Download URL: python_ffmpeg-2.0.3-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ab2407a3204963db73c1666c8865ab3b841023662f98886011ec5732fe86680 |
|
MD5 | 6e7175fe0c75969281be9435f91e737c |
|
BLAKE2b-256 | 02d610fa6f94a3082a40687e476cc7c12fd8d3c573fd7379098ead2c50891090 |