Ffmpeg generates m3u8 and segments manually

We are developing an application in which the m3u8 file should be generated on the fly for a given mp4 video. Can someone please tell us how we can generate mp4 file "on the fly" with the exact duration as a segmenter. In our case, the ffmpeg segment segment is created with variable length segments and has a decimal size. For example: # 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 create such a m3u8 file without creating any segments. We will manually create segments upon request.

Also, when we create segments manually, a slight stutter (flicker) occurs when the video moves to the next segment. When I read it on the Internet, he says that this may be due to the continuity counter. Can someone please help us fix this too.

Thanks.

+5
source share
1 answer

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 independently.

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 

EXT-X-BYTERANGE supported in version 4 . If you need version 3 , you need to convert this playlist to 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 

Decision 2

Use nginx with nginx-vod-module , which can also execute DASH and others

+2
source

All Articles