How to build ffmpeg with h.264 support

I had a requirement to use openwrt to decode a h.264 stream and process it. Since all the guides I found were very old and incomplete, I post here what I did to be able to compile a custom image with ffmpeg supporting h.264 codec.

WARNING: h.264 uses a LOT of memory. Don't use it unless your openwrt system has several GB of ram.

In make menuconfig, enable "Global Buils Settings" -> "Compile with support for patented functionality"
Make sure ffmpeg is enabled (multimedia section) as well as libx264 and libffmpeg-full (libraries section)
In <your_build_dir>/feeds/packages/multimedia/ffmpeg, change the Makefile in section "FFMPEG_CONFIGURE" to include --enable-libx264 --enable-gpl --enable-nonfree
That's it!