Zulko / moviepy

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

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

Open Lucky-Jay opened 1 year ago

Lucky-Jay commented 1 year ago

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

Lucky-Jay commented 1 year ago

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

Lucky-Jay commented 1 year ago

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