Search code examples
ffmpegvideo-streaminghtml5-videohttp-live-streamingmpeg-dash

is that possible to use ffmpeg convert .mp4 to .ts when get a http request


I search some article that tell me should convert the mp4 first,then wait the request and send the ts and m3u8.

But i looking for a way , that is when the request comes , then i will start to convert the video , and send the m3u8 immediately when the Conversion is not finish.

If the request come , but the ts file not ready ,then wait still the file ready and send it immediately .

Is that possible to do something like this? or can use another way to have the same effect?


Solution

  • When you start with a single bit rate MP4 and want to serve it as a HLS or MPEG-DASH (usually just called DASH) stream you typically do a number of steps:

    • transcode the video into however many bit rate versions you want
    • split the video into a segmented or fragmented format to allow HLS or MPEG-DASH streaming
    • 'Package' into the particular streaming protocol you want for the device you are streaming to, which is usually HLS or DASH these days.

    Assuming the video is not a live stream, it is common for the transcoding and splitting to be done initially when the video is first ingested into the system.

    The packaging is then applied 'Just In Time' when the user or client requests the video. Note, that the transcoding and splitting and even packaging can be combined in a single step, with some cloud encoding services offering exactly that service, however, 'Just In Time' packaging is still very common.

    The main reason for not doing 'Just In Time' transcoding also is that transcoding is processor intensive. Being able to schedule it when you have spare computing resources or can allow it plenty of time to complete is often the most cost effective approach.

    It is definitely possible to do 'Just In Time' transcoding - this is what Live Streams have to do anyway. However, what you save in storage costs may be eaten (several times over, sometimes) by processing costs so it is a business decision as much as a technical decision.