Opened 6 years ago

Last modified 2 weeks ago

#7799 open defect

hevc_mp4toannexb filter inserts extradata wrong position (hevc_cuvid ffplay too)

Reported by: Hyemin Lee Owned by: Carl Eugen Hoyos
Priority: normal Component: avcodec
Version: git-master Keywords: hevc
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

After applied hevc_mp4toannexb filter to the attached video (refer to the below link),
the frames become broken from the video players (e.g. VLC, ffplay)

The problem is caused by prepending the extra-data to IRAP frames in libavcodec/hevc_mp4toannexb_bsf.c.

This video contains own vps/sps/pps for every IRAP frames.
The extradata from hevcc is slightly different from every IRAP frames have (in this case QP value is different) and the hevc_mp4toannexb filter prepends the different extradata to every IRAP frames, causing the broken frames.

Video File Repo :
https://www.dropbox.com/s/tpyohk6vf096zxm/hevc_after_mp4toannexb_conversion_qp_value_modified.mp4?dl=0

I am afraid that I can't connect to ftp://upload.ffmpeg.org, so I just attached to the dropbox url
How to reproduce:

% ffmpeg -i hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 -codec copy -bsf:v hevc_mp4toannexb output.hevc
$vlc output.hevc

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Attachments (2)

hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 (719.7 KB ) - added by Carl Eugen Hoyos 6 years ago.
3files.zip (1.8 MB ) - added by Balling 3 years ago.

Change History (30)

comment:1 by Carl Eugen Hoyos, 6 years ago

How did you create the input file?

in reply to:  1 ; comment:3 by Hyemin Lee, 6 years ago

Replying to cehoyos:

How did you create the input file?

Unfortunately, I did not create the video. It is automatically transcoded via a messenger application. (I do not exactly know how they transcode)

I know how to avoid this issue, (just not prepend the extra-data, if the extra-data has already existed on IRAP frames)

However, I do not exactly know whether this solution is correct or not.

in reply to:  1 comment:2 by Hyemin Lee, 6 years ago

Last edited 6 years ago by Hyemin Lee (previous) (diff)

in reply to:  3 ; comment:3 by Carl Eugen Hoyos, 6 years ago

Replying to gudbooy:

Replying to cehoyos:

How did you create the input file?

Unfortunately, I did not create the video. It is automatically transcoded via a messenger application. (I do not exactly know how they transcode)

Which one? The file indicates that it was created with FFmpeg.

comment:4 by Hyemin Lee, 6 years ago

The file I uploaded (hevc_after_mp4toannexb_conversion_qp_value_modified.mp4​).

comment:5 by Carl Eugen Hoyos, 6 years ago

Which messenger application?

comment:6 by Hyemin Lee, 6 years ago

The messenger application called KAKAO-TALK, which is the famous app in Korea
The original one is H.264 encoded Video transcoded by Xiomi video editing application.

comment:7 by Carl Eugen Hoyos, 6 years ago

Keywords: hevc added
Version: unspecifiedgit-master

comment:8 by Andriy Gelman, 5 years ago

hevc_mp4toannexb bsf doesn't insert correct parameter sets if they change in-band. For now, you can just use hevc_metadata filter to do the same job:

./ffmpeg -i hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 -bsf:v hevc_metadata -codec:v copy output.hevc

in reply to:  8 comment:9 by Hyemin Lee, 5 years ago

Replying to taliho:

hevc_mp4toannexb bsf doesn't insert correct parameter sets if they change in-band. For now, you can just use hevc_metadata filter to do the same job:

./ffmpeg -i hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 -bsf:v hevc_metadata -codec:v copy output.hevc

Thanks, I will try it and let you know

comment:10 by Balling, 4 years ago

Status: newopen

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20191016025040.31273-2-andriy.gelman@gmail.com/

Apply that already.

Issue showed itself here:
https://github.com/rigaya/NVEnc/issues/237

Actually with warning!

[hevc_mp4toannexb @ 000001cea55b2f00] No parameter sets in the extradata
So maybe other issue??

Last edited 4 years ago by Balling (previous) (diff)

comment:11 by Balling, 4 years ago

Guys, when this will be fixed? We have a patch.

comment:13 by Balling, 3 years ago

Sorry, it does NOT just look related, it is the "same" patch since FATE had the same change!! PLEASE APPLY!!!

-fate-hevc-bsf-mp4toannexb: REF = 1873662a3af1848c37e4eb25722c8df9
+fate-hevc-bsf-mp4toannexb: REF = 3c9d998a3aa2b9e0fb1c1f434952bf8b

comment:14 by Balling, 3 years ago

Hey, please apply the LGTM'd patch!

comment:15 by Balling, 3 years ago

Ping again!

in reply to:  16 ; comment:17 by haihao, 3 years ago

Replying to Balling:

New patch: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220317063546.7429-1-haihao.xiang@intel.com/

Does this patch work for you ? Could you please comment on FFmpeg mailing list if it works ? thx

in reply to:  17 comment:18 by Balling, 3 years ago

Replying to haihao:

Replying to Balling:

New patch: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220317063546.7429-1-haihao.xiang@intel.com/

Does this patch work for you ? Could you please comment on FFmpeg mailing list if it works ? thx

Please note that there is workaround with hevc_metadata, that is not affected, but in 2019 at least it could not "-c copy" nuh_layer_id != 0

One difference is that hevc_metadata currently only keeps the base layers
(nuh_layer_id == 0), whereas hevc_mp4toannexb copies everything (before my
patch). hevc_metadata will have a slightly higher complexity as it parses the full
parameter sets.

I will just point out how to test this bug on latest master:
Bad:

ffmpeg.exe -i hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 -c copy ajcwsaq.h265
ffplay.exe ajcwsaq.h265

Good:

ffmpeg.exe -i hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 -bsf:v hevc_metadata -c copy ajcwsaq1.h265

ffplay ajcwsaq1.h265

Also bad for ffplay.exe -vcodec hevc_cuvid hevc_after_mp4toannexb_conversion_qp_value_modified.mp4 since that automatically insert Annex B convertion. Why, BTW???

Version 2, edited 3 years ago by Balling (previous) (next) (diff)

comment:19 by Balling, 3 years ago

Summary: hevc_mp4toannexb filter inserts extradata wrong positionhevc_mp4toannexb filter inserts extradata wrong position (hevc_cuvid ffplay too)

I can verify that your patch, Haihao, did fix the bug and additional bug in ffplay -vcodec hevc_cuvid! I will attach the original file and fixed one. I am not sure whether it is a good idea to put data right behind "x265 (build 110) - 2.3:[Linux][GCC 5.4.0] ..." decoder info... But what do I know.

hevc_metadata does not appear to be able to handle the file perfectly, it looks like it truncates some 00 00 00 01 from

00 00 00 01
40 01 0C 01 FF FF 01 60 00 00 03 00 90 00 00 03 00 00 03 00 5D 95 94 09 00 00 00 01 42 01 01 01 60 00 00 03 00 90 00 00 03 00 00 03 00 5D A0 02 80 80 2D 16 59 59 52 93 0B C0 40 40 00 00 03 00 40 00 00 07 82 00 00 00 01 44 01 C0 73 C1 89
Last edited 2 years ago by Balling (previous) (diff)

by Balling, 3 years ago

Attachment: 3files.zip added

comment:20 by Balling, 3 years ago

So the first file in 3files.zip is old broken one, second is old hevc_metadata (looks like missing some stuff in bitstream, but it plays) and third is with new patch from Intel guy.

The build is here on my github https://github.com/ValZapod/FFmpeg-Builds/actions/runs/2005445270 (click on artifacts)

Last edited 3 years ago by Balling (previous) (diff)

comment:21 by Balling, 3 years ago

Owner: set to mkver

Please merge the patch. The only issue is that it writes stuff before x265 internal SEI, but who cares.

comment:22 by Balling, 2 years ago

Still broken.

comment:23 by Balling, 2 years ago

Owner: changed from mkver to softworkz

So mkver, where is this genious sample

This only mitigates a certain case of wrongly inserted extradata; it

does not fix the underlying issue

Also

complexity emanating from HEVC's layers.

is hevc_metadata problem.

And to Soft Works:

I had missed this conversation and just recently noticed that Haihao's
Patch fixes HEVC decoding issues with certain files that I'm seeing
for a long time already

Where are the samples?

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

comment:24 by Balling, 2 years ago

When is this going to be applied??

comment:25 by Balling, 2 years ago

Mkver? Hey?

comment:26 by Balling, 2 years ago

Owner: changed from softworkz to Carl Eugen Hoyos

Carl?

comment:27 by Balling, 2 weeks ago

https://github.com/FFmpeg/FFmpeg/commit/0f824d792d20783fda64279ab94e16676e48c2e6

Chabged the md5 in FATE, but https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210910040948.14186-1-haihao.xiang@intel.com/ is still to be applied. So we need a new patch, btw this does not fix this issue, it is the other patch.

Note: See TracTickets for help on using tickets.