Opened 20 months ago

Last modified 14 months ago

#11298 new defect

AMD VAAPI HEVC encoding a 1080p video results in a 1920x1088 one

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

Description

Summary of the bug:

I'm trying to encode a 1080p video in hevc_vaapi with and AMD display card, but the resulting video has a 1920x1088 dimension (when played by mpv / ffplay).

How to reproduce:

I built ffmpeg from latest master (e35587250c3e036261ea9cfc266e74730b6f60ae) to reproduce the bug:

./configure --disable-debug --disable-static --enable-shared \
 --enable-gpl --disable-stripping --enable-libx265 --disable-x86asm

The command used is

LD_LIBRARY_PATH='libavcodec:libavdevice:libavfilter:libavformat:libavutil:libpostproc:libswresample:libswscale' \
  ./ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i a.mkv \
  -acodec copy -vcodec hevc_vaapi -rc_mode CQP -qp 36 a.mp4

mpv outputs

● Video  --vid=1  (hevc 1920x1080 60 fps) [default]
● Audio  --aid=1  (aac 2ch 48000 Hz 160 kbps) [default]
Using hardware decoding (vaapi).
AO: [pipewire] 48000Hz stereo 2ch floatp
VO: [gpu-next] 1920x1088 vaapi[nv12]
AV: 00:00:01 / 00:00:03 (43%) A-V:  0.000

Despite mpv / ffprobe / ffplay says the video stream is 1920x1080, it plays at 1920x1088.

Actually I was doing screen recording with obs-studio and got this bug since at least ffmpeg 7.0.1. There was a patch (https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240321170219.1487-1-Primeadvice@gmail.com/) fixed this for 7.0.x but it no longer applies to 7.1.

I'm using an AMD Radeon RX 6650 XT display card and so my only options are HEVC and AVC.

This is not reproducible on Intel cards.

Attachments (1)

ffmpeg.log (313.1 KB ) - added by lilydjwg 20 months ago.

Download all attachments as: .zip

Change History (9)

by lilydjwg, 20 months ago

Attachment: ffmpeg.log added

comment:1 by schigi, 18 months ago

Cc: schigi added

comment:2 by Balling, 18 months ago

"1920x1088" is what all 1920x1080 videos are. The coded heaight for all 1920x1080 videos in the wild is 1920x1088

but it no longer applies to 7.1.

Well find what changed and apply it anyway.

Last edited 18 months ago by Balling (previous) (diff)

comment:3 by Jhon, 14 months ago

Happening to me when downscaling a 1440 video to 1080. Any output video has a green line at the bottom for those 8 extra px.

I am running a .sh script that looks like this:

ffmpeg \
  -hwaccel_output_format vappi \
  -vaapi_device /dev/dri/renderD128 \
  -i input.mp4 \
  -vf 'format=nv12,hwupload,scale_vaapi=-1:1080' \
  -map 0:0 \
  -c:v hevc_vaapi \
  -map 0:a \
  -c:a copy \
  -rc_mode CQP \
  -global_quality 25 \
  -profile:v main \
  -v verbose output.mkv

Using version 7.0.2-3ubuntu1

comment:4 by Timo R., 14 months ago

That must basically mean that AMDs bitstream generator fails to include the cropping info, to get 1088 back to 1080 on playback.
Or our wrapper passed the wrong height to it at some point.

in reply to:  4 ; comment:5 by James, 14 months ago

Replying to Timo R.:

That must basically mean that AMDs bitstream generator fails to include the cropping info, to get 1088 back to 1080 on playback.
Or our wrapper passed the wrong height to it at some point.

I think the relevant change that fixes this is in 7.1, possibly commit bcfbf2bac8f9eeeedc407b40596f5c7aaa0d5b47. The vaapi hevc encoder should code the cropping information within the bitstream and not rely on container cropping like av1.

in reply to:  5 comment:6 by Jhon, 14 months ago

Replying to James:

Replying to Timo R.:

That must basically mean that AMDs bitstream generator fails to include the cropping info, to get 1088 back to 1080 on playback.
Or our wrapper passed the wrong height to it at some point.

I think the relevant change that fixes this is in 7.1, possibly commit bcfbf2bac8f9eeeedc407b40596f5c7aaa0d5b47. The vaapi hevc encoder should code the cropping information within the bitstream and not rely on container cropping like av1.

I just updated and its still happening in 7.1.1-1ubuntu1

If it helps to narrow the issue down, VLC plays it with no visible green line (before and now), but other players like Haruna (and the thumbnail in Dolphin file explorer) are showing the green line.

comment:7 by Balling, 14 months ago

Was not there a patch to fix cropping for amd encoder?

HEVC encoding a 1080p video results in a 1920x1088 one

It always results in 1088 even on nvidia, there is just metadata that signals that last 8 lines are fake and should be removed.

comment:8 by Jhon, 14 months ago

Just found this ticket, where someone comments the patch could not be applied to 7.1
https://fftrac-bg.ffmpeg.org/ticket/8506

Note: See TracTickets for help on using tickets.