原始视频是41秒,每秒30帧,opencv提供了简单的实现来切分视频。

代码:

# !/usr/bin/python3
# -*- coding:utf-8 -*-
# Author:WeiFeng Liu
# @Time: 2021/12/9 上午8:19
import cv2
import glob
import os

def video_to_frame(save_path,video_path):
    # save_path : frame save path
    # video_path : source video path
    # max_index :
    video = cv2.VideoCapture(video_path)
    index = 0
    if video.isOpened():
        rval,frame = video.read()
    else:
        rval = False
    while rval:
        print(index)
        rval,frame = video.read()
        cv2.imwrite(save_path + '/' + str(index)+'.jpg',frame)
        index += 1

if __name__ == "__main__":
    video_to_frame(video_path="video segmentation/cityscapes/fcn_result.mp4",
                    save_path="video_to_frame",
                    )
    print("succeed")
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐