How is possible for YouTube and Vimeo transcode so fast? For the bit I read YouTube and Vimeo rely on servers powered by some modified libs i guess like libavcodec and tools like ffmpeg in a serious custom build.

Let's assume a transcode to h264 but the same could be applied to other codecs, I think VP8 and VP9 works in the same way.

If I upload 1h video file on their servers, right after the upload i have all the versions ready... pratically like 1 seconds after.

But, if codecs doesn't scale horizontally in a good way unless you want to trade time vs compression (see h264) and I'm pretty sure this websites care about the size of the videos..

Given also that single threads speed are capped by CPU frequency and actual frequency isn't up to 3.5 ghz generally unless they use overclocked servers under liquid nitrogen :D

How the transcode is done so fast?

They use still multithread with a mix of settings, trading on initial file size, custom builds and everything else to have just the files insta-ready to the user and then continue a second transcode with a slow preset that will be swapped as soon this file will be ready? They start to transcode as soon they receive the file stream (aka: during the upload ?)
A common method is split-and-stitch where the file is cut into pieces and sent to multiple servers for transcode. That way you can transcode a file of any length in a fixed amount of time.

Telestreams Episode Engine can do this, but I'm sure Google uses something custom coded.