Build the. ts and. m3u8 files required to generate HLS under Linux

Source: Internet
Author: User

To use HLS for online video playback, you need to cut a complete video file into multiple TS video streams, and then use the m3u8 index file to play.

Under Mac, Apple offers Streamingtools tools with Mediafilesegmenter and Mediastreamsegmenter to cut the file and live stream separately, A single line of commands directly allows you to export the original video file into several TS and index files, which can be used directly. But the general server is Linux-based, and to achieve the same cutting under Linux, it really took some effort.

Online also found a lot of relevant information, the basic is the use of open source FFmpeg and segmenter tools to achieve, but the process of building this environment is tortuous, compile these tools when there will be a lot of errors, difficult to solve, a lot of the steps introduced by the article is also very complex, and install a variety of packages, But also modify the source code, after a few days of various repeated attempts to know in the source file is not directly cut, but first to convert, then cut, finally the pain of the groping to a successful path, hereby record down to prevent forgetting.

1, first get ffmpeg

Apt-get Install FFmpeg

2, install FFMPEG Support Library, prepare for M3u8-segmenter

Apt-get Install Libavformat-dev

3. Get M3u8-segmenter

Https://github.com/johnf/m3u8-segmenter

4. Compile and install M3u8-segmenter

Aclocal

Automake-ac

./configure

Make

sudo make install

4, compile the file M3u8-segmenter

Gcc-wall-g M3u8-segmenter.c-o Segmenter-lavformat

5. Convert existing video files to TS files using FFmpeg

Ffmpeg-y-I <in file>-vcodec copy-acodec copy-vbsf h264_mp4toannexb <output file>

Where file is the video file to be converted, for example, Input.mov,output file is converted, to be named Output.ts

6. Use Segmenter to cut the converted TS file into multiple TS slices and generate the. m3u8 index file

./segmenter-i out.ts-n 10-p segmenter_test-m test.m3u8-u

I represents the input file, n means cut for 10 seconds, p represents the prefix of the cut file. M represents the generated m3u8 file name, and U indicates in which directory of the Web server these files are cut

PS: The practice of the discovery of a problem, that is, after slicing, the last section of TS is not 10s, the same will press 10s to cut, resulting in a cut of the video after the last paragraph will be added to a few seconds of the black section to complement 10s, the reason is segmenter.c in the program written defects, the correct method is as follows:

Https://github.com/johnf/m3u8-segmenter/pull/10/files

Reference:

Http://blog.chinaunix.net/uid-25530360-id-3483535.html

http://shappy1978.iteye.com/blog/1071815

http://www.ioncannon.net/programming/452/iphone-http-streaming-with-ffmpeg-and-an-open-source-segmenter/

Http://hi.baidu.com/lphack/item/83865611c5f82c8988a956df

http://blog.cnrainbird.com/index.php/2012/03/25/ping_guo_http_shi_pin_dian_bo_ji_shu/

Build the. ts and. m3u8 files required to generate HLS under Linux

Related Article

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.