Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using --avhw while transcoding some source, random fragments can be lost. #101

Open
DimkaTsv opened this issue Feb 12, 2024 · 6 comments

Comments

@DimkaTsv
Copy link

DimkaTsv commented Feb 12, 2024

If issue requires to be passed to developers of particular component, tell me, please.

Issue description:
I have series of videos (films to be more specific) which i wanted to transcode to reduce size before remuxing package further (additing or forcing subtitles, and tweaking audio tracks).
Videos are encoded in AVC in .mkv container, nothing special or unique.
By default VCEEnc reasonably in my eyes uses --avhw. But something weird is happening with these particular videos.

When i do transcoding (i tried AVC, HEVC and preanalysis on and off), in at least 2 videos whole fragments are skipped. By "skipped" i mean literally black screen and no sound. Sound can stop later than black screen starts and start earlier than it ends. Fast forwarding to "skipped" fragment is also impossible it will default to some time at middle of skipped fragment. VCEEnc literally doesn't code these frames at all.
Such thing does not happen if i force --avsw instead.

Sources and transcoded samples:
Sadly these files ARE big enough (16GB for source and 8GB for transcoded ones), so i cut a fragment.
Source [it is there but for... potentially legal reasons i won't share it publicly]: -----
Source fragment that is being corrupted [Main difference is that in corrupted frament there is sound which lasts for full 23 minutes of encoded fragment, while actual video is only 2 seconds. In source transcoding, sound also goes blank]:
https://drive.google.com/file/d/17SqY4eXRZ8-QrJQR50ABo8z2lwdxfY02/view?usp=sharing

Corrupted video - fragment (--avhw) [In transcoded file from source broken fragment starts at 1:04:34, no sound and video. Sound appears at 1:27:43, while video appears at 1:30:22]:
https://drive.google.com/file/d/1vrd68dxFwPHXvvmCoXo2nxHgfJS-IBsc/view?usp=sharing

Logs and MediaInfo:
MediaInfo - Source [i will only link relevant tracks]:

General
Unique ID                      : 248221216510330680836342581051138536386 (0xBABDAAD8D2890A039315605C597473C2)
Complete name                  : C:\Users\DimkaTsv\Videos\Processing\Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p.mkv
Format                         : Matroska
Format version                 : Version 2
File size                      : 19.5 GiB
Duration                       : 2 h 22 min
Overall bit rate mode          : Variable
Overall bit rate               : 19.6 Mb/s
Frame rate                     : 23.976 FPS
Encoded date                   : 2010-06-02 14:33:07 UTC
Writing application            : mkvmerge v3.3.0 ('Language') built on Mar 24 2010 14:59:24
Writing library                : libebml v0.8.0 + libmatroska v0.9.0

Video
ID                             : 1
Format                         : AVC
Format/Info                    : Advanced Video Codec
Format profile                 : Main@L4
Format settings                : CABAC / 2 Ref Frames
Format settings, CABAC         : Yes
Format settings, Reference fra : 2 frames
Muxing mode                    : Container profile=
Codec ID                       : V_MPEG4/ISO/AVC
Duration                       : 2 h 22 min
Bit rate mode                  : Variable
Bit rate                       : 16.3 Mb/s
Maximum bit rate               : 40.0 Mb/s
Width                          : 1 920 pixels
Height                         : 1 080 pixels
Display aspect ratio           : 16:9
Frame rate mode                : Constant
Frame rate                     : 23.976 (24000/1001) FPS
Color space                    : YUV
Chroma subsampling             : 4:2:0
Bit depth                      : 8 bits
Scan type                      : Progressive
Bits/(Pixel*Frame)             : 0.327
Stream size                    : 16.2 GiB (83%)
Title                          : Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p
Language                       : English
Default                        : No
Forced                         : No
Color range                    : Limited
Color primaries                : BT.709
Transfer characteristics       : BT.709
Matrix coefficients            : BT.709

Audio #1
ID                             : 2
Format                         : AC-3
Format/Info                    : Audio Coding 3
Commercial name                : Dolby Digital
Codec ID                       : A_AC3
Duration                       : 2 h 22 min
Bit rate mode                  : Constant
Bit rate                       : 448 kb/s
Channel(s)                     : 6 channels
Channel layout                 : L R C LFE Ls Rs
Sampling rate                  : 48.0 kHz
Frame rate                     : 31.250 FPS (1536 SPF)
Compression mode               : Lossy
Stream size                    : 457 MiB (2%)
Title                          : Dubbed
Language                       : Russian
Service kind                   : Complete Main
Default                        : Yes
Forced                         : No

VCEEnc - corrupted fragment log

C:\Users\-----\Videos\Processing>C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i C:\Users\-----\Videos\Processing\[source]Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_fragmented.mkv -o "[source]Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_fragmented_processed.mkv" --codec avc --profile main --level 5.1 --preset balanced --ref 4 --ltr 3 --vbr 7500 --max-bitrate 15000 --qp-max 36 --audio-copy --chapter-copy --log vceencc_log.txt --log-level info
-----------------------------------------------------------------------------------------------
[source]Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_fragmented_processed.mkv
-----------------------------------------------------------------------------------------------
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24002.92]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 5.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, ac3 => matroska
Quality:       balanced
VBR:           7500 kbps
Max bitrate:   15000 kbps
QP:            Min: 0:0, Max: 36:36
VBV Bufsize:   7500 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    4 frames
LTR frames:    3 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock

encoded 50 frames, 1.58 fps, 8003.44 kbps, 1.99 MB
encode time 0:00:31, CPU: 0.2%, VE: 91.0%
frame type IDR  1
frame type I    1,  avgQP  24.00,  total size  0.11 MB
frame type P   49,  avgQP  20.92,  total size  1.88 MB

I won't give you debug log, as it was more than 1GB of text.
But default log also presented some info.
VCEEnc log - avhw = corrupted result

C:\Users\-----\Videos\Processing>C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i C:\Users\-----\Videos\Processing\Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p.mkv -o "Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv" --codec avc --profile main --level 5.1 --preset balanced --ref 4 --ltr 3 --vbr 7500 --max-bitrate 15000 --qp-max 36 --audio-copy --chapter-copy --log vceencc_log.txt --log-level info
--------------------------------------------------------------------------------
Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv
--------------------------------------------------------------------------------
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24002.92]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 5.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, ac3, ac3, ac3, ac3, ac3, ac3, ac3 => matroska
Quality:       balanced
VBR:           7500 kbps
Max bitrate:   15000 kbps
QP:            Min: 0:0, Max: 36:36
VBV Bufsize:   7500 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    4 frames
LTR frames:    3 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock

encoded 167657 frames, 415.03 fps, 7379.79 kbps, 6151.75 MB
encode time 0:06:43, CPU: 1.4%, GPU: 3.3%, VE: 100.0%
frame type IDR    699
frame type I      699,  avgQP  19.58,  total size    70.77 MB
frame type P   166958,  avgQP  20.62,  total size  6080.98 MB
--------------------------------------------------------------------------------
Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv
--------------------------------------------------------------------------------
Input #0, matroska,webm, from 'C:\Users\-----\Videos\Processing\Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p.mkv':
  Metadata:
    encoder         : libebml v0.8.0 + libmatroska v0.9.0
    creation_time   : 2010-06-02T14:33:07.000000Z
  Duration: 02:22:29.09, start: 0.000000, bitrate: 19550 kb/s
  Stream #0:0(eng): Video: h264 (Main), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn
    Metadata:
      title           : Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p
  Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
    Metadata:
      title           : Dubbed
  Stream #0:2(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Tycoon
  Stream #0:3(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Zhivov
  Stream #0:4(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Gavrilov
  Stream #0:5(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Glanz
  Stream #0:6(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : English
  Stream #0:7(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Metadata:
      title           : Comments
  Stream #0:8(rus): Subtitle: subrip (default)
    Metadata:
      title           : forced subtitles
  Stream #0:9(rus): Subtitle: subrip
    Metadata:
      title           : Full
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24002.92]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 5.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, ac3, ac3, ac3, ac3, ac3, ac3, ac3 => matroska
Quality:       balanced
VBR:           7500 kbps
Max bitrate:   15000 kbps
QP:            Min: 0:0, Max: 36:36
VBV Bufsize:   7500 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    4 frames
LTR frames:    3 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock 
Output #0, matroska, to 'Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv':
  Metadata:
    encoding_tool   : VCEEnc (x64) 8.21
    encoder         : Lavf60.16.100
  Stream #0:0(eng): Video: h264 (Main) (H264 / 0x34363248), nv12(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 1k tbn
  Stream #0:1(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
    Metadata:
      title           : Dubbed
  Stream #0:2(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Tycoon
  Stream #0:3(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Zhivov
  Stream #0:4(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Gavrilov
  Stream #0:5(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Glanz
  Stream #0:6(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : English
  Stream #0:7(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s
    Metadata:
      title           : Comments
[matroska @ 000002031b3daa00] Starting new cluster due to timestamp
[matroska @ 000002031b3daa00] Starting new cluster due to timestamp
[matroska @ 000002031b3daa00] Starting new cluster due to timestamp
[matroska @ 000002031b3daa00] Starting new cluster due to timestamp
...
... (a LOT!!! of those)
...
[matroska @ 000002031b3daa00] Starting new cluster due to timestamp
[matroska @ 000002031b3daa00] Starting new cluster due to timestamp
                                                                                                                       
encoded 167657 frames, 415.03 fps, 7379.79 kbps, 6151.75 MB
encode time 0:06:43, CPU: 1.4%, GPU: 3.3%, VE: 100.0%
frame type IDR    699
frame type I      699,  avgQP  19.58,  total size    70.77 MB
frame type P   166958,  avgQP  20.62,  total size  6080.98 MB

VCEEnc log - avsw = correctly transcoded file:

C:\Users\-----\Videos\Processing>C:\Users\DimkaTsv\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i C:\Users\-----\Videos\Processing\Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p.mkv -o "Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv" --avsw --codec avc --profile main --level 5.1 --preset balanced --ref 4 --ltr 3 --vbr 7500 --max-bitrate 15000 --qp-max 36 --audio-copy --chapter-copy --log vceencc_log.txt --log-level info
--------------------------------------------------------------------------------
Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv
--------------------------------------------------------------------------------
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24002.92]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avsw: h264(yv12)->nv12 [AVX2], 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 5.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, ac3, ac3, ac3, ac3, ac3, ac3, ac3 => matroska
Quality:       balanced
VBR:           7500 kbps
Max bitrate:   15000 kbps
QP:            Min: 0:0, Max: 36:36
VBV Bufsize:   7500 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    4 frames
LTR frames:    3 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock

encoded 204759 frames, 481.31 fps, 7400.85 kbps, 7534.55 MB
encode time 0:07:05, CPU: 2.2%, GPU: 4.6%, VE: 66.2%
frame type IDR    854
frame type I      854,  avgQP  19.47,  total size    87.82 MB
frame type P   203905,  avgQP  20.54,  total size  7446.73 MB

--------------------------------------------------------------------------------
Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_processed.mkv
--------------------------------------------------------------------------------
Input #0, matroska,webm, from 'C:\Users\-----\Videos\Processing\Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p.mkv':
  Metadata:
    encoder         : libebml v0.8.0 + libmatroska v0.9.0
    creation_time   : 2010-06-02T14:33:07.000000Z
  Duration: 02:22:29.09, start: 0.000000, bitrate: 19550 kb/s
  Stream #0:0(eng): Video: h264 (Main), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn
    Metadata:
      title           : Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p
  Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
    Metadata:
      title           : Dubbed
  Stream #0:2(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Tycoon
  Stream #0:3(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Zhivov
  Stream #0:4(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Gavrilov
  Stream #0:5(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Glanz
  Stream #0:6(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : English
  Stream #0:7(eng): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Metadata:
      title           : Comments
  Stream #0:8(rus): Subtitle: subrip (default)
    Metadata:
      title           : forced subtitles
  Stream #0:9(rus): Subtitle: subrip
    Metadata:
      title           : Full
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24002.92]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avsw: h264(yv12)->nv12 [AVX2], 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 5.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, ac3, ac3, ac3, ac3, ac3, ac3, ac3 => matroska
Quality:       balanced
VBR:           7500 kbps
Max bitrate:   15000 kbps
QP:            Min: 0:0, Max: 36:36
VBV Bufsize:   7500 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    4 frames
LTR frames:    3 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock 
[h264 @ 000002a9c481a440] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c481a440] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
[h264 @ 000002a9c5a54c00] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c5a54c00] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
[h264 @ 000002a9c5ceb7c0] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c5ceb7c0] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
[h264 @ 000002a9c5da6900] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c5da6900] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
[h264 @ 000002a9c5e61a00] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
...
... (a LOT of those, and yes, closer to end of transcoding text became not as pretty and properly aligned)
...
[h264 @ 000002a9c5f2fb80] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c5f2fb80] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
[h264 @ 000002a9c5f2cb80] Late SEI is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c481a440] Late SEIIf you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
[h264 @ 000002a9c481a440]  is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 000002a9c481a440] If you want to help, upload a sample of this file to https://streams.videolan.org/upload/ and contact the ffmpeg-devel mailing list. ([email protected])
encoded 204759 frames, 481.31 fps, 7400.85 kbps, 7534.55 MB
encode time 0:07:05, CPU: 2.2%, GPU: 4.6%, VE: 66.2%
frame type IDR    854
frame type I      854,  avgQP  19.47,  total size    87.82 MB
frame type P   203905,  avgQP  20.54,  total size  7446.73 MB

==============

As you can notice, in corrupted video with avhw VCEEnc was only able to encode 167657 frames (166958 Q-frames and 699 I-frames), while for correctly encoded video with avsw it was able to encode 204759 frames (203905 Q-frames and 854 I-frames respectively). Also corrupted video stream takes 6157.75 MB, while correct one takes 7534.55 MB

@DimkaTsv
Copy link
Author

DimkaTsv commented Feb 13, 2024

Interesting detail: There were 6 videos from same source (and they are basically 6 chapters, as you might guess based on log before).
4 of them will have parts skipped. Some more (time percentage wise), some less. And at very least these videos can be properly transcoded via --avsw flag.

But what is especially interesting, is that remaining 2 videos will actually straight up crash driver [24.1.1] closer to the end of the transcoding due to this error:
"AMFENC: Fatal error when getting output bitstream from encoder.
Break in task AMFENC: device operation failure."

Here is actual log. [it was quite large, so i compressed it into archive]
https://drive.google.com/file/d/13SpDouZKz4ZbSUu7juwtFBCJEqzlaDuL/view?usp=drive_link

[AMFVideoStreamParserImpl] 2024-02-13 02:33:41.178     4A04 [AMFVideoStreamParserImpl]   Debug: AMFVideoStreamParserImpl::SubmitInput()
[matroska @ 0000028f5ac78ec0] Writing block of size 768 with pts 7261760, dts 7261760, duration 32 at relative offset 2823405 in cluster at offset 9753243328. TrackNumber 9, keyframe 1
[AMFEncoderCoreH264] 2024-02-13 02:33:41.180     3590 [AMFEncoderCoreH264]   Debug: GetProperty(OutputMode), 0
[matroska @ 0000028f5ac78ec0] Writing block of size 1792 with pts 7261792, dts 7261792, duration 32 at relative offset 2824180 in cluster at offset 9753243328. TrackNumber 2, keyframe 1
[AMFVideoStreamParserImpl] 2024-02-13 02:33:41.180     4A04 [AMFVideoStreamParserImpl]   Debug: AMFVideoStreamParserImpl::QueryOutput()
[matroska @ 0000028f5ac78ec0] Writing block of size 1536 with pts 7261792, dts 7261792, duration 32 at relative offset 2825979 in cluster at offset 9753243328. TrackNumber 3, keyframe 1
AMFENC: Fatal error when getting output bitstream from encoder.
[AMFDecodeEngineImplDX11] 2024-02-13 02:33:46.662     4A04 [AMFDecodeEngineImplDX11]   Error: ..\..\..\..\..\runtime\src\components\DecoderUVD\DecodeEngines\DirectX\DirectX11\DecodeEngineDX11.cpp(1322):COM failed, HR = 80070057:InitDecoder() CreateVideoDecoderOutputView failed
Break in task AMFENC: device operation failure..
[AMFDecoderUVDImpl] 2024-02-13 02:33:46.663     4A04 [AMFDecoderUVDImpl]   Error: ..\..\..\..\..\runtime\src\components\DecoderUVD\DecoderUVDImpl.cpp(1879):AMF_ERROR 1 : AMF_FAIL: DecodeFrame() - BeginDecodeFrame failed
Clear vpp filters...
Closing m_pmfxDEC/ENC/VPP...
Closing Encoder...
[AMFEncoderCoreH264] 2024-02-13 02:33:46.664     3590 [AMFEncoderCoreH264]   Debug: AMFEncoderCoreH264Impl::Terminate()
[PrivateChannelDx11] 2024-02-13 02:33:46.665     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.665     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.665     3590 [PrivateChannel]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(480):AMF_ERROR 17 : AMF_NO_DEVICE: SubmitSessionInfo() Failed to transport function package.
[PrivateChannelDx11] 2024-02-13 02:33:46.666     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.666     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.666     3590 [PrivateChannel]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(251):AMF_ERROR 17 : AMF_NO_DEVICE: QueryProperties() Failed to transport function package.
[AMFEncoderCoreBaseImpl] 2024-02-13 02:33:46.666     3590 [AMFEncoderCoreBaseImpl] Warning: ReleaseThroughput() - Failed to release throughput.
[PrivateChannelDx11] 2024-02-13 02:33:46.666     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.667     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.667     3590 [PrivateChannel]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(321):AMF_ERROR 17 : AMF_NO_DEVICE: DestroyQueue() Failed to transport function package.
[EncodeQueueWinImpl] 2024-02-13 02:33:46.667     3590 [EncodeQueueWinImpl]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\EncodeQueueWinImpl.cpp(45):AMF_ERROR 17 : AMF_NO_DEVICE: Failed to destroy encode queue.
[PrivateChannelDx11] 2024-02-13 02:33:46.667     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(158):Assertion failed:D3D Device removed.
[PrivateChannelDx11] 2024-02-13 02:33:46.668     3590 [PrivateChannelDx11]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannelDx11.cpp(191):AMF_ERROR 17 : AMF_NO_DEVICE: Failed in ValidateDevice.
[PrivateChannel] 2024-02-13 02:33:46.668     3590 [PrivateChannel]   Error: ..\..\..\..\..\runtime\src\components\EncoderCore\PrivateChannel.cpp(54):AMF_ERROR 17 : AMF_NO_DEVICE: Failed to transport package for function. 7 
Closed Encoder.
Closing Decoder...
[AMFDecoderUVDImpl] 2024-02-13 02:33:46.670     3590 [AMFDecoderUVDImpl]   Debug: AMFDecoderUVDImpl::Terminate()
[AMFVideoStreamParserImpl] 2024-02-13 02:33:46.671     3590 [AMFVideoStreamParserImpl]   Debug: AMFVideoStreamParserImpl::Terminate()
[AMFDecoderUVDImpl] 2024-02-13 02:33:46.672     3590 [AMFDecoderUVDImpl]    Info: Submitted 174126, Queried 174117
Closed Decoder.
Clear pipeline tasks and allocated frames...
[AMFEncoderCoreH264] 2024-02-13 02:33:46.678     3590 [AMFEncoderCoreH264]   Debug: AMFEncoderCoreH264Impl::Terminate()
Waiting for writer to finish...
avout: closed audio process thread default.
avout: closed audio process thread 7.0.
avout: closed audio process thread 1.0.
avout: closed audio process thread 2.0.
avout: closed audio process thread 3.0.
avout: closed audio process thread 4.0.
avout: closed audio process thread 5.0.
avout: closed audio process thread 6.0.
avout: closed audio process thread 8.0.
avout: closed audio encode thread default.

After searching and some ffmpeg cutting i was left with 2 fragments 4-6 seconds each.
Both will crash driver even if you just watch it via HW decode.
With --awsw (or CPU decode) you will still bitstream error (or corruption artifacts) and small lag in playback?, but no crash will happen.

More information here.
GPUOpen-LibrariesAndSDKs/AMF#446

@rigaya
Copy link
Owner

rigaya commented Feb 13, 2024

Thank you for the input file and the detailed logs, I was able to reproduce the issue. Although not sure right now about the cause, it should be related to hw decoder. I'll check further later.

@DimkaTsv
Copy link
Author

DimkaTsv commented Feb 13, 2024

Well, yesterday i had original videos linked. Today i changed links for cropped samples that are specific to issue. They were directly cut from original without any additional tricks.
If you downloaded originals, you may want to swap for sample to speed up testing (easier to test 20 minute file, rather than 2 hours one), or crop it yourself via this ffmpeg command (use as .bat to drag and drop file on top of it):
%~dp0\ffmpeg -ss 01:04:34 -to 01:30:22 -i %1 -c copy "%~n1_fragmented%~x1"

@DimkaTsv
Copy link
Author

Installed 23.40.19.01 driver (aka 24.2.1 pre-release).

Now encoding begins after decently long waiting period, and with atrocious average FPS. Of course as result it will not encode most of the fragment.

E:\Corrupted_stuff>C:\Users\-----\Desktop\Utilites\VCE_Encoder\VCEEncC_x64\\VCEEncC64.exe -i E:\Corrupted_stuff\[avhw_novid_source]Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_fragmented.mkv -o "[avhw_novid_source]Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_fragmented_processed.mkv" --avhw --codec avc --profile main --level 5.1 --preset balanced --ref 4 --ltr 3 --vbr 7500 --max-bitrate 15000 --qp-max 36 --audio-copy --chapter-copy --log vceencc_log.txt --log-level info
---------------------------------------------------------------------------------------------------------
[avhw_novid_source]Star.Wars.Episode.II.Attack.Of.The.Clones.2002.HDTV.1080p_fragmented_processed.mkv
---------------------------------------------------------------------------------------------------------
VCEEnc (x64) 8.21 (r1577) by rigaya, Dec 10 2023 04:01:37 (VC 1937/Win)
OS:            Windows 11 x64 (22631) [UTF-8]
CPU:           AMD Ryzen 7 5800X3D 8-Core Processor [4.48GHz] (8C/16T)
GPU:           AMD Radeon RX 7800 XT [31.0.24019.1006]
AMF:           Runtime 1.4.33 / SDK 1.4.30
Input Info:    avvce: H.264/AVC, 1920x1080, 24000/1001 fps
Output:        H.264/AVC  Main @ Level 5.1
               1920x1080p 1:1 23.976fps (24000/1001fps)
               avwriter: h264, ac3 => matroska
Quality:       balanced
VBR:           7500 kbps
Max bitrate:   15000 kbps
QP:            Min: 0:0, Max: 36:36
VBV Bufsize:   7500 kb
Bframes:       0 frames
Pre Analysis:  off
Ref frames:    4 frames
LTR frames:    3 frames
Motion Est:    Q-pel
Slices:        1
GOP Len:       240 frames
Others:        skipframe:on deblock

encoded 50 frames, 1.40 fps, 7998.44 kbps, 1.99 MB
encode time 0:00:35, CPU: 0.2%, VE: 91.4%
frame type IDR  1
frame type I    1,  avgQP  24.00,  total size  0.11 MB
frame type P   49,  avgQP  20.92,  total size  1.87 MB

Actually, now that i checked that source cannot be played properly with AMD HW Playback tool [i... just recently figured out how to compile it myself, as AMF repo contains only source code. And i found one more tool], i probably should ask AMF what is wrong with file?

... Looks like corruption happens here

Cluster Element #384
CRC-32 Element #385
Timestamp Element #386
SimpleBlock Element #387
SimpleBlock Element #388
AVC Sequence Parameter Set (SPS) #389
AVC SPS Extension #390
AVC Picture Parameter Set (PPS) #391
AVC IDR Slice, I #392
SimpleBlock Element #393
SimpleBlock Element #394
SimpleBlock Element #395
AVC Non-IDR Slice, P #396
AVC SEI (pic_timing) #397
SimpleBlock Element #398
AVC Non-IDR Slice, P #399
SimpleBlock Element #400
SimpleBlock Element #401
SimpleBlock Element #402
SimpleBlock Element #403
SimpleBlock Element #404
AVC Non-IDR Slice, P #405
AVC SEI (pic_timing) #406
SimpleBlock Element #407
AVC Non-IDR Slice, B #408
SimpleBlock Element #409
AVC Non-IDR Slice, B #410
AVC SEI (pic_timing) #411
SimpleBlock Element #412
AVC Non-IDR Slice, B #413
SimpleBlock Element #414
AVC Non-IDR Slice, B #415
AVC SEI (pic_timing) #416
SimpleBlock Element #417
AVC Non-IDR Slice, P #418
SimpleBlock Element #419
SimpleBlock Element #420
SimpleBlock Element #421
SimpleBlock Element #422
AVC Non-IDR Slice, P #423
AVC SEI (pic_timing) #424
SimpleBlock Element #425
AVC Non-IDR Slice, B #426
SimpleBlock Element #427
AVC Non-IDR Slice, B #428
AVC SEI (pic_timing) #429
SimpleBlock Element #430
AVC Non-IDR Slice, B #431
SimpleBlock Element #432
AVC Non-IDR Slice, B #433
AVC SEI (pic_timing) #434
SimpleBlock Element #435
SimpleBlock Element #436
AVC Non-IDR Slice, P #437
SimpleBlock Element #438
SimpleBlock Element #439
SimpleBlock Element #440
SimpleBlock Element #441
AVC Non-IDR Slice, P #442
AVC SEI (pic_timing) #443
SimpleBlock Element #444
AVC Non-IDR Slice, B #445
SimpleBlock Element #446
AVC Non-IDR Slice, B #447
AVC SEI (pic_timing) #448
SimpleBlock Element #449
AVC Non-IDR Slice, B #450
SimpleBlock Element #451
AVC Non-IDR Slice, B #452
AVC SEI (pic_timing) #453
SimpleBlock Element #454
SimpleBlock Element #455
AVC Non-IDR Slice, P #456
SimpleBlock Element #457
SimpleBlock Element #458
AVC Non-IDR Slice, P #459
AVC SEI (buffering_period) #460
AVC SEI (pic_timing) #461
Cluster Element #462
CRC-32 Element #463
Timestamp Element #464
SimpleBlock Element #465
AVC Sequence Parameter Set (SPS) #466
AVC SEI (recovery_point) #467
AVC Picture Parameter Set (PPS) #468
AVC IDR Slice, I #469
AVC IDR Slice, I #470
AVC IDR Slice, I #471
AVC IDR Slice, I #472
AVC IDR Slice, I #473
AVC IDR Slice, I #474
AVC SEI (pic_timing) #475

There is part in source fragment where new SPS and PPS are being passed, then for some time every frame is in single slice instead of multiple.

@rigaya
Copy link
Owner

rigaya commented Feb 19, 2024

Seems like somehow the video files has progressive frames and interlaced fields mixed up, and the new SPS and PPS might be it's transition. I'm yet not being able to figure out how it can be made decoded properly now.

@DimkaTsv
Copy link
Author

DimkaTsv commented Feb 19, 2024

Seems like somehow the video files has progressive frames and interlaced fields mixed up, and the new SPS and PPS might be it's transition.

Well... I saw that other videos from same source could've had beginning as interlaced, then instant transition into progressive. And it played fine.
But seems like something had broke for this one... Neither i assumed there even would be progressive-interlaced-progressive transition here.

Oh, i now see what you mean. It is literally just few spikes... Never actually noticed them, weird. Moreover in original video FPS spikes incredibly during this fragment, like 11-140+FPS variation for several frames. I wonder why AMF HW Playback (and hw decoder here, i assume?) cannot approach this one, but ffmpeg can (at least LAV_filters, which is based on libavcodec and libavformat which are parts of ffmpeg).

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants