You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avformat/flvdec: handle exheader fourcc correctly in metadata
In metadata fourcc is carried in the AMF number, not as binary. Partially based on a patch by Steven Liu. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
@@ -304,30 +304,18 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flv_same_video_codec(AVFormatContext *s, AVCodecParameters *vpar, int flags)
|
static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)
|
||||||
{
|
{
|
||||||
int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
|
|
||||||
FLVContext *flv = s->priv_data;
|
|
||||||
|
|
||||||
if (!vpar->codec_id && !vpar->codec_tag)
|
if (!vpar->codec_id && !vpar->codec_tag)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (flv->exheader) {
|
switch (flv_codecid) {
|
||||||
uint8_t *codec_id_str = (uint8_t *)s->pb->buf_ptr;
|
|
||||||
uint32_t codec_id = codec_id_str[3] | codec_id_str[2] << 8 | codec_id_str[1] << 16 | codec_id_str[0] << 24;
|
|
||||||
switch(codec_id) {
|
|
||||||
case MKBETAG('h', 'v', 'c', '1'):
|
case MKBETAG('h', 'v', 'c', '1'):
|
||||||
return vpar->codec_id == AV_CODEC_ID_HEVC;
|
return vpar->codec_id == AV_CODEC_ID_HEVC;
|
||||||
case MKBETAG('a', 'v', '0', '1'):
|
case MKBETAG('a', 'v', '0', '1'):
|
||||||
return vpar->codec_id == AV_CODEC_ID_AV1;
|
return vpar->codec_id == AV_CODEC_ID_AV1;
|
||||||
case MKBETAG('v', 'p', '0', '9'):
|
case MKBETAG('v', 'p', '0', '9'):
|
||||||
return vpar->codec_id == AV_CODEC_ID_VP9;
|
return vpar->codec_id == AV_CODEC_ID_VP9;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (flv_codecid) {
|
|
||||||
case FLV_CODECID_H263:
|
case FLV_CODECID_H263:
|
||||||
return vpar->codec_id == AV_CODEC_ID_FLV1;
|
return vpar->codec_id == AV_CODEC_ID_FLV1;
|
||||||
case FLV_CODECID_SCREEN:
|
case FLV_CODECID_SCREEN:
|
||||||
@@ -346,36 +334,26 @@ static int flv_same_video_codec(AVFormatContext *s, AVCodecParameters *vpar, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
|
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
|
||||||
int flv_codecid, int read)
|
uint32_t flv_codecid, int read)
|
||||||
{
|
{
|
||||||
FFStream *const vstreami = ffstream(vstream);
|
FFStream *const vstreami = ffstream(vstream);
|
||||||
FLVContext *flv = s->priv_data;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
AVCodecParameters *par = vstream->codecpar;
|
AVCodecParameters *par = vstream->codecpar;
|
||||||
enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
|
enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
|
||||||
flv_codecid &= FLV_VIDEO_CODECID_MASK;
|
|
||||||
|
|
||||||
if (flv->exheader) {
|
switch (flv_codecid) {
|
||||||
uint32_t codec_id = avio_rb32(s->pb);
|
|
||||||
|
|
||||||
switch(codec_id) {
|
|
||||||
case MKBETAG('h', 'v', 'c', '1'):
|
case MKBETAG('h', 'v', 'c', '1'):
|
||||||
par->codec_id = AV_CODEC_ID_HEVC;
|
par->codec_id = AV_CODEC_ID_HEVC;
|
||||||
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
|
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
|
||||||
return 4;
|
break;
|
||||||
case MKBETAG('a', 'v', '0', '1'):
|
case MKBETAG('a', 'v', '0', '1'):
|
||||||
par->codec_id = AV_CODEC_ID_AV1;
|
par->codec_id = AV_CODEC_ID_AV1;
|
||||||
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
|
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
|
||||||
return 4;
|
break;
|
||||||
case MKBETAG('v', 'p', '0', '9'):
|
case MKBETAG('v', 'p', '0', '9'):
|
||||||
par->codec_id = AV_CODEC_ID_VP9;
|
par->codec_id = AV_CODEC_ID_VP9;
|
||||||
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
|
vstreami->need_parsing = AVSTREAM_PARSE_HEADERS;
|
||||||
return 4;
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (flv_codecid) {
|
|
||||||
case FLV_CODECID_H263:
|
case FLV_CODECID_H263:
|
||||||
par->codec_id = AV_CODEC_ID_FLV1;
|
par->codec_id = AV_CODEC_ID_FLV1;
|
||||||
break;
|
break;
|
||||||
@@ -1065,6 +1043,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
AVStream *st = NULL;
|
AVStream *st = NULL;
|
||||||
int last = -1;
|
int last = -1;
|
||||||
int orig_size;
|
int orig_size;
|
||||||
|
uint32_t video_codec_id = 0;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
/* pkt size is repeated at end. skip it */
|
/* pkt size is repeated at end. skip it */
|
||||||
@@ -1111,12 +1090,17 @@ retry:
|
|||||||
} else if (type == FLV_TAG_TYPE_VIDEO) {
|
} else if (type == FLV_TAG_TYPE_VIDEO) {
|
||||||
stream_type = FLV_STREAM_TYPE_VIDEO;
|
stream_type = FLV_STREAM_TYPE_VIDEO;
|
||||||
flags = avio_r8(s->pb);
|
flags = avio_r8(s->pb);
|
||||||
|
video_codec_id = flags & FLV_VIDEO_CODECID_MASK;
|
||||||
/*
|
/*
|
||||||
* Reference Enhancing FLV 2023-03-v1.0.0-B.8
|
* Reference Enhancing FLV 2023-03-v1.0.0-B.8
|
||||||
* https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
|
* https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
|
||||||
* */
|
* */
|
||||||
flv->exheader = (flags >> 7) & 1;
|
flv->exheader = (flags >> 7) & 1;
|
||||||
size--;
|
size--;
|
||||||
|
if (flv->exheader) {
|
||||||
|
video_codec_id = avio_rb32(s->pb);
|
||||||
|
size -= 4;
|
||||||
|
}
|
||||||
if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD)
|
if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD)
|
||||||
goto skip;
|
goto skip;
|
||||||
} else if (type == FLV_TAG_TYPE_META) {
|
} else if (type == FLV_TAG_TYPE_META) {
|
||||||
@@ -1174,7 +1158,7 @@ skip:
|
|||||||
break;
|
break;
|
||||||
} else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
|
} else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
|
||||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
||||||
(s->video_codec_id || flv_same_video_codec(s, st->codecpar, flags)))
|
(s->video_codec_id || flv_same_video_codec(st->codecpar, video_codec_id)))
|
||||||
break;
|
break;
|
||||||
} else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
|
} else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
|
||||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
|
||||||
@@ -1275,7 +1259,7 @@ retry_duration:
|
|||||||
avcodec_parameters_free(&par);
|
avcodec_parameters_free(&par);
|
||||||
}
|
}
|
||||||
} else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
|
} else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
|
||||||
int ret = flv_set_video_codec(s, st, flags, 1);
|
int ret = flv_set_video_codec(s, st, video_codec_id, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
size -= ret;
|
size -= ret;
|
||||||
|
Reference in New Issue
Block a user