moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

Why did the length of my video change after reading and writing directly

Open Lucky-Jay opened this issue 2 years ago • 2 comments

Expected Behavior

I want to stitch multiple videos into one video, but I found that the audio of the video after stitching is not what I expected, and after I debugged it I found that it is the video duration and frame rate that changed after reading. This confused me because I did not do any manipulation. The output I want should be of the same duration and frame rate.

Actual Behavior

The length of the video has changed, the output length is 5.78 and 5.83. The frame rate has also changed, one is 174 and one is 175.

Steps to Reproduce the Problem

Just run the code and see the output

from moviepy.editor import *

video = VideoFileClip('temp.mp4')
video.write_videofile('result.mp4')
video2 = VideoFileClip('result.mp4')

print(video.reader.nframes, video2.reader.nframes)
print(video.duration, video2.duration)

Specifications

  • Python Version:3.9.13
  • MoviePy Version:1.0.3
  • Platform Name:Windows11
  • Platform Version:22H2

Lucky-Jay avatar Jun 22 '23 07:06 Lucky-Jay

The uploaded video is the temp.mp4 in the code.

Lucky-Jay avatar Jun 22 '23 07:06 Lucky-Jay

And when I use opencv's videoCapture to read the video, I find that the frame rate is different from the frame rate displayed by moviepy.

Here is the code:

import cv2

cap1=cv2.VideoCapture('temp.mp4')
cap2=cv2.VideoCapture('result.mp4')

print(cap1.get(cv2.CAP_PROP_FRAME_COUNT), cap2.get(cv2.CAP_PROP_FRAME_COUNT))

The output is: 169.0 174.0

Lucky-Jay avatar Jun 22 '23 07:06 Lucky-Jay