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)

如果您觉得对您有帮助,可以请站长喝一杯咖啡哦!

支付宝或者微信扫描二维码

对站长进行赞助

支付宝扫一扫

微信扫一扫

金额随意,礼清义重

当前分类随机文章推荐

全站随机文章推荐

关于本站站长 StubbornHuang
opencv-python – 读取视频,不改变视频分辨率修改视频帧率-StubbornHuang Blog纵使晴明无雨色,入云深处亦沾衣。