[Python] UserWarning: x bytes wanted but 0 bytes read at frame index y (out of a total z...

Discussão em 'Python' iniciado por Stack, Julho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have a script which subclips a larger video and then stitches needed parts together using concatenate and write video file in moviepy. But the problem is everytime i run the script i get the video but the audio is off sync, usually the audio starts normally, but over time becomes delayed. I suspect it is because i want to concatenate around 220 smaller mp4 videos into one big mp4 video, but every smaller clips receives the error:'UserWarning: In file test.mp4, 1555200 bytes wanted but 0 bytes read at frame index y (out of a total y+1 frames), at time x sec. Using the last valid frame instead.'

    I use moviepy v2

    MY CODE (it doesnt produce any strict errors, but does give the aformentioned UserWarning when writing video_unsilenced.mp4):

    n = 0

    cuts = []
    input_paths = []
    vc = []
    os.makedirs(r"ShortsBot\SUBCLIPS")
    for timer in range(len(startsilence)-1):
    w = VideoFileClip(r"ShortsBot\output\cropped_video.mp4").subclipped(endsilence[n],(startsilence[n+1]+0.5))
    w.write_videofile(r"ShortsBot\SUBCLIPS\video" + str(n) + ".mp4")
    a = VideoFileClip(r"ShortsBot\SUBCLIPS\video" + str(n) + ".mp4")
    vc.append(a)
    n+=1

    output_fname = "video_unsilenced.mp4"
    clip = mpy.concatenate_videoclips(clips=vc, method= 'compose')
    clip.write_videofile(filename=output_fname, fps=30)
    _ = [a.close() for a in vc]


    Because moviepy is shaving off a frame or two for every video clip and at the same time writing the audio of the concatenated clip normally (without shaving off the audio that is in the missing frames), the video and audio slowly become out of sync.And the more clips i want to concatenate, the more the audio becomes out of sync, basically confirming my suspicion that it is because moviepy is using the last valid frame and writing the audio normally. The question i have is how can i fix this? Ive looked for similar questions, but havent found the exact answer i was looking for. Sorry if this is something basic, im a beginner programmer in python and would really appreciate some tips or some sort of fix. Thanks everyone!

    Continue reading...

Compartilhe esta Página