Use FFmpeg to convert MP4 files to TS files and generate m3u8 lists __ffmpeg

Source: Internet
Author: User

When playing a video stream using HLS technology, you first convert the video to a TS slice and a m3u8 playlist, using FFmpeg to do the conversion (the low version ffmpeg does not support direct turning, and can now be converted to TS and m3u8-segmenter slices, The author uses ffmpeg version-2.1.2), usually using the following command:

Ffmpeg-i input.mp4-c:v libx264-c:a aac-strict-2-F HLS output.m3u8

However, in this state, the default length of 2 seconds per piece, the default in the m3u8 file only save the latest 5 pieces of information, resulting in the last play can only broadcast a small part of the last.

There are actually some other parameters that can control these things:

The following is the original FFmpeg official website:
This muxer supports the following options: ' Hls_time seconds '

Set the segment length in seconds. Default value is 2. ' Hls_list_size size '

Set the maximum number of playlist entries. If set to 0 The list file would contain all the segments. Default value is 5. ' Hls_wrap Wrap '

Set the number after which the "segment filename number" (the number specified in each segment file) wraps. If set to 0 the number would be never wrapped. Default value is 0.

This option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files WR Itten to disk Towrap. ' Start_number number '

Start The playlist sequence number from number. Default value is 0.

Note that the playlist sequence number must are unique for each segment and it are not the confused with the segment Filen AME sequence number which can cyclic, for example if the ' wrap ' option is specified.


Translated as follows:

-hls_time N: Sets the length of each slice, the default value is 2. Unit is seconds

-hls_list_size N: Set the maximum number of entries saved by the playlist, set to 0 to save a piece of information, the default value is 5

-hls_wrap N: After setting 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 disk and can limit the number of slices written to disk

-hls_start_number N: Sets the value of sequence number in the playlist to number, the default value is 0

Note: The sequence number of the playlist must be unique for each segment, and it cannot be confused with the file name of the slice (when the wrap option is used, the file name may be reused)



With these parameters, the small partners can happily control the generated m3u8 file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.