opencv-python – 读取视频,不改变视频分辨率修改视频帧率
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:opencv-python – 读取视频,不改变视频分辨率修改视频帧率
原文链接:https://www.stubbornhuang.com/513/
发布于:2019年12月11日 17:11:21
修改于:2020年01月03日 9:05:24
1 代码
modify_video_frame_rate.py
import os
import cv2
# 修改视频帧率为指定帧率,分辨率保持不变
def modify_video_frame_rate(videoPath,destFps):
dir_name = os.path.dirname(videoPath)
basename = os.path.basename(videoPath)
video_name = basename[:basename.rfind('.')]
video_name = video_name + "moify_fps_rate"
resultVideoPath = f'{dir_name}/{video_name}.mp4'
videoCapture = cv2.VideoCapture(videoPath)
fps = videoCapture.get(cv2.CAP_PROP_FPS)
if fps != destFps:
frameSize = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
#这里的VideoWriter_fourcc需要多测试,如果编码器不对则会提示报错,根据报错信息修改编码器即可
videoWriter = cv2.VideoWriter(resultVideoPath,cv2.VideoWriter_fourcc('m','p','4','v'),destFps,frameSize)
i = 0;
while True:
success,frame = videoCapture.read()
if success:
i+=1
print('转换到第%d帧' % i)
videoWriter.write(frame)
else:
print('帧率转换结束')
break
if __name__ == '__main__':
modify_video_frame_rate('test.mp4',50)
当前分类随机文章推荐
- Python - 使用jsonpickle库对Python类对象进行json序列化和json反序列化操作 阅读3314次,点赞0次
- Python - 使用scikit-video库获取视频的旋转角度并使用opencv_python根据旋转角度对视频进行旋转复原 阅读3139次,点赞1次
- Python - 获取当前时间字符串 阅读1068次,点赞0次
- Python - 安装onnxruntime-gpu出现ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '...\\numpy-1.23.1.dist-info\\METADATA' 阅读419次,点赞0次
- Python:UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 12305,以及中文乱码的解决方案 阅读3140次,点赞0次
- Python - 使用websockets库构建websocket服务器 阅读1687次,点赞0次
- Python - 不依赖第三方库对类对象进行json序列化与反序列化 阅读1427次,点赞0次
- Python3爬虫 - requests的请求响应状态码(requests.status_code) 阅读9237次,点赞4次
- Python - 写爬虫时需要用到那些第三方库 阅读481次,点赞0次
- Python - 在子线程中使用OpenCV异步读取摄像头视频帧传递到主线程中进行处理 阅读1295次,点赞1次
全站随机文章推荐
- 我的Windows装机必备软件备忘 阅读330次,点赞0次
- 资源分享 - Speech and Language Processing - An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition , Third Edition draft 英文高清PDF下载 阅读657次,点赞0次
- 资源分享 - OpenGL Insights 英文高清PDF下载 阅读2712次,点赞0次
- C++ - 在两个互有依赖关系的类中使用std::shared_ptr和std::weak_ptr进行内存管理 阅读737次,点赞0次
- 资源分享 - Physically Based Rendering From Theory To Implementation (Second Edition)英文高清PDF下载 阅读2800次,点赞2次
- WordPress - wp_mail发送邮件失败,使用插件或者纯代码方式添加SMTP邮件发送功能 阅读1183次,点赞0次
- FFmpeg - 常用的视频像素格式以及使用SwsContext和sws_scale进行视频像素格式转换和视频缩放 阅读944次,点赞0次
- 资源分享 - Foundations of Physically Based Modeling and Animation 英文PDF下载 阅读3752次,点赞0次
- 资源分享 - Computer Graphics Through OpenGL - From Theory to Experiments (Second Edition)英文高清PDF下载 阅读2238次,点赞0次
- TensorRT - 使用torch普通算子组合替代torch.einsum爱因斯坦求和约定算子的一般性方法 阅读2896次,点赞1次
评论
169