1 Star 0 Fork 0

马乙华/harmonyos-oled-player

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
video2bin.py 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
import sys
import cv2 as cv
from oled.img2code import convert_frame_to_bytes
DEFAULT_PORT = 5678
def convert_video_to_bin(videoFile, binFile):
cap = cv.VideoCapture(videoFile)
frameCount = cap.get(cv.CAP_PROP_FRAME_COUNT)
print('frame count:', frameCount)
print('frame width:', cap.get(cv.CAP_PROP_FRAME_WIDTH))
print('frame height:', cap.get(cv.CAP_PROP_FRAME_HEIGHT))
lastPercent = 0
with open(binFile, 'wb+') as f:
while True:
retval, frame = cap.read()
if not retval:
print('video done!')
break
bitmap = convert_frame_to_bytes(frame)
f.write(bitmap)
pos = cap.get(cv.CAP_PROP_POS_FRAMES)
percent = pos / frameCount * 100
if percent - lastPercent >= 1:
lastPercent = percent
sys.stdout.write('=')
sys.stdout.flush()
print('convert all frames done!')
cap.release()
def main():
if len(sys.argv) < 3:
print("Usage: {} videoFile binFile\n\t".format(sys.argv[0]))
exit(-1)
try:
videoFile = sys.argv[1]
binFile = sys.argv[2]
convert_video_to_bin(videoFile, binFile)
except Exception as e:
print('exception raised:', e)
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mayihua/harmonyos-oled-player.git
git@gitee.com:mayihua/harmonyos-oled-player.git
mayihua
harmonyos-oled-player
harmonyos-oled-player
main

搜索帮助