Duplicate frame placed at the end of output file

i found out the silent cause of my headache trying to prepare a seamless loop from a TVAI output. here’s what i did:

  1. i grab a ffv1 mkv file. it’s 3840x1920, 24.00 fps and consists of 571 frames, 23 s 792 ms length.
input mediainfo
General
Unique ID                                : x
Complete name                            : <input>
Format                                   : Matroska
Format version                           : Version 4
File size                                : 1.01 GiB
Duration                                 : 23 s 792 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 365 Mb/s
Encoded date                             : UTC 2024-01-21 14:15:25
Writing application                      : Lavf60.20.100
Writing library                          : Lavf60.20.100
ErrorDetectionType                       : Per level 1

Video
ID                                       : 1
Format                                   : FFV1
Format version                           : Version 3.4
Codec ID                                 : V_MS/VFW/FOURCC / FFV1
Duration                                 : 23 s 792 ms
Bit rate mode                            : Variable
Bit rate                                 : 358 Mb/s
Width                                    : 3 840 pixels
Height                                   : 1 920 pixels
Display aspect ratio                     : 2.000
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : RGB
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossless
Bits/(Pixel*Frame)                       : 2.022
Stream size                              : 1 015 MiB (98%)
Writing library                          : Lavc60.37.100 ffv1
Default                                  : No
Forced                                   : No
Color range                              : Full
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : Identity
coder_type                               : Golomb Rice
MaxSlicesCount                           : 4
ErrorDetectionType                       : Per slice
  1. i use it as input in TVAI (v4.1.0). framerate unchanged, resize to 150%, enhancement used: Iris Low Quality, video type progressive, auto parameters, 0 noise, 20 recover detail, focus fix off. export settings: ffv1 10-bit 4:2:0, audio mode “none” because input file has no audio

  2. after processing, i inspect my output file. it’s suddenly a few ms longer. inspection with several players (mpc-be, virtualdub, avidemux) confirms there are now 572 frames in this video - the last frame was duplicated.

output mediainfo
General
Unique ID                                : x
Complete name                            : <output>
Format                                   : Matroska
Format version                           : Version 4
File size                                : 3.52 GiB
Duration                                 : 23 s 833 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 1 268 Mb/s
Encoded date                             : UTC 2024-01-21 14:15:25
Writing application                      : Lavf60.20.100
Writing library                          : Lavf60.20.100
ErrorDetectionType                       : Per level 1
VIDEOAI                                  : Enhanced using iris-3; mode: auto; revert compression at 0; recover details at 0; sharpen at 0; reduce noise at 0; dehalo at 0; anti-alias/deblur at 0; focus fix Off; and recover original detail at 20. Changed resolution to 5760x2880

Video
ID                                       : 1
Format                                   : FFV1
Format version                           : Version 3.4
Format settings, GOP                     : N=1
Codec ID                                 : V_MS/VFW/FOURCC / FFV1
Duration                                 : 23 s 833 ms
Bit rate mode                            : Variable
Bit rate                                 : 1 243 Mb/s
Width                                    : 5 760 pixels
Height                                   : 2 880 pixels
Display aspect ratio                     : 2.000
Frame rate mode                          : Constant
Frame rate                               : 24.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 10 bits
Scan type                                : Progressive
Compression mode                         : Lossless
Bits/(Pixel*Frame)                       : 3.121
Stream size                              : 3.45 GiB (98%)
Writing library                          : Lavc60.37.100 ffv1
Default                                  : No
Forced                                   : No
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
coder_type                               : Range Coder
MaxSlicesCount                           : 6
ErrorDetectionType                       : Per slice

upon further inspection of the duplicated frames, it seems like the last frame has been separately processed twice, because despite the content of the frame being the exact same, i can see very slight differences in processing done by TVAI (and because i’m using a lossless codec, i don’t think it’s a compression artifact or anything like that):
VirtualDub64_yPrVM2h2mE

a fix for this would be appreciated :pray:

1 Like

It may be useful to the investigators to know glodomorrapl is not alone in having this problem. I have experienced it myself whenever I input from a strip, apparently regardless of what TVAI model is applied (I have tried them all, or what seems to me like all - does not seem to be worth closely reporting every separate occurrence of the exact same problem).
One thing I have to add to the discussion: this does not ALWAYS happen. Half the time, the number of frames match. And I think it is as simple as this: when there are an odd number of input frames, the last output frame will be duplicated to make an even number of output frames.
Also: when there is a duplication, any further processing with ffmpeg will complain that the last frame has timestamp out of range.

2 Likes

i think there might be more to this.

i just processed a video with 285 frames and got no duplicates, even though that’s an odd number of frames. except there were two key differences:

  • my input was a png image sequence instead of an ffv1 mkv file
  • i used different enhancement this time: proteus relative to auto (+20 fix compression)

the output settings were the exact same as before

since you reported that you tested a lot of models and found no correlation, i think it’s the first difference that’s important here - an issue with decoding the file perhaps?

1 Like

Ahah, OK. I must admit my test for odd/even was not based on a huge sample. Since it seemed to me that it was happening roughly half the time, and those that I looked at more closely did follow the odd/even pattern, maybe I made 2 + 2 = 5.
So maybe it’s a combination of parity and framerate, and maybe length too … or maybe it’s not even that. Sorry if I’ve created a red herring.
What is for sure is that ffmpeg complains about the timestamping whenever you try to process a strip with the “extra” frame.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.