Streaming: FFMPEG generates m3u8 and ts clips of HLS.
Conversion method 1
1.Directly convert media files to ts
ffmpeg -i cat.mp4 -c copy -bsf h264_mp4toannexb cat.ts
2.Use the segment parameter for slicing
ffmpeg -i cat.ts -c copy -map 0 -f segment -segment_list playlist.m3u8 -segment_time 2 cat_output%03d.ts
Conversion method 2
1.ffmpeg slicing command, output video in the form of H264 and AAC
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict -2 -f hls output.m3u8
2.The instructions that come with ffmpeg when converting to HLS
-hls_time n: Sets the length of each slice, the default value is 2. The unit is seconds
-hls_list_size n: Set the maximum number of entries saved by the playlist, setting it to 0 will save the information of some pieces, the default value is 5
-hls_wrap n: Set how many slices to start overwriting, if set to 0 will not overwrite, the default value is 0. This option avoids storing too many slices on the disk and limits the number of slices written to the disk
-hls_start_number n: Set the value of sequence number in the playlist to number, and the default value is 0
3.Use of ffmpeg slicing instructions
ffmpeg -i output.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 -hls_time 5 data/output.m3u8
Parameter:
-hls_base_url m3u8 playback address prefix
-segment_list_entry_prefix m3u8 playback address prefix
-s 1280×720 : 720p resolution
-b 1500k bit rate
-r sets the frame rate, which defaults to 25
-aspect Sets the scale of the screen
-break_non_keyframes ( -break_non_keyframes 1 for each slice cut for absolutely the same time)
acodec means audio encoding, copy means not changing the codec, just changing the encapsulator
-vcodec means video encoding, copy means not changing the codec, just changing the encapsulator
My example:
ffmpeg -i 123.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 output.m3u8
ffmpeg -i 123.mp4 -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_list out.m3u8 -segment_time 10 out%03d.ts (-break_non_keyframes 1 Cut each slice for the same time)
ffmpeg -i 123.mp4 -codec copy -vbsf h264_mp4toannexb -map 0 -f segment -segment_list out.m3u8 -segment_time 10 -break_non_keyframes 1 -s 1280x720 -b 1500k out%03d.ts
ffmpeg -i 123.mp4 -strict -2 -c:v libx264 -s 1280x720 -c:a aac -f hls -hls_time 100 -hls_list_size 0 -b 1500k test_480_x.m3u8 (Resolution comes into play)
ffmpeg -i video-h265.mp4 -vcodec h264 -c:a aac -map 0 -f segment -segment_list out.m3u8 -segment_time 10 -segment_list_entry_prefix http://upload.xx.cn/video/QA22/ZHSQ/201810/ out%01d.ts (H265 transcoded to H264 and then sliced)
#Transcode & slice
6465 ffmpeg -i 1234.mp4 -strict -2 -c:v libx264 -s 1280x720 -c:a aac -f hls -hls_time 10 -hls_list_size 0 -maxrate 1000k -bufsize 2000k -hls_base_url http://upload.xx.cn/video/QA22/ZHSQ/201810/ 200_video.m3u8
#Only transpackage & slice
4586 ffmpeg -i 123.mp4 -strict -2 -c copy -s 1200x700 -bsf:v h264_mp4toannexb -f hls -hls_time 100 -hls_list_size 0 -b:v 1500k -minrate 1500k -maxrate 1500k -bufsize 3000k -hls_base_url http://localhost/test/ test_480_x.m3u8
ffmpeg -i 123.mp4 -strict -2 -c:v libx264 -s 1280x720 -c:a aac -f hls -hls_time 100 -hls_list_size 0 -b 1500k -minrate 1500k -maxrate 1500k -bufsize 3000k -hls_base_url http://localhost/php4hls/test/ test_480_x.m3u8 (Final use)
Leave a Reply