[FFMPEG- 协议]hls

来源:互联网 发布:为什么电信4g网络很慢 编辑:程序博客网 时间:2024/05/21 15:17

FFMPEG转换格式:

ffmpeg -i in.nut out.m3u8

See also the segment muxer, which provides a more generic and flexible implementation of a segmenter, and can be used to perform HLS segmentation.
22.12.1 Options

This muxer supports the following options:

hls_init_time seconds

Set the initial target segment length in seconds. Default value is 0. Segment will be cut on the next key frame after this time has passed on the first m3u8 list. After the initial playlist is filled ffmpeg will cut segments at duration equal to hls_time

hls_time seconds

Set the target segment length in seconds. Default value is 2. Segment will be cut on the next key frame after this time has passed.

hls_list_size size

Set the maximum number of playlist entries. If set to 0 the list file will contain all the segments. Default value is 5.

hls_ts_options options_list

Set output format options using a :-separated list of key=value parameters. Values containing : special characters must be escaped.

hls_wrap wrap

This is a deprecated option, you can use hls_list_size and hls_flags delete_segments instead itThis option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files written to disk to wrap.

hls_start_number_source

Start the playlist sequence number (#EXT-X-MEDIA-SEQUENCE) according to the specified source. Unless hls_flags single_file is set, it also specifies source of starting sequence numbers of segment and subtitle filenames. In any case, if hls_flags append_list is set and read playlist sequence number is greater than the specified start sequence number, then that value will be used as start value.It accepts the following values:generic (default)    Set the starting sequence numbers according to start_number option value.epoch    The start number will be the seconds since epoch (1970-01-01 00:00:00)datetime    The start number will be based on the current date/time as YYYYmmddHHMMSS. e.g. 20161231235759.

start_number number

Start the playlist sequence number (#EXT-X-MEDIA-SEQUENCE) from the specified number when hls_start_number_source value is generic. (This is the default case.) Unless hls_flags single_file is set, it also specifies starting sequence numbers of segment and subtitle filenames. Default value is 0.

hls_allow_cache allowcache

Explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments.

hls_base_url baseurl

Append baseurl to every entry in the playlist. Useful to generate playlists with absolute paths.Note that the playlist sequence number must be unique for each segment and it is not to be confused with the segment filename sequence number which can be cyclic, for example if the wrap option is specified.

hls_segment_filename filename

Set the segment filename. Unless hls_flags single_file is set, filename is used as a string format with the segment number:ffmpeg -i in.nut -hls_segment_filename 'file%03d.ts' out.m3u8This example will produce the playlist, out.m3u8, and segment files: file000.ts, file001.ts, file002.ts, etc.filename may contain full path or relative path specification, but only the file name part without any path info will be contained in the m3u8 segment list. Should a relative path be specified, the path of the created segment files will be relative to the current working directory. When use_localtime_mkdir is set, the whole expanded value of filename will be written into the m3u8 segment list.

use_localtime

Use strftime() on filename to expand the segment filename with localtime. The segment number is also available in this mode, but to use it, you need to specify second_level_segment_index hls_flag and %%d will be the specifier.ffmpeg -i in.nut -use_localtime 1 -hls_segment_filename 'file-%Y%m%d-%s.ts' out.m3u8This example will produce the playlist, out.m3u8, and segment files: file-20160215-1455569023.ts, file-20160215-1455569024.ts, etc. Note: On some systems/environments, the %s specifier is not available. See strftime() documentation.ffmpeg -i in.nut -use_localtime 1 -hls_flags second_level_segment_index -hls_segment_filename 'file-%Y%m%d-%%04d.ts' out.m3u8This example will produce the playlist, out.m3u8, and segment files: file-20160215-0001.ts, file-20160215-0002.ts, etc.

use_localtime_mkdir

Used together with -use_localtime, it will create all subdirectories which is expanded in filename.ffmpeg -i in.nut -use_localtime 1 -use_localtime_mkdir 1 -hls_segment_filename '%Y%m%d/file-%Y%m%d-%s.ts' out.m3u8This example will create a directory 201560215 (if it does not exist), and then produce the playlist, out.m3u8, and segment files: 20160215/file-20160215-1455569023.ts, 20160215/file-20160215-1455569024.ts, etc.ffmpeg -i in.nut -use_localtime 1 -use_localtime_mkdir 1 -hls_segment_filename '%Y/%m/%d/file-%Y%m%d-%s.ts' out.m3u8This example will create a directory hierarchy 2016/02/15 (if any of them do not exist), and then produce the playlist, out.m3u8, and segment files: 2016/02/15/file-20160215-1455569023.ts, 2016/02/15/file-20160215-1455569024.ts, etc.

hls_key_info_file key_info_file

Use the information in key_info_file for segment encryption. The first line of key_info_file specifies the key URI written to the playlist. The key URL is used to access the encryption key during playback. The second line specifies the path to the key file used to obtain the key during the encryption process. The key file is read as a single packed array of 16 octets in binary format. The optional third line specifies the initialization vector (IV) as a hexadecimal string to be used instead of the segment sequence number (default) for encryption. Changes to key_info_file will result in segment encryption with the new key/IV and an entry in the playlist for the new key URI/IV.Key info file format:key URIkey file pathIV (optional)Example key URIs:http://server/file.key/path/to/file.keyfile.keyExample key file paths:file.key/path/to/file.keyExample IV:0123456789ABCDEF0123456789ABCDEFKey info file example:http://server/file.key/path/to/file.key0123456789ABCDEF0123456789ABCDEFExample shell script:#!/bin/shBASE_URL=${1:-'.'}openssl rand 16 > file.keyecho $BASE_URL/file.key > file.keyinfoecho file.key >> file.keyinfoecho $(openssl rand -hex 16) >> file.keyinfoffmpeg -f lavfi -re -i testsrc -c:v h264 -hls_flags delete_segments \  -hls_key_info_file file.keyinfo out.m3u8

hls_flags flags

Possible values:‘single_file’    If this flag is set, the muxer will store all segments in a single MPEG-TS file, and will use byte ranges in the playlist. HLS playlists generated with this way will have the version number 4. For example:    ffmpeg -i in.nut -hls_flags single_file out.m3u8    Will produce the playlist, out.m3u8, and a single segment file, out.ts.‘delete_segments’    Segment files removed from the playlist are deleted after a period of time equal to the duration of the segment plus the duration of the playlist.‘append_list’    Append new segments into the end of old segment list, and remove the #EXT-X-ENDLIST from the old segment list.‘round_durations’    Round the duration info in the playlist file segment info to integer values, instead of using floating point.‘discont_start’    Add the #EXT-X-DISCONTINUITY tag to the playlist, before the first segment’s information.‘omit_endlist’    Do not append the EXT-X-ENDLIST tag at the end of the playlist.‘split_by_time’    Allow segments to start on frames other than keyframes. This improves behavior on some players when the time between keyframes is inconsistent, but may make things worse on others, and can cause some oddities during seeking. This flag should be used with the hls_time option.‘program_date_time’    Generate EXT-X-PROGRAM-DATE-TIME tags.‘second_level_segment_index’    Makes it possible to use segment indexes as %%d in hls_segment_filename expression besides date/time values when use_localtime is on. To get fixed width numbers with trailing zeroes, %%0xd format is available where x is the required width.‘second_level_segment_size’    Makes it possible to use segment sizes (counted in bytes) as %%s in hls_segment_filename expression besides date/time values when use_localtime is on. To get fixed width numbers with trailing zeroes, %%0xs format is available where x is the required width.‘second_level_segment_duration’    Makes it possible to use segment duration (calculated in microseconds) as %%t in hls_segment_filename expression besides date/time values when use_localtime is on. To get fixed width numbers with trailing zeroes, %%0xt format is available where x is the required width.‘temp_file’    Write segment data to filename.tmp and rename to filename only once the segment is complete. A webserver serving up segments can be configured to reject requests to *.tmp to prevent access to in-progress segments before they have been added to the m3u8 playlist.    ffmpeg -i sample.mpeg \       -f hls -hls_time 3 -hls_list_size 5 \       -hls_flags second_level_segment_index+second_level_segment_size+second_level_segment_duration \       -use_localtime 1 -use_localtime_mkdir 1 -hls_segment_filename "segment_%Y%m%d%H%M%S_%%04d_%%08s_%%013t.ts" stream.m3u8    This will produce segments like this: segment_20170102194334_0003_00122200_0000003000000.ts, segment_20170102194334_0004_00120072_0000003000000.ts etc.

hls_playlist_type event

Emit #EXT-X-PLAYLIST-TYPE:EVENT in the m3u8 header. Forces hls_list_size to 0; the playlist can only be appended to.

hls_playlist_type vod

Emit #EXT-X-PLAYLIST-TYPE:VOD in the m3u8 header. Forces hls_list_size to 0; the playlist must not change.

method

Use the given HTTP method to create the hls files.ffmpeg -re -i in.ts -f hls -method PUT http://example.com/live/out.m3u8This example will upload all the mpegts segment files to the HTTP server using the HTTP PUT method, and update the m3u8 files every refresh times using the same method. Note that the HTTP server must support the given method for uploading files. 
0 0
原创粉丝点击