The ffmpeg apt package now includes support for hardware encode and decode.
sudo apt install ffmpeg
To see which hardware codecs (using one of the following APIs: v4l2m2m, VAAPI, OMX, MMAL) are available run:
ffmpeg -codecs | grep 'omx\|m2m\|vaa\|mmal'
This will list them all and the first column indicates whether they're available for encode(E)/decode(D).
So for example to use the v4l2m2m H.264 codec to encode 30secs of colour bars:
ffmpeg -f lavfi -i smptebars -t 30 -vcodec h264_v4l2m2m out.mp4
Or use the OMX based H.264 hardware encoder to encode input_file:
ffmpeg -i input_file -vcodec h264_omx out.mp4
Also if you have changed the gpu_mem setting in /boot/config.txt it needs to be greater than 16, otherwise you will get an error with any hardware codecs.