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.1.tar.gz
(8.2 kB
view details)
Built Distribution
File details
Details for the file python-ffmpeg-2.0.1.tar.gz
.
File metadata
- Download URL: python-ffmpeg-2.0.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8fcec98bc6b1a4cb523eb119fb74d3e76fa18c7078982234609fdfe29d0e5ac |
|
MD5 | 9527d8f316ef7ed351443a1d6fcb5101 |
|
BLAKE2b-256 | 4f5a26d02d570e9127a7f851720e0eb4b0fae7c080090bba334ac740c45e3f24 |
File details
Details for the file python_ffmpeg-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: python_ffmpeg-2.0.1-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 | 1dba736d14cd00ff936ee30254094e4981aac606389f5efc9afbd2f978cf78bb |
|
MD5 | f3f92dc23083497eeb444b538c45ad5d |
|
BLAKE2b-256 | 448223c66eaa6a05f517094e595dda39ae47df5fd8afa21130a6d91193aafb92 |