# python-ffmpeg
![Build status](https://github.com/jonghwanhyeon/python-ffmpeg/actions/workflows/wheels.yml/badge.svg)
A python binding for FFmpeg which provides sync and async APIs
## Help
See [documentation](https://python-ffmpeg.readthedocs.io) for more details.
## Install
To install **python-ffmpeg**, simply use pip:
```console
$ pip install python-ffmpeg
```
## Examples
You can find more examples in [the documentation](https://python-ffmpeg.readthedocs.io/).
### Transcoding
#### Synchronous API
```python
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
``` python
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
```python
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
``` python
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())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/jonghwanhyeon/python-ffmpeg",
"name": "python-ffmpeg",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "ffmpeg, asyncio",
"author": "Jonghwan Hyeon",
"author_email": "jonghwanhyeon93@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/dd/4d/7ecffb341d646e016be76e36f5a42cb32f409c9ca21a57b68f067fad3fc7/python_ffmpeg-2.0.12.tar.gz",
"platform": null,
"description": "# python-ffmpeg\n![Build status](https://github.com/jonghwanhyeon/python-ffmpeg/actions/workflows/wheels.yml/badge.svg)\n\nA python binding for FFmpeg which provides sync and async APIs\n\n## Help\nSee [documentation](https://python-ffmpeg.readthedocs.io) for more details.\n\n## Install\nTo install **python-ffmpeg**, simply use pip:\n\n```console\n$ pip install python-ffmpeg\n```\n\n## Examples\nYou can find more examples in [the documentation](https://python-ffmpeg.readthedocs.io/).\n### Transcoding\n#### Synchronous API\n```python\nfrom ffmpeg import FFmpeg\n\n\ndef main():\n ffmpeg = (\n FFmpeg()\n .option(\"y\")\n .input(\"input.mp4\")\n .output(\n \"output.mp4\",\n {\"codec:v\": \"libx264\"},\n vf=\"scale=1280:-1\",\n preset=\"veryslow\",\n crf=24,\n )\n )\n\n ffmpeg.execute()\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n#### Asynchronous API\n``` python\nimport asyncio\n\nfrom ffmpeg.asyncio import FFmpeg\n\n\nasync def main():\n ffmpeg = (\n FFmpeg()\n .option(\"y\")\n .input(\"input.mp4\")\n .output(\n \"output.mp4\",\n {\"codec:v\": \"libx264\"},\n vf=\"scale=1280:-1\",\n preset=\"veryslow\",\n crf=24,\n )\n )\n\n await ffmpeg.execute()\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Recording\n#### Synchronous API\n```python\nfrom ffmpeg import FFmpeg, Progress\n\n\ndef main():\n ffmpeg = (\n FFmpeg()\n .option(\"y\")\n .input(\n \"rtsp://username:password@127.0.0.1/cam\",\n rtsp_transport=\"tcp\",\n rtsp_flags=\"prefer_tcp\",\n )\n .output(\"output.mp4\", vcodec=\"copy\")\n )\n\n @ffmpeg.on(\"progress\")\n def time_to_terminate(progress: Progress):\n if progress.frame > 200:\n ffmpeg.terminate()\n\n ffmpeg.execute()\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n#### Asynchronous API\n``` python\nimport asyncio\n\nfrom ffmpeg import Progress\nfrom ffmpeg.asyncio import FFmpeg\n\n\nasync def main():\n ffmpeg = (\n FFmpeg()\n .option(\"y\")\n .input(\n \"rtsp://username:password@127.0.0.1/cam\",\n rtsp_transport=\"tcp\",\n rtsp_flags=\"prefer_tcp\",\n )\n .output(\"output.mp4\", vcodec=\"copy\")\n )\n\n @ffmpeg.on(\"progress\")\n def time_to_terminate(progress: Progress):\n if progress.frame > 200:\n ffmpeg.terminate()\n\n await ffmpeg.execute()\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A python binding for FFmpeg which provides sync and async APIs",
"version": "2.0.12",
"project_urls": {
"Homepage": "https://github.com/jonghwanhyeon/python-ffmpeg"
},
"split_keywords": [
"ffmpeg",
" asyncio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7f6d02e817aec661defe148cb9eb0c4eca2444846305f625c2243fb9f92a9045",
"md5": "8da1b1492298f09141d4ce3bed06df4b",
"sha256": "d86697da8dfb39335183e336d31baf42fb217468adf5ac97fd743898240faae3"
},
"downloads": -1,
"filename": "python_ffmpeg-2.0.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8da1b1492298f09141d4ce3bed06df4b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 14411,
"upload_time": "2024-04-15T10:15:28",
"upload_time_iso_8601": "2024-04-15T10:15:28.966537Z",
"url": "https://files.pythonhosted.org/packages/7f/6d/02e817aec661defe148cb9eb0c4eca2444846305f625c2243fb9f92a9045/python_ffmpeg-2.0.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dd4d7ecffb341d646e016be76e36f5a42cb32f409c9ca21a57b68f067fad3fc7",
"md5": "15cf4f0b58c784498bfdb7ac8cfc1ed3",
"sha256": "19ac80af5a064a2f53c245af1a909b2d7648ea045500d96d3bcd507b88d43dc7"
},
"downloads": -1,
"filename": "python_ffmpeg-2.0.12.tar.gz",
"has_sig": false,
"md5_digest": "15cf4f0b58c784498bfdb7ac8cfc1ed3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 14126292,
"upload_time": "2024-04-15T10:15:31",
"upload_time_iso_8601": "2024-04-15T10:15:31.878096Z",
"url": "https://files.pythonhosted.org/packages/dd/4d/7ecffb341d646e016be76e36f5a42cb32f409c9ca21a57b68f067fad3fc7/python_ffmpeg-2.0.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-15 10:15:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jonghwanhyeon",
"github_project": "python-ffmpeg",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pyee",
"specs": []
},
{
"name": "typing_extensions",
"specs": []
}
],
"lcname": "python-ffmpeg"
}