Re: [FFmpeg-devel] [PATCH] avfilter: properly reduce YUV colorspace format lists
On Mon, Mar 25, 2024 at 4:10 PM Niklas Haas wrote: > From: Niklas Haas > > Doing this with REDUCE_FORMATS() instead of swap_color_*() is not only > shorter, but more importantly comes with the benefit of being done > inside a loop, allowing us to correctly propagate complex graphs > involving multiple conversion filters (e.g. -vf scale,zscale). > > The latter family of swapping functions is only used to settle the > best *remaining* entry if no exact match was found, and as such was > never the correct solution to YUV colorspaces, which only care about > exact matches. > I can confirm this fixes the issue I was seeing. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.
On Mon, Mar 25, 2024 at 2:40 PM Niklas Haas wrote: > > ffmpeg -i in.mp4 -vf > > "scale='width=1920:height=1080',zscale='width=1920:height=1080'" out.mp4 > > ffmpeg -i in.jpg -vf "zscale='width=1920:height=1080'" out.jpg > > > > it doesn't need a specific mp4 or jpg file. > > I cannot reproduce any error with your first command line. here's a sample file, and the output I get: https://subler.org/downloads/test.mp4 https://gist.github.com/galad87/a6ddc3318cf20cd2f1ac7d053e1a0786 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.
On Sun, Mar 24, 2024 at 6:53 PM Niklas Haas wrote: > But wait - aren't all filter's lists set to the same reference? Isn't that > the > point of the design? If they share the same format list, they will all > inherit the correct setting (via pick_format). Except for filters like > vf_scale which deliberately use separate format lists, since they can > perform conversion. But even in this case, > swap_color_spaces_on_filters() should ensure that both lists are set to > the same value IFF they support the same color spaces. > > Upon further inspection, it actually appears like the propagation you > propose in this patch is only needed for things which *aren't* subject > to format negotiation, which is why width, height and sample aspect > ratio are propagated here, but things like format or sample rates are not. > > So this patch as written should not be applied, I think. > > > What I meant was that your patch didn't make any difference from the > > existing behavior > > because even if it sets the default AVFilterLink values to AVCOL_SPC_NONE > > and AVCOL_SPC_NONE, > > when it's the time to call ff_filter_config_links(), those two values > have > > already been reset > > to a default unspecified value, so you still get a wrongly configure > graph > > with something like: > > > > Buffer > > Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG > > Scale > > Link: AVCOL_SPC_UNSPECIFIED AVCOL_RANGE_UNSPECIFIED > > Whateverfilter > > Link: AVCOL_SPC_UNSPECIFIED AVCOL_RANGE_UNSPECIFIED > > Buffersink > > > > instead of > > > > Buffer > > Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG > > Scale > > Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG > > Whateverfilter > > Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG > > Buffersink > > Perhaps you can describe this scenario more thoroughly? What filters are > you using downstream of 'scale' here, and does it advertise BT709 as > supported? > It's entirely possible that I am completely wrong, I took a look at avfilter code for the first time just a few days ago. Here's two way to reproduce with the cli something similar to what I am seeing when using the API directly: ffmpeg -i in.mp4 -vf "scale='width=1920:height=1080',zscale='width=1920:height=1080'" out.mp4 ffmpeg -i in.jpg -vf "zscale='width=1920:height=1080'" out.jpg it doesn't need a specific mp4 or jpg file. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.
On Sun, Mar 24, 2024 at 2:14 PM Niklas Haas wrote: > On Sun, 24 Mar 2024 13:49:04 +0100 Damiano Galassi > wrote: > > AVFilterLink colorspace and color_range are first set in > > avfiltergraph.c pick_format(), > > so in ff_filter_config_links() they will never be AVCOL_SPC_NONE or > > AVCOL_SPC_NONE. > > Wait, now I'm confused what this patch even accomplishes then. If it's > already set, what else is there to do? Because pick_format() doesn't set the right values, it doesn't know anything outside the AVFilterLink it's working on. So it sets a value that works for the link incfg and outcfg, but it doesn't propagate values between different links, and 99% of the times sets an unspecified value. What I meant was that your patch didn't make any difference from the existing behavior because even if it sets the default AVFilterLink values to AVCOL_SPC_NONE and AVCOL_SPC_NONE, when it's the time to call ff_filter_config_links(), those two values have already been reset to a default unspecified value, so you still get a wrongly configure graph with something like: Buffer Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG Scale Link: AVCOL_SPC_UNSPECIFIED AVCOL_RANGE_UNSPECIFIED Whateverfilter Link: AVCOL_SPC_UNSPECIFIED AVCOL_RANGE_UNSPECIFIED Buffersink instead of Buffer Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG Scale Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG Whateverfilter Link: AVCOL_SPC_BT709 AVCOL_RANGE_MPEG Buffersink Sorry if I'm not clear enough. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.
There two new fields were never sent down the filter chain, and no filter after the first had colorspace and color_range set, causing breakage in zscale and possible other filters. --- libavfilter/avfilter.c | 4 libavfilter/buffersrc.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 831871de90..66733f5ecf 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -391,6 +391,10 @@ int ff_filter_config_links(AVFilterContext *filter) link->w = inlink->w; if (!link->h) link->h = inlink->h; +if (link->colorspace == AVCOL_SPC_UNSPECIFIED) +link->colorspace = inlink->colorspace; +if (link->color_range == AVCOL_RANGE_UNSPECIFIED) +link->color_range = inlink->color_range; } else if (!link->w || !link->h) { av_log(link->src, AV_LOG_ERROR, "Video source filters must set their output link's " diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index ddcd403785..2760097edf 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -499,6 +499,8 @@ static int config_props(AVFilterLink *link) link->w = c->w; link->h = c->h; link->sample_aspect_ratio = c->pixel_aspect; +link->colorspace = c->color_space; +link->color_range = c->color_range; if (c->hw_frames_ctx) { link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx); -- 2.39.3 (Apple Git-146) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.
On Sat, Mar 23, 2024 at 1:11 PM Niklas Haas wrote: > On Fri, 22 Mar 2024 22:02:39 +0100 Damiano Galassi > wrote: > > There two new fields were never sent down the filter chain, and no > filter after the first had colorspace and color_range set, causing breakage > in zscale and possible other filters. > > --- > > libavfilter/avfilter.c | 4 > > libavfilter/buffersrc.c | 2 ++ > > 2 files changed, 6 insertions(+) > > > > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c > > index 831871de90..153fb700d3 100644 > > --- a/libavfilter/avfilter.c > > +++ b/libavfilter/avfilter.c > > @@ -391,6 +391,10 @@ int ff_filter_config_links(AVFilterContext *filter) > > link->w = inlink->w; > > if (!link->h) > > link->h = inlink->h; > > +if (link->colorspace == AVCOL_SPC_UNSPECIFIED) > > +link->colorspace = inlink->color_range; > > +if (link->color_range == AVCOL_RANGE_UNSPECIFIED) > > +link->color_range = inlink->color_range; > > } else if (!link->w || !link->h) { > > av_log(link->src, AV_LOG_ERROR, > > "Video source filters must set their output > link's " > > diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c > > index ddcd403785..2760097edf 100644 > > --- a/libavfilter/buffersrc.c > > +++ b/libavfilter/buffersrc.c > > @@ -499,6 +499,8 @@ static int config_props(AVFilterLink *link) > > link->w = c->w; > > link->h = c->h; > > link->sample_aspect_ratio = c->pixel_aspect; > > +link->colorspace = c->color_space; > > +link->color_range = c->color_range; > > > > if (c->hw_frames_ctx) { > > link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx); > > LGTM, good catch! > Unfortunately it breaks some tests: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240322210239.68833-1-dam...@gmail.com/ I didn't check yet what's going on there. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.
There two new fields were never sent down the filter chain, and no filter after the first had colorspace and color_range set, causing breakage in zscale and possible other filters. --- libavfilter/avfilter.c | 4 libavfilter/buffersrc.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 831871de90..153fb700d3 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -391,6 +391,10 @@ int ff_filter_config_links(AVFilterContext *filter) link->w = inlink->w; if (!link->h) link->h = inlink->h; +if (link->colorspace == AVCOL_SPC_UNSPECIFIED) +link->colorspace = inlink->color_range; +if (link->color_range == AVCOL_RANGE_UNSPECIFIED) +link->color_range = inlink->color_range; } else if (!link->w || !link->h) { av_log(link->src, AV_LOG_ERROR, "Video source filters must set their output link's " diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index ddcd403785..2760097edf 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -499,6 +499,8 @@ static int config_props(AVFilterLink *link) link->w = c->w; link->h = c->h; link->sample_aspect_ratio = c->pixel_aspect; +link->colorspace = c->color_space; +link->color_range = c->color_range; if (c->hw_frames_ctx) { link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx); -- 2.39.3 (Apple Git-146) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec: add ambient viewing environment packet side data.
Ping ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 2/2] avformat/mov: add support for 'amve' ambient viewing environment box. As defined in ISOBMFF (ISO/IEC 14496-12) document.
--- libavformat/dump.c | 15 +++ libavformat/isom.h | 3 +++ libavformat/mov.c| 36 libavformat/movenc.c | 22 ++ 4 files changed, 76 insertions(+) diff --git a/libavformat/dump.c b/libavformat/dump.c index d31e4c2ec6..88dc9dd89c 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -27,6 +27,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/log.h" #include "libavutil/mastering_display_metadata.h" +#include "libavutil/ambient_viewing_environment.h" #include "libavutil/dovi_meta.h" #include "libavutil/mathematics.h" #include "libavutil/opt.h" @@ -366,6 +367,17 @@ static void dump_content_light_metadata(void *ctx, const AVPacketSideData *sd) metadata->MaxCLL, metadata->MaxFALL); } +static void dump_ambient_viewing_environment_metadata(void *ctx, const AVPacketSideData *sd) +{ +const AVAmbientViewingEnvironment *ambient = +(const AVAmbientViewingEnvironment *)sd->data; +av_log(ctx, AV_LOG_INFO, "Ambient Viewing Environment, " + "ambient_illuminance=%f, ambient_light_x=%f, ambient_light_y=%f", + av_q2d(ambient->ambient_illuminance), + av_q2d(ambient->ambient_light_x), + av_q2d(ambient->ambient_light_y)); +} + static void dump_spherical(void *ctx, const AVCodecParameters *par, const AVPacketSideData *sd) { @@ -497,6 +509,9 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent) av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: "); dump_s12m_timecode(ctx, st, sd); break; +case AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT: +dump_ambient_viewing_environment_metadata(ctx, sd); +break; default: av_log(ctx, AV_LOG_INFO, "unknown side data type %d " "(%"SIZE_SPECIFIER" bytes)", sd->type, sd->size); diff --git a/libavformat/isom.h b/libavformat/isom.h index 4b1cd42f0f..e24dfb3dd0 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -29,6 +29,7 @@ #include "libavutil/encryption_info.h" #include "libavutil/mastering_display_metadata.h" +#include "libavutil/ambient_viewing_environment.h" #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" @@ -249,6 +250,8 @@ typedef struct MOVStreamContext { AVMasteringDisplayMetadata *mastering; AVContentLightMetadata *coll; size_t coll_size; +AVAmbientViewingEnvironment *ambient; +size_t ambient_size; uint32_t format; diff --git a/libavformat/mov.c b/libavformat/mov.c index 444aca5235..726341736e 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6010,6 +6010,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 = 1; +const int ambient_den = 5; +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(>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; @@ -7921,6 +7946,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */ { MKTAG('p','i','t','m'), mov_read_pitm }, { MKTAG('e','v','c','C'), mov_read_glbl }, +{ MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box */ { 0, NULL } }; @@ -8391,6 +8417,7 @@ static int mov_read_close(AVFormatContext *s) av_freep(>spherical); av_freep(>mastering); av_freep(>coll); +av_freep(>ambient); } av_freep(>dv_demux); @@ -8756,6 +8783,15 @@ static int mov_read_header(AVFormatContext *s) sc->coll = NULL; } +if (sc->ambient) { +err = av_stream_add_side_data(st, AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT, + (uint8_t *)sc->ambient, + sc->ambient_size); +if (err < 0) +return err; + +sc->ambient = NULL; +} break; } } diff --git
[FFmpeg-devel] [PATCH v2 1/2] avcodec: add ambient viewing environment packet side data.
--- fftools/ffprobe.c | 3 +++ libavcodec/avpacket.c | 1 + libavcodec/decode.c | 1 + libavcodec/packet.h | 7 +++ 4 files changed, 12 insertions(+) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 1ff76ce809..9f17567897 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2360,6 +2360,9 @@ static void print_pkt_side_data(WriterContext *w, AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data; print_int("max_content", metadata->MaxCLL); print_int("max_average", metadata->MaxFALL); +} else if (sd->type == AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT) { +print_ambient_viewing_environment( +w, (const AVAmbientViewingEnvironment *)sd->data); } else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR10_PLUS) { AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data; print_dynamic_hdr10_plus(w, metadata); diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 5fef65e97a..db9c0c95e8 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -300,6 +300,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type) case AV_PKT_DATA_DOVI_CONF: return "DOVI configuration record"; case AV_PKT_DATA_S12M_TIMECODE: return "SMPTE ST 12-1:2014 timecode"; case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic Metadata (SMPTE 2094-40)"; +case AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT:return "Ambient viewing environment"; } return NULL; } diff --git a/libavcodec/decode.c b/libavcodec/decode.c index a19cca1a7c..68f82e8980 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1408,6 +1408,7 @@ int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, { AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE }, { AV_PKT_DATA_DYNAMIC_HDR10_PLUS, AV_FRAME_DATA_DYNAMIC_HDR_PLUS }, { AV_PKT_DATA_SKIP_SAMPLES, AV_FRAME_DATA_SKIP_SAMPLES }, +{ AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT }, }; frame->pts = pkt->pts; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index f28e7e7011..199baad763 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -299,6 +299,13 @@ enum AVPacketSideDataType { */ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, +/** + * Ambient viewing environment metadata, as defined by H.274.. This metadata + * should be associated with a video stream and contains data in the form + * of the AVAmbientViewingEnvironment struct. + */ +AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT, + /** * The number of side data types. * This is not part of the public API/ABI in the sense that it may -- 2.39.2 (Apple Git-143) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add ambient viewing environment packet side data.
On Tue, Jul 11, 2023 at 6:45 PM Anton Khirnov wrote: > A FATE test would be much appreciated. > Is there some documentation on how to write a FATE test? I've got a small sample (2 bytes) ready, but I am not too sure how to write the test. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/2] avformat/mov: add support for 'amve' ambient viewing environment box. As defined in ISOBMFF (ISO/IEC 14496-12) document.
On Tue, Jul 11, 2023 at 6:53 PM James Almer wrote: > On 7/11/2023 4:41 AM, Damiano Galassi wrote: > > AVDictionaryEntry *encoder; > > @@ -2430,6 +2451,7 @@ static int mov_write_video_tag(AVFormatContext *s, > AVIOContext *pb, MOVMuxContex > > if (track->mode == MODE_MOV || track->mode == MODE_MP4) { > > Is it allowed in mov? > Yes, it’s currently used on movie recorded on recent iOS versions: https://developer.apple.com/documentation/technotes/tn3145-hdr-video-metadata ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/2] avformat/mov: add support for 'amve' ambient viewing environment box. As defined in ISOBMFF (ISO/IEC 14496-12) document.
--- libavformat/dump.c | 15 +++ libavformat/isom.h | 2 ++ libavformat/mov.c| 36 libavformat/movenc.c | 22 ++ 4 files changed, 75 insertions(+) diff --git a/libavformat/dump.c b/libavformat/dump.c index d31e4c2ec6..eca6e733ae 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -27,6 +27,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/log.h" #include "libavutil/mastering_display_metadata.h" +#include "libavutil/ambient_viewing_environment.h" #include "libavutil/dovi_meta.h" #include "libavutil/mathematics.h" #include "libavutil/opt.h" @@ -366,6 +367,17 @@ static void dump_content_light_metadata(void *ctx, const AVPacketSideData *sd) metadata->MaxCLL, metadata->MaxFALL); } +static void dump_ambient_viewing_environment_metadata(void *ctx, const AVPacketSideData *sd) +{ +const AVAmbientViewingEnvironment *ambient = +(const AVAmbientViewingEnvironment *)sd->data; +av_log(ctx, AV_LOG_INFO, "Ambvient Viewing Environment, " + "ambient_illuminance=%f, ambient_light_x=%f, ambient_light_y=%f", + av_q2d(ambient->ambient_illuminance), + av_q2d(ambient->ambient_light_x), + av_q2d(ambient->ambient_light_y)); +} + static void dump_spherical(void *ctx, const AVCodecParameters *par, const AVPacketSideData *sd) { @@ -497,6 +509,9 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent) av_log(ctx, AV_LOG_INFO, "SMPTE ST 12-1:2014: "); dump_s12m_timecode(ctx, st, sd); break; +case AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT: +dump_ambient_viewing_environment_metadata(ctx, sd); +break; default: av_log(ctx, AV_LOG_INFO, "unknown side data type %d " "(%"SIZE_SPECIFIER" bytes)", sd->type, sd->size); diff --git a/libavformat/isom.h b/libavformat/isom.h index 4b1cd42f0f..486836fd62 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -29,6 +29,7 @@ #include "libavutil/encryption_info.h" #include "libavutil/mastering_display_metadata.h" +#include "libavutil/ambient_viewing_environment.h" #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" @@ -249,6 +250,7 @@ typedef struct MOVStreamContext { AVMasteringDisplayMetadata *mastering; AVContentLightMetadata *coll; size_t coll_size; +AVAmbientViewingEnvironment *ambient; uint32_t format; diff --git a/libavformat/mov.c b/libavformat/mov.c index 444aca5235..693baa01a3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6010,6 +6010,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 = 1; +const int ambient_den = 5; +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(NULL); +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; @@ -7921,6 +7946,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */ { MKTAG('p','i','t','m'), mov_read_pitm }, { MKTAG('e','v','c','C'), mov_read_glbl }, +{ MKTAG('a','m','v','e'), mov_read_amve }, /* ambient viewing environment box */ { 0, NULL } }; @@ -8391,6 +8417,7 @@ static int mov_read_close(AVFormatContext *s) av_freep(>spherical); av_freep(>mastering); av_freep(>coll); +av_freep(>ambient); } av_freep(>dv_demux); @@ -8756,6 +8783,15 @@ static int mov_read_header(AVFormatContext *s) sc->coll = NULL; } +if (sc->ambient) { +err = av_stream_add_side_data(st, AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT, + (uint8_t *)sc->ambient, + sizeof(*sc->ambient)); +if (err < 0) +return err; + +sc->ambient = NULL; +} break; } } diff --git a/libavformat/movenc.c
[FFmpeg-devel] [PATCH 1/2] avcodec: add ambient viewing environment packet side data.
--- fftools/ffprobe.c | 3 +++ libavcodec/avpacket.c | 1 + libavcodec/decode.c | 1 + libavcodec/packet.h | 7 +++ 4 files changed, 12 insertions(+) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 1ff76ce809..9f17567897 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2360,6 +2360,9 @@ static void print_pkt_side_data(WriterContext *w, AVContentLightMetadata *metadata = (AVContentLightMetadata *)sd->data; print_int("max_content", metadata->MaxCLL); print_int("max_average", metadata->MaxFALL); +} else if (sd->type == AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT) { +print_ambient_viewing_environment( +w, (const AVAmbientViewingEnvironment *)sd->data); } else if (sd->type == AV_PKT_DATA_DYNAMIC_HDR10_PLUS) { AVDynamicHDRPlus *metadata = (AVDynamicHDRPlus *)sd->data; print_dynamic_hdr10_plus(w, metadata); diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 5fef65e97a..db9c0c95e8 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -300,6 +300,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type) case AV_PKT_DATA_DOVI_CONF: return "DOVI configuration record"; case AV_PKT_DATA_S12M_TIMECODE: return "SMPTE ST 12-1:2014 timecode"; case AV_PKT_DATA_DYNAMIC_HDR10_PLUS: return "HDR10+ Dynamic Metadata (SMPTE 2094-40)"; +case AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT:return "Ambient viewing environment"; } return NULL; } diff --git a/libavcodec/decode.c b/libavcodec/decode.c index a47abeca06..d8ba94d363 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1374,6 +1374,7 @@ int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, { AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE }, { AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE }, { AV_PKT_DATA_DYNAMIC_HDR10_PLUS, AV_FRAME_DATA_DYNAMIC_HDR_PLUS }, +{ AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT }, }; frame->pts = pkt->pts; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index f28e7e7011..199baad763 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -299,6 +299,13 @@ enum AVPacketSideDataType { */ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, +/** + * Ambient viewing environment metadata, as defined by H.274.. This metadata + * should be associated with a video stream and contains data in the form + * of the AVAmbientViewingEnvironment struct. + */ +AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT, + /** * The number of side data types. * This is not part of the public API/ABI in the sense that it may -- 2.39.2 (Apple Git-143) ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".