Kanav Raina
Kanav Raina

Reputation: 43

Load video from url in moviepy and save frame

from moviepy.editor import *

clip = ( VideoFileClip("https://filelink/file.mp4"))

clip.save_frame("frame.png", t = 3)

I am able to load video using moviepy but its loading complete video and then saving the frame. Is it possible not to load the complete video but only first four second and then save the frame at 3 second.

Upvotes: 0

Views: 2755

Answers (1)

Rotem
Rotem

Reputation: 32144

Unless I missed something, it's not possible using MoviePy.
You may use ffmpeg-python instead.

Here is a code sample using ffmpeg-python:

import ffmpeg

stream_url = "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"

# Input seeking example: https://trac.ffmpeg.org/wiki/Seeking
(
    ffmpeg
    .input(stream_url, ss='00:00:03')  # Seek to third second
    .output("frame.png", pix_fmt='rgb24', frames='1')  # Select PNG codec in RGB color space and one frame.
    .overwrite_output()
    .run()
)

Notes:

  • The solution may not work for all mp4 URL files, because mp4 format is not so "WEB friendly" - I think the moov atom must be located at the beginning of the file.
  • You may need to manually install FFmpeg command line tool (but it supposed to be installed with MoviePy).

Result frame:
enter image description here

Upvotes: 1

Related Questions