FFmpeg Formats Documentation
  NYfg2BRCcXho 2023年11月02日 33 0


Table of Contents
1 Description
2 Format Options
2.1 Format stream specifiers
3 Demuxers
3.1 aa
3.2 applehttp
3.3 apng
3.4 asf
3.5 concat
3.5.1 Syntax
3.5.2 Options
3.5.3 Examples
3.6 dash
3.7 flv, live_flv
3.8 gif
3.9 hls
3.10 image2
3.10.1 Examples
3.11 libgme
3.12 libopenmpt
3.13 mov/mp4/3gp/QuickTime
3.14 mpegts
3.15 mpjpeg
3.16 rawvideo
3.17 sbg
3.18 tedcaptions
4 Muxers
4.1 aiff
4.1.1 Options
4.2 asf
4.2.1 Options
4.3 avi
4.3.1 Options
4.4 chromaprint
4.4.1 Options
4.5 crc
4.5.1 Examples
4.6 flv
4.7 dash
4.8 framecrc
4.8.1 Examples
4.9 framehash
4.9.1 Examples
4.10 framemd5
4.10.1 Examples
4.11 gif
4.12 hash
4.12.1 Examples
4.13 hls
4.13.1 Options
4.14 ico
4.15 image2
4.15.1 Examples
4.15.2 Options
4.16 matroska
4.16.1 Metadata
4.16.2 Options
4.17 md5
4.17.1 Examples
4.18 mov, mp4, ismv
4.18.1 Options
4.18.2 Example
4.18.3 Audible AAX
4.19 mp3
4.20 mpegts
4.20.1 Options
4.20.2 Example
4.21 mxf, mxf_d10
4.21.1 Options
4.22 null
4.23 nut
4.24 ogg
4.25 segment, stream_segment, ssegment
4.25.1 Options
4.25.2 Examples
4.26 smoothstreaming
4.27 fifo
4.27.1 Examples
4.28 tee
4.28.1 Options
4.28.2 Examples
4.29 webm_dash_manifest
4.29.1 Options
4.29.2 Example
4.30 webm_chunk
4.30.1 Options
4.30.2 Example
5 Metadata
6 See Also
7 Authors
1 Description
This document describes the supported formats (muxers and demuxers) provided by the libavformat library.

2 Format Options
The libavformat library provides some generic global options, which can be set on all the muxers and demuxers. In addition each muxer or demuxer may support so-called private options, which are specific for that component.

Options may be set by specifying -option value in the FFmpeg tools, or by setting the value explicitly in the AVFormatContext options or using the libavutil/opt.h API for programmatic use.

The list of supported options follows:

avioflags flags (input/output)
Possible values:

‘direct’
Reduce buffering.

probesize integer (input)
Set probing size in bytes, i.e. the size of the data to analyze to get stream information. A higher value will enable detecting more information in case it is dispersed into the stream, but will increase latency. Must be an integer not lesser than 32. It is 5000000 by default.

packetsize integer (output)
Set packet size.

fflags flags
Set format flags. Some are implemented for a limited number of formats.

Possible values for input files:

‘discardcorrupt’
Discard corrupted packets.

‘fastseek’
Enable fast, but inaccurate seeks for some formats.

‘genpts’
Generate missing PTS if DTS is present.

‘igndts’
Ignore DTS if PTS is set. Inert when nofillin is set.

‘ignidx’
Ignore index.

‘keepside (deprecated,inert)’
‘nobuffer’
Reduce the latency introduced by buffering during initial input streams analysis.

‘nofillin’
Do not fill in missing values in packet fields that can be exactly calculated.

‘noparse’
Disable AVParsers, this needs +nofillin too.

‘sortdts’
Try to interleave output packets by DTS. At present, available only for AVIs with an index.

Possible values for output files:

‘autobsf’
Automatically apply bitstream filters as required by the output format. Enabled by default.

‘bitexact’
Only write platform-, build- and time-independent data. This ensures that file and data checksums are reproducible and match between platforms. Its primary use is for regression testing.

‘flush_packets’
Write out packets immediately.

‘latm (deprecated,inert)’
‘shortest’
Stop muxing at the end of the shortest stream. It may be needed to increase max_interleave_delta to avoid flushing the longer streams before EOF.

seek2any integer (input)
Allow seeking to non-keyframes on demuxer level when supported if set to 1. Default is 0.

analyzeduration integer (input)
Specify how many microseconds are analyzed to probe the input. A higher value will enable detecting more accurate information, but will increase latency. It defaults to 5,000,000 microseconds = 5 seconds.

cryptokey hexadecimal string (input)
Set decryption key.

indexmem integer (input)
Set max memory used for timestamp index (per stream).

rtbufsize integer (input)
Set max memory used for buffering real-time frames.

fdebug flags (input/output)
Print specific debug info.

Possible values:

‘ts’
max_delay integer (input/output)
Set maximum muxing or demuxing delay in microseconds.

fpsprobesize integer (input)
Set number of frames used to probe fps.

audio_preload integer (output)
Set microseconds by which audio packets should be interleaved earlier.

chunk_duration integer (output)
Set microseconds for each chunk.

chunk_size integer (output)
Set size in bytes for each chunk.

err_detect, f_err_detect flags (input)
Set error detection flags. f_err_detect is deprecated and should be used only via the ffmpeg tool.

Possible values:

‘crccheck’
Verify embedded CRCs.

‘bitstream’
Detect bitstream specification deviations.

‘buffer’
Detect improper bitstream length.

‘explode’
Abort decoding on minor error detection.

‘careful’
Consider things that violate the spec and have not been seen in the wild as errors.

‘compliant’
Consider all spec non compliancies as errors.

‘aggressive’
Consider things that a sane encoder should not do as an error.

max_interleave_delta integer (output)
Set maximum buffering duration for interleaving. The duration is expressed in microseconds, and defaults to 1000000 (1 second).

To ensure all the streams are interleaved correctly, libavformat will wait until it has at least one packet for each stream before actually writing any packets to the output file. When some streams are “sparse” (i.e. there are large gaps between successive packets), this can result in excessive buffering.

This field specifies the maximum difference between the timestamps of the first and the last packet in the muxing queue, above which libavformat will output a packet regardless of whether it has queued a packet for all the streams.

If set to 0, libavformat will continue buffering packets until it has a packet for each stream, regardless of the maximum timestamp difference between the buffered packets.

use_wallclock_as_timestamps integer (input)
Use wallclock as timestamps if set to 1. Default is 0.

avoid_negative_ts integer (output)
Possible values:

‘make_non_negative’
Shift timestamps to make them non-negative. Also note that this affects only leading negative timestamps, and not non-monotonic negative timestamps.

‘make_zero’
Shift timestamps so that the first timestamp is 0.

‘auto (default)’
Enables shifting when required by the target format.

‘disabled’
Disables shifting of timestamp.

When shifting is enabled, all output timestamps are shifted by the same amount. Audio, video, and subtitles desynching and relative timestamp differences are preserved compared to how they would have been without shifting.

skip_initial_bytes integer (input)
Set number of bytes to skip before reading header and frames if set to 1. Default is 0.

correct_ts_overflow integer (input)
Correct single timestamp overflows if set to 1. Default is 1.

flush_packets integer (output)
Flush the underlying I/O stream after each packet. Default is -1 (auto), which means that the underlying protocol will decide, 1 enables it, and has the effect of reducing the latency, 0 disables it and may increase IO throughput in some cases.

output_ts_offset offset (output)
Set the output time offset.

offset must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.

The offset is added by the muxer to the output timestamps.

Specifying a positive offset means that the corresponding streams are delayed bt the time duration specified in offset. Default value is 0 (meaning that no offset is applied).

format_whitelist list (input)
“,” separated list of allowed demuxers. By default all are allowed.

dump_separator string (input)
Separator used to separate the fields printed on the command line about the Stream parameters. For example to separate the fields with newlines and indention:

ffprobe -dump_separator ”
” -i ~/videos/matrixbench_mpeg2.mpg
max_streams integer (input)
Specifies the maximum number of streams. This can be used to reject files that would require too many resources due to a large number of streams.

2.1 Format stream specifiers
Format stream specifiers allow selection of one or more streams that match specific properties.

Possible forms of stream specifiers are:

stream_index
Matches the stream with this index.

stream_type[:stream_index]
stream_type is one of following: ’v’ for video, ’a’ for audio, ’s’ for subtitle, ’d’ for data, and ’t’ for attachments. If stream_index is given, then it matches the stream number stream_index of this type. Otherwise, it matches all streams of this type.

p:program_id[:stream_index]
If stream_index is given, then it matches the stream with number stream_index in the program with the id program_id. Otherwise, it matches all streams in the program.

stream_id

Matches the stream by a format-specific ID.

The exact semantics of stream specifiers is defined by the avformat_match_stream_specifier() function declared in the libavformat/avformat.h header.

3 Demuxers
Demuxers are configured elements in FFmpeg that can read the multimedia streams from a particular type of file.

When you configure your FFmpeg build, all the supported demuxers are enabled by default. You can list all available ones using the configure option –list-demuxers.

You can disable all the demuxers using the configure option –disable-demuxers, and selectively enable a single demuxer with the option –enable-demuxer=DEMUXER, or disable it with the option –disable-demuxer=DEMUXER.

The option -demuxers of the ff* tools will display the list of enabled demuxers. Use -formats to view a combined list of enabled demuxers and muxers.

The description of some of the currently available demuxers follows.

3.1 aa
Audible Format 2, 3, and 4 demuxer.

This demuxer is used to demux Audible Format 2, 3, and 4 (.aa) files.

3.2 applehttp
Apple HTTP Live Streaming demuxer.

This demuxer presents all AVStreams from all variant streams. The id field is set to the bitrate variant index number. By setting the discard flags on AVStreams (by pressing ’a’ or ’v’ in ffplay), the caller can decide which variant streams to actually receive. The total bitrate of the variant that the stream belongs to is available in a metadata key named “variant_bitrate”.

3.3 apng
Animated Portable Network Graphics demuxer.

This demuxer is used to demux APNG files. All headers, but the PNG signature, up to (but not including) the first fcTL chunk are transmitted as extradata. Frames are then split as being all the chunks between two fcTL ones, or between the last fcTL and IEND chunks.

-ignore_loop bool
Ignore the loop variable in the file if set.

-max_fps int
Maximum framerate in frames per second (0 for no limit).

-default_fps int
Default framerate in frames per second when none is specified in the file (0 meaning as fast as possible).

3.4 asf
Advanced Systems Format demuxer.

This demuxer is used to demux ASF files and MMS network streams.

-no_resync_search bool
Do not try to resynchronize by looking for a certain optional start code.

3.5 concat
Virtual concatenation script demuxer.

This demuxer reads a list of files and other directives from a text file and demuxes them one after the other, as if all their packets had been muxed together.

The timestamps in the files are adjusted so that the first file starts at 0 and each next file starts where the previous one finishes. Note that it is done globally and may cause gaps if all streams do not have exactly the same length.

All files must have the same streams (same codecs, same time base, etc.).

The duration of each file is used to adjust the timestamps of the next file: if the duration is incorrect (because it was computed using the bit-rate or because the file is truncated, for example), it can cause artifacts. The duration directive can be used to override the duration stored in each file.

3.5.1 Syntax

The script is a text file in extended-ASCII, with one directive per line. Empty lines, leading spaces and lines starting with ’#’ are ignored. The following directive is recognized:

file path
Path to a file to read; special characters and spaces must be escaped with backslash or single quotes.

All subsequent file-related directives apply to that file.

ffconcat version 1.0
Identify the script type and version. It also sets the safe option to 1 if it was -1.

To make FFmpeg recognize the format automatically, this directive must appear exactly as is (no extra space or byte-order-mark) on the very first line of the script.

duration dur
Duration of the file. This information can be specified from the file; specifying it here may be more efficient or help if the information from the file is not available or accurate.

If the duration is set for all files, then it is possible to seek in the whole concatenated video.

inpoint timestamp
In point of the file. When the demuxer opens the file it instantly seeks to the specified timestamp. Seeking is done so that all streams can be presented successfully at In point.

This directive works best with intra frame codecs, because for non-intra frame ones you will usually get extra packets before the actual In point and the decoded content will most likely contain frames before In point too.

For each file, packets before the file In point will have timestamps less than the calculated start timestamp of the file (negative in case of the first file), and the duration of the files (if not specified by the duration directive) will be reduced based on their specified In point.

Because of potential packets before the specified In point, packet timestamps may overlap between two concatenated files.

outpoint timestamp
Out point of the file. When the demuxer reaches the specified decoding timestamp in any of the streams, it handles it as an end of file condition and skips the current and all the remaining packets from all streams.

Out point is exclusive, which means that the demuxer will not output packets with a decoding timestamp greater or equal to Out point.

This directive works best with intra frame codecs and formats where all streams are tightly interleaved. For non-intra frame codecs you will usually get additional packets with presentation timestamp after Out point therefore the decoded content will most likely contain frames after Out point too. If your streams are not tightly interleaved you may not get all the packets from all streams before Out point and you may only will be able to decode the earliest stream until Out point.

The duration of the files (if not specified by the duration directive) will be reduced based on their specified Out point.

file_packet_metadata key=value
Metadata of the packets of the file. The specified metadata will be set for each file packet. You can specify this directive multiple times to add multiple metadata entries.

stream
Introduce a stream in the virtual file. All subsequent stream-related directives apply to the last introduced stream. Some streams properties must be set in order to allow identifying the matching streams in the subfiles. If no streams are defined in the script, the streams from the first file are copied.

exact_stream_id id
Set the id of the stream. If this directive is given, the string with the corresponding id in the subfiles will be used. This is especially useful for MPEG-PS (VOB) files, where the order of the streams is not reliable.

3.5.2 Options

This demuxer accepts the following option:

safe
If set to 1, reject unsafe file paths. A file path is considered safe if it does not contain a protocol specification and is relative and all components only contain characters from the portable character set (letters, digits, period, underscore and hyphen) and have no period at the beginning of a component.

If set to 0, any file name is accepted.

The default is 1.

-1 is equivalent to 1 if the format was automatically probed and 0 otherwise.

auto_convert
If set to 1, try to perform automatic conversions on packet data to make the streams concatenable. The default is 1.

Currently, the only conversion is adding the h264_mp4toannexb bitstream filter to H.264 streams in MP4 format. This is necessary in particular if there are resolution changes.

segment_time_metadata
If set to 1, every packet will contain the lavf.concat.start_time and the lavf.concat.duration packet metadata values which are the start_time and the duration of the respective file segments in the concatenated output expressed in microseconds. The duration metadata is only set if it is known based on the concat file. The default is 0.

3.5.3 Examples

Use absolute filenames and include some comments:

my first filename

file /mnt/share/file-1.wav

my second filename including whitespace

file ‘/mnt/share/file 2.wav’

my third filename including whitespace plus single quote

file ‘/mnt/share/file 3’\”.wav’
Allow for input format auto-probing, use safe filenames and set the duration of the first file:
ffconcat version 1.0

file file-1.wav
duration 20.0

file subdir/file-2.wav
3.6 dash
Dynamic Adaptive Streaming over HTTP demuxer.

This demuxer presents all AVStreams found in the manifest. By setting the discard flags on AVStreams the caller can decide which streams to actually receive. Each stream mirrors the id and bandwidth properties from the as metadata keys named “id” and “variant_bitrate” respectively.

3.7 flv, live_flv
Adobe Flash Video Format demuxer.

This demuxer is used to demux FLV files and RTMP network streams. In case of live network streams, if you force format, you may use live_flv option instead of flv to survive timestamp discontinuities.

ffmpeg -f flv -i myfile.flv …
ffmpeg -f live_flv -i rtmp://

!/bin/sh

BASE_URL=1:−‘.′opensslrand16>file.keyecho 1 : − ‘ . ′ o p e n s s l r a n d 16 > f i l e . k e y e c h o BASE_URL/file.key > file.keyinfo
echo file.key >> file.keyinfo
echo $(openssl rand -hex 16) >> file.keyinfo
ffmpeg -f lavfi -re -i testsrc -c:v h264 -hls_flags delete_segments \
-hls_key_info_file file.keyinfo out.m3u8
-hls_enc enc
Enable (1) or disable (0) the AES128 encryption. When enabled every segment generated is encrypted and the encryption key is saved as playlist name.key.

-hls_enc_key key
Hex-coded 16byte key to encrypt the segments, by default it is randomly generated.

-hls_enc_key_url keyurl
If set, keyurl is prepended instead of baseurl to the key filename in the playlist.

-hls_enc_iv iv
Hex-coded 16byte initialization vector for every segment instead of the autogenerated ones.

hls_segment_type flags
Possible values:

‘mpegts’
If this flag is set, the hls segment files will format to mpegts. the mpegts files is used in all hls versions.

‘fmp4’
If this flag is set, the hls segment files will format to fragment mp4 looks like dash. the fmp4 files is used in hls after version 7.

hls_fmp4_init_filename filename
set filename to the fragment files header file, default filename is init.mp4.

When var_stream_map is set with two or more variant streams, the filename pattern must contain the string “%v”, this string specifies the position of variant stream index in the generated init file names. The string “%v” may be present in the filename or in the last directory name containing the file. If the string is present in the directory name, then sub-directories are created after expanding the directory name pattern. This enables creation of init files corresponding to different variant streams in subdirectories.

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.

‘periodic_rekey’
The file specified by hls_key_info_file will be checked periodically and detect updates to the encryption info. Be sure to replace this file atomically, including the file containing the AES encryption key.

‘independent_segments’
Add the #EXT-X-INDEPENDENT-SEGMENTS to playlists that has video segments and when all the segments of that playlist are guaranteed to start with a Key frame.

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

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.

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

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.m3u8​​​
This 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.

http_user_agent
Override User-Agent field in HTTP header. Applicable only for HTTP output.

var_stream_map
Map string which specifies how to group the audio, video and subtitle streams into different variant streams. The variant stream groups are separated by space. Expected string format is like this “a:0,v:0 a:1,v:1 ….”. Here a:, v:, s: are the keys to specify audio, video and subtitle streams respectively. Allowed values are 0 to 9 (limited just based on practical usage).

When there are two or more variant streams, the output filename pattern must contain the string “%v”, this string specifies the position of variant stream index in the output media playlist filenames. The string “%v” may be present in the filename or in the last directory name containing the file. If the string is present in the directory name, then sub-directories are created after expanding the directory name pattern. This enables creation of variant streams in subdirectories.

ffmpeg -re -i in.ts -b:v:0 1000k -b:v:1 256k -b:a:0 64k -b:a:1 32k \
-map 0:v -map 0:a -map 0:v -map 0:a -f hls -var_stream_map “v:0,a:0 v:1,a:1” \
​​​http://example.com/live/out_%v.m3u8​​​
This example creates two hls variant streams. The first variant stream will contain video stream of bitrate 1000k and audio stream of bitrate 64k and the second variant stream will contain video stream of bitrate 256k and audio stream of bitrate 32k. Here, two media playlist with file names out_0.m3u8 and out_1.m3u8 will be created.

ffmpeg -re -i in.ts -b:v:0 1000k -b:v:1 256k -b:a:0 64k \
-map 0:v -map 0:a -map 0:v -f hls -var_stream_map “v:0 a:0 v:1” \
​​​http://example.com/live/out_%v.m3u8​​​
This example creates three hls variant streams. The first variant stream will be a video only stream with video bitrate 1000k, the second variant stream will be an audio only stream with bitrate 64k and the third variant stream will be a video only stream with bitrate 256k. Here, three media playlist with file names out_0.m3u8, out_1.m3u8 and out_2.m3u8 will be created.

ffmpeg -re -i in.ts -b:v:0 1000k -b:v:1 256k -b:a:0 64k -b:a:1 32k \
-map 0:v -map 0:a -map 0:v -map 0:a -f hls -var_stream_map “v:0,a:0 v:1,a:1” \
​​​http://example.com/live/vs_%v/out.m3u8​​​
This example creates the variant streams in subdirectories. Here, the first media playlist is created at ​​​http://example.com/live/vs_0/out.m3u8​​​ and the second one at ​​http://example.com/live/vs_1/out.m3u8​​.

ffmpeg -re -i in.ts -b:a:0 32k -b:a:1 64k -b:v:0 1000k -b:v:1 3000k \
-map 0:a -map 0:a -map 0:v -map 0:v -f hls \
-var_stream_map “a:0,agroup:aud_low a:1,agroup:aud_high v:0,agroup:aud_low v:1,agroup:aud_high” \
-master_pl_name master.m3u8 \
​​​http://example.com/live/out_%v.m3u8​​​
This example creates two audio only and two video only variant streams. In addition to the #EXT-X-STREAM-INF tag for each variant stream in the master playlist, #EXT-X-MEDIA tag is also added for the two audio only variant streams and they are mapped to the two video only variant streams with audio group names ’aud_low’ and ’aud_high’.

By default, a single hls variant containing all the encoded streams is created.

cc_stream_map
Map string which specifies different closed captions groups and their attributes. The closed captions stream groups are separated by space. Expected string format is like this “ccgroup:,instreamid:,language: ….”. ’ccgroup’ and ’instreamid’ are mandatory attributes. ’language’ is an optional attribute. The closed captions groups configured using this option are mapped to different variant streams by providing the same ’ccgroup’ name in the var_stream_map string. If var_stream_map is not set, then the first available ccgroup in cc_stream_map is mapped to the output variant stream. The examples for these two use cases are given below.

ffmpeg -re -i in.ts -b:v 1000k -b:a 64k -a53cc 1 -f hls \
-cc_stream_map “ccgroup:cc,instreamid:CC1,language:en” \
-master_pl_name master.m3u8 \
​​​http://example.com/live/out.m3u8​​​
This example adds #EXT-X-MEDIA tag with TYPE=CLOSED-CAPTIONS in the master playlist with group name ’cc’, langauge ’en’ (english) and INSTREAM-ID ’CC1’. Also, it adds CLOSED-CAPTIONS attribute with group name ’cc’ for the output variant stream.

ffmpeg -re -i in.ts -b:v:0 1000k -b:v:1 256k -b:a:0 64k -b:a:1 32k \
-a53cc:0 1 -a53cc:1 1\
-map 0:v -map 0:a -map 0:v -map 0:a -f hls \
-cc_stream_map “ccgroup:cc,instreamid:CC1,language:en ccgroup:cc,instreamid:CC2,language:sp” \
-var_stream_map “v:0,a:0,ccgroup:cc v:1,a:1,ccgroup:cc” \
-master_pl_name master.m3u8 \
​​​http://example.com/live/out_%v.m3u8​​​
This example adds two #EXT-X-MEDIA tags with TYPE=CLOSED-CAPTIONS in the master playlist for the INSTREAM-IDs ’CC1’ and ’CC2’. Also, it adds CLOSED-CAPTIONS attribute with group name ’cc’ for the two output variant streams.

master_pl_name
Create HLS master playlist with the given name.

ffmpeg -re -i in.ts -f hls -master_pl_name master.m3u8 ​​http://example.com/live/out.m3u8​​​
This example creates HLS master playlist with name master.m3u8 and it is published at ​​​http://example.com/live/​

master_pl_publish_rate
Publish master play list repeatedly every after specified number of segment intervals.

ffmpeg -re -i in.ts -f hls -master_pl_name master.m3u8 \
-hls_time 2 -master_pl_publish_rate 30 ​​​http://example.com/live/out.m3u8​​​
This example creates HLS master playlist with name master.m3u8 and keep publishing it repeatedly every after 30 segments i.e. every after 60s.

http_persistent
Use persistent HTTP connections. Applicable only for HTTP output.

timeout
Set timeout for socket I/O operations. Applicable only for HTTP output.

4.14 ico
ICO file muxer.

Microsoft’s icon file format (ICO) has some strict limitations that should be noted:

Size cannot exceed 256 pixels in any dimension
Only BMP and PNG images can be stored
If a BMP image is used, it must be one of the following pixel formats:
BMP Bit Depth FFmpeg Pixel Format
1bit pal8
4bit pal8
8bit pal8
16bit rgb555le
24bit bgr24
32bit bgra
If a BMP image is used, it must use the BITMAPINFOHEADER DIB header
If a PNG image is used, it must use the rgba pixel format
4.15 image2
Image file muxer.

The image file muxer writes video frames to image files.

The output filenames are specified by a pattern, which can be used to produce sequentially numbered series of files. The pattern may contain the string “%d” or “%0Nd”, this string specifies the position of the characters representing a numbering in the filenames. If the form “%0Nd” is used, the string representing the number in each filename is 0-padded to N digits. The literal character ’%’ can be specified in the pattern with the string “%%”.

If the pattern contains “%d” or “%0Nd”, the first filename of the file list specified will contain the number 1, all the following numbers will be sequential.

The pattern may contain a suffix which is used to automatically determine the format of the image files to write.

For example the pattern “img-%03d.bmp” will specify a sequence of filenames of the form img-001.bmp, img-002.bmp, …, img-010.bmp, etc. The pattern “img%%-%d.jpg” will specify a sequence of filenames of the form img%-1.jpg, img%-2.jpg, …, img%-10.jpg, etc.

4.15.1 Examples

The following example shows how to use ffmpeg for creating a sequence of files img-001.jpeg, img-002.jpeg, …, taking one image every second from the input video:

ffmpeg -i in.avi -vsync cfr -r 1 -f image2 ‘img-%03d.jpeg’
Note that with ffmpeg, if the format is not specified with the -f option and the output filename specifies an image file format, the image2 muxer is automatically selected, so the previous command can be written as:

ffmpeg -i in.avi -vsync cfr -r 1 ‘img-%03d.jpeg’
Note also that the pattern must not necessarily contain “%d” or “%0Nd”, for example to create a single image file img.jpeg from the start of the input video you can employ the command:

ffmpeg -i in.avi -f image2 -frames:v 1 img.jpeg
The strftime option allows you to expand the filename with date and time information. Check the documentation of the strftime() function for the syntax.

For example to generate image files from the strftime() “%Y-%m-%d_%H-%M-%S” pattern, the following ffmpeg command can be used:

ffmpeg -f v4l2 -r 1 -i /dev/video0 -f image2 -strftime 1 “%Y-%m-%d_%H-%M-%S.jpg”
You can set the file name with current frame’s PTS:

ffmpeg -f v4l2 -r 1 -i /dev/video0 -copyts -f image2 -frame_pts true %d.jpg”
4.15.2 Options

frame_pts
If set to 1, expand the filename with pts from pkt->pts. Default value is 0.

start_number
Start the sequence from the specified number. Default value is 1.

update
If set to 1, the filename will always be interpreted as just a filename, not a pattern, and the corresponding file will be continuously overwritten with new images. Default value is 0.

strftime
If set to 1, expand the filename with date and time information from strftime(). Default value is 0.

The image muxer supports the .Y.U.V image file format. This format is special in that that each image frame consists of three files, for each of the YUV420P components. To read or write this image file format, specify the name of the ’.Y’ file. The muxer will automatically open the ’.U’ and ’.V’ files as required.

4.16 matroska
Matroska container muxer.

This muxer implements the matroska and webm container specs.

4.16.1 Metadata

The recognized metadata settings in this muxer are:

title
Set title name provided to a single track.

language
Specify the language of the track in the Matroska languages form.

The language can be either the 3 letters bibliographic ISO-639-2 (ISO 639-2/B) form (like “fre” for French), or a language code mixed with a country code for specialities in languages (like “fre-ca” for Canadian French).

stereo_mode
Set stereo 3D video layout of two views in a single video track.

The following values are recognized:

‘mono’
video is not stereo

‘left_right’
Both views are arranged side by side, Left-eye view is on the left

‘bottom_top’
Both views are arranged in top-bottom orientation, Left-eye view is at bottom

‘top_bottom’
Both views are arranged in top-bottom orientation, Left-eye view is on top

‘checkerboard_rl’
Each view is arranged in a checkerboard interleaved pattern, Left-eye view being first

‘checkerboard_lr’
Each view is arranged in a checkerboard interleaved pattern, Right-eye view being first

‘row_interleaved_rl’
Each view is constituted by a row based interleaving, Right-eye view is first row

‘row_interleaved_lr’
Each view is constituted by a row based interleaving, Left-eye view is first row

‘col_interleaved_rl’
Both views are arranged in a column based interleaving manner, Right-eye view is first column

‘col_interleaved_lr’
Both views are arranged in a column based interleaving manner, Left-eye view is first column

‘anaglyph_cyan_red’
All frames are in anaglyph format viewable through red-cyan filters

‘right_left’
Both views are arranged side by side, Right-eye view is on the left

‘anaglyph_green_magenta’
All frames are in anaglyph format viewable through green-magenta filters

‘block_lr’
Both eyes laced in one Block, Left-eye view is first

‘block_rl’
Both eyes laced in one Block, Right-eye view is first

For example a 3D WebM clip can be created using the following command line:

ffmpeg -i sample_left_right_clip.mpg -an -c:v libvpx -metadata stereo_mode=left_right -y stereo_clip.webm
4.16.2 Options

This muxer supports the following options:

reserve_index_space
By default, this muxer writes the index for seeking (called cues in Matroska terms) at the end of the file, because it cannot know in advance how much space to leave for the index at the beginning of the file. However for some use cases – e.g. streaming where seeking is possible but slow – it is useful to put the index at the beginning of the file.

If this option is set to a non-zero value, the muxer will reserve a given amount of space in the file header and then try to write the cues there when the muxing finishes. If the available space does not suffice, muxing will fail. A safe size for most use cases should be about 50kB per hour of video.

Note that cues are only written if the output is seekable and this option will have no effect if it is not.

4.17 md5
MD5 testing format.

This is a variant of the hash muxer. Unlike that muxer, it defaults to using the MD5 hash function.

4.17.1 Examples

To compute the MD5 hash of the input converted to raw audio and video, and store it in the file out.md5:

ffmpeg -i INPUT -f md5 out.md5
You can print the MD5 to stdout with the command:

ffmpeg -i INPUT -f md5 -
See also the hash and framemd5 muxers.

4.18 mov, mp4, ismv
MOV/MP4/ISMV (Smooth Streaming) muxer.

The mov/mp4/ismv muxer supports fragmentation. Normally, a MOV/MP4 file has all the metadata about all packets stored in one location (written at the end of the file, it can be moved to the start for better playback by adding faststart to the movflags, or using the qt-faststart tool). A fragmented file consists of a number of fragments, where packets and metadata about these packets are stored together. Writing a fragmented file has the advantage that the file is decodable even if the writing is interrupted (while a normal MOV/MP4 is undecodable if it is not properly finished), and it requires less memory when writing very long files (since writing normal MOV/MP4 files stores info about every single packet in memory until the file is closed). The downside is that it is less compatible with other applications.

4.18.1 Options

Fragmentation is enabled by setting one of the AVOptions that define how to cut the file into fragments:

-moov_size bytes
Reserves space for the moov atom at the beginning of the file instead of placing the moov atom at the end. If the space reserved is insufficient, muxing will fail.

-movflags frag_keyframe
Start a new fragment at each video keyframe.

-frag_duration duration
Create fragments that are duration microseconds long.

-frag_size size
Create fragments that contain up to size bytes of payload data.

-movflags frag_custom
Allow the caller to manually choose when to cut fragments, by calling av_write_frame(ctx, NULL) to write a fragment with the packets written so far. (This is only useful with other applications integrating libavformat, not from ffmpeg.)

-min_frag_duration duration
Don’t create fragments that are shorter than duration microseconds long.

If more than one condition is specified, fragments are cut when one of the specified conditions is fulfilled. The exception to this is -min_frag_duration, which has to be fulfilled for any of the other conditions to apply.

Additionally, the way the output file is written can be adjusted through a few other options:

-movflags empty_moov
Write an initial moov atom directly at the start of the file, without describing any samples in it. Generally, an mdat/moov pair is written at the start of the file, as a normal MOV/MP4 file, containing only a short portion of the file. With this option set, there is no initial mdat atom, and the moov atom only describes the tracks but has a zero duration.

This option is implicitly set when writing ismv (Smooth Streaming) files.

-movflags separate_moof
Write a separate moof (movie fragment) atom for each track. Normally, packets for all tracks are written in a moof atom (which is slightly more efficient), but with this option set, the muxer writes one moof/mdat pair for each track, making it easier to separate tracks.

This option is implicitly set when writing ismv (Smooth Streaming) files.

-movflags faststart
Run a second pass moving the index (moov atom) to the beginning of the file. This operation can take a while, and will not work in various situations such as fragmented output, thus it is not enabled by default.

-movflags rtphint
Add RTP hinting tracks to the output file.

-movflags disable_chpl
Disable Nero chapter markers (chpl atom). Normally, both Nero chapters and a QuickTime chapter track are written to the file. With this option set, only the QuickTime chapter track will be written. Nero chapters can cause failures when the file is reprocessed with certain tagging programs, like mp3Tag 2.61a and iTunes 11.3, most likely other versions are affected as well.

-movflags omit_tfhd_offset
Do not write any absolute base_data_offset in tfhd atoms. This avoids tying fragments to absolute byte positions in the file/streams.

-movflags default_base_moof
Similarly to the omit_tfhd_offset, this flag avoids writing the absolute base_data_offset field in tfhd atoms, but does so by using the new default-base-is-moof flag instead. This flag is new from 14496-12:2012. This may make the fragments easier to parse in certain circumstances (avoiding basing track fragment location calculations on the implicit end of the previous track fragment).

-write_tmcd
Specify on to force writing a timecode track, off to disable it and auto to write a timecode track only for mov and mp4 output (default).

-movflags negative_cts_offsets
Enables utilization of version 1 of the CTTS box, in which the CTS offsets can be negative. This enables the initial sample to have DTS/CTS of zero, and reduces the need for edit lists for some cases such as video tracks with B-frames. Additionally, eases conformance with the DASH-IF interoperability guidelines.

-write_prft
Write producer time reference box (PRFT) with a specified time source for the NTP field in the PRFT box. Set value as ‘wallclock’ to specify timesource as wallclock time and ‘pts’ to specify timesource as input packets’ PTS values.

Setting value to ‘pts’ is applicable only for a live encoding use case, where PTS values are set as as wallclock time at the source. For example, an encoding use case with decklink capture source where video_pts and audio_pts are set to ‘abs_wallclock’.

4.18.2 Example

Smooth Streaming content can be pushed in real time to a publishing point on IIS with this muxer. Example:

ffmpeg -re

chapter ends at 0:01:00

END=60000
title=chapter #1
[STREAM]
title=multi\
line
By using the ffmetadata muxer and demuxer it is possible to extract metadata from an input file to an ffmetadata file, and then transcode the file into an output file with the edited ffmetadata file.

Extracting an ffmetadata file with ffmpeg goes as follows:

ffmpeg -i INPUT -f ffmetadata FFMETADATAFILE
Reinserting edited metadata information from the FFMETADATAFILE file can be done as:

ffmpeg -i INPUT -i FFMETADATAFILE -map_metadata 1 -codec copy OUTPUT
6 See Also
ffmpeg, ffplay, ffprobe, libavformat

7 Authors
The FFmpeg developers.

For details about the authorship, see the Git history of the project (git://source.ffmpeg.org/ffmpeg), e.g. by typing the command git log in the FFmpeg source directory, or browsing the online repository at ​​http://source.ffmpeg.org​​.

Maintainers for the specific components are listed in the file MAINTAINERS in the source code tree.

This document was generated on July 4, 2018 using makeinfo.


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  4koL3J55wyKx   2023年11月13日   38   0   0 icogitCentOS
  b1UHV4WKBb2S   2023年11月13日   40   0   0 ide抗锯齿
  b1UHV4WKBb2S   2023年11月13日   37   0   0 裁剪ideflutter
  zSWNgACtCQuP   2023年11月13日   32   0   0 ide
NYfg2BRCcXho