From b76053d8bf322b197a9d07bd27bbdad14fd5bc15 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Fri, 10 Jan 2025 21:41:55 +0100 Subject: [PATCH] avformat/flvdec: add support for legacy HEVC files --- libavformat/flv.h | 3 +++ libavformat/flvdec.c | 6 ++++-- libavformat/version.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libavformat/flv.h b/libavformat/flv.h index 1ea88ff851193..74d3b8de8be9f 100644 --- a/libavformat/flv.h +++ b/libavformat/flv.h @@ -117,6 +117,9 @@ enum { FLV_CODECID_H264 = 7, FLV_CODECID_REALH263= 8, FLV_CODECID_MPEG4 = 9, + + // non-standard protocol extension that is in use in the wild + FLV_CODECID_X_HEVC = 12, }; enum { diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 7d56c3e4038f4..2f46475d08261 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -381,6 +381,7 @@ static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid) return 1; switch (flv_codecid) { + case FLV_CODECID_X_HEVC: case MKBETAG('h', 'v', 'c', '1'): return vpar->codec_id == AV_CODEC_ID_HEVC; case MKBETAG('a', 'v', '0', '1'): @@ -414,6 +415,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, enum AVCodecID old_codec_id = vstream->codecpar->codec_id; switch (flv_codecid) { + case FLV_CODECID_X_HEVC: case MKBETAG('h', 'v', 'c', '1'): par->codec_id = AV_CODEC_ID_HEVC; vstreami->need_parsing = AVSTREAM_PARSE_HEADERS; @@ -1660,8 +1662,8 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 || - (st->codecpar->codec_id == AV_CODEC_ID_H264 && (!enhanced_flv || type == PacketTypeCodedFrames)) || - (st->codecpar->codec_id == AV_CODEC_ID_HEVC && type == PacketTypeCodedFrames)) { + ((st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC) && + (!enhanced_flv || type == PacketTypeCodedFrames))) { // sign extension int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000; pts = av_sat_add64(dts, cts); diff --git a/libavformat/version.h b/libavformat/version.h index 57d1cb04105ca..4a2f9ab9cb7c5 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ #include "version_major.h" #define LIBAVFORMAT_VERSION_MINOR 9 -#define LIBAVFORMAT_VERSION_MICRO 104 +#define LIBAVFORMAT_VERSION_MICRO 105 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \