40 #define VALIDATE_INDEX_TS_THRESH 2500
42 #define RESYNC_BUFFER_SIZE (1<<20)
96 d[3] < 5 && d[5] == 0 &&
99 int is_live = !memcmp(d +
offset + 40,
"NGINX RTMP", 10);
169 if (
s->nb_streams>=3 ||(
s->nb_streams==2
204 switch (flv_codecid) {
207 codec_id = bits_per_coded_sample == 8
216 codec_id = bits_per_coded_sample == 8
246 switch (flv_codecid) {
310 switch (flv_codecid) {
329 int flv_codecid,
int read)
334 switch (flv_codecid) {
389 if (length >= buffsize) {
408 unsigned int timeslen = 0, fileposlen = 0,
i;
410 int64_t *times =
NULL;
411 int64_t *filepositions =
NULL;
427 int64_t **current_array;
428 unsigned int arraylen;
439 current_array = ×
443 current_array = &filepositions;
444 fileposlen = arraylen;
450 if (!(*current_array =
av_mallocz(
sizeof(**current_array) * arraylen))) {
460 if (
isnan(d) || d < INT64_MIN || d > INT64_MAX)
462 current_array[0][
i] = d;
464 if (times && filepositions) {
472 if (timeslen == fileposlen && fileposlen>1 &&
max_pos <= filepositions[0]) {
473 for (
i = 0;
i <
FFMIN(2,fileposlen);
i++) {
482 filepositions =
NULL;
564 av_log(
s,
AV_LOG_ERROR,
"Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
571 unsigned int arraylen,
i;
598 if (!strcmp(
key,
"duration"))
600 else if (!strcmp(
key,
"videodatarate") &&
601 0 <= (
int)(num_val * 1024.0))
603 else if (!strcmp(
key,
"audiodatarate") &&
604 0 <= (
int)(num_val * 1024.0))
606 else if (!strcmp(
key,
"datastream")) {
611 }
else if (!strcmp(
key,
"framerate")) {
616 if (!strcmp(
key,
"videocodecid") && vpar) {
620 }
else if (!strcmp(
key,
"audiocodecid") && apar) {
623 }
else if (!strcmp(
key,
"audiosamplerate") && apar) {
625 }
else if (!strcmp(
key,
"audiosamplesize") && apar) {
627 }
else if (!strcmp(
key,
"stereo") && apar) {
632 }
else if (!strcmp(
key,
"width") && vpar) {
633 vpar->
width = num_val;
634 }
else if (!strcmp(
key,
"height") && vpar) {
640 if (!strcmp(
key,
"encoder")) {
642 if (1 == sscanf(str_val,
"Open Broadcaster Software v0.%d", &
version)) {
646 }
else if (!strcmp(
key,
"metadatacreator")) {
647 if ( !strcmp (str_val,
"MEGA")
648 || !strncmp(str_val,
"FlixEngine", 10))
655 ((!apar && !strcmp(
key,
"audiocodecid")) ||
656 (!vpar && !strcmp(
key,
"videocodecid"))))
659 if ((!strcmp(
key,
"duration") ||
660 !strcmp(
key,
"filesize") ||
661 !strcmp(
key,
"width") ||
662 !strcmp(
key,
"height") ||
663 !strcmp(
key,
"videodatarate") ||
664 !strcmp(
key,
"framerate") ||
665 !strcmp(
key,
"videocodecid") ||
666 !strcmp(
key,
"audiodatarate") ||
667 !strcmp(
key,
"audiosamplerate") ||
668 !strcmp(
key,
"audiosamplesize") ||
669 !strcmp(
key,
"stereo") ||
670 !strcmp(
key,
"audiocodecid") ||
676 av_strlcpy(str_val, num_val > 0 ?
"true" :
"false",
680 snprintf(str_val,
sizeof(str_val),
"%.f", num_val);
690 strftime(datestr,
sizeof(datestr),
"%a, %d %b %Y %H:%M:%S %z", &t);
699 #define TYPE_ONTEXTDATA 1
700 #define TYPE_ONCAPTION 2
701 #define TYPE_ONCAPTIONINFO 3
702 #define TYPE_UNKNOWN 9
708 AVStream *stream, *astream, *vstream;
725 if (!strcmp(
buffer,
"onTextData"))
728 if (!strcmp(
buffer,
"onCaption"))
731 if (!strcmp(
buffer,
"onCaptionInfo"))
734 if (strcmp(
buffer,
"onMetaData") && strcmp(
buffer,
"onCuePoint") && strcmp(
buffer,
"|RtmpSampleAccess")) {
741 for (
i = 0;
i <
s->nb_streams;
i++) {
742 stream =
s->streams[
i];
766 int pre_tag_size = 0;
769 if(!strcmp(
s->iformat->name,
"kux"))
789 av_log(
s,
AV_LOG_WARNING,
"Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
842 "Found invalid index entries, clearing the index.\n");
843 for (
i = 0;
i <
s->nb_streams;
i++) {
856 int nb = -1, ret, parse_name = 1;
904 int64_t dts, int64_t next)
944 for (
i = 0;
i <
s->nb_streams;
i++) {
950 if (
i ==
s->nb_streams) {
987 d[3] < 5 && d[5] == 0) {
1001 if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
1018 int64_t next,
pos, meta_pos;
1034 dts |= (unsigned)
avio_r8(
s->pb) << 24;
1035 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));
1043 if (
pos == validate_pos) {
1051 }
else if (
pos > validate_pos) {
1076 if (
size > 13 + 1 + 4) {
1080 if (
type == 0 && dts == 0 ||
type < 0) {
1081 if (type < 0 && flv->validate_count &&
1100 "Skipping flv packet: type %d, size %d, flags %d.\n",
1103 if (
avio_seek(
s->pb, next, SEEK_SET) != next) {
1121 for (
i = 0;
i <
s->nb_streams;
i++) {
1139 if (
i ==
s->nb_streams) {
1183 ts |= (unsigned)
avio_r8(
s->pb) << 24;
1188 goto retry_duration;
1198 int bits_per_coded_sample;
1260 "Negative cts, previous timestamps might be wrong.\n");
1262 }
else if (
FFABS(dts -
pts) > 1000*60*15) {
1264 "invalid timestamps %"PRId64
" %"PRId64
"\n", dts,
pts);
1330 if (last != orig_size + 11 && last != orig_size + 10 &&
1351 int64_t ts,
int flags)
1358 #define OFFSET(x) offsetof(FLVContext, x)
1359 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1361 {
"flv_metadata",
"Allocate streams according to the onMetaData array",
OFFSET(trust_metadata),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VD },
1362 {
"flv_full_metadata",
"Dump full metadata of the onMetadata",
OFFSET(dump_full_metadata),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VD },
1363 {
"flv_ignore_prevtag",
"Ignore the Size of previous tag",
OFFSET(trust_datasize),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VD },
1384 .extensions =
"flv",
1404 .extensions =
"flv",
1425 .extensions =
"kux",
static int64_t fsize(FILE *f)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
uint64_t avio_rb64(AVIOContext *s)
int64_t avio_size(AVIOContext *s)
Get the filesize.
unsigned int avio_rb16(AVIOContext *s)
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
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.
unsigned int avio_rb24(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define flags(name, subs,...)
audio channel layout utility functions
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
#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 const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_TEXT
raw UTF-8 text
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_BIDIR
discard all bidirectional frames
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
FF_ENABLE_DEPRECATION_WARNINGS int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
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.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
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.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define LIBAVUTIL_VERSION_INT
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
enum AVMediaType codec_type
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
uint64_t channel_layout
Audio only.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
Audio only.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int eof_reached
true if was unable to read due to error or eof
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int64_t pos
byte position in stream, -1 if unknown
This structure contains the data a format has to probe a file.
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.
Rational number (pair of numerator and denominator).
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int index
stream index in AVFormatContext
AVRational avg_frame_rate
Average framerate.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
enum AVStreamParseType need_parsing
AVStreamInternal * internal
An opaque field for libavformat internal usage.
uint8_t resync_buffer[2 *RESYNC_BUFFER_SIZE]
int wrong_dts
wrong dts due to negative cts
int new_extradata_size[FLV_STREAM_TYPE_NB]
int trust_datasize
trust data size of FLVTag
struct FLVContext::@255 validate_index[2]
int last_keyframe_stream_index
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
int64_t * keyframe_filepositions
int dump_full_metadata
Dump full metadata of the onMetadata.
int trust_metadata
configure streams according onMetaData
#define avpriv_request_sample(...)
static int array[MAX_W *MAX_W]
static const uint8_t offset[127][2]