Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.55k stars 1.57k forks source link

MoviePy error: failed to display the last frame of VideoFileClip #1513

Open seanc1505 opened 3 years ago

seanc1505 commented 3 years ago

Expected Behavior

Building a video editor using tkinter and moviepy

User enters the end time of the subclip the frame at the specified time of the source clip is displayed. if user does not specify a time, the duration of the source clip is used.

Actual Behavior

If the does not specify the end time, the duration of the source video is used. which leads to the error:

File "c:/Users/...gui_basics.py", line 292, in on_create_subclip_button end_frame_image_array = source_video.get_frame((end_time))

OSError: MoviePy error: failed to read the first frame of video file C:/Users/.../sample_video_clip.mp4. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.

Steps to Reproduce the Problem

When testing this i used a clip that was 56.11 seconds long. (tested on other .mp4 of varying length also) I entered the end time as 45 seconds and the end frame displays as desired this Continues up to 56.038 if the end time is set to 56.039 the error is displayed and no image is displayed.

The Stack Overflow question may give some more detail on this bug. Suggested by another user to raise this bug.

import tkinter as tk
from tkinter.constants import END, NE
from tkinter import filedialog
from typing import Text
from datetime import date, datetime
from PIL import ImageTk, Image  
from moviepy.editor import *
import math

end_time = 0 
source_video = VideoFileClip("sample_video_clip.mp4")
end_time_entry_sec = tk.Text(end_time_frame,width=3,height=1)
end_time_entry_sec.insert("1.0","0")
time_entry_button = tk.Button(time_entry_frame, text="Calculate time", command=on_time_entry_button)
create_subclip_button= tk.Button(time_entry_frame, text="Create subclip", command=on_create_subclip_button)

def on_time_entry_button():
     end_time = float(end_time_entry_sec.get('1.0',"end-1c"))
     if end_time == "0":
              end_time = source_video.duration

def on_create_subclip_button():
            end_frame_image_array = self.source_video.get_frame(end_time)
            end_frame_image_location = Image.fromarray(end_frame_image_array)
            end_frame_image_resized = end_frame_image_location.resize((150,100))
            end_frame_image = ImageTk.PhotoImage(end_frame_image_resized)
            end_frame_label.config(image=end_frame_image)
            end_frame_label.image = end_frame_image

Specifications

My first time logging a github bug. Please advise if edits/more info are needed.

seanc1505 commented 3 years ago

Repeated this with a clip of length 1778.82 seconds.

The frame is displayed if end_time is <=1778.725 seconds. The frame is not displayed if end_time is set to 1778.75 seconds

tburrows13 commented 3 years ago

You could try with v2.0.0.dev2 or the current master branch.

seanc1505 commented 3 years ago

Successfully installed moviepy-2.0.0.dev2 numpy-1.20.0

What wasn't highlighted in the above post was that the user also sets the start time of the subclip (wasn't relevant to the issue i thought). And this is displayed also

Using v2.0.0.dev2 build.

The end frame is still displayed up until 56.038.

When end time is set to 56.04 the end frame displayed is the same frame as the one displayed for the start frame and the following error is highlighted

C:\Users...\io\ffmpeg_reader.py:165: UserWarning: In file C:/Users/.../sample_video_clip.mp4, 6220800 bytes wanted but 0 bytes read at frame index 3359 (out of a total 3363 frames), at time 56.04/56.11 sec. Using the last valid frame instead. UserWarning,

keikoro commented 2 years ago

@seanc1505 The above sounds like instructions or (future) docs could be improved. If you have suggestions/would submit a PR, that'd be great.

Also, if you could update your comment using proper formatting (so code, output, regular text can be differentiated), that'd be helpful.