FFmpeg (https://ffmpeg.org) is the usual go to solution in this area, certainly in the open source world.
There is a guide here to use h.264 encoding which is supported by most browsers and devices at this time: https://trac.ffmpeg.org/wiki/Encode/H.264
This includes some guidance on quality vs processing etc - look at the two pass graph.
Its also worth nothing that for streamed video, most serious streaming services will offer multiple bit rate versions of a given video also, and allow the client player download the file in, for example 10 second, chunks and select for each chunk the best bit rate for the current device and network conditions.
This is referred to as ABR, Adaptive Bit rate Streaming. See a little ore info in this answer: https://stackoverflow.com/a/42365034/334402
This is quite a specialist area and most people will use either a video hosting service which provides this or a dedicated video streaming server e.g. Wowza is a commercial example, or GStreamer with ABR plugins is an open source example.