40 #define VALIDATE_INDEX_TS_THRESH 2500
42 #define RESYNC_BUFFER_SIZE (1<<20)
74 d[3] < 5 && d[5] == 0 &&
77 int is_live = !memcmp(d + offset + 40,
"NGINX RTMP", 10);
122 switch (flv_codecid) {
125 codec_id = bits_per_coded_sample == 8
132 return codec_id == acodec->
codec_id;
134 codec_id = bits_per_coded_sample == 8
137 return codec_id == acodec->
codec_id;
164 switch (flv_codecid) {
228 switch (flv_codecid) {
247 int flv_codecid,
int read)
250 switch (flv_codecid) {
296 if (length >= buffsize) {
312 unsigned int timeslen = 0, fileposlen = 0, i;
314 int64_t *times =
NULL;
315 int64_t *filepositions =
NULL;
329 int64_t **current_array;
330 unsigned int arraylen;
341 current_array = ×
345 current_array = &filepositions;
346 fileposlen = arraylen;
352 if (!(*current_array =
av_mallocz(
sizeof(**current_array) * arraylen))) {
357 for (i = 0; i < arraylen &&
avio_tell(ioc) < max_pos - 1; i++) {
362 if (times && filepositions) {
370 if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
371 for (i = 0; i < fileposlen; i++) {
421 if ((vstream || astream) && key &&
455 av_log(s,
AV_LOG_ERROR,
"Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
462 unsigned int arraylen, i;
465 for (i = 0; i < arraylen &&
avio_tell(ioc) < max_pos - 1; i++)
480 acodec = astream ? astream->
codec :
NULL;
481 vcodec = vstream ? vstream->
codec :
NULL;
487 if (!strcmp(key,
"duration"))
489 else if (!strcmp(key,
"videodatarate") && vcodec &&
490 0 <= (
int)(num_val * 1024.0))
491 vcodec->
bit_rate = num_val * 1024.0;
492 else if (!strcmp(key,
"audiodatarate") && acodec &&
493 0 <= (
int)(num_val * 1024.0))
494 acodec->
bit_rate = num_val * 1024.0;
495 else if (!strcmp(key,
"datastream")) {
501 if (!strcmp(key,
"videocodecid") && vcodec) {
503 }
else if (!strcmp(key,
"audiocodecid") && acodec) {
506 }
else if (!strcmp(key,
"audiosamplerate") && acodec) {
508 }
else if (!strcmp(key,
"audiosamplesize") && acodec) {
510 }
else if (!strcmp(key,
"stereo") && acodec) {
515 }
else if (!strcmp(key,
"width") && vcodec) {
516 vcodec->
width = num_val;
517 }
else if (!strcmp(key,
"height") && vcodec) {
523 if (!strcmp(key,
"encoder")) {
525 if (1 == sscanf(str_val,
"Open Broadcaster Software v0.%d", &version)) {
526 if (version > 0 && version <= 655)
529 }
else if (!strcmp(key,
"metadatacreator") && !strcmp(str_val,
"MEGA")) {
536 ((!acodec && !strcmp(key,
"audiocodecid")) ||
537 (!vcodec && !strcmp(key,
"videocodecid"))))
540 if (!strcmp(key,
"duration") ||
541 !strcmp(key,
"filesize") ||
542 !strcmp(key,
"width") ||
543 !strcmp(key,
"height") ||
544 !strcmp(key,
"videodatarate") ||
545 !strcmp(key,
"framerate") ||
546 !strcmp(key,
"videocodecid") ||
547 !strcmp(key,
"audiodatarate") ||
548 !strcmp(key,
"audiosamplerate") ||
549 !strcmp(key,
"audiosamplesize") ||
550 !strcmp(key,
"stereo") ||
551 !strcmp(key,
"audiocodecid") ||
552 !strcmp(key,
"datastream"))
557 av_strlcpy(str_val, num_val > 0 ?
"true" :
"false",
561 snprintf(str_val,
sizeof(str_val),
"%.f", num_val);
570 #define TYPE_ONTEXTDATA 1
571 #define TYPE_ONCAPTION 2
572 #define TYPE_ONCAPTIONINFO 3
573 #define TYPE_UNKNOWN 9
578 AVStream *stream, *astream, *vstream;
597 if (!strcmp(buffer,
"onTextData"))
600 if (!strcmp(buffer,
"onCaption"))
603 if (!strcmp(buffer,
"onCaptionInfo"))
606 if (strcmp(buffer,
"onMetaData") && strcmp(buffer,
"onCuePoint")) {
693 "Found invalid index entries, clearing the index.\n");
707 int nb = -1, ret, parse_name = 1;
747 int64_t dts, int64_t next)
767 while (array || (ret =
amf_get_string(pb, buf,
sizeof(buf))) > 0) {
827 if (lsize2 >= 11 && lsize2 + 8LL <
FFMIN(i, RESYNC_BUFFER_SIZE)) {
830 if (lsize1 >= 11 && lsize1 + 8LL + lsize2 <
FFMIN(i, RESYNC_BUFFER_SIZE)) {
832 if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
833 avio_seek(s->
pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
849 int64_t next, pos, meta_pos;
866 av_log(s,
AV_LOG_TRACE,
"type:%d, size:%d, last:%d, dts:%"PRId64
" pos:%"PRId64
"\n", type, size, last, dts,
avio_tell(s->
pb));
874 if (pos == validate_pos) {
882 }
else if (pos > validate_pos) {
907 if (size > 13 + 1 + 4) {
911 if (type == 0 && dts == 0 || type < 0 || type ==
TYPE_UNKNOWN) {
930 "Skipping flv packet: type %d, size %d, flags %d.\n",
996 if (size > 0 && size < fsize) {
1005 else if (fsize >= 8 && fsize - 8 >= size) {
1007 goto retry_duration;
1017 int bits_per_coded_sample;
1063 "Negative cts, previous timestamps might be wrong.\n");
1065 }
else if (
FFABS(dts - pts) > 1000*60*15) {
1067 "invalid timestamps %"PRId64
" %"PRId64
"\n", dts, pts);
1147 if (last != orig_size + 11 &&
1162 int64_t ts,
int flags)
1169 #define OFFSET(x) offsetof(FLVContext, x)
1170 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1172 {
"flv_metadata",
"Allocate streams according to the onMetaData array",
OFFSET(trust_metadata),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VD },
1192 .extensions =
"flv",
1193 .priv_class = &flv_class,
1212 .extensions =
"flv",
1213 .priv_class = &live_flv_class,
struct FLVContext::@170 validate_index[2]
discard all frames except keyframes
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t avio_size(AVIOContext *s)
Get the filesize.
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
#define LIBAVUTIL_VERSION_INT
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
int index
stream index in AVFormatContext
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
enum AVMediaType codec_type
int event_flags
Flags for the user to detect events happening on the file.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define AV_CH_LAYOUT_STEREO
unsigned int avio_rb16(AVIOContext *s)
int ctx_flags
Flags signalling stream properties.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
unsigned int avio_rb32(AVIOContext *s)
int wrong_dts
wrong dts due to negative cts
enum AVStreamParseType need_parsing
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
AVStream ** streams
A list of all streams in the file.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int trust_metadata
configure streams according onMetaData
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
enum AVCodecID video_codec_id
Forced video codec_id.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
discard all bidirectional frames
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
static const uint8_t offset[127][2]
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
uint8_t resync_buffer[2 *RESYNC_BUFFER_SIZE]
int flags
A combination of AV_PKT_FLAG values.
uint64_t channel_layout
Audio channel layout.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
audio channel layout utility functions
unsigned int avio_rb24(AVIOContext *s)
#define AV_TIME_BASE
Internal time base represented as integer.
enum AVCodecID audio_codec_id
Forced audio codec_id.
int width
picture width / height.
int new_extradata_size[FLV_STREAM_TYPE_NB]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
enum AVMediaType codec_type
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
int sample_rate
samples per second
AVIOContext * pb
I/O context.
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
This structure contains the data a format has to probe a file.
static int64_t pts
Global timestamp for the audio frames.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bit_size, int sync_extension)
Parse MPEG-4 systems extradata to retrieve audio configuration.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
int eof_reached
true if eof reached
int channels
number of audio channels
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
#define AV_CH_LAYOUT_MONO
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.