Stitching MKV files in HEVC+AAC produces corrupt output
This seems to be a regression introduced in v56.0.0 and still present in v59.0.0, v55 and earlier are not affected.
How to reproduce:
issue-3170-sample-source-file-1.mkv to MKVToolNix GUI, drop
issue-3170-sample-source-file-2.mkv and choose "Append to an existing source file", hit OK, hit Start multiplexing.
The output file will show obvious video corruption artifacts at the point of stitching when played in mpv or any other FFmpeg-based video player, and is smaller than it should be (v56 produces a file that's 72 865 259 bytes, v55 produces 78 180 333 bytes);
mpv (the video player) prints the following error:
[ffmpeg/video] hevc: Could not find ref with POC 30
Also, it seems to only happen if there's audio present - if I remove the audio stream from both files with FFmpeg and try stitching, the issue no longer reproduces. The test files were produced using OBS Studio with the NVENC HEVC video encoder and CoreAudio AAC audio encoder, then trimmed using FFmpeg stream copy.