https://github.com/natlee/ffmpeg-video-writter-with-python
This is a video writter used to write video with FRENDLY ffmpeg.
https://github.com/natlee/ffmpeg-video-writter-with-python
ffmpeg image-processing opencv python video-processing videowriter
Last synced: about 2 months ago
JSON representation
This is a video writter used to write video with FRENDLY ffmpeg.
- Host: GitHub
- URL: https://github.com/natlee/ffmpeg-video-writter-with-python
- Owner: NatLee
- License: mit
- Created: 2020-01-31T10:21:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-03T03:20:21.000Z (over 6 years ago)
- Last Synced: 2025-07-13T02:41:53.365Z (12 months ago)
- Topics: ffmpeg, image-processing, opencv, python, video-processing, videowriter
- Language: Python
- Size: 10.9 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FFmpeg Video Writter with Python
[](./LICENSE) [](https://www.python.org/)
## Introduction
As title, this is a video writter used to write video with **friendly** ffmpeg.
I'm angry with the fucking OpenCV because the video writter always saves only **6KB** video header instead of saving videos.
> I found the reason is that the video writter in OpenCV dose **NOT** check the shape of frame when writting into a file and it does **NOT** give any errors and warnings. In short, if the size is different from the original setting of video writter, it will **NOT** write any frames.
## Requirements
- ffmpeg-python
- opencv-python
- numpy
> OpenCV is optional and it's only used in the demo.
## Usage
### Quick Start
```python
import cv2
from FFmpegVideoWritter import FFmpegVideoWritter
ffvw = FFmpegVideoWritter('./data/test.mp4', './result/result.mp4')
while True:
frame = ffvw.get_frame()
if frame is not None:
out_frame = cv2.resize(frame, None, fx=0.5, fy=0.5)
cv2.imshow('frame', cv2.cvtColor(out_frame, cv2.COLOR_BGR2RGB))
cv2.waitKey(1)
ffvw.write(out_frame)
else:
break
ffvw.close()
# You can get gif output!
ffvw.output_to_gif('./result/test.gif')
```
### Demo
You can run the DEMO with the following command.
```
python main.py
```
## Results
Drawing ramdomly rectangles from original video in `main.py`.
