[Python] Long video files are shortened when exported

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on videos with a maximal length of 23h59m59s (let's say 24h). I wanted to do several modifications on these videos, including dividing them into smaller parts and converting them into images. I'm doing it with Python in the Anaconda interface.

    My 24-hour videos are properly read by the Windows "Films & TV" player. They are also properly read by VLC media player. However, as soon as I try to use them:

    • in editing software (Movavi);
    • on an online editing site (Video-cutter);
    • on Python (cv2 and moviepy packages); or
    • on ffmpeg

    the indicated video duration is correct only if the video is less than 13h15m22s. If it is longer than that, the indicated duration is equal to the real duration minus 13h15m22s, regardless of the loaded video's metadata (size, weight, fps, duration).

    I have tried with videos of different durations, different pixel sizes and weights in GB, and different fps. I had variable fps mode on the videos, so I tried to set them to fixed mode using ffmpeg, but the exported video with fixed fps still has 13h15m22s missing. For videos taken from the web (YouTube), this problem does not appear on any of the 4 tested supports, so there is no problem coming from my machine or software. The issue must be in the videos. But I don't understand what could be in the videos for it to always be 13h15m22s that are removed, regardless of the video size. Moreover, if the video was corrupted, I wouldn't be able to display it in Films & TV or VLC media player.

    I used ffmpeg to see if the video was corrupted:

    ffmpeg.exe -v error -i "/Users/myname/Desktop/myvideo.mp4" -f null >error.log 2>&1

    ffmpeg.exe -v error -i "/Users/myname/Desktop/myvideo.mp4" -f null

    ffprobe -show_entries stream=r_frame_rate,nb_read_frames,duration -select_streams v -count_frames -of compact=p=1:nk=1 -threads 3 -v 0


    And nothing appears in the output so I guess there's no error detected. I tried to repair my video with ffmpeg anyway:

    ffmpeg -i "/Users/myname/Desktop/myvideo.mp4" -c copy "/Users/myname/Desktop/myvideo_fixed.mp4”


    And there is still 13h15m22s missing.

    I finally tried to repair it with Untrunc, which gave me a completely black video of 55 minutes for a video supposed to last several hours. Untrunc asks for the corrupted file and a functional video file taken by the same camera as input, so I used a 3min26 file for this, assuming that since the file is less than 13h15m22s and does not appear truncated on the software, it is not corrupted. Maybe I should have taken a larger video file (a few hours for example), but I'm not sure it's going to change anything.

    I don't know what to do to be able to cut these videos and use them in Python without them being truncated.

    Continue reading...

Compartilhe esta Página