FFmpeg segmentation and transcoding missing frames

257 views Asked by At

I code videos for hobbies and have a decent understanding of ffmpeg and mkvmerge. I prefer to encode video when my computer is on for other things as well, so I recently looked for a way that I could resume encoding after the computer was turned off.

I tried a virtual machine, saving the whole state and it seems to work very well, but the performance is very slow and with the same settings the encoding time is much longer than normal.

I then tried to divide the starting video into several segments, so as to resume from the appropriate segment after restarting the computer.

I tried to do this with ffmpeg:

ffmpeg -i input -map 0:v:0 -c copy -f segment -segment_time 300 -reset_timestamps 1 segment%03d.mkv

But also with the mkvtoolnix gui.

Both operations provide an excellent result.Trying to merge the segments into one video, with ffconcat or mkvtoolnix the result is perfect.

The problem arises when segments are encoded. I use a simple script based on slow preset for every segment in loop (I use both windows and linux):

ffmpeg -i input.mkv -threads 0 -map 0 -c:a copy -c:s copy -preset slow -pix_fmt yuv420p10le -c:v libx265 -x265-params crf=18:bframes=8:aq-mode=2:aq-strength=1.0 output.mkv

Putting them together in the same way, the video also looks quite good, and with the naked eye you don't notice the passage of the various segments, but analyzing them with ffmpeg I notice that the individual segments have slightly shorter durations and a different number of frames, even 2 or 3 less. When putting together very long videos, you notice even 2 seconds of difference with the original, which also causes the audio and subtitles to go into desynch.

I know the problem has to do with keyframes, timestamps and stuff like that. But I don't understand why. FFmpeg, as well as mkvmerge should split the video exactly where the keyframes are, about 300 seconds apart, so as not to mess up the video structure and allow for good encoding and reassembling.

The problem is just encoding with ffmpeg that removes some frames from the original segments. Sometimes I noticed during the encoding of some segments the following error code, or maybe warning, because the encoding worked anyway:

[hevc @ 0x55758bf92dc0] First slice in a frame missing.
    Last message repeated 6 times
[hevc @ 0x55758c2000c0] First slice in a frame missing.

I've read every discussion about it on the net, I've tried to segment both with mp4 and mkv format, with and without audio, but the problem remains. Where am I doing wrong?

0

There are 0 answers