Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This gist contains instructions on setting up FFmpeg and Libav to use VAAPI-based hardware accelerated encoding (on supported platforms) for H.264 (and H.265 on supported hardware) video formats.

Using VAAPI's hardware accelerated video encoding on Linux with Intel's hardware on FFmpeg and libav

Hello, brethren :-)

As it turns out, the current version of FFmpeg (version 3.1 released earlier today) and libav (master branch) supports full H.264 and HEVC encode in VAAPI on supported hardware that works reliably well to be termed "production-ready".

Assumptions:

Before taking on this manual, the author assumes that:

  1. The end-user can comfortably install and configure their Linux distribution of choice.
  2. The end user can install, upgrade, downgrade and resolve both conflicts and dependency resolution of packages on his/her distribution's package manager.
  3. That the user is comfortable with the Linux terminal, and can navigate through it.
  4. Basic competence on the shell, such as reading man files, using a text editor of choice, manipulating file operations on the same, etc is assumed.

And as an indemnity clause, I, the author, will not be liable for any damage, implied or otherwise, to your files, hardware or the stability of your machine as a consequence to using these instructions to achieve a similar feat as described in this gist.

Implications:

It means that when you're encoding content for use with your blogs or some fancy youtube download, you can do it much, much faster on hardware with lower processor utilization (so you can multi-task) , lesser heat output and, as a plus, is significantly faster (As tested on my end, ~8.7x for 1080p and ~4.2x for 4k encodes with reference media) compared to a pure, software-based approach as offered by libx264 and similar implementations, albeit at an acceptable quality compromise.

Here goes:

First, you will need to build ffmpeg (and libav,as per your preferences) with appropriate arguments. --enable-vaapi switch should be enough, though.

Here are my build options (Note that I load ffmpeg and libav via the module system):

FFmpeg's module files are here, and as more versions are compiled, more modules will be added. Libav's module files are here, and as more versions are compiled, more modules will be added.

FFmpeg's configuration switches used:

./configure --enable-nonfree --enable-gpl --enable-version3
--enable-libass --enable-libbluray --enable-libmp3lame
--enable-libopencv --enable-libopenjpeg --enable-libopus
--enable-libfaac --enable-libfdk-aac --enable-libtheora
--enable-libvpx --enable-libwebp --enable-opencl --enable-x11grab
--enable-opengl --cpu=native --enable-nvenc --enable-vaapi
--enable-vdpau  --enable-ladspa --enable-libass  --enable-libgsm
--enable-libschroedinger --enable-libsmbclient --enable-libsoxr
--enable-libspeex --enable-libssh --enable-libwavpack --enable-libxvid
--enable-libx264 --enable-libx265 --enable-netcdf  --enable-openal
--enable-openssl --enable-cuda --prefix=/apps/ffmpeg/git --enable-omx

Libav's configuration switches used:

./configure --prefix=/apps/libav/11.7 --enable-gpl --enable-version3
--enable-nonfree --enable-runtime-cpudetect --enable-gray
--enable-vaapi --enable-vdpau --enable-vda --enable-libmp3lame
--enable-libopenjpeg --enable-libopus --enable-libfaac
--enable-libfdk-aac --enable-libtheora --enable-libvpx
--enable-libwebp  --enable-x11grab  --cpu=native  --enable-vaapi
--enable-vdpau  --enable-libgsm --enable-libschroedinger
--enable-libspeex --enable-libwavpack --enable-libxvid
--enable-libx264 --enable-libx265 --enable-openssl --enable-nvenc
--enable-cuda --enable-omx

Then run make and make install to build and install the toolkits respectively.

Warning: These options are for reference only, a useful FFmpeg build will require you to install appropriate dependencies for some build options as suited to your environment and platform. Modify as needed. Also see the indemnity clause at the top of this document.

Here are the dependencies I had to install on my end (without acounting for the OpenMAX IL bellagio back-end):

sudo apt-get install yasm ladspa-sdk ladspa-foo-plugins ladspalist libass5 libass-dev libbluray-bdj libbluray-bin libbluray-dev libbluray-doc libbluray1 libmp3lame-dev \ libmp3lame-ocaml libmp3lame-ocaml-dev libmp3lame0 libsox-fmt-mp3 libopencv-* opencv-* python-cv-bridge python-image-geometry python-opencv python-opencv-apps gstreamer1.0-vaapi gstreamer1.0-vaapi-doc libopenjp2-* libopenjp2-7-dev libopenjp2-7-dbg libopenjp3d7 libopenjpeg-dev libopenjpeg-java libopenjpeg5 libopenjpeg5-dbg libopenjpip7 openjpeg-tools libopus-dbg libopus-dev libopus-doc libopus0 libtag1-dev libtag1-doc libtag1v5 libtagc0 libtagc0-dev libopus-ocaml libopus-ocaml-dev libopusfile-dev libopusfile-doc libopusfile0 libvorbis-java opus-tools opus-tools-dbg libfaac-dev libfaac0 fdkaac  libfdk-aac0 libfdk-aac0-dbg libfdk-aac-dev libtheora-dbg libtheora-dev libtheora-doc libtheora0 libtheora-bin libtheora-ocaml libtheora-ocaml-dev libvpx-dev libvpx-doc libvpx3 libvpx3-dbg libwebp-dev libwebp5 libwebpdemux1 libwebpmux1 opencl-headers mesa-vdpau-drivers libvdpau-va-gl1 vdpauinfo vdpau-va-driver libvdpau-doc libvdpau-dev libvdpau1 libvdpau1-dbg libgsm-tools libgsm0710-0 libgsm0710-dev libgsm0710mux3 libgsm1 libgsm1-dbg libgsm1-dev sox libsox-dev libsox-fmt-all libsox-fmt-alsa libsox-fmt-ao libsox-fmt-base libsox-fmt-mp3 libsox-fmt-oss libsox-fmt-pulse libsox2 libsoxr-dev libsoxr-lsr0 libschroedinger-dev libschroedinger-doc libschroedinger-ocaml libschroedinger-ocaml-dev libschroedinger-1.0-0 libsmbclient libsmbclient-dev  smbclient  libspeex-dev libspeex1 libspeexdsp-dev libspeexdsp1 libspeex-ocaml libspeex-ocaml-dev libspeex-dbg libssh-4 libssh-dev libssh-dbg libssh-doc  libssh-gcrypt-4 libssh2-1 libssh2-1-dev libwavpack-dev libwavpack1 libxvidcore-dev libxvidcore4  libx265-dev libx265-79 libx265-doc libx264-148 libx264-dev libnetcdf-* netcdf-* libopenal-* openal-info  openssl 

When done, you may then create and load the appropriate environment modules for both ffmpeg and libav as your choices go. Don't load both at the same time, though :-) (Mark them as module conflicts to ensure that if this is set up on a cluster, library conflicts do not occur when users inadvertently load both of them by accident in the same session).

Now, we get to the interesting bits:

Encoding with VAAPI

You'll notice that we pass several arguments to ffmpeg as indicated below:

ffmpeg -loglevel debug -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i "input
file" -vf 'format=nv12,hwupload' -map 0:0 -map 0:1 -threads 8 -aspect
16:9 -y -f matroska -acodec copy -b:v 12500k -vcodec h264_vaapi
"output file"

Let's break down these arguments to their meaning:

(a) .-loglevel tells ffmpeg to log ffmpeg events as debug output. This will be very verbose, and is completely optional. You can disregard this.

(b). -vaapi_device: This is important. You must select a valid VAAPI H/W context device to which you will upload textures to via hwupload, formatted in the NV12 colorspace. This points to a /dev/dri/render*_ file on your Linux system.

(c). -vf : This is an inbuilt ffmpeg option that allows you to specify codec options/arguments to be passed to our encoder, in this case, h264_vaapi (Remember, we built this when we passed --enable-vaapi at the configuration stage). Here, we tell ffmpeg to convert all textures to one colorspace, NV12 (As it's the one accepted by Intel's QuickSync hardware encoder) and to also use hwupload, an ffmpeg intrinsic, that tells the program to asynchronously copy the converted pixel data to VAAPI's surfaces.

(d). - threads : Specifies the number of threads that FFmpeg should use. By default, use the number of logical processors available on your processor here. On Intel processors that support Hyperthreading, multiply the number of cores your processor has by 2.

(e). -f : Specifies the container format specification you can use. This can be Matroska, webm, mp4, etc. Take your pick (as per your container constraints).

(f). -acodec: Specifies the audio codec to use when transcoding the video's audio stream. In the example given above, we use ffmpeg's muxers to copy the audio stream as is, untouched.

(g). -vcodec: Selects the video encoder to use. In this case, we selected h264_vaapi, our key point of interest here.

(h).-hwaccel vaapi: This instructs ffmpeg to use VAAPI based hardware accelerated decode (for supported codecs, see platform limits), and it can drastically lower the processor load during the process. Note that you should only use this option if your hardware supports hardware-accelerated decoding via VAAPI for the source fornat being encoded.

(i). Using the vaapi_scaler in the video filters: It is possible to use Intel's QuickSync hardware via VAAPI for resize and scaling (when up-or downscaling the input source to a higher or lower resolution), using a filter snippet such as the one shown below:

vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080'

You may specify a different resolution by changing the dimensions in =w= and :h= to suit your needs.

See an example of this filter snippet used above in the two-pass example in FFmpeg below.

(j). -hwaccel_output_format : This option should be used every time you declare the -hwaccel method as vaapi , so that the decode stage takes place entirely in hardware. This option generates decode output directly on VAAPI hardware surfaces, speeding up decode performance significantly.

You may confirm supported decode formats on your setup by running vainfo:

vainfo

Sample output on a Haswell testbed:

libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Haswell Mobile - 1.7.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD

Supported encode formats are appended with the VAEntrypointEncSlice fields, and all decode formats(s) for your SKU will be listed under the VAEntryPointVLD and VAEntrypointVideoProc fields.

To interpret the output above, we can learn that the Haswell SKU above supports VAAPI - based hardware-accelerated decode for H.264 Simple, Main and Stereo High profiles (I'd assume that the Stereo High profile infers to H.264's Multi-view coding encode mode, useful for encoding 3D Blurays and similar media, implying feature parity with Windows-based implementations where MVC encodes and decodes are supported by Intel QuickSync. Need to test that sometime).

The other arguments are pretty standard to FFmpeg and need no introduction :-)

You may also use extra options such as QP mode (for constant-rate quality encoding) with this codec in ffmpeg as shown:

ffmpeg -loglevel debug -vaapi_device /dev/dri/renderD128 -i "input file" -vf 'format=nv12,hwupload' -map 0:0 -map 0:1 -threads 8 -aspect 16:9 -y -f matroska -acodec copy -vcodec h264_vaapi -qp 19 -bf 2 "output file"

Here, you'll notice that we've added a few extra options to the arguments passed to the selected video encoder, h264_vaapi, and they are as follows:

(a). -qp: This option selects Fixed QP of P frames, and is ignored if bit-rate is set instead. Particularly useful for CRF-based encodes where a constant quality is required without bit-rate constraints. For a standard reference, a QP value of ~18 gives an approximate visual quality value similar to lossless compression, and going higher (~51) will give you way worse visual quality.

(b). -bf: This option toggles the maximum number of B-frames (bi-directional) between P-(progressive) frames. You may pump this higher than the default (2) if your selected encoder profile is High or better. Recommended: Leave this at the default (2).

In my tests, it's also possible to do two-pass encoding with this encoder (h264_vaapi) in ffmpeg, as illustrated in the example below:

ffmpeg -loglevel debug -hwaccel vaapi -hwaccel_output_format vaapi -i "input-file" -vaapi_device /dev/dri/renderD129  -vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' -pass 1 -qp:v 19 -b:v 10.5M -c:v h264_vaapi -bf 4 -threads 4 -aspect 16:9 -an -y -f mp4 "/dev/null" && ffmpeg -loglevel debug -hwaccel vaapi -hwaccel_output_format vaapi -i "phfx4k.mkv" -vaapi_device /dev/dri/renderD129 -vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' -pass 2 -acodec copy -c:v h264_vaapi -bf 4 -qp:v 19 -b:v 10.5M -threads 4 -aspect 16:9 -y -f mp4 "output.mp4"

Let's break that down:

With ffmpeg (and libav also), you must specify both passes sequentially (-pass 1 and -pass 2) because ffmpeg does not reiterate over input files for multiple passes. Secondly, this allows the user to tune the two-pass encoding as he/she sees fit, for example, by skipping audio processing in the first pass (-an) and only copying/muxing the audio stream from the input file's container specification into the output file's container (-acodec copy), as illustrated in the examples above.

And now we move on to libav's options for a similar encode:

avconv -v 55 -y -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -i input.mkv \
-c:a copy -vf 'format=nv12|vaapi,hwupload' -c:v h264_vaapi -bf 2 -b 12500k output.mkv

Let's break down these arguments to their meaning:

(a) .-v : This defines avconv's verbosity level. This one is completely optional, though its' regarded as good practice to leave it enabled and set to a reasonable verbosity level as desired for troubleshooting and diagnostics purposes.

(b). -vaapi_device: This is important. You must select a valid VAAPI H/W context device to which you will upload textures to via hwupload, formatted in the NV12 colorspace. This points to a /dev/dri/render*_ file on your Linux system.

(c). -hwaccel: This option allows you to select the hardware - based accelerated decoding to use for the encode session. In our case above, we are picking vaapi as this has a positive impact on encoder performance. A nice freebie.

(d). -hwaccel_output_format : This option should be used every time you declare the -hwaccel method as vaapi , so that the decode stage takes place entirely in hardware. This option generates decode output directly on VAAPI hardware surfaces, speeding up decode performance significantly.

(e). -vf : This is an inbuilt libav option that allows you to specify video filter options to be passed to our encoder, in this case, h264_vaapi (Remember, we built this when we passed --enable-vaapi at the configuration stage). Here, we tell libav to convert all textures to one colorspace, NV12 (As it's the one accepted by Intel's QuickSync hardware encoder) and to also use hwupload, a libav intrinsic, that tells the program to asynchronously copy the converted pixel data to VAAPI's surfaces. This argument also includes the hardware accelerated decode output format we requested earlier, raw VAAPI hardware surfaces.

(f). -bf : Specifies the bframe setting to use. Sane values for Intel 's Quick Sync encode hardware should be between 2 and 4. Test and report back.

(g). -c:a: Specifies the audio codec to use when transcoding the video's audio stream. In the example given above, we use libav's muxers to copy the audio stream as is, untouched.

(h). -c:v: Selects the video encoder to use. In this case, we selected h264_vaapi, our key point of interest here. (i). -b: Selects the video stream's bitrate passed to the encoder, h264_vaapi.

You may see the original documentation on Libav's website here on build instructions, using the alternate hevc_vaapi on supported hardware, encoder limitations, caveats, etc.

If all well according to plan, your video file should be encoded to H.264, muxed into the selected container and be done with.

See the screen-shot library here.

Extra information:

You can always view the build configuration of your Ffmpeg pipeline at any times by running:

For FFmpeg:

lin@mjanja:~$ ffmpeg -buildconf
ffmpeg version N-80785-g0fd76d7 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.1 (Ubuntu 5.3.1-14ubuntu2.1) 20160413
  configuration: --enable-nonfree --enable-gpl --enable-version3 --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libfaac --enable-libfdk-aac --enable-libtheora --enable-libvpx --enable-libwebp --enable-opencl --enable-x11grab --enable-opengl --cpu=native --enable-nvenc --enable-vaapi --enable-vdpau --enable-ladspa --enable-libass --enable-libgsm --enable-libschroedinger --enable-libsmbclient --enable-libsoxr --enable-libspeex --enable-libssh --enable-libwavpack --enable-libxvid --enable-libx264 --enable-libx265 --enable-netcdf --enable-openal --enable-openssl --prefix=/apps/ffmpeg/git --enable-omx
  libavutil      55. 27.100 / 55. 27.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 40.101 / 57. 40.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 46.102 /  6. 46.102
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100

  configuration:
    --enable-nonfree
    --enable-gpl
    --enable-version3
    --enable-libass
    --enable-libbluray
    --enable-libmp3lame
    --enable-libopencv
    --enable-libopenjpeg
    --enable-libopus
    --enable-libfaac
    --enable-libfdk-aac
    --enable-libtheora
    --enable-libvpx
    --enable-libwebp
    --enable-opencl
    --enable-x11grab
    --enable-opengl
    --cpu=native
    --enable-nvenc
    --enable-vaapi
    --enable-vdpau
    --enable-ladspa
    --enable-libass
    --enable-libgsm
    --enable-libschroedinger
    --enable-libsmbclient
    --enable-libsoxr
    --enable-libspeex
    --enable-libssh
    --enable-libwavpack
    --enable-libxvid
    --enable-libx264
    --enable-libx265
    --enable-netcdf
    --enable-openal
    --enable-openssl
    --prefix=/apps/ffmpeg/git
    --enable-omx

On help and documentation:

List all formats:

ffmpeg -formats

Display options specific to, and information about, a particular muxer:

ffmpeg -h muxer=matroska

Display options specific to, and information about, a particular demuxer:

ffmpeg -h demuxer=gif

Codecs (encoders and decoders):

List all codecs:

ffmpeg -codecs

List all encoders:

ffmpeg -encoders

List all decoders:

ffmpeg -decoders

Display options specific to, and information about, a particular encoder:

ffmpeg -h encoder=mpeg4

Display options specific to, and information about, a particular decoder:

ffmpeg -h decoder=aac

Reading the results

There is a key near the top of the output that describes each letter that precedes the name of the format, encoder, decoder, or codec:

$ ffmpeg -encoders
[…]
Encoders:
 V..... = Video
 A..... = Audio
 S..... = Subtitle
 .F.... = Frame-level multithreading
 ..S... = Slice-level multithreading
 ...X.. = Codec is experimental
 ....B. = Supports draw_horiz_band
 .....D = Supports direct rendering method 1
 ------
[…]
 V.S... mpeg4                MPEG-4 part 2

In this example V.S... indicates that the encoder mpeg4 is a Video encoder and supports Slice-level multithreading.

Extra notes for AMD hardware supporting VCE:

If you have a supported GCN+ AMD GPU running on Linux with the mesa driver stack, you may be able to use the AMD VCE Block via VAAPI with an example such as the one shown below:

DRI_PRIME=1 LIBVA_DRIVER_NAME=radeonsi ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi \
-framerate 30 -video_size 1920x1200 -f x11grab -i :0.0 -f pulse -ac 2 -i 1 \
-vf 'format=nv12,hwupload' -threads 8 \
-vcodec h264_vaapi -bf 0 -acodec pcm_s16le output.mkv

Where we capture from the screen via x11grab and the audio from a pulseaudio device.

You must set the LIBVA_DRIVER_NAME and the DRI_PRIME=1 environment variables to radeonsi prior to using VAAPI on VCE, and ensure that the -vaapi_device points to the correct renderer.

Note that with AMD hardware, we generally disable B-Frame support as newer SKUs such as the RX 460/470/480 and their rebrands (Polaris-based) do not support B-Frames in H.264 encoding. See this issue on Github for more details.

@lvml

This comment has been minimized.

Copy link

commented Jul 26, 2016

On an Intel Core i7-3517U CPU this works fine for me for 1080p clips from my camera, but unluckily, for 2160p clips the hardware encoding produces encoding errors (areas in the bottom half of the screen with false-color regions).
(I tried the git master head of ffmpeg and libva and intel-driver as of today.)

@lvml

This comment has been minimized.

Copy link

commented Jul 27, 2016

I found that https://git.libav.org/?p=libav.git;a=patch;h=8a62d2c28fbacd1ae20c35887a1eecba2be14371 fixes the 2160p hardware encoding problems I encountered.

By the way: You could mention that also when using the ffmpeg executable, it is well possible to use "-hwaccel vaapi" at the same time for decoding input while also using h264_vaapi as an output codec. For 4k video, this can lower your CPU usage from "everything" to "a few percent" ;-)

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 12, 2016

@lvml thanks a lot, I'll do so.

@gurabli

This comment has been minimized.

Copy link

commented Aug 30, 2016

Great work, thanks! I see you are really comfortable with ffmpeg and VAAPI. Could you help me (and the VDR and Emby community) with making ffmpeg vaapi encoding work on headless install (I'm using Ubuntu Server 16.04 LTS now). I know that even no X is required for vaapi to work, but need to find the correct command how to run encoding task with ffmpeg on server. Basically, I would like to:

  1. what are the dependencies for server to build ffmpeg with vaapi enabled?
  1. what other dependencies are required to make vaapi work on server?
  • I follow closely the development in Kodi forum where devs implemented VAAPI support for Kodi v17 Krypton. You can find it here: http://forum.kodi.tv/showthread.php?tid=231955
    Of course, it is for running Kodi and decoding, and they do need to install X for Kodi, but I think the following packages are needed to make vaapi work: libva1 vainfo i965-va-driver and since libva / libva-driver-intel version 1.7.0 of Xenial has a color issue (https://bugs.freedesktop.org/show_bug.cgi?id=94845) they recommend to install version 1.7.1 from ppa:wsnipex/vaapi I'm not sure that for encoding it matters anything. Apart from these, I think nothing else should be needed.
  1. get the proper ffmpeg settings to encode on server
    I use VDR for live tv, and streamdev server & externremux.sh to encode live tv to clients like Android smartphone. Take a look at it here: http://pastebin.com/7vnPsJLi
    Actually the important part is obviously at the end. I have customized the way to include Hungarian and English audio, and enabled deinterlacing, these don't matter at all now. The output should be -f mpegts pipe:1 and I guess the libx264 should be somehow replaced with vaapi.

Sorry for being so long, I hope you have some time to help and find this also useful. It would be very nice to make this work.

@Enverex

This comment has been minimized.

Copy link

commented Nov 5, 2016

Is there no "preset" setting for vaapi? e.g. -preset:v slow ? Can't find reference to it anywhere other than h264_qsv which isn't what's being used here.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Nov 23, 2016

Hello @gurabli ,

Sorry for getting back to you late. Been busy on academics.

Fire me a PM (via email, see github profile) or a reply here to carry on this conversation.

I'd be very interested in seeing this work on VDR and Emby :-)

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Nov 23, 2016

@Enverex,

Let me confirm if such a preset exists.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 2, 2016

Hello @Enverex,

See this page for details on supported profiles.

Regards,

Brainiarc7

@saiarcot895

This comment has been minimized.

Copy link

commented Dec 11, 2016

Hi,

I have a laptop with an i3-7100U (Kaby Lake) processor. I'm on Ubuntu 16.10, but backported ffmpeg from 17.04 (the one in 16.10 doesn't have VAAPI support). I tried converting a MPEG2-TS file (containing mpeg2 video and ac3 audio) into another MPEG2-TS, but with h264 video instead. The original video is 1080p and has a bitrate of about 15 Mb/s, and I'm trying to decrease it down to around 8 Mb/s. When using the hardware video encoder, I'm seeing what looks like compression artifacts (the video gets pixellated when there is movement). However, when I don't use the hardware video encoder, the video looks fine at the same bit rate. Any suggestions as to why this might be happening and how to fix it?

The command I'm running is ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -i "inputFile" -vf 'format=nv12,hwupload' -b:v 7500k -bf 0 -c:v h264_vaapi -c:a copy "outputFile".

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 17, 2016

Hello @saiarcot895 ,

You might want to use the VAAPI presets mode and ensure that you do enable B-frames (I see that you force-disabled them in your case, don't know why). and disable specifying a specific bitrate, instead use the -qp value of 19 (for best visual results), as shown in the example below:

ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -i "inputFile" -vf 'format=nv12,hwupload' -qp 19 -bf 4 -c:v h264_vaapi -c:a copy "outputFile"

Let me know how that goes.

@saiarcot895

This comment has been minimized.

Copy link

commented Dec 25, 2016

@Brainiarc7, I tried it and got good results, but the resulting bitrate was around 15Mb/s (about the same as the original). I was hoping to be able to use a lower bitrate and maintain a similar quality.

Also, this may or may not be related, but in VLC, when I use accelerated video overlay, the video that is shown isn't scaled to the window size. It's shown at a much smaller resolution. It could be that the version of Mesa I have doesn't fully support Kaby Lake graphics yet.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 27, 2016

Fascinating observation, @saiarcot895 , let me investigate further.

@porjo

This comment has been minimized.

Copy link

commented Feb 10, 2017

Thanks for the post. Any thoughts on Intel QSV? (as per ffmpeg page on HW accel)

For the benefit of anyone else who cares: ffmpeg RPM available from rpmfusion has been built with vaapi support. I'm using ffmpeg-3.1.6-1.fc25.x86_64 which works with my Skylake processor.

@libero08

This comment has been minimized.

Copy link

commented Feb 11, 2017

Hi,
"B" i try to use vaapi ona small sitem called"minipc" with a kabylake proc i7 7500u.
I install all as was described here (http://ubuntuhandbook.org/index.php/2016/09/install-ffmpeg-3-1-ubuntu-16-04-ppa/).
i want to transcode a live raw-ed stream , all goes fine only with more static immages. wheen movments are accelerated immage become instable with a lot of huge pixels, and maybe need to be deinterlaced some how.
this is my line for encapsulate 👍 ffmpeg -fflags +genpts -fpsprobesize 200 -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -i "http://192.168.1.10:9998/out/test1" -c:v h264_vaapi -force_key_frames "expr:gte(t,n_forced*5)" -vf "format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720" -b:v 2500k -maxrate 2500k -level 31 -threads 0 -c:a aac -f flv "rtmp://my_nginx_server/localmedia/vaapi_test"

@h00re1337

This comment has been minimized.

Copy link

commented Feb 11, 2017

libero08 i have the same errors with artefacts when there is a movement in the stream. haswell and kaby lake tested...

@libero08

This comment has been minimized.

Copy link

commented Feb 11, 2017

i try also to do un this way :
fmpeg -fflags +genpts -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i "http://192.168.1.10:9998/out/test1" -c:v h264_vaapi -force_key_frames "expr:gte(t,n_forced*5)" -vf "format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720" -bf 4 -qp 25 -level 31 -threads 0 -c:a aac -f flv "rtmp://my_nginx_server/localmedia/vaapi_test"
quality is a little bit better butcompression is minimal.
maybe a litle help from our Brain?

@syst5

This comment has been minimized.

Copy link

commented Feb 14, 2017

Hi,
My vainfo returns no VAEntrypointEncSlice entrypoint, does it means that my device can't encode ?

ffmpeg vaapi error ?
[h264_vaapi @ 0x55da51aac940] Encoding entrypoint not found (7 / 6).

vainfo:

libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/gallium_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.0)
vainfo: Driver version: mesa gallium vaapi
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc

log debug:

./ffmpeg.sh -loglevel debug -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -max_delay 500000 -rtsp_transport tcp -r 30 -i "rtsp://192.168.5.200:554/rtpstream/config5=u" -an -vf 'format=nv12,hwupload' -threads 8 -vcodec h264_vaapi -b:v 700k -f flv testvideo.flv -y
ffmpeg version 3.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/home/dsa/ffmpeg-nvenc/ffmpeg-nvenc --extra-cflags='-fPIC -m64 -I/home/dsa/ffmpeg-nvenc/ffmpeg-nvenc/include' --extra-ldflags=-L/home/dsa/ffmpeg-nvenc/ffmpeg-nvenc/lib --bindir=/home/dsa/ffmpeg-nvenc/ffmpeg-nvenc/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-nvenc --enable-pic --enable-x11grab --extra-ldexeflags=-pie --enable-shared
  libavutil      55. 27.100 / 55. 27.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 40.101 / 57. 40.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.102 /  6. 46.102
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-hwaccel' ... matched as option 'hwaccel' (use HW accelerated decoding) with argument 'vaapi'.
Reading option '-vaapi_device' ... matched as option 'vaapi_device' (set VAAPI hardware device (DRM path or X11 display name)) with argument '/dev/dri/renderD128'.
Reading option '-max_delay' ... matched as AVOption 'max_delay' with argument '500000'.
Reading option '-rtsp_transport' ... matched as AVOption 'rtsp_transport' with argument 'tcp'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '30'.
Reading option '-i' ... matched as input file with argument 'rtsp://192.168.5.200:554/rtpstream/config5=u'.
Reading option '-an' ... matched as option 'an' (disable audio) with argument '1'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'format=nv12,hwupload'.
Reading option '-threads' ... matched as AVOption 'threads' with argument '8'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'h264_vaapi'.
Reading option '-b:v' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '700k'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'.
Reading option 'testvideo.flv' ... matched as output file.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Applying option vaapi_device (set VAAPI hardware device (DRM path or X11 display name)) with argument /dev/dri/renderD128.
[AVHWDeviceContext @ 0x55da51a39ce0] Opened VA display via DRM device /dev/dri/renderD128.
libva info: VA-API version 0.39.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/gallium_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
[AVHWDeviceContext @ 0x55da51a39ce0] Initialised VAAPI connection: version 0.39
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x3231564e -> nv12.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x32315659 -> unknown.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x56595559 -> unknown.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x59565955 -> unknown.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x41524742 -> bgra.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x41424752 -> rgba.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x58524742 -> bgr0.
[AVHWDeviceContext @ 0x55da51a39ce0] Format 0x58424752 -> rgb0.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file rtsp://192.168.5.200:554/rtpstream/config5=u.
Applying option hwaccel (use HW accelerated decoding) with argument vaapi.
Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 30.
Successfully parsed a group of options.
Opening an input file: rtsp://192.168.5.200:554/rtpstream/config5=u.
[tcp @ 0x55da51a6a520] No default whitelist set
[rtsp @ 0x55da51a735c0] SDP:
v=0
o=- 0 0 IN IP4 192.168.5.200
s=rtsp://192.168.5.200/rtpstream/config5
c=IN IP4 0.0.0.0
t=0 0
a=control:*
m=video 0 RTP/AVP 99
a=rtpmap:99 H264/90000
a=fmtp:99 sprop-parameter-sets=Z0LgKdoB4Aiflm4CAgwE,aM48gA==;packetization-mode=1;profile-level-id=42e029
a=control:rtsp://192.168.5.200/rtpstream/config5/AVCESEnc
a=framerate:30.0

[rtsp @ 0x55da51a735c0] video codec set to: h264
[rtsp @ 0x55da51a735c0] Extradata set to 0x55da51a73d10 (size: 27)
[rtsp @ 0x55da51a735c0] RTP Packetization Mode: 1
[rtsp @ 0x55da51a735c0] RTP Profile IDC: 42 Profile IOP: e0 Level: 29
[rtsp @ 0x55da51a735c0] setting jitter buffer size to 0
[rtsp @ 0x55da51a735c0] hello state=0
[h264 @ 0x55da51a76740] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 0x55da51a76740] nal_unit_type: 1, nal_ref_idc: 3
    Last message repeated 5 times
[rtsp @ 0x55da51a735c0] All info found
[rtsp @ 0x55da51a735c0] rfps: 29.333333 0.016582
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 29.416667 0.012729
[rtsp @ 0x55da51a735c0] rfps: 29.500000 0.009389
[rtsp @ 0x55da51a735c0] rfps: 29.583333 0.006562
[rtsp @ 0x55da51a735c0] rfps: 29.666667 0.004248
[rtsp @ 0x55da51a735c0] rfps: 29.750000 0.002447
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 29.833333 0.001160
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 29.916667 0.000385
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 30.000000 0.000124
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 60.000000 0.000496
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 120.000000 0.001984
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 240.000000 0.007936
[rtsp @ 0x55da51a735c0] rfps: 29.970030 0.000159
    Last message repeated 1 times
[rtsp @ 0x55da51a735c0] rfps: 59.940060 0.000636
    Last message repeated 1 times
Input #0, rtsp, from 'rtsp://192.168.5.200:554/rtpstream/config5=u':
  Metadata:
    title           : rtsp://192.168.5.200/rtpstream/config5
  Duration: N/A, start: 0.277000, bitrate: N/A
    Stream #0:0, 28, 1/90000: Video: h264 (Constrained Baseline), 1 reference frame, yuvj420p(pc, smpte170m/bt709/bt709, left), 1920x1080 (1920x1088), 0/1, 30 tbr, 90k tbn, 180k tbc
Successfully opened the file.
Parsing a group of options: output file testvideo.flv.
Applying option an (disable audio) with argument 1.
Applying option vf (set video filters) with argument format=nv12,hwupload.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument h264_vaapi.
Applying option b:v (video bitrate (please use -b:v)) with argument 700k.
Applying option f (force format) with argument flv.
Successfully parsed a group of options.
Opening an output file: testvideo.flv.
[file @ 0x55da51c0ae20] Setting default whitelist 'file,crypto'
Successfully opened the file.
[Parsed_format_0 @ 0x55da51c498c0] compat: called with args=[nv12]
[Parsed_format_0 @ 0x55da51c498c0] Setting 'pix_fmts' to value 'nv12'
[graph 0 input from stream 0:0 @ 0x55da51aace60] Setting 'video_size' to value '1920x1080'
[graph 0 input from stream 0:0 @ 0x55da51aace60] Setting 'pix_fmt' to value '12'
[graph 0 input from stream 0:0 @ 0x55da51aace60] Setting 'time_base' to value '1/30'
[graph 0 input from stream 0:0 @ 0x55da51aace60] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x55da51aace60] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x55da51aace60] Setting 'frame_rate' to value '30/1'
[graph 0 input from stream 0:0 @ 0x55da51aace60] w:1920 h:1080 pixfmt:yuvj420p tb:1/30 fr:30/1 sar:0/1 sws_param:flags=2
[force CFR for input from stream 0:0 @ 0x55da51ca9140] Setting 'expr' to value 'N'
[format @ 0x55da51ca9f40] compat: called with args=[vaapi_vld]
[format @ 0x55da51ca9f40] Setting 'pix_fmts' to value 'vaapi_vld'
[auto-inserted scaler 0 @ 0x55da51cab3a0] Setting 'flags' to value 'bicubic'
[auto-inserted scaler 0 @ 0x55da51cab3a0] w:iw h:ih flags:'bicubic' interl:0
[force CFR for input from stream 0:0 @ 0x55da51ca9140] auto-inserting filter 'auto-inserted scaler 0' between the filter 'graph 0 input from stream 0:0' and the filter 'force CFR for input from stream 0:0'
[AVFilterGraph @ 0x55da51bef100] query_formats: 6 queried, 4 merged, 1 already done, 0 delayed
[swscaler @ 0x55da51bef660] deprecated pixel format used, make sure you did set range correctly
[auto-inserted scaler 0 @ 0x55da51cab3a0] w:1920 h:1080 fmt:yuvj420p sar:0/1 -> w:1920 h:1080 fmt:nv12 sar:0/1 flags:0x4
[auto-inserted scaler 0 @ 0x55da51cab3a0] TB:0.033333 FRAME_RATE:30.000000 SAMPLE_RATE:nan
[hwupload @ 0x55da51ca8a60] Surface format is nv12.
[AVHWFramesContext @ 0x55da51aacca0] Created surface 0x1.
[AVHWFramesContext @ 0x55da51aacca0] Direct mapping disabled: deriving image does not work: 6 (invalid VASurfaceID).
detected 4 logical cores
[h264 @ 0x55da51be6a00] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x55da51be6a00] nal_unit_type: 8, nal_ref_idc: 3
[h264_vaapi @ 0x55da51aac440] Using constant-bitrate = 700000 bps.
[h264_vaapi @ 0x55da51aac940] Encoding entrypoint not found (7 / 6).
Output #0, flv, to 'testvideo.flv':
  Metadata:
    title           : rtsp://192.168.5.200/rtpstream/config5
    Stream #0:0, 0, 0/0: Unknown: none
    Metadata:
      encoder         : Lavc57.48.101 h264_vaapi
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_vaapi))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[AVIOContext @ 0x55da51c31a80] Statistics: 0 seeks, 0 writeouts
@shmerl

This comment has been minimized.

Copy link

commented Mar 15, 2017

For AMD, you need to add: LIBVA_DRIVER_NAME=radeonsi, though I still didn't manage it to work. It just hangs.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 25, 2017

Hey guys,

I'm truly sorry for the late replies, mainly because Github still doesn't offer notification support for Gists, which sucks!

If you need urgent help, PLEASE go to my Github profile and fire me an email.

In the meanwhile, I'll look into the comments raised here and assist in any way that I can.

Regards,

Brainiarc7

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 25, 2017

Hello @sync5,

What is the make of your GPU on the testbed you're on?

Output from vainfo and lspci -K would be helpful.

Also useful, a dmesg log with drm verbose debugging toggled on.

Thanks and regards,

Brainiarc7

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 25, 2017

Hello @libero08 ,

Concerning quality tuning on this encoder, omit the -level argument and set the QP to a value between 19 and 21.
Secondly, you stated that you're on a Kabylake or an equivalent platform, correct?

If that is the case, please take a look at this first.

Reasons: Since Skylake, the fixed function encoding bits that VAAPI uses are now under the direct control of the GuC and the DmC units in the GPUs, which now require binary firmware blobs from Intel to utilize fully. Apply the workarounds in the linked gists above and retest, particularly concerning GuC firmware loading.

If possible, after applying these changes, give us a dmesg with verbose drm logging enabled and an ffmpeg log snippet set to verbose/debug logging so we can see if there are any changes on that platform.

And as always, do ensure that you're always running FFmpeg's master branch.

@libero08

This comment has been minimized.

Copy link

commented Jun 11, 2017

Thank you for replay B7, unfortunately this is for me an hobby and i have less time to experiment, i need to try next days and after that i report you the results.

@fullTalgoRythm

This comment has been minimized.

Copy link

commented Jun 21, 2017

I've done some testing to see if I could get this working with my AMD KABINI which should have VCE 2.0. Been very frustrating so far, ffmpeg now runs but the output is an unusable file. Given the effort / hassle getting this far I suspect in typical Debian / Ubuntu fashion that there are some broken dependencies or incompatible packages somewhere on the system (I wouldn't be surprised if VAAPI was completely broken on my system). I didn't really need this feature when I purchased the system but it would have been handy to have it now as requirements have changed. Sort of regretting not getting an Intel based system :)

Not sure I can really draw any conclusions about performance as it's not working but if what ffmpeg is reporting so far are any indication it suggests speed up is not that amazing and bit rates seem very high. As it's broken it's probably not a fair assessment but just feels like its steering me in the direction of not going any further with this.

So here are some notes about things at least the ones I can remember.

Ubuntu 16.04 does not support AMD VCE and there are multiple issues with the official AMD driver. Some are basic install issues but I don't believe the reported cogl issue was affecting me. There was no /dev/dri node present and kernel modesetting was not working (blank screen) although oddly I could get an X session running (maybe using a fallback driver I didn't check). I believe this was likely just a lack of compatibility with the KABINI.

As far as I can tell the AMD VCE (OpenMax) support via the opensource driver requires a recent version of Mesa to work and vainfo does not report any VAEntrypointEncSlice entry points for the shipped version of Mesa. You can load a recent version of Mesa (currently 17.1) via a Ubuntu backports ppa (https://launchpad.net/~ubuntu-x-swat/+archive/ubuntu/updates). You also need the mesa-va-drivers package (Mesa VA-API video acceleration drivers).

There is a support matrix here https://www.x.org/wiki/RadeonFeature/

I tried the ffmpeg snapshot, I guess I could try the 3.3 release too in case that is a source of problems.

The following gives some explanation of options and config. There is hwdecode and encode. I tried both independently as well as the transcoding option. I go the impression it was not using the hwdecode at all though as ffmpeg probably decided the input stream was not compatible.

https://wiki.libav.org/Hardware/vaapi

It is mentioned that not everything that is possible is currently supported so it's also possible that my specific hardware doesn't work properly with the current implementation looks like some of the underlying support may not be complete.

I did look at the OpenMax support which I thought may be an alternative as ffmpeg can apparently also use this although I think it's typically used via GStreamer. Again it looks like there are old versions of the packages perhaps preventing things from running. I think ffmpeg does not look for Belagio. I did create a symlink which got me a bit further but there is a missing libomx_mesa.so and doing a search didn't find any package that provided it so I'm guessing it's not very likely to work.

@rbrito

This comment has been minimized.

Copy link

commented Jun 22, 2017

You should mention the DRI_PRIME=1 variable for those that want to check their setup with vainfo or ffmpeg.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jun 27, 2017

Hello @rbrito,

Thanks for this :-)

Added.

@dynek

This comment has been minimized.

Copy link

commented Jul 15, 2017

@sync5 - did you find an answer to your question? I am in the same situation with my AMD cpu with integrated Radeon GPU. Thanks!

@gerrit507

This comment has been minimized.

Copy link

commented Aug 3, 2017

Hello Guys,
I've compiled ffmepg with following switches:
--enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-vaapi

When I run
ffmpeg -decoders | grep i 'vaapi'
it doesnt show me any vaapi decoder. Is that normal?
The output of
ffmpeg -encoders | grep i 'vaapi'
is as expected. All vaapi codecs I need are there. When I transcode with ffmpeg in emby it does use vaapi for hw-encoding but I'm not quite sure if it's using hw-decoding.

Moreover, is there any list that explains what each enable flag actually does? It's quite hard to find any good info on that. What's also curious is that, I get nvenc and cuda codecs even I haven't enabled them but the libx codecs are missing entirely.

I hope someone can help me clear this up :)

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 18, 2017

Hello @gerrit507 ,

In FFmpeg, we expose the same decode capabilities on the platform as shown in the output from vainfo through the -hwaccel method vaapi.

This gist illustrates the decoder selection better, and remember that with VAAPI, the -hwaccel option also expects the -vaapi_device argument to be passed as well.

@emreuenal

This comment has been minimized.

Copy link

commented Oct 30, 2017

hi @Brainiarc7

Thank you for the great infos.

I am using intel quicksync on Centos 7.2 with intel media server studio 2017 r3. My main goal was using h264_qsv with self compiled ffmpeg and it is working but i have no luck with vaapi.

If i check vainfo, get the following:

libva info: VA-API version 0.99.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.99 (libva 1.67.0.pre1)
vainfo: Driver version: 16.5.2.64009-ubit
vainfo: Supported profile and entrypoints
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: <unknown entrypoint>
      VAProfileH264ConstrainedBaseline: <unknown entrypoint>
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264Main               : <unknown entrypoint>
      VAProfileH264Main               : <unknown entrypoint>
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264High               : <unknown entrypoint>
      VAProfileH264High               : <unknown entrypoint>
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileVP8Version0_3          : VAEntrypointEncSlice
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP8Version0_3          : <unknown entrypoint>
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileVP9Profile0            : <unknown entrypoint>
      <unknown profile>               : VAEntrypointVideoProc
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileNone                   : <unknown entrypoint>

Can you say/explain me, why i have "unknown entrypoint" on some profiles?

@emreuenal

This comment has been minimized.

Copy link

commented Oct 31, 2017

Hey there,

That's because you're using the proprietary driver from Intel's Media SDK.

Some of these entry points are only exposed to and by the proprietary driver, and as such, the exported symbols are not generally available to other utilities that use VAAPI.

If you want to list and use all the publicly known VAAPI interfaces, you'll need to stick to the opensource i965 driver.

@papajo-r

This comment has been minimized.

Copy link

commented Dec 8, 2017

I want to record my screen using the AMD VCE of my rX 580 all the code I look for have that "input file" and I dont know what to link there.. If i leave it just as input.mp4 as some codes have I get an red letter error input.mp4 no such file or directory.... I am on ubuntu 17.10/kernel 4.15 lowlatency and MESA 17.4

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 16, 2017

Hello @papajo-r ,

On FFmpeg, when handling inputs, the full path to the file and its' file name must be explicitly specified.

For example, with FFprobe,

ffprobe -i "some-file"

Would only work IF the command is ran within the same working directory as the file you're operating on.

If the file were at a location such as /var/trollfiles and you're not intending to use that path as your working directory, you should run:

ffprobe -i /var/trollfiles/some-file

For the command to work.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Dec 16, 2017

If you need any further help, you may contact me directly.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Mar 26, 2018

@valkjsaaa

This comment has been minimized.

Copy link

commented Feb 18, 2019

Thanks for this great guide.

I was using ffmpeg to make a security camera HomeKit compatible. However, it was using around 100% of my CPU out of my 2 cores. So I want to use libva to accelerate this process. However, I keeps encounter this wired error. Here is my command with libva:

ffmpeg \
-hwaccel vaapi \
-rtsp_transport tcp \
-i rtsp://192.168.144.101:8554/unicast \
-map 0:0 \
-pix_fmt yuv420p \
-r 15 \
-f rawvideo \
-tune zerolatency \
-vf 'scale=1280:720,format=nv12' \
-vcodec h264_vaapi \
-b:v 299k \
-bufsize 299k \
-maxrate 299k -payload_type 99 \
-ssrc 13314026 \
-f rtp \
-srtp_out_suite AES_CM_128_HMAC_SHA1_80 \
-srtp_out_params ils+c7v2WkNjdFFgICwYAeDKZ5oVaUAs1moiaGFB \
"srtp://192.168.144.129:59295?rtcpport=59295&localrtcpport=59295&pkt_size=1316" \
-map 0:1 \
-acodec libfdk_aac \
-profile:a aac_eld -flags +global_header \
-f null \
-ar 16k \
-b:a 24k \
-bufsize 24k \
-ac 1 \
-payload_type 110 \
-ssrc 823920 \
-f rtp \
-srtp_out_suite AES_CM_128_HMAC_SHA1_80 \
-srtp_out_params u3K1xOSXFToXTC9d2n2YiGp+tNPsqbwK3NSx9qxr \
"srtp://192.168.144.129:57651?rtcpport=57651&localrtcpport=57651&pkt_size=1316"

And here is the output:

ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libfdk-aac --enable-nonfree --enable-vaapi --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[mp3 @ 0x5620d316cf80] Header missing
Input #0, rtsp, from 'rtsp://192.168.144.101:8554/unicast':
  Metadata:
    title           : LIVE555 Streaming Media v2017.10.28
    comment         : LIVE555 Streaming Media v2017.10.28
  Duration: N/A, start: 0.171911, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
Codec AVOption tune (Tune the encoding to a specific scenario) specified for output file #0 (srtp://192.168.144.129:59295?rtcpport=59295&localrtcpport=59295&pkt_size=1316) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_vaapi))
  Stream #0:1 -> #1:0 (mp3 (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[mp3 @ 0x5620d34040e0] Header missing
Error while decoding stream #0:1: Invalid data found when processing input
Output #1, rtp, to 'srtp://192.168.144.129:57651?rtcpport=57651&localrtcpport=57651&pkt_size=1316':
  Metadata:
    title           : LIVE555 Streaming Media v2017.10.28
    comment         : LIVE555 Streaming Media v2017.10.28
    encoder         : Lavf57.83.100
    Stream #1:0: Audio: aac (libfdk_aac) (ELD), 16000 Hz, mono, s16, 24 kb/s
    Metadata:
      encoder         : Lavc57.107.100 libfdk_aac
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 2367, current: 371; changing to 2367. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 9484, current: 7071; changing to 9484. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 12714, current: 10300; changing to 12714. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 19222, current: 16808; changing to 19222. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 25380, current: 22966; changing to 25380. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 29124, current: 26710; changing to 29124. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 36420, current: 34006; changing to 36420. This may result in incorrect timestamps in the output file.
[libfdk_aac @ 0x5620d31b9560] Queue input is backward in time
[rtp @ 0x5620d31acd80] Non-monotonous DTS in output stream 1:0; previous: 39358, current: 36944; changing to 39358. This may result in incorrect timestamps in the output file.
Incompatible pixel format 'yuv420p' for codec 'h264_vaapi', auto-selecting format 'vaapi_vld'
Impossible to convert between the formats supported by the filter 'Parsed_format_1' 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
[libfdk_aac @ 0x5620d31b9560] 2 frames left in the queue on closing
Conversion failed!

Here is the original command (which works but consume half of my CPU):

ffmpeg \
-rtsp_transport tcp \
-i rtsp://192.168.144.101:8554/unicast \
-map 0:0 \
-pix_fmt yuv420p \
-r 15 \
-f rawvideo \
-tune zerolatency \
-vf 'scale=1280:720,format=nv12' \
-b:v 299k \
-bufsize 299k \
-maxrate 299k -payload_type 99 \
-ssrc 13314026 \
-f rtp \
-srtp_out_suite AES_CM_128_HMAC_SHA1_80 \
-srtp_out_params ils+c7v2WkNjdFFgICwYAeDKZ5oVaUAs1moiaGFB \
"srtp://192.168.144.129:59295?rtcpport=59295&localrtcpport=59295&pkt_size=1316" \
-map 0:1 \
-acodec libfdk_aac \
-profile:a aac_eld -flags +global_header \
-f null \
-ar 16k \
-b:a 24k \
-bufsize 24k \
-ac 1 \
-payload_type 110 \
-ssrc 823920 \
-f rtp \
-srtp_out_suite AES_CM_128_HMAC_SHA1_80 \
-srtp_out_params u3K1xOSXFToXTC9d2n2YiGp+tNPsqbwK3NSx9qxr \
"srtp://192.168.144.129:57651?rtcpport=57651&localrtcpport=57651&pkt_size=1316"

Any idea how I can fix this?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Feb 18, 2019

@valksajaa I'll be back with a solution for this.

@Programming4life

This comment has been minimized.

Copy link

commented Mar 19, 2019

How can you rotate using h264_vaapi?

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Mar 21, 2019

@Programming4life, look into the transpose_vaapi filter:

ffmpeg -hide_banner -h filter=transpose_vaapi
Filter transpose_vaapi
  VAAPI VPP for transpose
    Inputs:
       #0: default (video)
    Outputs:
       #0: default (video)
transpose_vaapi AVOptions:
  dir               <int>        ..FV..... set transpose direction (from 0 to 6) (default cclock_flip)
     cclock_flip                  ..FV..... rotate counter-clockwise with vertical flip
     clock                        ..FV..... rotate clockwise
     cclock                       ..FV..... rotate counter-clockwise
     clock_flip                   ..FV..... rotate clockwise with vertical flip
     reversal                     ..FV..... rotate by half-turn
     hflip                        ..FV..... flip horizontally
     vflip                        ..FV..... flip vertically
  passthrough       <int>        ..FV..... do not apply transposition if the input matches the specified geometry (from 0 to INT_MAX) (default none)
     none                         ..FV..... always apply transposition
     portrait                     ..FV..... preserve portrait geometry
     landscape                    ..FV..... preserve landscape geometry

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Mar 21, 2019

@valksajaa show me your vainfo output.

@namespace7

This comment has been minimized.

Copy link

commented Mar 22, 2019

hey i'm trying to generate two resolutions m3u8 video output from a input,
the command i have used is

     **ffmpeg -vaapi_device /dev/dri/renderD128 -rtsp_flags listen -i rtsp://0.0.0.0:2222/live.sdp -b:v:0 4000k  -vf 'hwupload,scale_vaapi=w=1280:h=720:format=nv12,scale_vaapi=w=1080:h=720:format=nv12' -c:v:0 hevc_vaapi -b:a:0 512k  -b:v:1 2500k -b:a:1 256k -c:v:1 hevc_vaapi -hls_time 6 -hls_init_time 3 -hls_list_size 10 -hls_flags delete_segments -map 0:v -map 0:a -map 0:v -map 0:a  -var_stream_map "v:0,a:0 v:1,a:1 " -f hls -master_pl_name "new.m3u8" -hls_segment_filename "/var/www/html/v-%d-%v.ts" "/var/www/html/v_%v.m3u8"**

this command should generate hls stream of two resolutions but right now it is generating same resolutions 2 time m3u8 stream where it should generate 2 of different types..
Here is the output in the terminal while generating the stream

               pas@pas-Z370N-WIFI:~$ sudo ./ffmpeg -vaapi_device /dev/dri/renderD128 -rtsp_flags listen -i rtsp://0.0.0.0:2222/live.sdp -b:v:0 4000k  -vf 'hwupload,scale_vaapi=w=1280:h=720:format=nv12,scale_vaapi=w=1080:h=720:format=nv12' -c:v:0 hevc_vaapi -b:a:0 512k  -b:v:1 2500k -b:a:1 256k -c:v:1 hevc_vaapi -hls_time 6 -hls_init_time 3 -hls_list_size 10 -hls_flags delete_segments -map 0:v -map 0:a -map 0:v -map 0:a  -var_stream_map "v:0,a:0 v:1,a:1 " -f hls -master_pl_name "new.m3u8" -hls_segment_filename "/var/www/html/v-%d-%v.ts" "/var/www/html/v_%v.m3u8"

ffmpeg version N-93432-g4d8875e Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
configuration: --prefix=/home/pas/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pas/ffmpeg_build/include --extra-ldflags=-L/home/pas/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/pas/bin --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-gpl
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.105 / 58. 47.105
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, rtsp, from 'rtsp://0.0.0.0:2222/live.sdp':
Metadata:
title : No Name
Duration: N/A, start: -0.036958, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 29.97 tbc
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> hevc (hevc_vaapi))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Stream #0:0 -> #0:2 (hevc (native) -> hevc (hevc_vaapi))
Stream #0:1 -> #0:3 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Duplicate formats in ff_merge_formats detected
Last message repeated 1 times
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-0-0.ts' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-0-1.ts' for writing
Output #0, hls, to '/var/www/html/v_%v.m3u8':
Metadata:
title : No Name
encoder : Lavf58.26.101
Stream #0:0: Video: hevc (hevc_vaapi) (Main), vaapi_vld(progressive), 1080x720 [SAR 32:27 DAR 16:9], q=-1--1, 4000 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
Metadata:
encoder : Lavc58.47.105 hevc_vaapi
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 512 kb/s
Metadata:
encoder : Lavc58.47.105 aac
Stream #0:2: Video: hevc (hevc_vaapi) (Main), vaapi_vld(progressive), 1080x720 [SAR 32:27 DAR 16:9], q=-1--1, 2500 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
Metadata:
encoder : Lavc58.47.105 hevc_vaapi
Stream #0:3: Audio: aac (LC), 48000 Hz, stereo, fltp, 256 kb/s
Metadata:
encoder : Lavc58.47.105 aac
frame= 23 fps=0.0 q=-0.0 q=-0.0 size=N/A time=00:00:00.66 bitrate=N/A dup=2 drframe= 47 fps= 44 q=-0.0 q=-0.0 size=N/A time=00:00:01.60 bitrate=N/A dup=2 drframe= 64 fps= 41 q=-0.0 q=-0.0 size=N/A time=00:00:02.17 bitrate=N/A dup=2 drframe= 81 fps= 39 q=-0.0 q=-0.0 size=N/A time=00:00:02.75 bitrate=N/A dup=2 drframe= 104 fps= 40 q=-0.0 q=-0.0 size=N/A time=00:00:03.45 bitrate=N/A dup=2 dr[hls @ 0x563f843c8a80] Opening '/var/www/html/v-1-0.ts' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-1-1.ts' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/new.m3u8' for writing
frame= 128 fps= 41 q=-0.0 q=-0.0 size=N/A time=00:00:04.17 bitrate=N/A dup=2 drframe= 142 fps= 39 q=-0.0 q=-0.0 size=N/A time=00:00:04.75 bitrate=N/A dup=2 drop=0 spe[hls @ 0x563f843c8a80] Opening '/var/www/html/v-2-0.ts' for writing=N/A dup=2 drop=0 speed= 1.3x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-2-1.ts' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-3-0.ts' for writing=N/A dup=2 drop=0 speed= 1.2x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-3-1.ts' for writing=N/A dup=2 drop=0 speed=1.22x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-4-0.ts' for writing=N/A dup=2 drop=0 speed=1.23x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-4-1.ts' for writing=N/A dup=2 drop=0 speed=1.24x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-5-0.ts' for writing=N/A dup=2 drop=0 speed=1.24x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-5-1.ts' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-6-0.ts' for writing=N/A dup=2 drop=0 speed=1.23x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v-6-1.ts' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_0.m3u8.tmp' for writing dup=2 drop=0 speed=1.24x
[hls @ 0x563f843c8a80] Opening '/var/www/html/v_1.m3u8.tmp' for writing
frame= 835 fps= 37 q=-0.0 Lq=-0.0 size=N/A time=00:00:27.94 bitrate=N/A dup=2 drop=0 speed=1.25x
video:1549kB audio:2076kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[aac @ 0x563f843c5d40] Qavg: 65483.102
[aac @ 0x563f843dc640] Qavg: 9305.980
Exiting normally, received signal 2.

  **Help Will be Appreciated**
@nyinyinyanlin

This comment has been minimized.

Copy link

commented Mar 26, 2019

@namespace7 You might want to split the input video stream into two video streams first.

In your case - hwupload,scale_vaapi=w=1280:h=720:format=nv12,scale_vaapi=w=1080:h=720,format=nv12

What's happening with your filter complex is:

  1. FFMPEG parse the 0:v stream and upload it to VAAPI device
  2. VAAPI device scale the 0:v stream into 1280x720 resolution and output it back as 0:v stream
  3. VAAPI device format 0:v stream as nv12 pixel format and output it back as 0:v stream
  4. VAAPI device scale 0:v stream again as 1080x720 resolution and output it back as 0:v stream
  5. VAAPI device formats 0:v stream as nv12 pixel format again and pass it back into 0:v stream after filter complex
  6. VAAPI device consume 0:v stream as input for h264_vaapi encoding.

As you can see, your filter complex has been doing redundant scaling and formatting processes on the same video stream. When it is finally mapped for multiple outputs (2 in your case), FFMPEG's muxer uses the same video stream 0:v for generating two output files.

What you should have done is split the input video stream into two individual streams and scale these streams individually in VAAPI and map it back using labels.

Here's what I have done with similar process lately.

ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -re -i input.mp4 -filter_complex "scale_vaapi=w=1280:h=720,split=2[720][480],[480]scale_vaapi=w=854:h=480[480],asplit=2[720a][480a]" -map '[720]' -map '[720a]' -c:v h264_vaapi -b:v 2400k -c:a libfdk_aac -b:a 128k -f mp4 output_vaapi720.mp4 -map '[480]' -map '[480a]' -c:v h264_vaapi -b:v 1200k -c:a libfdk_aac -b:a 128k -f mp4 output_vaapi480.mp4

What's happening with this setup is:

  1. FFMPEG parse the input file
  2. VAAPI device decodes and formats video stream into vaapi_vdl pixel format as 0:v internally. (Omitted hwupload in this case. VAAPI device use vaapi_vdl pixel format as native)
  3. VAAPI device scales 0:v into 1280x720 resolution and passes it back into 0:v stream.
  4. 1280x720 0:v stream is split into two 1280x720 streams labelled [720] and [480] by VAAPI device.
  5. [480] 1280x720 stream is scaled into 854x480 resolution by VAAPI and passed back into [480] stream. (Now we have [720] 1280x720 and [480] 854x480 video streams)
  6. 0:a audio stream is split into two streams labelled [720a] and [480a]
  7. [720] video and [720a] audio streams are mapped as source inputs for h264_vaapi and libfdk_aac encoders
  8. These two streams are encoded, muxed and produced into output_720vaapi.mp4
  9. Same as step 7 for [480] and [480p] streams
  10. Same as step 8 for [480] and [480p] streams

(Step 1 and 2 are just guessed thoughts since I don't know much about how FFMPEG and VAAPI handle the input file internally. I have used -hwaccel_output_format nv12 -complex_filter 'hwupload,......' before but I found out that -hwaccel_output_format vaapi -complex_filter '.........' is a little bit faster. May be the input file is first formatted as nv12 pixel format and then uploaded to hardware, and this might caused the extra time. @Brainiarc7 Can you please share us some knowledge on this process?)

You can swap scale_vaapi and split around and achieve the similar result by -

split=2[720][480],[720]scale_vaapi=w=1280:h=720[720],[480]scale_vaapi=w=854:h=480[480],asplit=2[720a][480a]

This split the input video stream 0:v into two streams first and then scaled each of them individually.

Please let me know if there is any better work around for improved efficiency for my case. I found out that without splitting the audio input stream into two, only 720 output file is muxed with audio and 480 output file is muted.

Is there is any better way to encode the audio stream only once and duplicate the streams so that there is less overhead? I might as well want to produce 360 and 240 output files with same audio quality as well and want to avoid redundant audio encoding.

@nyinyinyanlin

This comment has been minimized.

Copy link

commented Mar 26, 2019

@valkjsaaa Can you try using this?

ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/yourvideodevice -rtsp_transport tcp -i rtsp://192.168.144.101:8554/unicast -vf 'scale_vaapi=1280:720' -vcodec h264_vaapi .........

Apparently, in your case, you're not using VAAPI device to scale your video stream. Instead, you're using CPU to scale it. And you've declared yuv420 as pixel format but that is not supported by your VAAPI device and it changed the input stream's pixel format to vaapi_vld automatically. And since scale is done by CPU, it might expects pixel format as yuv420 or nv12 but what it got was vaapi_vld. This is where formatting error occurs I think.

Also, h264_vaapi encoder might probably be happy with vaapi_vld as pixel format and format conversion from vaapi_vld to nv12 is unnecessary I think.

Please correct me if I am wrong.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Mar 27, 2019

@namespace7 see the solution below:

   ffmpeg -hwaccel vaapi  -vaapi_device /dev/dri/renderD128 -rtsp_flags listen \
   -threads:v 2 -threads:a 4 -filter_complex_threads 4 -filter_threads 4 \
   -i rtsp://0.0.0.0:2222/live.sdp' -filter_complex \
  "[0:v]split=2[a][b]; \
   [a]format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720[k0]; \
   [b]format=nv12|vaapi,hwupload,scale_vaapi=w=1080:h=720[k1]" \
   -c:a aac -b:a:0 512k -b:a:1 256k \
  -b:v:0 4000k -minrate:v:0 4000k -maxrate:v:0 4000k -bufsize:v:0 533k -c:v:0 hevc_vaapi -qp:v:0 19  \
  -rc_mode:v:0 2 -level:v:0 4.1 -r:v:0 29.970 -g:v:0 60 -bf:v:0 3  \
  -b:v:1 2500k -minrate:v:1 2500k -maxrate:v:1 2500k -bufsize:v:1 333k -c:v:1 hevc_vaapi -qp:v:1 19  \
  -rc_mode:v:1 2 -level:v:1 4.1 -r:v:1 29.970 -g:v:1 60 -bf:v:1 3  \
  -flags +global_header+low_delay -fflags +genpts \
  -map "[k0]" -map "[k1]" -map 0:a -map 0:a \
  -f hls -hls_init_time 3 -hls_list_size 10 -hls_flags delete_segments -var_stream_map "v:0,a:0 v:1,a:1" \
  -master_pl_name "new.m3u8" -hls_segment_filename "/var/www/html/v-%d-%v.ts" "/var/www/html/v_%v.m3u8"

@nyinyinyanlin that extra hwupload step (see this snippet above) is often necessary when the format of the decoded content may not be supported natively by vaapi (or the combination of the vaapi driver & platform in use). In that case, you use a hwupload filter that will either pass the native vaapi_vld surfaces to the encoder OR convert them to nv12 which the encoder supports if full hwaccel isn't available. This also makes the pipeline much more robust against sporadic failure should the stream specifics change on the fly.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Mar 27, 2019

Hello @valkjsaaa use this:

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 \
-threads:v 2 -threads:a 4 \
-rtsp_transport tcp \
-i rtsp://192.168.144.101:8554/unicast \
-map 0:0 \
-pix_fmt yuv420p \
-r 15 \
-f rawvideo \
-vf 'format=nv12|vaapi,hwupload,scale_vaapi=1280:720' \
-c:v h264_vaapi \
-b:v 299k \
-bufsize 299k \
-maxrate 299k -payload_type 99 \
-ssrc 13314026 \
-f rtp \
-srtp_out_suite AES_CM_128_HMAC_SHA1_80 \
-srtp_out_params ils+c7v2WkNjdFFgICwYAeDKZ5oVaUAs1moiaGFB \
"srtp://192.168.144.129:59295?rtcpport=59295&localrtcpport=59295&pkt_size=1316" \
-map 0:1 \
-acodec libfdk_aac \
-profile:a aac_eld -flags +global_header \
-f null \
-ar 16k \
-b:a 24k \
-bufsize 24k \
-ac 1 \
-payload_type 110 \
-ssrc 823920 \
-f rtp \
-srtp_out_suite AES_CM_128_HMAC_SHA1_80 \
-srtp_out_params u3K1xOSXFToXTC9d2n2YiGp+tNPsqbwK3NSx9qxr \
"srtp://192.168.144.129:57651?rtcpport=57651&localrtcpport=57651&pkt_size=1316"
@namespace7

This comment has been minimized.

Copy link

commented Apr 1, 2019

@namespace7 see the solution below:
ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -rtsp_flags listen
-threads:v 2 -threads:a 4 -filter_complex_threads 4 -filter_threads 4
-i rtsp://0.0.0.0:2222/live.sdp' -filter_complex
"[0:v]split=2[a][b];
[a]format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720[k0];
[b]format=nv12|vaapi,hwupload,scale_vaapi=w=1080:h=720[k1]"
-c:a aac -b🅰️0 512k -b🅰️1 256k
-b✌️0 4000k -minrate✌️0 4000k -maxrate✌️0 4000k -bufsize✌️0 533k -c✌️0 hevc_vaapi -qp✌️0 19
-profile✌️0 high -rc_mode✌️0 2 -level✌️0 4.1 -r✌️0 29.970 -g✌️0 60 -bf✌️0 3
-b✌️1 2500k -minrate✌️1 2500k -maxrate✌️1 2500k -bufsize✌️1 333k -c✌️1 hevc_vaapi -qp✌️1 19
-profile✌️1 high -rc_mode✌️1 2 -level✌️1 4.1 -r✌️0 29.970 -g✌️0 60 -bf✌️1 3
-flags +global_header+low_delay -fflags +genpts
-map "[k0]" -map "[k1]" -map 0:a -map 0:a
-f hls -hls_init_time 3 -hls_list_size 10 -hls_flags delete_segments -var_stream_map "v:0,a:0 v:1,a:1"
-master_pl_name "new.m3u8" -hls_segment_filename "/var/www/html/v-%d-%v.ts" "/var/www/html/v_%v.m3u8"
@nyinyinyanlin that extra hwupload step (see this snippet above) is often necessary when the format of the decoded content may not be supported natively by vaapi (or the combination of the vaapi driver & platform in use). In that case, you use a hwupload filter that will either pass the native vaapi_vld surfaces to the encoder OR convert them to nv12 which the encoder supports if full hwaccel isn't available. This also makes the pipeline much more robust against sporadic failure should the stream specifics change on the fly.

Sorry,i'm late . The command throws the Error

      unrecognized option 'rc_mode:v:0'

:(

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 1, 2019

How are you escaping characters in your shell? Are you calling that up from within node(js) or a similar environment?

I've edited the response above.

On what to expect in terms of performance, throughput and system load, see this.

@namespace7

This comment has been minimized.

Copy link

commented Apr 2, 2019

How are you escaping characters in your shell? Are you calling that up from within node(js) or a similar environment?
I've edited the response above.
On what to expect in terms of performance, throughput and system load, see this.

hey @Brainiarc7 you're genius !

    -profile:v:0 high

was creating a error! but the command works excellent after removing it..
I appreciated your support 💃

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2019

Hey @namespace7 can you show me the error you were encountering with that option present?
Let me edit my answer above with that correction.

@namespace7

This comment has been minimized.

Copy link

commented Apr 3, 2019

@Brainiarc7
output Error

image

once I start sending the video file, the above command crashes with this error..

How I'm using the command?

image

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2019

Add -loglevel debug to ffmpeg, so we can see what triggers the error in #1 and #2.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2019

And do paste the actual commands in the comments. Screenshots are wasteful.

@namespace7

This comment has been minimized.

Copy link

commented Apr 4, 2019

Sure

 here

pas@pas-To-be-filled-by-O-E-M:$ sudo ./ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -rtsp_flags listen -threads:v 2 -threads:a 4 -filter_complex_threads 4 -filter_threads 4 -i rtsp://0.0.0.0:2222/live.sdp -filter_complex "[0:v]split=2[a][b]; [a]format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720[k0]; [b]format=nv12|vaapi,hwupload,scale_vaapi=w=1080:h=720[k1]" -c:a aac -b: a:0 512k -b : a:1 256k -b: v:0 4000k -minrate: v:0 4000k -maxrate : v:0 4000k -bufsize: v:0 533k -c: v:0 hevc_vaapi -qp: v:0 19 -profile: v:0 high -rc_mode: v:0 2 -level: v:0 4.1 -r: v :0 29.970 -g: v:0 60 -bf: v:0 3 -b: v:1 2500k -minrate: v:1 2500k -maxrate: v:1 2500k -bufsize: v:1 333k -c: v:1 hevc_vaapi -qp: v:1 19 -profile: v:1 high -rc_mode: v:1 2 -level: v:1 4.1 -r : v:0 29.970 -g: v:0 60 -bf: v:1 3 -flags +global_header+low_delay -fflags +genpts -map "[k0]" -map "[k1]" -map 0:a -map 0:a -f hls -hls_init_time 3 -hls_list_size 10 -hls_flags delete_segments -var_stream_map "v:0,a:0 v:1,a:1" -master_pl_name "new.m3u8" -hls_segment_filename "/var/www/html/v-%d-%v.ts" "/var/www/html/v_%v.m3u8" -loglevel debug
ffmpeg version N-93468-g6bc800d Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
configuration: --prefix=/home/pas/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pas/ffmpeg_build/include --extra-ldflags=-L/home/pas/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/pas/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.105 / 58. 47.105
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Splitting the commandline.
Reading option '-hwaccel' ... matched as option 'hwaccel' (use HW accelerated decoding) with argument 'vaapi'.
Reading option '-vaapi_device' ... matched as option 'vaapi_device' (set VAAPI hardware device (DRM path or X11 display name)) with argument '/dev/dri/renderD128'.
Reading option '-rtsp_flags' ... matched as AVOption 'rtsp_flags' with argument 'listen'.
Reading option '-threads:v' ... matched as AVOption 'threads :v' with argument '2'.
Reading option '-threads:a' ... matched as AVOption 'threads :a' with argument '4'.
Reading option '-filter_complex_threads' ... matched as option 'filter_complex_threads' (number of threads for -filter_complex) with argument '4'.
Reading option '-filter_threads' ... matched as option 'filter_threads' (number of non-complex filter threads) with argument '4'.
Reading option '-i' ... matched as input url with argument 'rtsp://0.0.0.0:2222/live.sdp'.
Reading option '-filter_complex' ... matched as option 'filter_complex' (create a complex filtergraph) with argument '[0:v]split=2[a][b]; [a]format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720[k0]; [b]format=nv12|vaapi,hwupload,scale_vaapi=w=1080:h=720[k1]'.
Reading option '-c: a' ... matched as option 'c' (codec name) with argument 'aac'.
Reading option '-b : a:0' ... matched as option 'b' (video bitrate (please use -b :v)) with argument '512k'.
Reading option '-b : a:1' ... matched as option 'b' (video bitrate (please use -b :v)) with argument '256k'.
Reading option '-b: v:0' ... matched as option 'b' (video bitrate (please use -b :v)) with argument '4000k'.
Reading option '-minrate: v:0' ... matched as AVOption 'minrate: v:0' with argument '4000k'.
Reading option '-maxrate: v:0' ... matched as AVOption 'maxrate: v:0' with argument '4000k'.
Reading option '-bufsize: v:0' ... matched as AVOption 'bufsize: v:0' with argument '533k'.
Reading option '-c: v:0' ... matched as option 'c' (codec name) with argument 'hevc_vaapi'.
Reading option '-qp: v:0' ... matched as AVOption 'qp: v:0' with argument '19'.
Reading option '-profile: v:0' ... matched as option 'profile' (set profile) with argument 'high'.
Reading option '-rc_mode: v:0' ... matched as AVOption 'rc_mode: v:0' with argument '2'.
Reading option '-level: v:0' ... matched as AVOption 'level: v:0' with argument '4.1'.
Reading option '-r: v:0' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '29.970'.
Reading option '-g: v:0' ... matched as AVOption 'g: v:0' with argument '60'.
Reading option '-bf: v:0' ... matched as AVOption 'bf: v:0' with argument '3'.
Reading option '-b: v:1' ... matched as option 'b' (video bitrate (please use -b: v)) with argument '2500k'.
Reading option '-minrate: v:1' ... matched as AVOption 'minrate: v:1' with argument '2500k'.
Reading option '-maxrate: v:1' ... matched as AVOption 'maxrate: v:1' with argument '2500k'.
Reading option '-bufsize: v:1' ... matched as AVOption 'bufsize: v:1' with argument '333k'.
Reading option '-c: v:1' ... matched as option 'c' (codec name) with argument 'hevc_vaapi'.
Reading option '-qp: v:1' ... matched as AVOption 'qp: v:1' with argument '19'.
Reading option '-profile: v:1' ... matched as option 'profile' (set profile) with argument 'high'.
Reading option '-rc_mode: v:1' ... matched as AVOption 'rc_mode: v:1' with argument '2'.
Reading option '-level: v:1' ... matched as AVOption 'level: v:1' with argument '4.1'.
Reading option '-r:v :0' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '29.970'.
Reading option '-g:v :0' ... matched as AVOption 'g: v:0' with argument '60'.
Reading option '-bf: v:1' ... matched as AVOption 'bf: v:1' with argument '3'.
Reading option '-flags' ... matched as AVOption 'flags' with argument '+global_header+low_delay'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument '+genpts'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '[k0]'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '[k1]'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:a'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:a'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'hls'.
Reading option '-hls_init_time' ... matched as AVOption 'hls_init_time' with argument '3'.
Reading option '-hls_list_size' ... matched as AVOption 'hls_list_size' with argument '10'.
Reading option '-hls_flags' ... matched as AVOption 'hls_flags' with argument 'delete_segments'.
Reading option '-var_stream_map' ... matched as AVOption 'var_stream_map' with argument 'v:0,a:0 v:1,a:1'.
Reading option '-master_pl_name' ... matched as AVOption 'master_pl_name' with argument 'new.m3u8'.
Reading option '-hls_segment_filename' ... matched as AVOption 'hls_segment_filename' with argument '/var/www/html/v-%d-%v.ts'.
Reading option '/var/www/html/v_%v.m3u8' ... matched as output url.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option vaapi_device (set VAAPI hardware device (DRM path or X11 display name)) with argument /dev/dri/renderD128.
[AVHWDeviceContext @ 0x55c0238b8200] Opened VA display via DRM device /dev/dri/renderD128.
[AVHWDeviceContext @ 0x55c0238b8200] libva: VA-API version 1.1.0
[AVHWDeviceContext @ 0x55c0238b8200] libva: va_getDriverName() returns 0
[AVHWDeviceContext @ 0x55c0238b8200] libva: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
[AVHWDeviceContext @ 0x55c0238b8200] libva: Found init function __vaDriverInit_1_1
[AVHWDeviceContext @ 0x55c0238b8200] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x55c0238b8200] Initialised VAAPI connection: version 1.1
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x32315659 -> yuv420p.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x30323449 -> yuv420p.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x3231564e -> nv12.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x32595559 -> yuyv422.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x59565955 -> uyvy422.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x48323234 -> yuv422p.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x58424752 -> rgb0.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x58524742 -> bgr0.
[AVHWDeviceContext @ 0x55c0238b8200] Format 0x30313050 -> p010le.
[AVHWDeviceContext @ 0x55c0238b8200] VAAPI driver: Intel i965 driver for Intel(R) Skylake - 2.1.0.
[AVHWDeviceContext @ 0x55c0238b8200] Driver not found in known nonstandard list, using standard behaviour.
Applying option filter_complex_threads (number of threads for -filter_complex) with argument 4.
Applying option filter_threads (number of non-complex filter threads) with argument 4.
Applying option filter_complex (create a complex filtergraph) with argument [0:v]split=2[a][b]; [a]format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720[k0]; [b]format=nv12|vaapi,hwupload,scale_vaapi=w=1080:h=720[k1].
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url rtsp://0.0.0.0:2222/live.sdp.
Applying option hwaccel (use HW accelerated decoding) with argument vaapi.
Successfully parsed a group of options.
Opening an input file: rtsp://0.0.0.0:2222/live.sdp.
[tcp @ 0x55c0238dbf80] No default whitelist set
[rtsp @ 0x55c0238d9d40] SDP: v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 58.26.101
m=video 0 RTP/AVP 96
a=rtpmap:96 H265/90000
a=fmtp:96 sprop-vps=QAEMAf//AWAAAAMAkAAAAwAAAwB4ugJA; sprop-sps=QgEBAWAAAAMAkAAAAwAAAwB4oAPAgBEHy5bpKTC8BAQAAAMABAAAAwBkIA==; sprop-pps=RAHAcYMS
a=control:streamid=0
m=audio 0 RTP/AVP 97
b=AS:96
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=119056E500
a=control:streamid=1

[rtsp @ 0x55c0238d9d40] video codec set to: hevc
[rtsp @ 0x55c0238d9d40] audio codec set to: aac
[rtsp @ 0x55c0238d9d40] audio samplerate set to: 48000
[rtsp @ 0x55c0238d9d40] audio channels set to: 2
[rtsp @ 0x55c0238d9d40] setting jitter buffer size to 0
Last message repeated 1 times
Failed to parse interval end specification ''
[hevc @ 0x55c0238dd400] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] Decoding VPS
[hevc @ 0x55c0238dd400] Main profile bitstream
[hevc @ 0x55c0238dd400] Decoding SPS
[hevc @ 0x55c0238dd400] Main profile bitstream
[hevc @ 0x55c0238dd400] Decoding VUI
[hevc @ 0x55c0238dd400] Decoding PPS
[hevc @ 0x55c0238dd400] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] Decoding VPS
[hevc @ 0x55c0238dd400] Main profile bitstream
[hevc @ 0x55c0238dd400] Decoding SPS
[hevc @ 0x55c0238dd400] Main profile bitstream
[hevc @ 0x55c0238dd400] Decoding VUI
[hevc @ 0x55c0238dd400] Decoding PPS
[hevc @ 0x55c0238dd400] nal_unit_type: 20(IDR_N_LP), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c0238dd400] nal_unit_type: 1(TRAIL_R), nuh_layer_id: 0, temporal_id: 0
Last message repeated 1 times
[rtsp @ 0x55c0238d9d40] first_dts -6990 not matching first dts NOPTS (pts NOPTS, duration 3600) in the queue
[hevc @ 0x55c0238dd400] nal_unit_type: 1(TRAIL_R), nuh_layer_id: 0, temporal_id: 0
Last message repeated 18 times
[rtsp @ 0x55c0238d9d40] All info found
Input #0, rtsp, from 'rtsp://0.0.0.0:2222/live.sdp':
Metadata:
title : No Name
Duration: N/A, start: -0.139000, bitrate: N/A
Stream #0:0, 22, 1/90000: Video: hevc (Main), 1 reference frame, yuv420p(tv), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 0/1, 25 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1, 42, 1/48000: Audio: aac (LC), 48000 Hz, stereo, fltp
Successfully opened the file.
[Parsed_split_0 @ 0x55c0238e6380] Setting 'outputs' to value '2'
[Parsed_format_1 @ 0x55c0238e2f40] Setting 'pix_fmts' to value 'nv12|vaapi'
[Parsed_scale_vaapi_3 @ 0x55c0238f0d40] Setting 'w' to value '1280'
[Parsed_scale_vaapi_3 @ 0x55c0238f0d40] Setting 'h' to value '720'
[Parsed_format_4 @ 0x55c0238efd40] Setting 'pix_fmts' to value 'nv12|vaapi'
[Parsed_scale_vaapi_6 @ 0x55c0238f3940] Setting 'w' to value '1080'
[Parsed_scale_vaapi_6 @ 0x55c0238f3940] Setting 'h' to value '720'
Parsing a group of options: output url /var/www/html/v_%v.m3u8.
Applying option c :a (codec name) with argument aac.
Applying option b : a:0 (video bitrate (please use -b :v)) with argument 512k.
Applying option b : a:1 (video bitrate (please use -b :v)) with argument 256k.
Applying option b: v:0 (video bitrate (please use -b :v)) with argument 4000k.
Applying option c: v:0 (codec name) with argument hevc_vaapi.
Applying option profile: v:0 (set profile) with argument high.
Applying option r: v:0 (set frame rate (Hz value, fraction or abbreviation)) with argument 29.970.
Applying option b: v:1 (video bitrate (please use -b:v)) with argument 2500k.
Applying option c: v:1 (codec name) with argument hevc_vaapi.
Applying option profile: v:1 (set profile) with argument high.
Applying option r: v:0 (set frame rate (Hz value, fraction or abbreviation)) with argument 29.970.
Applying option map (set input stream mapping) with argument [k0].
Applying option map (set input stream mapping) with argument [k1].
Applying option map (set input stream mapping) with argument 0:a.
Last message repeated 1 times
Applying option f (force format) with argument hls.
Successfully parsed a group of options.
Opening an output file: /var/www/html/v_%v.m3u8.
Successfully opened the file.
[hevc @ 0x55c023947e80] nal_unit_type: 32(VPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c023947e80] nal_unit_type: 33(SPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c023947e80] nal_unit_type: 34(PPS), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c023947e80] Decoding VPS
[hevc @ 0x55c023947e80] Main profile bitstream
[hevc @ 0x55c023947e80] Decoding SPS
[hevc @ 0x55c023947e80] Main profile bitstream
[hevc @ 0x55c023947e80] Decoding VUI
[hevc @ 0x55c023947e80] Decoding PPS
Stream mapping:
Stream #0:0 (hevc) -> split (graph 0)
scale_vaapi (graph 0) -> Stream #0:0 (hevc_vaapi)
scale_vaapi (graph 0) -> Stream #0:1 (hevc_vaapi)
Stream #0:1 -> #0:2 (aac (native) -> aac (native))
Stream #0:1 -> #0:3 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
Last message repeated 1 times
[hevc @ 0x55c023947e80] nal_unit_type: 20(IDR_N_LP), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c023947e80] Format vaapi_vld chosen by get_format().
[hevc @ 0x55c023947e80] Format vaapi_vld requires hwaccel initialisation.
[hevc @ 0x55c023947e80] Considering format 0x3231564e -> nv12.
[hevc @ 0x55c023947e80] Picked nv12 (0x3231564e) as best match for yuv420p.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000000.
[AVHWFramesContext @ 0x7fe4940d0b40] Direct mapping disabled: derived image format 3231564e does not match expected format 32315659.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000001.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000002.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000003.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000004.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000005.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000006.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000007.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000008.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000009.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x400000a.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x400000b.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x400000c.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x400000d.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x400000e.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x400000f.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000010.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000011.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000012.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000013.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000014.
[AVHWFramesContext @ 0x7fe4940d0b40] Created surface 0x4000015.
[hevc @ 0x55c023947e80] Considering format 0x3231564e -> nv12.
[hevc @ 0x55c023947e80] Picked nv12 (0x3231564e) as best match for yuv420p.
[hevc @ 0x55c023947e80] Decode context initialised: 0x1000000/0x2000000.
[hevc @ 0x55c023947e80] Output frame with POC 0.
[hevc @ 0x55c023947e80] Param buffer (type 0, 604 bytes) is 0x8000000.
[hevc @ 0x55c023947e80] Slice 0 param buffer (264 bytes) is 0x8000001.
[hevc @ 0x55c023947e80] Slice 0 data buffer (7382 bytes) is 0x8000002.
[hevc @ 0x55c023947e80] Decode to surface 0x4000015.
[AVHWFramesContext @ 0x7fe4940d0b40] Map surface 0x4000015.
[hevc @ 0x55c023903a00] nal_unit_type: 1(TRAIL_R), nuh_layer_id: 0, temporal_id: 0
[hevc @ 0x55c023903a00] Output frame with POC 1.
[hevc @ 0x55c023903a00] Param buffer (type 0, 604 bytes) is 0x8000001.
[hevc @ 0x55c023903a00] Slice 0 param buffer (264 bytes) is 0x8000000.
[hevc @ 0x55c023903a00] Slice 0 data buffer (615 bytes) is 0x8000003.
[hevc @ 0x55c023903a00] Decode to surface 0x4000014.
[AVHWFramesContext @ 0x7fe4940d0b40] Unmap surface 0x4000015.
[Parsed_split_0 @ 0x55c023ad7840] Setting 'outputs' to value '2'
[Parsed_format_1 @ 0x55c023ae4880] Setting 'pix_fmts' to value 'nv12|vaapi'
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Setting 'w' to value '1280'
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Setting 'h' to value '720'
[Parsed_format_4 @ 0x55c023ae5d80] Setting 'pix_fmts' to value 'nv12|vaapi'
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Setting 'w' to value '1080'
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Setting 'h' to value '720'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] Setting 'video_size' to value '1920x1080'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] Setting 'pix_fmt' to value '23'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] Setting 'time_base' to value '1/90000'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0x55c023ae8080] w:1920 h:1080 pixfmt:nv12 tb:1/90000 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 0x55c023ae44c0] Setting 'pix_fmts' to value 'vaapi_vld'
[format @ 0x55c023ae6ec0] Setting 'pix_fmts' to value 'vaapi_vld'
[AVFilterGraph @ 0x55c0238e6240] query_formats: 12 queried, 11 merged, 0 already done, 0 delayed
[hwupload @ 0x55c023ae6900] Surface format is nv12.
[AVHWFramesContext @ 0x55c023aedd00] Created surface 0x4000016.
[AVHWFramesContext @ 0x55c023aedd00] Direct mapping possible.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x4000017.
[AVHWFramesContext @ 0x55c023aeef40] Direct mapping possible.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x4000018.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x4000019.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x400001a.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x400001b.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x400001c.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x400001d.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x400001e.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x400001f.
[AVHWFramesContext @ 0x55c023aeef40] Created surface 0x4000020.
[hwupload @ 0x55c023914b80] Surface format is nv12.
[AVHWFramesContext @ 0x55c023ae7ac0] Created surface 0x4000021.
[AVHWFramesContext @ 0x55c023ae7ac0] Direct mapping possible.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000022.
[AVHWFramesContext @ 0x55c023ae5ac0] Direct mapping possible.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000023.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000024.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000025.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000026.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000027.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000028.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x4000029.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x400002a.
[AVHWFramesContext @ 0x55c023ae5ac0] Created surface 0x400002b.
[AVHWFramesContext @ 0x55c023ae7ac0] Map surface 0x4000021.
[AVHWFramesContext @ 0x55c023ae7ac0] Unmap surface 0x4000021.
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Filter input: vaapi_vld, 1920x1080 (0).
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Using surface 0x4000021 for scale input.
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Using surface 0x400002b for scale output.
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Pipeline parameter buffer is 0x8000002.
[Parsed_scale_vaapi_3 @ 0x55c023ae5380] Filter output: vaapi_vld, 1280x720 (0), mode: HQ.
[AVHWFramesContext @ 0x55c023aedd00] Map surface 0x4000016.
[AVHWFramesContext @ 0x55c023aedd00] Unmap surface 0x4000016.
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Filter input: vaapi_vld, 1920x1080 (0).
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Using surface 0x4000016 for scale input.
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Using surface 0x4000020 for scale output.
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Pipeline parameter buffer is 0x8000002.
[Parsed_scale_vaapi_6 @ 0x55c023ae7000] Filter output: vaapi_vld, 1080x720 (0), mode: HQ.
[h265_vaapi @ 0x7fe49d260040] [Eval @ 0x7ffc773a5220] Undefined constant or missing '(' in 'high'
[h265_vaapi @ 0x7fe49d260040] Unable to parse option value "high"
[h265_vaapi @ 0x7fe49d260040] Error setting option profile to value high.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

    Stream Sending command log    *ffmpeg -stream_loop -1 -i /home/pas/Downloads/angrybird.mp4 -c:v libx265 -preset ultrafast -tune zerolatency -c:a aac -ab 96k -ar 48000 -f rtsp -rtsp_transport tcp  rtsp://0.0.0.0:2222/live.sdp*

Output #0, rtsp, to 'rtsp://0.0.0.0:2222/live.sdp':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.26.101
Stream #0:0(und), 0, 1/90000: Video: hevc (libx265), 1 reference frame, yuv420p(left), 1920x1080 [SAR 1:1 DAR 16:9], 0/1, q=2-31, 25 fps, 90k tbn, 25 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 03/29/2019.
encoder : Lavc58.47.105 libx265
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1(eng), 0, 1/48000: Audio: aac (LC), 48000 Hz, stereo, fltp, delay 1024, 96 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 03/29/2019.
encoder : Lavc58.47.105 aac
Clipping frame in rate conversion by 0.000008
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
Last message repeated 2 times
[h264 @ 0x55c46586f880] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
Last message repeated 2 times
[h264 @ 0x55c4656c8b00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 8 of len 7381 M=1
[rtp @ 0x55c465f68e40] NAL size 7381 > 1460
[h264 @ 0x55c465732800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 614 M=1
[h264 @ 0x55c465821380] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 990 M=1
[h264 @ 0x55c4656edec0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 1392 M=1
[h264 @ 0x55c46586f880] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 1949 M=1
[rtp @ 0x55c465f68e40] NAL size 1949 > 1460
[h264 @ 0x55c4656c8b00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 2282 M=1
[rtp @ 0x55c465f68e40] NAL size 2282 > 1460
[h264 @ 0x55c465732800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 2019 M=1
[rtp @ 0x55c465f68e40] NAL size 2019 > 1460
[h264 @ 0x55c465821380] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 2176 M=1
[rtp @ 0x55c465f68e40] NAL size 2176 > 1460
[h264 @ 0x55c4656edec0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 3690 M=1
[rtp @ 0x55c465f68e40] NAL size 3690 > 1460
[h264 @ 0x55c46586f880] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 3161 M=1
[rtp @ 0x55c465f68e40] NAL size 3161 > 1460
[h264 @ 0x55c4656c8b00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 3902 M=1
[rtp @ 0x55c465f68e40] NAL size 3902 > 1460
[h264 @ 0x55c465732800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 3690 M=1
[rtp @ 0x55c465f68e40] NAL size 3690 > 1460
[h264 @ 0x55c465821380] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4344 M=1
[rtp @ 0x55c465f68e40] NAL size 4344 > 1460
[h264 @ 0x55c4656edec0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4786 M=1
[rtp @ 0x55c465f68e40] NAL size 4786 > 1460
[h264 @ 0x55c46586f880] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 6049 M=1
[rtp @ 0x55c465f68e40] NAL size 6049 > 1460
[h264 @ 0x55c4656c8b00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 5907 M=1
[rtp @ 0x55c465f68e40] NAL size 5907 > 1460
[h264 @ 0x55c465732800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4360 M=1
[rtp @ 0x55c465f68e40] NAL size 4360 > 1460
[h264 @ 0x55c465821380] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4206 M=1
[rtp @ 0x55c465f68e40] NAL size 4206 > 1460
[h264 @ 0x55c4656edec0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 3678 M=1
[rtp @ 0x55c465f68e40] NAL size 3678 > 1460
[h264 @ 0x55c46586f880] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4295 M=1
[rtp @ 0x55c465f68e40] NAL size 4295 > 1460
[h264 @ 0x55c4656c8b00] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 3561 M=1
[rtp @ 0x55c465f68e40] NAL size 3561 > 1460
[h264 @ 0x55c465732800] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4098 M=1
[rtp @ 0x55c465f68e40] NAL size 4098 > 1460
[h264 @ 0x55c465821380] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4160 M=1
[rtp @ 0x55c465f68e40] NAL size 4160 > 1460
[h264 @ 0x55c4656edec0] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 0
[rtp @ 0x55c465f68e40] Sending NAL 2 of len 4320 M=1
[rtp @ 0x55c465f68e40] NAL size 4320 > 1460
[h264 @ 0x55c46586f880] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2
av_interleaved_write_frame(): Broken pipe
No more output streams to write to, finishing.
av_interleaved_write_frame(): Broken pipe
Error writing trailer of rtsp://0.0.0.0:2222/live.sdp: Broken pipe
frame= 27 fps=0.0 q=-0.0 Lsize=N/A time=00:00:01.17 bitrate=N/A speed=1.74x
video:89kB audio:14kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: unknown
Input file #0 (/home/pas/Downloads/angry.mp4):
Input stream #0:0 (video): 32 packets read (131732 bytes); 28 frames decoded;
Input stream #0:1 (audio): 52 packets read (19843 bytes); 52 frames decoded (53248 samples);
Total: 84 packets (151575 bytes) demuxed
Output file #0 (rtsp://0.0.0.0:2222/live.sdp):
Output stream #0:0 (video): 27 frames encoded; 25 packets muxed (91489 bytes);
Output stream #0:1 (audio): 56 frames encoded (57344 samples); 56 packets muxed (14844 bytes);
Total: 81 packets (106333 bytes) muxed
80 frames successfully decoded, 0 decoding errors
x265 [info]: frame I: 1, Avg QP:25.09 kb/s: 1476.20
x265 [info]: frame P: 26, Avg QP:24.31 kb/s: 720.17
x265 [info]: consecutive B-frames: 100.0%

encoded 27 frames in 0.65s (41.22 fps), 748.17 kb/s, Avg QP:24.34
[aac @ 0x55c4656f0100] Qavg: 6812.111
[AVIOContext @ 0x55c465698640] Statistics: 500410 bytes read, 2 seeks
Conversion failed!
pas@pas-To-be-filled-by-O-E-M:~$

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 5, 2019

Can you show me the output of vainfo and ffmpeg -h encoder=hevc_vaapi?
I need to confirm something with that info

@namespace7

This comment has been minimized.

Copy link

commented Apr 6, 2019

  vainfo

sudo ./ffmpeg -hwaccel vaapi vainfo -vaapi_device /dev/dri/renderD128 -rtsp_flags listen -threads:v 2 -threads:a 4 -filter_complex_threads 4 -filter_threads 4 -i rtsp://0.0.0.0:2222/live.sdp -filter_complex "[0:v]split=2[a][b]; [a]format=nv12|vaapi,hwupload,scale_vaapi=w=1280:h=720[k0]; [b]format=nv12|vaapi,hwupload,scale_vaapi=w=1080:h=720[k1]" -c:a aac -b: a :0 512k -b: a:1 256k -b: v:0 4000k -minrate: v:0 4000k -maxrate: v :0 4000k -bufsize: v :0 533k -c: v:0 hevc_vaapi -qp: v:0 19 -profile: v:0 high -rc_mode: v:0 2 -level: v:0 4.1 -r: v:0 29.970 -g: v:0 60 -bf: v:0 3 -b: v:1 2500k -minrate: v:1 2500k -maxrate: v:1 2500k -bufsize: v:1 333k -c: v:1 hevc_vaapi -qp: v:1 19 -profile: v:1 high -rc_mode: v:1 2 -level: v:1 4.1 -r: v:0 29.970 -g: v:0 60 -bf: v:1 3 -flags +global_header+low_delay -fflags +genpts -map "[k0]" -map "[k1]" -map 0:a -map 0:a -f hls -hls_init_time 3 -hls_list_size 10 -hls_flags delete_segments -var_stream_map "v:0,a:0 v:1,a:1" -master_pl_name "new.m3u8" -hls_segment_filename "/var/www/html/v-%d-%v.ts" "/var/www/html/v_%v.m3u8"
ffmpeg version N-93468-g6bc800d Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
configuration: --prefix=/home/pas/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pas/ffmpeg_build/include --extra-ldflags=-L/home/pas/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/pas/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.105 / 58. 47.105
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, rtsp, from 'rtsp://0.0.0.0:2222/live.sdp':
Metadata:
title : No Name
Duration: N/A, start: -0.144000, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 25 tbc
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp
Option hwaccel (use HW accelerated decoding) cannot be applied to output url vainfo -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for output file vainfo.
Error opening output files: Invalid argument

  ffmpeg -h encoder=hevc_vaapi

sudo ./ffmpeg -h encoder=hevc_vaapi
ffmpeg version N-93468-g6bc800d Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
configuration: --prefix=/home/pas/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pas/ffmpeg_build/include --extra-ldflags=-L/home/pas/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/pas/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 26.100 / 56. 26.100
libavcodec 58. 47.105 / 58. 47.105
libavformat 58. 26.101 / 58. 26.101
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 48.100 / 7. 48.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Encoder hevc_vaapi [H.265/HEVC (VAAPI)]:
General capabilities: delay hardware
Threading capabilities: none
Supported pixel formats: vaapi_vld
h265_vaapi AVOptions:
-low_power E..V..... Use low-power encoding mode (only available on some platforms; may not support all encoding features) (default false)
-idr_interval E..V..... Distance (in I-frames) between IDR frames (from 0 to INT_MAX) (default 0)
-b_depth E..V..... Maximum B-frame reference depth (from 1 to INT_MAX) (default 1)
-rc_mode E..V..... Set rate control mode (from 0 to 6) (default auto)
auto E..V..... Choose mode automatically based on other parameters
CQP E..V..... Constant-quality
CBR E..V..... Constant-bitrate
VBR E..V..... Variable-bitrate
ICQ E..V..... Intelligent constant-quality
QVBR E..V..... Quality-defined variable-bitrate
AVBR E..V..... Average variable-bitrate
-qp E..V..... Constant QP (for P-frames; scaled by qfactor/qoffset for I/B) (from 0 to 52) (default 0)
-aud E..V..... Include AUD (default false)
-profile E..V..... Set profile (general_profile_idc) (from -99 to 255) (default -99)
main E..V.....
main10 E..V.....
rext E..V.....
-tier E..V..... Set tier (general_tier_flag) (from 0 to 1) (default main)
main E..V.....
high E..V.....
-level E..V..... Set level (general_level_idc) (from -99 to 255) (default -99)
1 E..V.....
2 E..V.....
2.1 E..V.....
3 E..V.....
3.1 E..V.....
4 E..V.....
4.1 E..V.....
5 E..V.....
5.1 E..V.....
5.2 E..V.....
6 E..V.....
6.1 E..V.....
6.2 E..V.....
-sei E..V..... Set SEI to include (default hdr)
hdr E..V..... Include HDR metadata for mastering display colour volume and content light level information

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Apr 9, 2019

I've fixed the sample above.
It seems that the previous profile (high) doesn't exist for the hevc_vaapi encoder. It's only main, main10 and rext.

@mattold7

This comment has been minimized.

Copy link

commented May 6, 2019

I have a question for those using hardware transcoding. When I use the qp setting of lets say 18 its not the same as using crf of 18 and I understand that, but for those using this how are you doing your transcoding, are you using two pass VBR to get similar results of crf, what I'm really looking for the basically visually lossless and reduced file size? I'm trying to find a better way using h264_vaapi purely for archival purposes.

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Jul 3, 2019

@mattold7 what driver are you using with VAAPI? Show me the output of vainfo.
You may also reach me directly via email, thanks.

@barolo

This comment has been minimized.

Copy link

commented Jul 10, 2019

I'm trying to transcode 10bit hevc into 8bit h264_vaapi, but the output is garbled [ half of the screen flashes green ] on AMD RAVEN APU.
Could you check if I'm doing it properly?

ffmpeg
-init_hw_device vaapi=amd:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi
-hwaccel_device amd -filter_hw_device amd
-i nexp.mkv'
-vf "scale_vaapi=format=nv12,hwupload" -threads 6
-c:v h264_vaapi -profile:v 578
-c:a copy -bf 0 -c:s copy
-f mpegts -y plop.mkv

vainfo:
libva info: VA-API version 1.6.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib64/va/drivers/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_6
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.6 (libva 2.6.0.pre1)
vainfo: Driver version: Mesa Gallium driver 19.2.0-devel for AMD RAVEN (DRM 3.32.0, 5.2.0-gentoo, LLVM 8.0.0)
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileNone : VAEntrypointVideoProc

@mj43

This comment has been minimized.

Copy link

commented Aug 12, 2019

I am trying to use vaapi to cutdown on cpu load as I have fairly low level systems z8350 (Cherrytrail) and N4200 (Broxton). When I use libx264 cpu on the z8350 usage is +95% and video is soft, situation with the N4200 is a bit better but leaves a bit to be desired in terms of video quality.
Using vaapi encoding gives better results and cuts overall CPU usage to ~50% z8350 and <50% N4200. However, there appears to be a memory leak and I can watch RAM usage creep from 600MB up until after about 15 minutes my available 3.7GB are used up and the system locks up. This occurs on both machines, OS in both cases is Ubuntu 18.04.3 LTS.
Is memory leak with vaapi not an issue with your build of FFMPEG? I ask as I am using the standard Ubuntu build.

ffmpeg -y -vaapi_device /dev/dri/renderD128 -i overlays/VB12.png -thread_queue_size 32768 -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt bgr24 -framerate 25 -i - -filter_complex [1:v][0:v]overlay=705:572, format=nv12,hwupload -thread_queue_size 65536 -f alsa -ac 1 -i hw:0 -af adelay=250, volume=1, atempo=1.0 -vcodec h264_vaapi -qp:v 23 -profile:v 100 -level:v 31 /media/mark/Test/VR100test_0828.mp4

ffmpeg version 4.1.4-0york318.04 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1
18.04.1)
configuration: --prefix=/usr --extra-version='0york3~18.04' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-nonfree --enable-libfdk-aac --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Input #0, png_pipe, from 'overlays/VB12.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, pal8(pc), 575x148 [SAR 11810:11810 DAR 575:148], 25 tbr, 25 tbn, 25 tbc
Input #1, rawvideo, from 'pipe:':
Duration: N/A, start: 0.000000, bitrate: 552960 kb/s
Stream #1:0: Video: rawvideo (BGR[24] / 0x18524742), bgr24, 1280x720, 552960 kb/s, 25 tbr, 25 tbn, 25 tbc
Guessed Channel Layout for Input Stream #2.0 : mono
Input #2, alsa, from 'hw:0':
Duration: N/A, start: 1565594935.407496, bitrate: 768 kb/s
Stream #2:0: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Stream mapping:
Stream #0:0 (png) -> overlay:overlay (graph 0)
Stream #1:0 (rawvideo) -> overlay:main (graph 0)
hwupload (graph 0) -> Stream #0:0 (h264_vaapi)
Stream #2:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Output #0, mp4, to '/media/mark/Test/VR100test_0828.mp4':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (h264_vaapi) (High) (avc1 / 0x31637661), vaapi_vld(progressive), 1280x720, q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
encoder : Lavc58.35.100 h264_vaapi
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s
Metadata:
encoder : Lavc58.35.100 aac

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Aug 16, 2019

Hello @mj43,

You'd be best sorted by building FFmpeg + Libva components from source.
The git tip on FFmpeg sees a lot of commits, often with bug fixes and this is why I cannot recommend release versions for any production workflow.

@barolo that sounds like a bug in the radeonsi VAAPI driver, perhaps you should report that upstream?
The dri-devel mailing list is a good place to start.
For Intel-related bugs (such as with their vaapi drivers, i965 and iHD respectively), report these to the respective projects.
You may also want to post the same bug report on libva.

@barolo

This comment has been minimized.

Copy link

commented Aug 16, 2019

@Brainiarc7
Reported it both to mesa and ffmpeg month ago, no response so far.
Solved it by using command below, unsure if it's a proper solution [ changing 10->8bit pixel format with hwaccel ]:

ffmpeg -threads 4 -init_hw_device vaapi=amd:/dev/dri/renderD128
-hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device amd -filter_hw_device amd
-i test.mkv \
-vf "hwdownload,format=p010,format=nv12,hwupload" \
-c:v h264_vaapi -profile:v 578 -c:a copy -c:s copy
-f mpegts out.mkv

@ferdnyc

This comment has been minimized.

Copy link

commented Sep 13, 2019

@Brainiarc7 Great resource, thanks.

Just a quick housekeeping request: Do you think you could line-wrap the sudo apt-get command line, and the two ffmpeg commands in your Haswell example, the same way you did the earlier ffmpeg examples? The three I mentioned are kind of #XXXtreemHorizontalScrolling right now. Thx!

(And as always, curse you GitHub for capping the page width, when you know you have to display unwrapped <pre> blocks.)

@Brainiarc7

This comment has been minimized.

Copy link
Owner Author

commented Sep 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.