6

on Linux i am trying to encode file to H€VC using hardware acceleration. Successful attempt is:

ffmpeg -v verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i '/path/file.mkv' -vcodec libx265 -crf 28 '/path/file.mp4'

but it is slow like 30fps, "ffmpeg -codecs|grep 265" shows: (encoders: libx265 nvenc_hevc hevc_amf hevc_nvenc hevc_qsv hevc_v4l2m2m hevc_vaapi )

so i have tried hevc_vaapi:

ffmpeg -v verbose -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i '/path/file.mkv' -vcodec hevc_vaapi -crf 28 '/path/file.mp4'

but it fails:

Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
[AVIOContext @ 0x55d831121340] Statistics: 0 seeks, 0 writeouts
[aac @ 0x55d831142a00] Qavg: 30414.529
[aac @ 0x55d831142a00] 2 frames left in the queue on closing
[AVIOContext @ 0x55d831109ec0] Statistics: 65536 bytes read, 0 seeks
Conversion failed!

$ ffmpeg -hwaccels shows "

Hardware acceleration methods:
vdpau
cuda
vaapi
qsv
drm

"

$ vaapi shows this (seems like va-api is there, mesa driver)

$ ls /dev/dri/*

/dev/dri/card0 /dev/dri/renderD128

/dev/dri/by-path:

pci-0000:0a:00.0-card pci-0000:0a:00.0-render

What do you think about this error or how would you proceed to discover which ffmpeg parameters to use for HW H€VC accelerated?

Update: i think that the "-hwaccel vaapi" may be redundant parameter

4 Answers 4

6

I think that it requires proper encoding parameters like -vf 'format=nv12,hwupload' and following one-liner may work if you have VAAPI driver:

echo "Input file:" && read -r i && echo "Quality: 25=identic, 30=a bit worse but small file size, or other numbers:" && read -r q && ffmpeg -vaapi_device /dev/dri/renderD128 -i "$i" -vf 'format=nv12,hwupload' -c:v hevc_vaapi -f mp4 -rc_mode 1 -qp "$q" "$i.hevc.mp4"
1
  • adding -vf 'format=nv12,hwupload' works but doesn't import the encoding speed at all
    – 19wolf
    Jun 20, 2021 at 19:15
2

none of other answer helps me, not until I install intel-media-va-driver-non-free following the Installation of https://wiki.debian.org/HardwareVideoAcceleration.

sudo apt install intel-media-va-driver-non-free

It should help if you are using intel gpu.

And if you need to scale video, use '-vf scale_vaapi=640:360' to scale video without string like 'format=nv12,hwupload'

1
  • great, this is the only solution that worked for me on ubuntu 23.04 using i915 on i5-7400 intel cpu Jun 6, 2023 at 6:41
1

Your first command shows that you use the GPU to decode, but the encoding is performed using the CPU (libx265). The GPU decodes quickly, but the decoded content can only be processed by the CPU after it is downloaded from the graphics card memory to the computer memory. This download process is system-wide. The overhead is very high, even exceeding the overhead of simultaneous encoding and decoding with cpu pure software, so the speed is very low; Your second command finally decided to use gpu to simultaneously decode and encode hardware acceleration, but you did not tell the gpu that the content to be encoded has been decoded into the video memory by the graphics card hardware, and you used the crf parameter that hardware encoding does not support, the hardware The parameter encoding similar to crf is qp. PS:The following are the parameters I commonly use:

ffmpeg -init_hw_device vaapi=foo:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device foo -i '/path/file.mkv' -filter_hw_device foo -vf 'format=nv12|vaapi,hwupload' -c:v hevc_vaapi  -qp 24  -filter:a volume=1.5 -ar 44100 -acodec aac -ab 64k -y '/path/file_n.mkv'
4
  • Thank you, I will use this as it is indeed faster. Btw, it does not seem to work for .webp file with VP9 codec with apparently only one stream: Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown), RETURNING: [webm @ 0x557eeb7a27c0] Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM. Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument. What works is the command from first answer on this page (even it is 57 fps slow): superuser.com/a/1637922
    – 16851556
    Sep 6, 2023 at 13:23
  • The command setting decoding and encoding I provided above are completely completed by the graphics card hardware. On supported hardware, it is of course very fast, but unfortunately there are currently very few graphics cards that support hardware decoding of vp9 encoded files (most of them have only been launched recently). Once the corresponding coding graphics card does not provide hardware support, the situation you mentioned above will occur. Oct 25, 2023 at 4:30
  • The reason why the first answer is valid is that its setting is to use the CPU to decode, then upload the CPU-decoded content to the video memory and then use the graphics card hardware to perform encoding. In fact, encoding always consumes more resources than decoding, so it is set like this. It will definitely improve the overall encoding speed significantly. Oct 25, 2023 at 4:32
  • On Linux, you can check the hardware encoding and decoding capabilities supported by your current system's graphics card by executing the VAinfo command in the terminal. If the command prompts that the command is not found, you can install the Vainfo package through your system's package manager. Obtain. Oct 25, 2023 at 4:42
0

May I suggest you add the two following flags:

  • -hwaccel vaapi
  • -hwaccel_output_format vaapi

so the command line look like this:

ffmpeg -v verbose -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -i INPUT.VIDEO -vf 'format=nv12,hwupload' -c:v hevc_vaapi OUTPUT.mp4

(on my computer, specify vaapi_device is not necessary)

2
  • this btw. does not work for webm video file VP9 format, that I have tried -> "Impossible to convert between the formats supported by the filter 'graph 0 input from stream 0:0' and the filter 'auto_scaler_0'"
    – 16851556
    Sep 6, 2023 at 12:26
  • Actually it not worked even for mp4 that I have tried bin.disroot.org/…
    – 16851556
    Oct 26, 2023 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .