rigaya / NVEnc

NVENCによる高速エンコードの性能実験
https://rigaya34589.blog.fc2.com/blog-category-17.html
Other
1.08k stars 114 forks source link

Enconding breaks and video is saved incompletely #517

Closed rainman74 closed 7 months ago

rainman74 commented 1 year ago

When this error occurs, the encoding breaks and video is saved incompletely.

check_pts(222352): timestamp of video frame is smaller than previous frame, changing pts: 889404 -> 889405 (previous pts 889404).

Output Info H.265/HEVC main @ Level auto 1920x804p 1:1 23.976fps (24000/1001fps) avwriter: hevc, ac3, #2:eac3/5.1(side) -> ac3/5.1(side)/384kbps

But if I then encode the same file with FFmpeg or Avidemux with the same parameters, both run through without any error message and the video is saved correctly.

rigaya commented 1 year ago

This kind of problem is due to the input file or the filter used, will be difficult to solve without reproducing the issue.

rainman74 commented 1 year ago

This kind of problem is due to the input file or the filter used, will be difficult to solve without reproducing the issue.

I just turned on the verbose logging in FFmpeg and see that bad frames are simply dropped, but the video continues to be written and saved correctly to the end. Visually you don't see that even during playback, when only isolated frames are dropped.

Maybe that would also be an idea to handle it this way? nvencc64 unfortunately does not write the video correctly in such cases, probably because the pts are changed.

Or maybe even better, cancel the encoding then and don't save the video, since it's broken anyway and you might not even notice it if you batch convert dozens of videos.

Shanghai-Tom commented 1 year ago

When I receive these kind of error I use ffmpeg with -ignore_unknown -fflags +genpts+igndts+discardcorrupt -avoid_negative_ts make_zero -map 0 -c copy and create a new copy file without performing any encoding, so far all the problem files I have pre-processed with ffmpeg are then accepted by nvencc Maybe this can help fix your file too.

rainman74 commented 1 year ago

@rigaya Couldn't you also build in an analog handling like in FFmpeg, so that a video is still saved correctly to the end and the defective frames are omitted?

rainman74 commented 1 year ago

[NULL @ 000001f68f310540] Invalid NAL unit size (0 > 14281). GPU 86%, VE 99%, VD 21%, est out size 533.6MB [NULL @ 000001f68f310540] missing picture in access unit with size 14285 avcuvid: failed to run h264_mp4toannexb bitstream filter: Invalid data found when processing input.

Here too, the encoding is aborted and the file is saved incomplete. FFmeg also saves to the end here.

rigaya commented 1 year ago

I'm not sure about ffmpeg handling, but it is the issue only with the specific input file, I will not be able to do anything unless I can reproduce the error.

rainman74 commented 1 year ago

I'm not sure about ffmpeg handling, but it is the issue only with the specific input file, I will not be able to do anything unless I can reproduce the error.

The idea here is NOT to fix the error, because the video file is really defective in some frames, but to handle it like FFmpeg, namely to simply continue encoding the file and only omit the broken frames.

NVEnc, however, simply breaks off and leaves the file half-finished. FFmpeg continues writing until the end and the file is then error-free (without the defective frames, because they cannot be repaired anyway) and is also written until the end.

Maybe via parameter -omitbrokenframes or as default setting.

DJATOM commented 1 year ago

I'd suggest to use vapoursynth or avisynth to deal with defective stream (by cutting damaged frames or freezing them if audio is fine).

rainman74 commented 1 year ago

I'd suggest to use vapoursynth or avisynth to deal with defective stream (by cutting damaged frames or freezing them if audio is fine).

Yes, you could do that, but why not make everything the same in one programme?

I batch code hundreds of files per day with NVenc and don't want to have to do it all twice. Either I use FFmpeg, although I like NVenc better, or I have to provide error handling myself via ERRORLEVEL (if that works) and then encode the defective files again via FFmpeg.

It's just not a fancy solution, as NVenc is currently doing.

rigaya commented 1 year ago

NVEnc 7.34 might be able to drop the corrupt frame, but please note that this change is untested at all, so might not work properly!

As I have mentioned many times through this issue, I don't have a input file which cause the error you have mentioned, I am not able to reproduce or test at all.

rainman74 commented 1 year ago

NVEnc 7.34 might be able to drop the corrupt frame, but please note that this change is untested at all, so might not work properly!

As I have mentioned many times through this issue, I don't have a input file which cause the error you have mentioned, I am not able to reproduce or test at all.

Great, thank you! I will keep an eye on that. I don't have a test file at the moment either, as I have already converted the faulty ones with FFmpeg. I'll let you know.