DoseLibrary / ContentServer

A media library built with node and NextJS
5 stars 1 forks source link

[not an issue] how the HLS live streaming works? #53

Open hellozyemlya opened 1 week ago

hellozyemlya commented 1 week ago

Hello. Seems to be great project. Found it by https://stackoverflow.com/questions/58898638/precise-method-of-segmenting-transcoding-videoaudio-via-ffmpeg-into-an-on answer.

I have a quick questions related to your implementation.

I will put my suggestions, please correct me if required.

You generating m3u8 playlist manually, right? Then upon requesting m3u8 playlist you start transcoding. If seek happens to segment which is faaaar from currently existing segment, you starting generating new segments from selected one, right?

How you ensured that ffmpeg producing segments with predictable length? Most of command lines I found in the internet producing segments with some nearly random length in some range.

Thanks in advance.

GustavPS commented 1 week ago

Hi!

It's a combination of the settings. Sadly I don't exactly remember but I did a lot of trial and error to figure out a combination that works.

I think that these are important: -force_key_frames expr:gte(t,n_forced*2), (forcing consistant keyframes) -hls_time ${Transcoding.SEGMENT_DURATION}, (setting the segment duration)

Also, you have to use a either h264_nvenc (for gpu transcoding) or libx265 or libx264 (for cpu transcoding, libx264 will give you much better performance). If you use videocodec copy you will not get consistant segment lengths.