LoginSignup
2
1

More than 1 year has passed since last update.

画像から動画を生成 OpenCV

Last updated at Posted at 2023-02-02
import sys
import cv2
import os

video_dir = "videos"
video_list = os.listdir(video_dir)

codec = cv2.VideoWriter_fourcc(*'mp4v')
# video = cv2.VideoWriter(filepath, codec, CLIP_FPS, (w, h))
# encoder(for mp4)
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
# output file name, encoder, fps, size(fit to image size)
out_file_name = 'video.mp4'
video = cv2.VideoWriter(out_file_name,fourcc, 20.0, (1280, 720))


for frame in video_list:
    # hoge0000.png, hoge0001.png,..., hoge0090.png
    img = cv2.imread(os.path.join(video_dir,frame))

    # can't read image, escape
    if img is None:
        print("can't read")
        break

    # add
    video.write(img)

video.release()
print('written')

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

機械学習、ARアプリ(Web/iOS)を作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium
GitHub

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1