Skip to content

Commit

Permalink
avformat/flvdec: add support for legacy HEVC files
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Jan 10, 2025
1 parent 5cd49e1 commit b76053d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions libavformat/flv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions libavformat/flvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down

0 comments on commit b76053d

Please sign in to comment.