6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

moviepyによる動画変換処理 with ndarray

Last updated at Posted at 2017-12-28

動画を処理するためのtipsです。

moviepyのインストールは

pip install moviepy

と簡単です。

VideoFileClipクラスのメソッドfl_imageにコールバック関数をセットします。
このコールバック関数は、各フレームの画像を'(Height, Width, Channel)'のndarrayとして受け取り、同様の形式のndarrayを返すことで動画を変換できます。便利ですね。

下記は、各ピクセル0〜255で表現されているndarrayを反転させることで色の反転を行った例です。

from moviepy.editor import VideoFileClip

def func(frame):
    """
    :param frame: (H, W, Channel) [ndarray]
    :return: (H, W, Channel) [ndarray]
    """
    return -frame + 255 # 色を反転

inpout_video = "test_input.mp4"
output_video = 'test_output.mp4'

clip1 = VideoFileClip(inpout_video)
project_clip = clip1.fl_image(func)

project_clip.write_videofile(output_video, audio=True)
6
3
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
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?