diff options
author | Damiano Galassi <damiog@gmail.com> | 2024-02-04 15:14:12 +0000 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-02-04 13:36:25 -0300 |
commit | 112d3618ca47ac7a8243bb16eebdb2c4460d06d1 (patch) | |
tree | 903eb7c47442580a8ba28755583a452536826501 /libavformat/mov.c | |
parent | dda4b25e2d92e3e72f500daef2de143587752126 (diff) | |
download | ffmpeg-112d3618ca47ac7a8243bb16eebdb2c4460d06d1.tar.gz |
avformat/mov: add support for 'amve' ambient viewing environment box
As defined in ISOBMFF (ISO/IEC 14496-12) document.
Co-Authored-By: Cosmin Stejerean <cosmin@cosmin.at>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r-- | libavformat/mov.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c index 5fae777adb..42b0135987 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6039,6 +6039,31 @@ static int mov_read_clli(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_amve(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + MOVStreamContext *sc; + const int illuminance_den = 10000; + const int ambient_den = 50000; + if (c->fc->nb_streams < 1) + return AVERROR_INVALIDDATA; + sc = c->fc->streams[c->fc->nb_streams - 1]->priv_data; + if (atom.size < 6) { + av_log(c->fc, AV_LOG_ERROR, "Empty Ambient Viewing Environment Info box\n"); + return AVERROR_INVALIDDATA; + } + if (sc->ambient){ + av_log(c->fc, AV_LOG_WARNING, "Ignoring duplicate AMVE\n"); + return 0; + } + sc->ambient = av_ambient_viewing_environment_alloc(&sc->ambient_size); + if (!sc->ambient) + return AVERROR(ENOMEM); + sc->ambient->ambient_illuminance = av_make_q(avio_rb32(pb), illuminance_den); + sc->ambient->ambient_light_x = av_make_q(avio_rb16(pb), ambient_den); + sc->ambient->ambient_light_y = av_make_q(avio_rb16(pb), ambient_den); + return 0; +} + static int mov_read_st3d(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -8215,6 +8240,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('i','s','p','e'), mov_read_ispe }, { MKTAG('i','p','r','p'), mov_read_iprp }, { MKTAG('i','i','n','f'), mov_read_iinf }, +{ MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box */ { 0, NULL } }; @@ -8680,6 +8706,7 @@ static void mov_free_stream_context(AVFormatContext *s, AVStream *st) av_freep(&sc->spherical); av_freep(&sc->mastering); av_freep(&sc->coll); + av_freep(&sc->ambient); } static int mov_read_close(AVFormatContext *s) @@ -9072,6 +9099,14 @@ static int mov_read_header(AVFormatContext *s) sc->coll = NULL; } + if (sc->ambient) { + if (!av_packet_side_data_add(&st->codecpar->coded_side_data, &st->codecpar->nb_coded_side_data, + AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT, + (uint8_t *) sc->ambient, sc->ambient_size, 0)) + return AVERROR(ENOMEM); + + sc->ambient = NULL; + } break; } } |