No project description provided
Project description
FFMPEGCV is an alternative to OPENCV for video read and write.
The ffmpegcv provide faster and powerful VideoCapture and VideoWriter to cv2 in python.
- The ffmpegcv is api compatible to open-cv
- The ffmpegcv can use GPU accelerate encoding and decoding.
- The ffmpegcv support much more video codecs v.s. open-cv.
- The ffmpegcv support RGB & BGR format as you like.
- The ffmpegcv can resize video to specific size with/without padding.
In all, ffmpegcv is just similar to opencv api. But is faster and with more codecs.
Video Reader
The ffmpegcv is just similar to opencv in api.
# open cv
cap = cv2.VideoCapture(file)
while True:
ret, frame = cap.read()
if not ret:
break
pass
# ffmpegcv
cap = ffmpegcv.VideoCapture(file)
while True:
ret, frame = cap.read()
if not ret:
break
pass
# alternative, recommand
cap = ffmpegcv.VideoCapture(file)
nframe = len(cap)
for frame in cap:
pass
Use GPU to accelerate decoding. It depends on the video codes. h264_nvcuvid, hevc_nvcuvid ....
cap_cpu = ffmpegcv.VideoCapture(file, codec='h264')
cap_gpu = ffmpegcv.VideoCapture(file, codec='h264_cuvid')
Use rgb24 instead of bgr24
cap = ffmpegcv.VideoCapture(file, pix_fmt='rgb24')
ret, frame = cap.read()
plt.imshow(frame)
Resize the video to the given size
cap = ffmpegcv.VideoCapture(file, resize=(640, 480))
Resize and keep the aspect ratio with black border padding.
cap = ffmpegcv.VideoCapture(file, resize=(640, 480), resize_keepratio=True)
Video Writer
# cv2
out = cv2.VideoWriter('outpy.avi',
cv2.VideoWriter_fourcc('M','J','P','G'),
10,
(w, h))
out.write(frame1)
out.write(frame2)
out.release()
# ffmpegcv
out = ffmpegcv.VideoWriter('outpy.avi', None, 10, (w, h))
out.write(frame1)
out.write(frame2)
out.release()
Use GPU to accelerate encoding. Such as h264_nvenc, hevc_nvenc.
out_cpu = ffmpegcv.VideoWriter('outpy.avi', None, 10, (w, h))
out_gpu = ffmpegcv.VideoWriter('outpy.avi', 'h264_nvenc', 10, (w, h))
Use rgb24 instead of bgr24
out = ffmpegcv.VideoWriter('outpy.avi', None, 10, (w, h), pix_fmt='rgb24')
out.write(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
Video Reader and Writer
vfile_in = 'A.mp4'
vfile_out = 'A_h264.mp4'
vidin = ffmpegcv.VideoCapture(vfile_in)
w, h = vidin.width, vidin.height
vidout = ffmpegcv.VideoWriter(vfile_out, 'h264_nvenc', vidin.fps, (w, h))
for frame in vidin:
vidout.write(frame)
vidin.release()
vidout.release()
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
ffmpegcv-0.1.1.tar.gz
(3.8 kB
view details)
File details
Details for the file ffmpegcv-0.1.1.tar.gz
.
File metadata
- Download URL: ffmpegcv-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f6c2ef4a504eaf5449956d1f315c926d2b94869a1947a98412c91f45b3fcc75 |
|
MD5 | abe0769f051b96f5b6a7cc792d65591c |
|
BLAKE2b-256 | 2596fc54df90e1ee706e09885e82d45a6628e34b65b1013d47b4ed5a94658025 |