Opened 2 years ago

Closed 16 months ago

#6494 closed defect (invalid)

Concat'ing HEVC streams with different encoding parameters produces gibberish

Reported by: birdie Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: after you concat two HEVC streams with different encoding parameters and you try to play the resulting file, when ffplay/mpv/mplayer reaches the second file, you see garbage instead of the actual output.

How to reproduce:

The first file parameters:
$ ffmpeg -i input1 -an -c:v libx265 -preset veryslow -x265-params crf=20:no-sao=1    file1.mkv

The second file parameters:
$ ffmpeg -i input2 -an -c:v libx265 -preset veryslow -tune grain -x265-params crf=20 file2.mkv

$ cat list.txt
file file1.mkv
file file2.mkv

Concat:
$ ffmpeg -f concat -i list.txt -c copy out.mkv

When reaching the second part of the output multiple messages like this one are logged in console:

[ffmpeg/video] hevc: The cu_qp_delta -56 is outside the valid range [-26, 25].

mkvtoolnix produces the same broken output.

However if you first transcode the mkv files to TS and then concat the resulting ts files, then everything works fine:

$ ffmpeg -i part1.mkv -c copy output1.ts
$ ffmpeg -i part2.mkv -c copy output2.ts

Change History (5)

comment:1 Changed 2 years ago by birdie

A person on IRC told me this problem is caused by the fact that the concat filter doesn't recreate/reinitialize RAPs. When you perform a TS transformation this gets done.

I have found the following tickets which seemingly exhibit the same problem:

#2319
#3600
#5236
#6494

Last edited 2 years ago by birdie (previous) (diff)

comment:2 Changed 2 years ago by oromit

This is entirely normal and expected, the concat demuxer can only work on 100% compatible files, like for example the ones a HLS playlist would contain.
Use the concat filter if you want to combine incompatible sources.

comment:3 Changed 2 years ago by birdie

Um, sorry, didn't get you:

the concat demuxer can only work on 100% compatible files

then

Use the concat filter if you want to combine incompatible sources

What's the difference? ;-)

comment:4 Changed 2 years ago by heleppkes

The concat filter works on decoded streams, so you can re-encode them all into a common format, it does not allow using the original streams as-is.

To elaborate some, while it would in theory be possible to make those files somewhat playable and seekable (at least by avcodec, who knows what other decoders might think), it requires rewriting the bitstreams to adjust the SPS/PPS/VPS ids and whatnot, which is at this point out of scope for the concat demuxer - its specifically documented to require compatible streams.

comment:5 Changed 16 months ago by cehoyos

  • Component changed from ffmpeg to undetermined
  • Keywords concat hevc removed
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.