[新需求]: 获取MP4 stts和ctts

Signed-off-by: Atrotro <wanganzhouhh@163.com>
This commit is contained in:
Atrotro 2024-08-19 17:19:02 +08:00
parent d79e6e01b9
commit f176ab52a4
4 changed files with 75 additions and 0 deletions

View File

@ -145,6 +145,7 @@ config("ffmpeg_config") {
"-DOHOS_NONSTANDARD_BOM",
"-DOHOS_TIMED_META_TRACK",
"-DOHOS_SUBTITLE_DEMUXER",
"-DOHOS_EXPAND_MP4_INFO",
]
if (use_musl) {
cflags += [ "-Wno-bool-operation" ]

View File

@ -940,6 +940,16 @@ const char *av_disposition_to_string(int disposition);
#define AV_PTS_WRAP_ADD_OFFSET 1 ///< add the format specific offset on wrap detection
#define AV_PTS_WRAP_SUB_OFFSET -1 ///< subtract the format specific offset on wrap detection
typedef struct AVMOVStts {
unsigned int count;
unsigned int duration;
} AVMOVStts;
typedef struct AVMOVCtts {
unsigned int count;
int duration;
} AVMOVCtts;
/**
* Stream structure.
* New fields can be added to the end with minor version bumps.
@ -1117,6 +1127,19 @@ typedef struct AVStream {
*
*/
int pts_wrap_bits;
/**
* Array derived from ffmpeg
*
* used to fetch stts_data and ctts_data of mov files
*/
unsigned int stts_count;
AVMOVStts *stts_data;
unsigned int ctts_count;
AVMOVCtts *ctts_data;
int time_scale;
} AVStream;
struct AVCodecParserContext *av_stream_get_parser(const AVStream *s);

View File

@ -1543,6 +1543,10 @@ static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_dict_set(&st->metadata, "language", language, 0);
avio_rb16(pb); /* quality */
#ifdef OHOS_EXPAND_MP4_INFO
st->time_scale = sc->time_scale;
#endif
return 0;
}
@ -3192,6 +3196,19 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc->stts_count = i;
#ifdef OHOS_EXPAND_MP4_INFO
if (sc->stts_count > 0) {
st->stts_count = sc->stts_count;
st->stts_data = malloc(st->stts_count * sizeof(AVMOVStts));
if (st->stts_data != NULL) {
memcpy(st->stts_data, sc->stts_data, st->stts_count * sizeof(AVMOVStts));
} else {
av_log(c->fc, AV_LOG_WARNING, "st->stts_data malloc failed\n");
st->stts_count = 0;
}
}
#endif
if (duration > 0 &&
duration <= INT64_MAX - sc->duration_for_fps &&
total_sample_count <= INT_MAX - sc->nb_frames_for_fps) {
@ -3312,6 +3329,19 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc->ctts_count = ctts_count;
#ifdef OHOS_EXPAND_MP4_INFO
if (sc->ctts_count > 0) {
st->ctts_count = sc->ctts_count;
st->ctts_data = malloc(st->ctts_count * sizeof(AVMOVCtts));
if (st->ctts_data != NULL) {
memcpy(st->ctts_data, sc->ctts_data, st->ctts_count * sizeof(AVMOVCtts));
} else {
av_log(c->fc, AV_LOG_WARNING, "st->ctts_data malloc failed\n");
st->ctts_count = 0;
}
}
#endif
if (pb->eof_reached) {
av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted CTTS atom\n");
return AVERROR_EOF;
@ -8433,6 +8463,18 @@ static int mov_read_close(AVFormatContext *s)
AVStream *st = s->streams[i];
MOVStreamContext *sc = st->priv_data;
#ifdef OHOS_EXPAND_MP4_INFO
if (st->stts_data != NULL) {
free(st->stts_data);
st->stts_data = NULL;
}
if (st->ctts_data != NULL) {
free(st->ctts_data);
st->ctts_data = NULL;
}
#endif
if (!sc)
continue;

View File

@ -295,6 +295,15 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
st->start_time = AV_NOPTS_VALUE;
st->duration = AV_NOPTS_VALUE;
sti->first_dts = AV_NOPTS_VALUE;
#ifdef OHOS_EXPAND_MP4_INFO
st->stts_count = 0;
st->stts_data = NULL;
st->ctts_count = 0;
st->ctts_data = NULL;
st->time_scale = 0;
#endif
sti->probe_packets = s->max_probe_packets;
sti->pts_wrap_reference = AV_NOPTS_VALUE;
sti->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;