Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg generate m3u8 and segments manually

Tags:

ffmpeg

We are developing an application where the m3u8 file should be generated on the fly for a given mp4 video. Can someone please let us know how can we generate the mp4 file on the fly with the exact duration as the segmenter. In our case ffmpeg segmenter is created variable length segments and are of decimal size. For eg : #EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:7 #EXT-X-PLAYLIST-TYPE:VOD

#EXTINF:5.005,
test.mp4.ts?start=0.000&end=5.005
#EXTINF:6.715,
test.mp4.ts?start=5.005&end=11.720
#EXTINF:6.548,

Can someone help us to create such m3u8 file without creating any segments. We will manually create the segments on request.

Also when we create the segments manually there is a small stuttering (flicker) when the video goes to the next segment. When I read it online, it says it might be due to continuity counter. Can someone please help us fix that too

Thanks.

like image 263
Darshan Bhandari Avatar asked Jun 26 '15 08:06

Darshan Bhandari


1 Answers

Solution 1

You can use -hls_flags single_file to store all segments in a single ts file. The resulting playlist will contain the lengths and offsets of each segment and the client will request them on its own.

Example for 6s segments:

ffmpeg -i input -c:v libx264 -r 25 -g 75 -sc_threshold 0 -c:a libfdk_aac -hls_time 6 -hls_playlist_type vod -hls_flags single_file out.m3u8

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:6.000000,
#EXT-X-BYTERANGE:1397404@0
out.ts
#EXTINF:6.000000,
#EXT-X-BYTERANGE:1049416@1397404
out.ts
#EXTINF:6.000000,
#EXT-X-BYTERANGE:1423348@2446820
out.ts
[...]
#EXT-X-ENDLIST

The EXT-X-BYTERANGE is supported in version 4. If you need version 3 you need to transform this playlist in a version 3 one and make a handler to return the correct range with the correct MIME type:

#EXTINF:6.000000,
handler?file=out.ts&offset=xxx&length=yyy

Solution 2

Use nginx with the nginx-vod-module which can also do DASH and others

like image 120
aergistal Avatar answered Oct 27 '22 05:10

aergistal