Re: [FFmpeg-devel] [PATCH v2 0/3] Properly decode ogg metadata in ogg/flac chained bitstreams
Le mar. 4 févr. 2025 à 06:15, Romain Beauxis a écrit : > > This is a series of 3 patches to allow proper decoding of ogg metadata > in chained ogg/flac streams. > > ogg/flac streams are pretty important because there are perhaps the only > combination of lossless audio codec and open-source container that > allows for proper transmittion of lossless audio data accross systems > such as Icecast, browser media tags and more. > > In the context of long-running audio streams, the ogg bitstream specs[1] > have historically been very badly implemented. For each new track and > each new metadata, the specs require the logical bitstream to come to a > full EOF and then start with a full new logical stream. > > These specs have often been confused with a gobal EOF by most > implementations. > > Furtunately, FFmpeg is a little better at that in that it is capable to > parsing chained logical ogg bitstreams and properly output either > encoded ogg packets or decoded audio. > > Chained bitstreams with more than one underlying type of content > (audio+video, etc) is not yet supported though this is a much less needed > feature. > > The purpose of these changes is to also allow proper decoding of > metadata associated with subsequent streams in chained ogg/flac > bitstream. > > This is done by simply intercepting ogg packets with comments in the > flac decoded, parsing the comment block and retaining it to be attached > with the next decoded audio frame. > > Along with the changes is a new FATE test validating the implementation. > > This solution keeps a proper separation of concerns: ogg packets are > sill output by the demuxer (as shown in the test) but consumer of decoded > data see decoded metadata in the decoded frames. > > Only drawback is that this adds a dependency on libavformat to > libavcodec. > > I have looked at moving the vorbis metadata parsing to libavutil but a > lot of definitions and utilities related to metadata are in fact located > in libavformat so perhaps this makes sense. Of course, it was only after posting all this that I figured out how to properly do this. About to send an updated patch set sorry for the noise. -- Romain > Follow-up work not addressed in this series of patch: > * Ensure valid PTS in decoded frames of subsequent streams? > * Generalize this approach to other chained ogg codec. > > Thanks, > -- Romain > > Romain Beauxis (3): > libavformat/oggdec: Allow first parameter in ff_vorbis_comment to be a > generic AVClass struct > libavcodec/flacdec: parse vorbis metadata from ogg packets, add them > to the next decoded frame. > Add stream dump test with test for ogg/flac. > > libavcodec/flacdec.c | 12 +- > libavformat/oggdec.h | 5 +- > libavformat/oggparsevorbis.c | 4 +- > tests/Makefile| 2 + > tests/api/Makefile| 2 +- > tests/api/api-dump-stream-meta-test.c | 169 ++ > tests/fate/api.mak| 5 + > tests/fate/ogg-flac.mak | 11 ++ > 8 files changed, 205 insertions(+), 5 deletions(-) > create mode 100644 tests/api/api-dump-stream-meta-test.c > create mode 100644 tests/fate/ogg-flac.mak > > -- > 2.39.5 (Apple Git-154) > ___ 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] [FFmpeg-cvslog] avcodec/nvenc: Enable recovery point SEI for intra refresh mode
On Mon, 3 Feb 2025, Zhao Zhili wrote: ffmpeg | branch: master | Zhao Zhili | Thu Jan 23 22:17:29 2025 +0800| [1438f6997db70945173f01aea1768e3b27ce2679] | committer: Zhao Zhili avcodec/nvenc: Enable recovery point SEI for intra refresh mode Otherwise all frames can be dropped after seek without the output_corrupt/showall flags. Signed-off-by: Zhao Zhili Reviewed-by: Timo Rothenpieler http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1438f6997db70945173f01aea1768e3b27ce2679 --- libavcodec/nvenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c52e47734e..c359c2bc8a 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1281,6 +1281,7 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) h264->intraRefreshPeriod = cc->gopLength; h264->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; +h264->outputRecoveryPointSEI = 1; This change breaks building with older versions of nv-codec-headers installed. // Martin ___ 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 v3 1/2] Parse and process ogg/flac comments in chained bitstreams.
libavformat/oggparseflac: Parse ogg/flac comments in new ogg packets, add them to ogg stream new_metadata. libavcodec/flacdec: Process AV_PKT_DATA_METADATA_UPDATE on new packets, add them as new metadata on the new decoded audio frame. --- libavcodec/flacdec.c | 20 +++- libavformat/oggparseflac.c | 28 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index ad921a1bd1..337f3e1702 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -68,6 +68,8 @@ typedef struct FLACContext { unsigned int decoded_buffer_size_33bps; int buggy_lpc; ///< use workaround for old lavc encoded files +AVDictionary *pending_metadata; + FLACDSPContext dsp; } FLACContext; @@ -718,6 +720,8 @@ static int flac_decode_frame(AVCodecContext *avctx, AVFrame *frame, int buf_size = avpkt->size; FLACContext *s = avctx->priv_data; int bytes_read = 0; +const uint8_t *side_metadata; +size_t size; int ret; *got_frame_ptr = 0; @@ -728,7 +732,14 @@ static int flac_decode_frame(AVCodecContext *avctx, AVFrame *frame, } if (buf_size > 0 && (*buf & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) { -av_log(s->avctx, AV_LOG_DEBUG, "skipping vorbis comment\n"); +/* New metadata */ +side_metadata = av_packet_get_side_data(avpkt, AV_PKT_DATA_METADATA_UPDATE, &size); +if (side_metadata) { +av_dict_free(&s->pending_metadata); +ret = av_packet_unpack_dictionary(side_metadata, size, &s->pending_metadata); +if (ret < 0) +return ret; +} return buf_size; } @@ -788,6 +799,12 @@ static int flac_decode_frame(AVCodecContext *avctx, AVFrame *frame, buf_size - bytes_read, buf_size); } + +if (s->pending_metadata) { +av_dict_copy(&frame->metadata, s->pending_metadata, AV_DICT_APPEND); +av_dict_free(&s->pending_metadata); +} + *got_frame_ptr = 1; return bytes_read; @@ -799,6 +816,7 @@ static av_cold int flac_decode_close(AVCodecContext *avctx) av_freep(&s->decoded_buffer); av_freep(&s->decoded_buffer_33bps); +av_dict_free(&s->pending_metadata); return 0; } diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index f25ed9cc15..3810806112 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -78,6 +78,32 @@ flac_header (AVFormatContext * s, int idx) return 1; } +static int +flac_packet (AVFormatContext * s, int idx) +{ +struct ogg *ogg = s->priv_data; +struct ogg_stream *os = ogg->streams + idx; +AVDictionary *new_metadata = NULL; +int ret; + +if (os->psize > 0 && os->buf[os->pstart] && +(os->buf[os->pstart] & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) { +ret = ff_vorbis_comment(s, &new_metadata, os->buf + os->pstart + 4, +os->psize - 4, 1); + +if (ret < 0) +return ret; + +os->new_metadata = av_packet_pack_dictionary(new_metadata, &os->new_metadata_size); +av_dict_free(&new_metadata); + +if (!os->new_metadata) +return AVERROR(ENOMEM); +} + +return 0; +} + static int old_flac_header (AVFormatContext * s, int idx) { @@ -130,6 +156,7 @@ const struct ogg_codec ff_flac_codec = { .magic = "\177FLAC", .magicsize = 5, .header = flac_header, +.packet = flac_packet, .nb_header = 2, }; @@ -137,5 +164,6 @@ const struct ogg_codec ff_old_flac_codec = { .magic = "fLaC", .magicsize = 4, .header = old_flac_header, +.packet = flac_packet, .nb_header = 0, }; -- 2.39.5 (Apple Git-154) ___ 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 v3 0/2] Properly decode ogg metadata in ogg/flac chained bitstreams
This is a series of 2 patches to allow proper decoding of ogg metadata in chained ogg/flac streams. ogg/flac streams are pretty important because there are perhaps the only combination of lossless audio codec and open-source container that allows for proper transmittion of lossless audio data accross systems such as Icecast, browser media tags and more. In the context of long-running audio streams, the ogg bitstream specs[1] have historically been very badly implemented. For each new track and/or each new metadata, the specs require the logical bitstream to come to a full EOS and then start with a full new logical stream. These specs have often been confused with a gobal EOS by most implementations. Furtunately, FFmpeg is a little better at that in that it is able to parsed subsequent chained logical ogg bitstreams and properly output either encoded ogg packets or decoded audio. Current limitations with chained ogg streams in FFmpeg include: * No adjustment underlying PTS or DTS * Chained bitstreams with more than one underlying type of content (audio+video, etc) is not yet supported though this is a much less needed feature. The purpose of the changes in this patch series is to also allow proper decoding of metadata associated with subsequent streams in chained ogg/flac bitstream. This is done by intercepting ogg packets with comments in the ogg flac demuxer, parsing the comment block and attaching it as packed AV_PKT_DATA_METADATA_UPDATE side-data. The new metadata can then be unpacked in the flac decoder and properly added to the first decoded audio frame after the comment packet. Along with the changes is a new FATE test validating the implementation. This solution keeps a proper separation of concerns: ogg packets are sill output by the demuxer (as shown in the test) but consumer of decoded data see decoded metadata in the decoded frames. It is worth noting that is using a mechanism specific to ogg stream that seemed to only have been used for vorbis streams so far. Follow-up work not addressed in this series of patch: * Ensure valid PTS in decoded frames of subsequent streams? * Generalize this approach to other chained ogg codec. Thanks, -- Romain [1]: https://xiph.org/ogg/doc/framing.html Romain Beauxis (2): libavformat/oggparseflac: Parse ogg/flac comments in new ogg packets, add them to ogg stream new_metadata. Add stream dump test with test for ogg/flac. libavcodec/flacdec.c | 20 ++- libavformat/oggparseflac.c| 28 + tests/Makefile| 2 + tests/api/Makefile| 2 +- tests/api/api-dump-stream-meta-test.c | 169 ++ tests/fate/api.mak| 5 + tests/fate/ogg-flac.mak | 11 ++ 7 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 tests/api/api-dump-stream-meta-test.c create mode 100644 tests/fate/ogg-flac.mak -- 2.39.5 (Apple Git-154) ___ 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 v3 2/2] Add stream dump test with test for ogg/flac.
This is the new FATE test. Test samples are available here: https://www.dropbox.com/scl/fo/fxt2edwkyj2mjc9qubku5/AICHxJyxMMAK8MIJqWLcvk4?rlkey=mlt12lsu741ejukz0p5qtn9rq&dl=0 Output prior to the changes is: Stream ID: 0, codec name: flac, metadata: encoder=Lavc61.19.100 flac:title=First Stream Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: Output after the changes: Stream ID: 0, codec name: flac, metadata: encoder=Lavc61.19.100 flac:title=First Stream Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: encoder=Lavc61.19.100 flac:title=Second Stream Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: --- tests/Makefile| 2 + tests/api/Makefile| 2 +- tests/api/api-dump-stream-meta-test.c | 169 ++ tests/fate/api.mak| 5 + tests/fate/ogg-flac.mak | 11 ++ 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/api/api-dump-stream-meta-test.c create mode 100644 tests/fate/ogg-flac.mak diff --git a/tests/Makefile b/tests/Makefile index f9f5fc07f3..66e5189e6d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -219,6 +219,7 @@ include $(SRC_PATH)/tests/fate/mpeg4.mak include $(SRC_PATH)/tests/fate/mpegps.mak include $(SRC_PATH)/tests/fate/mpegts.mak include $(SRC_PATH)/tests/fate/mxf.mak +include $(SRC_PATH)/tests/fate/ogg-flac.mak include $(SRC_PATH)/tests/fate/oma.mak include $(SRC_PATH)/tests/fate/opus.mak include $(SRC_PATH)/tests/fate/pcm.mak @@ -277,6 +278,7 @@ $(FATE_FFPROBE) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FF $(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF) $(FATE_SAMPLES_DUMP_DATA) $(FATE_SAMPLES_DUMP_DATA-yes): tools/venc_data_dump$(EXESUF) $(FATE_SAMPLES_SCALE_SLICE): tools/scale_slice_test$(EXESUF) +$(FATE_SAMPLES_DUMP_STREAM_META): tests/api/api-dump-stream-meta-test$(EXESUF) ifdef SAMPLES FATE += $(FATE_EXTERN) diff --git a/tests/api/Makefile b/tests/api/Makefile index c96e636756..a2cb06a729 100644 --- a/tests/api/Makefile +++ b/tests/api/Makefile @@ -1,7 +1,7 @@ APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264-slice -APITESTPROGS-yes += api-seek +APITESTPROGS-yes += api-seek api-dump-stream-meta APITESTPROGS-$(call DEMDEC, H263, H263) += api-band APITESTPROGS-$(HAVE_THREADS) += api-threadmessage APITESTPROGS += $(APITESTPROGS-yes) diff --git a/tests/api/api-dump-stream-meta-test.c b/tests/api/api-dump-stream-meta-test.c new file mode 100644 index 00..4ffdfe8213 --- /dev/null +++ b/tests/api/api-dump-stream-meta-test.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2025 Romain Beauxis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Dump stream metadata + */ + +#include "libavcodec/avcodec.h" +#include "libavformat/avformat.h" +#include "libavutil/timestamp.h" + +static int dump_stream_meta(const char *input_filename) +{ +const AVCodec *codec = NULL; +AVPacket *pkt = NULL; +AVFrame *fr = NULL; +AVFormatContext *fmt_ctx = NULL; +AVCodecContext *ctx = NULL; +AVCodecParameters *origin_par = NULL; +int audio_stream; +int result; +char
[FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration. Signed-off-by: Jack Lau --- doc/examples/transcoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 013f89fc7d..847bdb7e1a 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -172,7 +172,7 @@ static int open_output_file(const char *filename) else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ -enc_ctx->time_base = av_inv_q(dec_ctx->framerate); +enc_ctx->time_base = dec_ctx->time_base; } else { enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); @@ -180,7 +180,7 @@ static int open_output_file(const char *filename) return ret; /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; -enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; +enc_ctx->time_base = dec_ctx->time_base; } if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) -- 2.48.1 ___ 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 0/3] avcodec/hevc: Add alpha video decoding support
On 03.02.2025 18:38, Zhao Zhili wrote: Hi Timo, You have added encoding support for hevc alpha video, may I invite you to help review the decoding support? I'm a bit busy with work at the moment, but I'll get to it. Don't have the most experience with that code, but I can at least give it a look and a 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".
[FFmpeg-devel] [PATCHv3] examples/transcoding: Fix time_base handling
--- Begin Message --- From bfd5500a5448ad468d32994816e8a55c0d4a2428 Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Tue, 4 Feb 2025 21:39:20 +0800 Subject: [PATCH] examples/transcoding: Fix time_base handling X-Unsent: 1 To: ffmpeg-devel@ffmpeg.org The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration. Signed-off-by: JackLau1222 <2366536...@qq.com> --- doc/examples/transcoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 013f89fc7d..847bdb7e1a 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -172,7 +172,7 @@ static int open_output_file(const char *filename) else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ -enc_ctx->time_base = av_inv_q(dec_ctx->framerate); +enc_ctx->time_base = dec_ctx->time_base; } else { enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); @@ -180,7 +180,7 @@ static int open_output_file(const char *filename) return ret; /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; -enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; +enc_ctx->time_base = dec_ctx->time_base; } if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) -- 2.45.2 --- End Message --- ___ 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] examples/transcoding: Fix time_base handling
fix-time-base-handling.patch Description: Binary data ___ 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] examples/transcoding: Fix time_base handling
From bfd5500a5448ad468d32994816e8a55c0d4a2428 Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Tue, 4 Feb 2025 21:39:20 +0800 Subject: [PATCH] examples/transcoding: Fix time_base handling The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration. --- doc/examples/transcoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 013f89fc7d..847bdb7e1a 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -172,7 +172,7 @@ static int open_output_file(const char *filename) else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ -enc_ctx->time_base = av_inv_q(dec_ctx->framerate); +enc_ctx->time_base = dec_ctx->time_base; AVCodecContext.time_base is not used for decoding. } else { enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); @@ -180,7 +180,7 @@ static int open_output_file(const char *filename) return ret; /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; -enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; +enc_ctx->time_base = dec_ctx->time_base; } if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) -- 2.45.2 OpenPGP_signature.asc Description: OpenPGP digital signature ___ 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] examples/transcoding: Fix time_base handling
> > AVCodecContext.time_base is not used for decoding. Thank you for your reply. I understand that time_base is not used during decoding, but the transcoding code calls av_packet_rescale_ts twice, once before decoding and once after encoding, as shown below: 540 if (filter_ctx[stream_index].filter_graph) { 541 StreamContext *stream = &stream_ctx[stream_index]; 542 543 av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n"); 544 545 av_packet_rescale_ts(packet, 546 ifmt_ctx->streams[stream_index]->time_base, 547 stream->dec_ctx->time_base); 548 ret = avcodec_send_packet(stream->dec_ctx, packet); 448 /* prepare packet for muxing */ 449 enc_pkt->stream_index = stream_index; 450 av_packet_rescale_ts(enc_pkt, 451 stream->enc_ctx->time_base, 452 ofmt_ctx->streams[stream_index]->time_base); 453 454 av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n"); 455 /* mux encoded frame */ 456 ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can lead to incorrect packet duration, which in turn causes issues with the output file's duration. ___ 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] examples/transcoding: Fix time_base handling
> > AVCodecContext.time_base is not used for decoding. Thank you for your reply. I understand that time_base is not used during decoding, but the transcoding code calls av_packet_rescale_ts twice, once before decoding and once after encoding, as shown below: 540 if (filter_ctx[stream_index].filter_graph) { 541 StreamContext *stream = &stream_ctx[stream_index]; 542 543 av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n"); 544 545 av_packet_rescale_ts(packet, 546 ifmt_ctx->streams[stream_index]->time_base, 547 stream->dec_ctx->time_base); 548 ret = avcodec_send_packet(stream->dec_ctx, packet); 448 /* prepare packet for muxing */ 449 enc_pkt->stream_index = stream_index; 450 av_packet_rescale_ts(enc_pkt, 451 stream->enc_ctx->time_base, 452 ofmt_ctx->streams[stream_index]->time_base); 453 454 av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n"); 455 /* mux encoded frame */ 456 ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can lead to incorrect packet duration, which in turn causes issues with the output file's duration. ___ 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] Replace broken Web IRC link
Thank you Timo for removing the flag. Now users should be able to join correctly. Patch LGTM. I don't have access to merge to web. ___ 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] Replace broken Web IRC link
On 2025-02-04 11:58 pm, Marth64 wrote: Thank you Timo for removing the flag. Now users should be able to join correctly. Patch LGTM. I don't have access to merge to web. Will push tomorrow morning, if no one else has. Regards, Gyan ___ 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 0/3] Patch to create a circular delogo area
Dear list, sorry for the previous posting. I noticed the lines got mangled. So here is a new try to get the patches right. Old text: I made a patch for the delogo filter. With this I can create a circular or elliptic zone to apply the delogo algorithm. The borders are defined with x,y,w,h parameter just like the rectangular area definition. To become circular I added an additional parameter 'r'=0/1 defaulting to '0' i.e. rectangular area definition. I added a large comment to the function body describing the calculation of the ellipse. Hope you don't mind. The patch has been tested with 'make fate-rsync fate' and applies clean to the master branch, commit 957eb2323a924aa0b148927889eae581185c367b . Please have a look. best regards Jörg Jörg Habenicht (3): avfilter/delogo: add parameter to switch on circular delogo avfilter/delogo: added circular delogo algorithm description avfilter/delogo: added the circular delogo algorithm libavfilter/vf_delogo.c | 59 + 1 file changed, 54 insertions(+), 5 deletions(-) -- 2.45.3 ___ 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 3/3] avfilter/delogo: added the circular delogo algorithm
Use the corrected x,y,w,h values with boundaries and clipping to calculate the points inside the ellipse. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 28 ++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index ea741e2700..fcf14d3e4f 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -90,6 +90,7 @@ static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void * * @param logo_w width of the logo * @param logo_h height of the logo * @param band the size of the band around the processed area + * @param round whether delogo is applied to a rectangular or round area * @param show show a rectangle around the processed area, useful for * parameters tweaking * @param direct if non-zero perform in-place processing @@ -98,7 +99,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize, int w, int h, AVRational sar, int logo_x, int logo_y, int logo_w, int logo_h, - unsigned int band, int show, int direct) + unsigned int band, int round, int show, int direct) { /* Round area algorithm description: * @@ -132,6 +133,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, unsigned int left_sample, right_sample; int xclipl, xclipr, yclipt, yclipb; int logo_x1, logo_x2, logo_y1, logo_y2; +double a, b, logo_w2, logo_h2; xclipl = FFMAX(-logo_x, 0); xclipr = FFMAX(logo_x+logo_w-w, 0); @@ -147,6 +149,13 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, topright = src+logo_y1 * src_linesize+logo_x2; botleft = src+logo_y2 * src_linesize+logo_x1; +if (round) { +logo_w2 = (logo_x2 - logo_x1) / 2.0; +logo_h2 = (logo_y2 - logo_y1) / 2.0; +a = logo_x1 + logo_w2; +b = logo_y1 + logo_h2; +} + if (!direct) av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h); @@ -171,6 +180,21 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, continue; } +if (round) { +double xf, yf; +/* Evaluate if x,y is inside the ellipse, else continue + * This is the calculation + * (px - a)^2 / (logo_w / 2)^2 + + * (py - b)^2 / (logo_h / 2)^2 <= 1 + */ +xf = ((double)x - a) / logo_w2; +xf *= xf; +yf = ((double)y - b) / logo_h2; +yf *= yf; +if (xf + yf > 1.0) +continue; +} + /* Weighted interpolation based on relative distances, taking SAR into account */ weightl = (uint64_t) (logo_x2-x) * (y-logo_y1) * (logo_y2-y) * sar.den; weightr = (uint64_t)(x-logo_x1) * (y-logo_y1) * (logo_y2-y) * sar.den; @@ -388,7 +412,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AV_CEIL_RSHIFT(s->w + (s->x & ((1y & ((1 >FFMIN(hsub, vsub), - s->show, direct); + s->round, s->show, direct); } if (!direct) -- 2.45.3 ___ 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/3] avfilter/delogo: added circular delogo algorithm description
Added a description of the elliptic formed delogo algorithm. Placed it outside the doxygen function comment. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 24 1 file changed, 24 insertions(+) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 7641c3b483..ea741e2700 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -100,6 +100,30 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, int logo_x, int logo_y, int logo_w, int logo_h, unsigned int band, int show, int direct) { +/* Round area algorithm description: + * + * logo_x, logo_y, logo_w and logo_h define the boundaries of the + * ellipse. In the ellipse formula x^2 / a^2 + y^2 / b^2 = 1 let + * a = logo_w/2, b = logo_h/2 and the center of the ellipse + * (0,0) = (logo_x + a, logo_y + b). + * Let the picture dimensions (px,py,pw,ph) := function API(x,y,w,h). + * A point of the picture is transformed into the ellipse coordinates + * by using x = px - (logo_x + a), y = py - (logo_y +b). + * + * A point is inside the ellipse if x^2 / a^2 + y^2 / b^2 <= 1 + * <=> (x + logo_x)^2 / (logo_w / 2)^2 + * + (y + logo_y)^2 / (logo_h / 2)^2 <= 1 + * <=> (px - logo_x - a + logo_x)^2 / (logo_w / 2)^2 + * + (py - logo_y - b + logo_y)^2 / (logo_h / 2)^2 <= 1 + * <=> (px - a)^2 / (logo_w / 2)^2 + * + (py - b)^2 / (logo_h / 2)^2 <= 1 + * <=> ((px - a) / (logo_w / 2))^2 + * + ((py - b) / (logo_h / 2))^2 <= 1 + * + * px is later defined x, py defined y. + * logo_w is later defined logo_w2, logo_h defined logo_h2. + */ + int x, y; uint64_t interp, weightl, weightr, weightt, weightb, weight; uint8_t *xdst, *xsrc; -- 2.45.3 ___ 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 1/3] avfilter/delogo: add parameter to switch on circular delogo
Add a parameter (boolean) r to switch the area from rectangular (r=0) to circular(r=1) delogo. Signed-off-by: Jörg Habenicht --- libavfilter/vf_delogo.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index bfbf8e6f4c..7641c3b483 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -195,7 +195,7 @@ static void apply_delogo(uint8_t *dst, int dst_linesize, typedef struct DelogoContext { const AVClass *class; -int x, y, w, h, band, show; +int x, y, w, h, band, show, round; char *x_expr, *y_expr, *w_expr, *h_expr; AVExpr *x_pexpr, *y_pexpr, *w_pexpr, *h_pexpr; double var_values[VAR_VARS_NB]; @@ -209,6 +209,7 @@ static const AVOption delogo_options[]= { { "y","set logo y position", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str = "-1" }, 0, 0, FLAGS }, { "w","set logo width",OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "-1" }, 0, 0, FLAGS }, { "h","set logo height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "-1" }, 0, 0, FLAGS }, +{ "r","logo is round/ellipse", OFFSET(round), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { "show", "show delogo area", OFFSET(show), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { NULL } }; @@ -259,8 +260,8 @@ static av_cold int init(AVFilterContext *ctx) s->band = 1; -av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", - s->x, s->y, s->w, s->h, s->band, s->show); +av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d round:%d show:%d\n", + s->x, s->y, s->w, s->h, s->band, s->round, s->show); s->w += s->band*2; s->h += s->band*2; -- 2.45.3 ___ 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/xpsnr: avoid division by zero
On 2025-02-02 11:27 pm, Gyan Doshi wrote: The ref input may have its frame rate unset, which would then lead to SIGFPE. So fall back to the main link frame rate. If that too is unset, default to 0. Related to #11428 Plan to push tomorrow. Regards, Gyan --- libavfilter/vf_xpsnr.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_xpsnr.c b/libavfilter/vf_xpsnr.c index 1b2c2a7c2c..3097db0878 100644 --- a/libavfilter/vf_xpsnr.c +++ b/libavfilter/vf_xpsnr.c @@ -552,6 +552,7 @@ static int config_input_ref(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; XPSNRContext *const s = ctx->priv; FilterLink *il = ff_filter_link(inlink); +FilterLink *ml = ff_filter_link(ctx->inputs[0]); if ((ctx->inputs[0]->w != ctx->inputs[1]->w) || (ctx->inputs[0]->h != ctx->inputs[1]->h)) { @@ -568,7 +569,9 @@ static int config_input_ref(AVFilterLink *inlink) s->max_error_64 = (1 << s->depth) - 1; /* conventional limit */ s->max_error_64 *= s->max_error_64; -s->frame_rate = il->frame_rate.num / il->frame_rate.den; +// Avoid division by zero +s->frame_rate = il->frame_rate.den ? (il->frame_rate.num / il->frame_rate.den) : +ml->frame_rate.den ? (ml->frame_rate.num / ml->frame_rate.den) : 0; s->num_comps = (desc->nb_components > 3 ? 3 : desc->nb_components); ___ 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] examples/transcoding: Fix time_base handling
The `dec_ctx->time_base` was incorrectly default set by avcodec_open2(), while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch corrects the issue by adjusting the `enc_ctx->time_base` calculation to account for `ticks_per_frame`, ensuring that the time base is consistent between the decoder and encoder contexts. --- Begin Message --- From 6a02fbaf6c6068040640ff105ad70115fb81b5d2 Mon Sep 17 00:00:00 2001 From: Jack Lau Date: Tue, 4 Feb 2025 21:39:20 +0800 Subject: [PATCH] examples/transcoding: Fix time_base handling X-Unsent: 1 To: ffmpeg-devel@ffmpeg.org The `dec_ctx->time_base` was incorrectly default set by avcodec_open2(), while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch corrects the issue by adjusting the `enc_ctx->time_base` calculation to account for `ticks_per_frame`, ensuring that the time base is consistent between the decoder and encoder contexts. Signed-off-by: Jack Lau --- doc/examples/transcoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 013f89fc7d..8cc1991267 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -172,7 +172,7 @@ static int open_output_file(const char *filename) else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ -enc_ctx->time_base = av_inv_q(dec_ctx->framerate); +enc_ctx->time_base = av_inv_q(av_mul_q(dec_ctx->framerate, (AVRational){dec_ctx->ticks_per_frame, 1})); } else { enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); @@ -180,7 +180,7 @@ static int open_output_file(const char *filename) return ret; /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; -enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; +enc_ctx->time_base = (AVRational){1,dec_ctx->sample_rate}; } if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) -- 2.48.1 --- End Message --- ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
On Tue, 4 Feb 2025, James Almer wrote: Thanks, this does indeed seem to fix compilation in my setup. Applied. Why don't don't just update the headers? Is it a system package provided by your distro? I guess I could, but as long as I don't have a pressing need to, just staying with the current version is easiest. Do the headers major version need to match the installed drivers/proprietary nvidia libs? (In my setup, the drivers/nvidia libs are distributed entirely separately - touching that bit is a lot of effort.) // Martin ___ 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] avformat/mov: Store trak > udta metadata on each stream
Hi Rémi, On Wed, 15 Jan 2025, Rémi Bernon wrote: Some files keep extra metadata such as 'name' fields within udta, and it is useful for Wine to access them with the "export_all" option so they can then be exposed to Windows applications. Signed-off-by: Rémi Bernon --- libavformat/mov.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index c016ce8e41..f067ca4905 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -354,6 +354,12 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom) int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL; int raw = 0; int num = 0; +AVDictionary **metadata; + +if (c->trak_index >= 0 && c->trak_index < c->fc->nb_streams) +metadata = &c->fc->streams[c->trak_index]->metadata; +else +metadata = &c->fc->metadata; switch (atom.type) { case MKTAG( '@','P','R','M'): key = "premiere_version"; raw = 1; break; @@ -572,10 +578,10 @@ retry: str[str_size] = 0; } c->fc->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; -av_dict_set(&c->fc->metadata, key, str, 0); +av_dict_set(metadata, key, str, 0); if (*language && strcmp(language, "und")) { snprintf(key2, sizeof(key2), "%s-%s", key, language); -av_dict_set(&c->fc->metadata, key2, str, 0); +av_dict_set(metadata, key2, str, 0); } if (!strcmp(key, "encoder")) { int major, minor, micro; -- 2.45.2 So instead of storing metadata on the demuxer level, it is stored on the stream level, to avoid clobbering metadata if multiple streams provide metadata with the same name. I guess that sounds reasonable. However, wouldn't this be a notable change for consumers that currently expect to see such metadata on the demuxer level? I guess we don't have any firm guarantees about such things, and if the metadata specifically is for a track, it is the more correct thing to do anyway. I don't have all the usual cases around mov/mp4 metadata fresh in mind though. CCing James to hear his opinion on this. // Martin ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
On 2/4/2025 10:52 AM, Martin Storsjö wrote: On Tue, 4 Feb 2025, James Almer wrote: Thanks, this does indeed seem to fix compilation in my setup. Applied. Why don't don't just update the headers? Is it a system package provided by your distro? I guess I could, but as long as I don't have a pressing need to, just staying with the current version is easiest. Do the headers major version need to match the installed drivers/proprietary nvidia libs? (In my setup, the drivers/nvidia libs are distributed entirely separately - touching that bit is a lot of effort.) No, they don't need to match afaik. The headers are meant to be ABI backwards compatible (hence all the reserved fields). I was just wondering if the headers were provided by your distro or not (Given they are compile time deps and not runtime), and looking now at the package lists in some, i see they are, so disregard my question. OpenPGP_signature.asc Description: OpenPGP digital signature ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
On Tue, 4 Feb 2025, James Almer wrote: No, they don't need to match afaik. The headers are meant to be ABI backwards compatible (hence all the reserved fields). Right, then there's probably less concern about updating them. I was just wondering if the headers were provided by your distro or not (Given they are compile time deps and not runtime), and looking now at the package lists in some, i see they are, so disregard my question. In my case I actually don't use distro provided headers, I use a manually installed set, but I don't really touch it unless I need to. // Martin ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
> On Feb 4, 2025, at 22:00, Martin Storsjö wrote: > > On Tue, 4 Feb 2025, James Almer wrote: > >> No, they don't need to match afaik. The headers are meant to be ABI >> backwards compatible (hence all the reserved fields). > > Right, then there's probably less concern about updating them. > >> I was just wondering if the headers were provided by your distro or not >> (Given they are compile time deps and not runtime), and looking now at the >> package lists in some, i see they are, so disregard my question. > > In my case I actually don't use distro provided headers, I use a manually > installed set, but I don't really touch it unless I need to. How about put a copy of nv-codec-headers inside ffmpeg source tree? So it can always up to date and easy to handle the dependency (I encountered some trouble on Unix path vs Window path with ffnvcodec.pc in msys environment). What are the disadvantages of this method? > > // Martin > > ___ > 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 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] examples/transcoding: Fix time_base handling
The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration. Signed-off-by: Jack Lau --- doc/examples/transcoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 013f89fc7d..847bdb7e1a 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -172,7 +172,7 @@ static int open_output_file(const char *filename) else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ -enc_ctx->time_base = av_inv_q(dec_ctx->framerate); +enc_ctx->time_base = dec_ctx->time_base; } else { enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); @@ -180,7 +180,7 @@ static int open_output_file(const char *filename) return ret; /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; -enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; +enc_ctx->time_base = dec_ctx->time_base; } if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) -- 2.45.2 ___ 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] examples/transcoding: Fix time_base handling
The `dec_ctx->time_base` was incorrectly default set to 0/60, while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output. This patch aligns `enc_ctx->time_base` with `dec_ctx->time_base` to prevent rescaling issues and ensure correct video duration. Signed-off-by: JackLau1222 <2366536...@qq.com> --- doc/examples/transcoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 013f89fc7d..847bdb7e1a 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -172,7 +172,7 @@ static int open_output_file(const char *filename) else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ -enc_ctx->time_base = av_inv_q(dec_ctx->framerate); +enc_ctx->time_base = dec_ctx->time_base; } else { enc_ctx->sample_rate = dec_ctx->sample_rate; ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout); @@ -180,7 +180,7 @@ static int open_output_file(const char *filename) return ret; /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; -enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; +enc_ctx->time_base = dec_ctx->time_base; } if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) -- 2.45.2 ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
On 04/02/2025 15:58, Zhao Zhili wrote: On Feb 4, 2025, at 22:00, Martin Storsjö wrote: On Tue, 4 Feb 2025, James Almer wrote: No, they don't need to match afaik. The headers are meant to be ABI backwards compatible (hence all the reserved fields). Right, then there's probably less concern about updating them. I was just wondering if the headers were provided by your distro or not (Given they are compile time deps and not runtime), and looking now at the package lists in some, i see they are, so disregard my question. In my case I actually don't use distro provided headers, I use a manually installed set, but I don't really touch it unless I need to. How about put a copy of nv-codec-headers inside ffmpeg source tree? So it can always up to date and easy to handle the dependency (I encountered some trouble on Unix path vs Window path with ffnvcodec.pc in msys environment). What are the disadvantages of this method? That's how it's been in the past, and I have no plans to go back to that. It forces everyone to use bleeding edge drivers whenever we bump the headers, which in some distros is outright impossible. Outsourcing the headers enabled us to build modern FFmpeg with support for old drivers, just sacrificing modern features. ___ 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] avcodec/nvenc: add support for writing mastering metadata SEI messages
Including Mastering Display and Content Light Level. Requires SDK 13.0, and only supports HEVC and AV1. Signed-off-by: James Almer --- libavcodec/nvenc.c | 82 ++ libavcodec/nvenc.h | 2 ++ 2 files changed, 84 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 1f6b670c1b..9780fc712c 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -35,6 +35,7 @@ #include "libavutil/mem.h" #include "libavutil/pixdesc.h" #include "libavutil/mathematics.h" +#include "libavutil/mastering_display_metadata.h" #include "atsc_a53.h" #include "codec_desc.h" #include "encode.h" @@ -1470,6 +1471,15 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) #endif } +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +ctx->mdm = hevc->outputMasteringDisplay = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +ctx->cll = hevc->outputMaxCll = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); +#endif + #ifdef NVENC_HAVE_HEVC_CONSTRAINED_ENCODING if (ctx->constrained_encoding) hevc->enableConstrainedEncoding = 1; @@ -1638,6 +1648,15 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx) av1->pixelBitDepthMinus8 = (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) ? 2 : 0; #endif +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +ctx->mdm = av1->outputMasteringDisplay = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +ctx->cll = av1->outputMaxCll = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); +#endif + if (ctx->b_ref_mode >= 0) av1->useBFramesAsRef = ctx->b_ref_mode; @@ -2892,6 +2911,10 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) int res, res2; int sei_count = 0; int i; +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +MASTERING_DISPLAY_INFO mastering_disp_info = { 0 }; +CONTENT_LIGHT_LEVEL content_light_level = { 0 }; +#endif NvencContext *ctx = avctx->priv_data; NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs; @@ -2956,6 +2979,65 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) sei_count = res; } +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +if (ctx->mdm || ctx->cll) { +const AVFrameSideData *sd_mdm = av_frame_get_side_data(frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +const AVFrameSideData *sd_cll = av_frame_get_side_data(frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); +const int chroma_den = (avctx->codec->id == AV_CODEC_ID_AV1) ? 1 << 16 : 5; +const int max_luma_den = (avctx->codec->id == AV_CODEC_ID_AV1) ? 1 << 8 : 1; +const int min_luma_den = (avctx->codec->id == AV_CODEC_ID_AV1) ? 1 << 14 : 1; + +if (!sd_mdm) +sd_mdm = av_frame_side_data_get(avctx->decoded_side_data, +avctx->nb_decoded_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +if (!sd_cll) +sd_cll = av_frame_side_data_get(avctx->decoded_side_data, +avctx->nb_decoded_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + +if (sd_mdm) { +const AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd_mdm->data; + +mastering_disp_info.r.x = av_rescale(mdm->display_primaries[0][0].num, chroma_den, + mdm->display_primaries[0][0].den); +mastering_disp_info.r.y = av_rescale(mdm->display_primaries[0][1].num, chroma_den, + mdm->display_primaries[0][1].den); +mastering_disp_info.g.x = av_rescale(mdm->display_primaries[1][0].num, chroma_den, + mdm->display_primaries[1][0].den); +mastering_disp_info.g.y = av_rescale
[FFmpeg-devel] [PATCH] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
Fixes compilation when using API headers older than 12.0 Signed-off-by: James Almer --- libavcodec/nvenc.c | 2 ++ libavcodec/nvenc.h | 5 + 2 files changed, 7 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c359c2bc8a..eea3e8d703 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1462,7 +1462,9 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) hevc->intraRefreshPeriod = cc->gopLength; hevc->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; +#ifdef NVENC_HAVE_OUTPUT_RECOVERY_POINT_SEI hevc->outputRecoveryPointSEI = 1; +#endif #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh; #endif diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 341a242cf7..d395221870 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -78,6 +78,11 @@ typedef void ID3D11Device; #define NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH #endif +// SDK 12.0 compile time feature checks +#if NVENCAPI_CHECK_VERSION(12, 0) +#define NVENC_HAVE_OUTPUT_RECOVERY_POINT_SEI +#endif + // SDK 12.1 compile time feature checks #if NVENCAPI_CHECK_VERSION(12, 1) #define NVENC_NO_DEPRECATED_RC -- 2.48.1 ___ 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] [FFmpeg-cvslog] avcodec/nvenc: Enable recovery point SEI for intra refresh mode
On 2/4/2025 10:23 AM, Martin Storsjö wrote: On Tue, 4 Feb 2025, Timo Rothenpieler wrote: On 04/02/2025 13:25, Martin Storsjö wrote: On Mon, 3 Feb 2025, Zhao Zhili wrote: ffmpeg | branch: master | Zhao Zhili | Thu Jan 23 22:17:29 2025 +0800| [1438f6997db70945173f01aea1768e3b27ce2679] | committer: Zhao Zhili avcodec/nvenc: Enable recovery point SEI for intra refresh mode Otherwise all frames can be dropped after seek without the output_corrupt/showall flags. Signed-off-by: Zhao Zhili Reviewed-by: Timo Rothenpieler http://git.videolan.org/gitweb.cgi/ffmpeg.git/? a=commit;h=1438f6997db70945173f01aea1768e3b27ce2679 --- libavcodec/nvenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c52e47734e..c359c2bc8a 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1281,6 +1281,7 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) h264->intraRefreshPeriod = cc->gopLength; h264->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; + h264->outputRecoveryPointSEI = 1; This change breaks building with older versions of nv-codec-headers installed. Even the 8.1 SDK has this, which is the oldest version still supported by FFmpeg: https://github.com/FFmpeg/nv-codec-headers/blob/sdk/8.1/include/ ffnvcodec/nvEncodeAPI.h#L1279 Sorry, I quoted the wrong part of the patch. The case in NV_ENC_CONFIG_H264 does indeed exist in older SDKs, but the one in NV_ENC_CONFIG_HEVC doesn't seem to exist in 8.1, or in 11.1 either. Just sent a patch, can you test it? OpenPGP_signature.asc Description: OpenPGP digital signature ___ 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] [FFmpeg-cvslog] avcodec/nvenc: Enable recovery point SEI for intra refresh mode
On Tue, 4 Feb 2025, Timo Rothenpieler wrote: On 04/02/2025 13:25, Martin Storsjö wrote: On Mon, 3 Feb 2025, Zhao Zhili wrote: ffmpeg | branch: master | Zhao Zhili | Thu Jan 23 22:17:29 2025 +0800| [1438f6997db70945173f01aea1768e3b27ce2679] | committer: Zhao Zhili avcodec/nvenc: Enable recovery point SEI for intra refresh mode Otherwise all frames can be dropped after seek without the output_corrupt/showall flags. Signed-off-by: Zhao Zhili Reviewed-by: Timo Rothenpieler http://git.videolan.org/gitweb.cgi/ffmpeg.git/? a=commit;h=1438f6997db70945173f01aea1768e3b27ce2679 --- libavcodec/nvenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c52e47734e..c359c2bc8a 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1281,6 +1281,7 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) h264->intraRefreshPeriod = cc->gopLength; h264->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; + h264->outputRecoveryPointSEI = 1; This change breaks building with older versions of nv-codec-headers installed. Even the 8.1 SDK has this, which is the oldest version still supported by FFmpeg: https://github.com/FFmpeg/nv-codec-headers/blob/sdk/8.1/include/ffnvcodec/nvEncodeAPI.h#L1279 Sorry, I quoted the wrong part of the patch. The case in NV_ENC_CONFIG_H264 does indeed exist in older SDKs, but the one in NV_ENC_CONFIG_HEVC doesn't seem to exist in 8.1, or in 11.1 either. // Martin ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
On Tue, 4 Feb 2025, James Almer wrote: Fixes compilation when using API headers older than 12.0 Signed-off-by: James Almer --- libavcodec/nvenc.c | 2 ++ libavcodec/nvenc.h | 5 + 2 files changed, 7 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c359c2bc8a..eea3e8d703 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1462,7 +1462,9 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) hevc->intraRefreshPeriod = cc->gopLength; hevc->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; +#ifdef NVENC_HAVE_OUTPUT_RECOVERY_POINT_SEI hevc->outputRecoveryPointSEI = 1; +#endif #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh; #endif diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 341a242cf7..d395221870 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -78,6 +78,11 @@ typedef void ID3D11Device; #define NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH #endif +// SDK 12.0 compile time feature checks +#if NVENCAPI_CHECK_VERSION(12, 0) +#define NVENC_HAVE_OUTPUT_RECOVERY_POINT_SEI +#endif + // SDK 12.1 compile time feature checks #if NVENCAPI_CHECK_VERSION(12, 1) #define NVENC_NO_DEPRECATED_RC -- 2.48.1 Thanks, this does indeed seem to fix compilation in my setup. // Martin ___ 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] avcodec/nvenc: add compile time check for outputRecoveryPointSEI for HEVC
On 2/4/2025 10:38 AM, Martin Storsjö wrote: On Tue, 4 Feb 2025, James Almer wrote: Fixes compilation when using API headers older than 12.0 Signed-off-by: James Almer --- libavcodec/nvenc.c | 2 ++ libavcodec/nvenc.h | 5 + 2 files changed, 7 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c359c2bc8a..eea3e8d703 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1462,7 +1462,9 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) hevc->intraRefreshPeriod = cc->gopLength; hevc->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; +#ifdef NVENC_HAVE_OUTPUT_RECOVERY_POINT_SEI hevc->outputRecoveryPointSEI = 1; +#endif #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH hevc->singleSliceIntraRefresh = ctx->single_slice_intra_refresh; #endif diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 341a242cf7..d395221870 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -78,6 +78,11 @@ typedef void ID3D11Device; #define NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH #endif +// SDK 12.0 compile time feature checks +#if NVENCAPI_CHECK_VERSION(12, 0) +#define NVENC_HAVE_OUTPUT_RECOVERY_POINT_SEI +#endif + // SDK 12.1 compile time feature checks #if NVENCAPI_CHECK_VERSION(12, 1) #define NVENC_NO_DEPRECATED_RC -- 2.48.1 Thanks, this does indeed seem to fix compilation in my setup. Applied. Why don't don't just update the headers? Is it a system package provided by your distro? OpenPGP_signature.asc Description: OpenPGP digital signature ___ 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] [FFmpeg-cvslog] avcodec/nvenc: Enable recovery point SEI for intra refresh mode
On 04/02/2025 13:25, Martin Storsjö wrote: On Mon, 3 Feb 2025, Zhao Zhili wrote: ffmpeg | branch: master | Zhao Zhili | Thu Jan 23 22:17:29 2025 +0800| [1438f6997db70945173f01aea1768e3b27ce2679] | committer: Zhao Zhili avcodec/nvenc: Enable recovery point SEI for intra refresh mode Otherwise all frames can be dropped after seek without the output_corrupt/showall flags. Signed-off-by: Zhao Zhili Reviewed-by: Timo Rothenpieler http://git.videolan.org/gitweb.cgi/ffmpeg.git/? a=commit;h=1438f6997db70945173f01aea1768e3b27ce2679 --- libavcodec/nvenc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index c52e47734e..c359c2bc8a 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1281,6 +1281,7 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) h264->intraRefreshPeriod = cc->gopLength; h264->intraRefreshCnt = cc->gopLength - 1; cc->gopLength = NVENC_INFINITE_GOPLENGTH; + h264->outputRecoveryPointSEI = 1; This change breaks building with older versions of nv-codec-headers installed. Even the 8.1 SDK has this, which is the oldest version still supported by FFmpeg: https://github.com/FFmpeg/nv-codec-headers/blob/sdk/8.1/include/ffnvcodec/nvEncodeAPI.h#L1279 ___ 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] avformat/dvdvideodec: fix seeking on multi-angle discs
When seeking on multi-angle titles, libdvdnav does not lock on to the correct sectors initially as it seeks to find the right NAV packet. This manifests itself as two bugs: (1) When seeking on the first angle in a multi-angle segment, frames from another angle will appear (for example in intro or credits scenes). This issue is present in VLC also. (2) When seeking during a segment on angle n+1, the demuxer cannot deduce the right position from dvdnav and does not allow seeking within the segment (due to it maintaining a strict state). Correct the issue by switching to angle 1 before doing the seek operation, and skipping 3 VOBUs (NAV packet led segments) ahead where dvdnav will have positioned itself correctly. Reported-by: Kacper Michajlow Signed-off-by: Marth64 --- libavformat/dvdvideodec.c | 36 1 file changed, 36 insertions(+) diff --git a/libavformat/dvdvideodec.c b/libavformat/dvdvideodec.c index 5b9abebbf2..9596468ce2 100644 --- a/libavformat/dvdvideodec.c +++ b/libavformat/dvdvideodec.c @@ -111,6 +111,7 @@ typedef struct DVDVideoPlaybackState { int in_vts; /* if our navigator is in the VTS */ int is_seeking; /* relax navigation path while seeking */ int64_t nav_pts;/* PTS according to IFO, not frame-accurate */ +int nb_vobu_skip; /* number of VOBUs we should skip */ uint64_tpgc_duration_est; /* estimated duration as reported by IFO */ uint64_tpgc_elapsed;/* the elapsed time of the PGC, cell-relative */ int pgc_nb_pg_est; /* number of PGs as reported by IFOs */ @@ -165,6 +166,7 @@ typedef struct DVDVideoDemuxContext { /* playback control */ int64_t first_pts; /* the PTS of the first video keyframe */ +int nb_angles; /* number of angles in the current title */ int play_started; /* signal that playback has started */ DVDVideoPlaybackState play_state; /* the active playback state */ int64_t *prev_pts; /* track the previous PTS emitted per stream */ @@ -298,6 +300,8 @@ static int dvdvideo_ifo_open(AVFormatContext *s) return AVERROR_INVALIDDATA; } +c->nb_angles = title_info.nr_of_angles; + return 0; } @@ -759,6 +763,13 @@ static int dvdvideo_play_next_ps_block(AVFormatContext *s, DVDVideoPlaybackState return AVERROR_INVALIDDATA; } +if (state->nb_vobu_skip > 0) { +av_log(s, AV_LOG_VERBOSE, "Skipping VOBU at SCR %d\n", + e_dsi->dsi_gi.nv_pck_scr); +state->nb_vobu_skip -= 1; +continue; +} + state->vobu_duration = e_pci->pci_gi.vobu_e_ptm - e_pci->pci_gi.vobu_s_ptm; state->pgc_elapsed += state->vobu_duration; state->nav_pts = dvdnav_get_current_time(state->dvdnav); @@ -1736,6 +1747,7 @@ static int dvdvideo_read_seek(AVFormatContext *s, int stream_index, int64_t time int64_t new_nav_pts; pci_t* new_nav_pci; dsi_t* new_nav_dsi; +int seek_failed = 0; if (c->opt_menu || c->opt_chapter_start > 1) { av_log(s, AV_LOG_ERROR, "Seeking is not compatible with menus or chapter extraction\n"); @@ -1755,9 +1767,30 @@ static int dvdvideo_read_seek(AVFormatContext *s, int stream_index, int64_t time c->seek_warned = 1; } +/* dvdnav loses NAV packets when seeking on multi-angle discs, so enforce angle 1 then revert */ +if (c->nb_angles > 1) { +if (dvdnav_angle_change(c->play_state.dvdnav, 1) != DVDNAV_STATUS_OK) { +av_log(s, AV_LOG_ERROR, "Unable to open angle 1 for seeking\n"); + +return AVERROR_EXTERNAL; +} +} + /* XXX(PATCHWELCOME): use dvdnav_jump_to_sector_by_time(c->play_state.dvdnav, timestamp, 0) * when it is available in a released version of libdvdnav; it is more accurate */ if (dvdnav_time_search(c->play_state.dvdnav, timestamp) != DVDNAV_STATUS_OK) { +seek_failed = 1; +} + +if (c->nb_angles > 1) { +if (dvdnav_angle_change(c->play_state.dvdnav, c->opt_angle) != DVDNAV_STATUS_OK) { +av_log(s, AV_LOG_ERROR, "Unable to revert to angle %d after seeking\n", c->opt_angle); + +return AVERROR_EXTERNAL; +} +} + +if (seek_failed) { av_log(s, AV_LOG_ERROR, "libdvdnav: seeking to %" PRId64 " failed\n", timestamp); return AVERROR_EXTERNAL; @@ -1781,6 +1814,9 @@ static int dvdvideo_read_seek(AVFormatContext *s, int stream_index, int64_t time c->play_state.ptm_discont = 0; c->play_state.vobu_e
Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: add support for writing mastering metadata SEI messages
On 04.02.2025 17:30, James Almer wrote: Including Mastering Display and Content Light Level. Requires SDK 13.0, and only supports HEVC and AV1. Signed-off-by: James Almer --- libavcodec/nvenc.c | 82 ++ libavcodec/nvenc.h | 2 ++ 2 files changed, 84 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 1f6b670c1b..9780fc712c 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -35,6 +35,7 @@ #include "libavutil/mem.h" #include "libavutil/pixdesc.h" #include "libavutil/mathematics.h" +#include "libavutil/mastering_display_metadata.h" #include "atsc_a53.h" #include "codec_desc.h" #include "encode.h" @@ -1470,6 +1471,15 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) #endif } +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +ctx->mdm = hevc->outputMasteringDisplay = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +ctx->cll = hevc->outputMaxCll = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); +#endif + #ifdef NVENC_HAVE_HEVC_CONSTRAINED_ENCODING if (ctx->constrained_encoding) hevc->enableConstrainedEncoding = 1; @@ -1638,6 +1648,15 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx) av1->pixelBitDepthMinus8 = (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) ? 2 : 0; #endif +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +ctx->mdm = av1->outputMasteringDisplay = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +ctx->cll = av1->outputMaxCll = !!av_frame_side_data_get(avctx->decoded_side_data, + avctx->nb_decoded_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); +#endif + if (ctx->b_ref_mode >= 0) av1->useBFramesAsRef = ctx->b_ref_mode; @@ -2892,6 +2911,10 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) int res, res2; int sei_count = 0; int i; +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +MASTERING_DISPLAY_INFO mastering_disp_info = { 0 }; +CONTENT_LIGHT_LEVEL content_light_level = { 0 }; +#endif NvencContext *ctx = avctx->priv_data; NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs; @@ -2956,6 +2979,65 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) sei_count = res; } +#ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA +if (ctx->mdm || ctx->cll) { +const AVFrameSideData *sd_mdm = av_frame_get_side_data(frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +const AVFrameSideData *sd_cll = av_frame_get_side_data(frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); +const int chroma_den = (avctx->codec->id == AV_CODEC_ID_AV1) ? 1 << 16 : 5; +const int max_luma_den = (avctx->codec->id == AV_CODEC_ID_AV1) ? 1 << 8 : 1; +const int min_luma_den = (avctx->codec->id == AV_CODEC_ID_AV1) ? 1 << 14 : 1; + +if (!sd_mdm) +sd_mdm = av_frame_side_data_get(avctx->decoded_side_data, +avctx->nb_decoded_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); +if (!sd_cll) +sd_cll = av_frame_side_data_get(avctx->decoded_side_data, +avctx->nb_decoded_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + +if (sd_mdm) { +const AVMasteringDisplayMetadata *mdm = (AVMasteringDisplayMetadata *)sd_mdm->data; + +mastering_disp_info.r.x = av_rescale(mdm->display_primaries[0][0].num, chroma_den, + mdm->display_primaries[0][0].den); +mastering_disp_info.r.y = av_rescale(mdm->display_primaries[0][1].num, chroma_den, + mdm->display_primaries[0][1].den); +mastering_disp_info.g.x = av_rescale(mdm->display_primaries[1][0].num, chroma_den, + mdm->display_
Re: [FFmpeg-devel] [PATCH v2] lavc/videotoolboxenc: Add spatial_aq option
On Mon, 16 Dec 2024, Dennis Sädtler via ffmpeg-devel wrote: From: Dennis Sädtler Added in macOS 15 "Sequoia". Signed-off-by: Dennis Sädtler --- Fixed line-endings, otherwise identical to v1. libavcodec/videotoolboxenc.c | 12 1 file changed, 12 insertions(+) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index da7b291b03..fb2de7b960 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -121,6 +121,7 @@ static struct{ CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality; CFStringRef kVTCompressionPropertyKey_ConstantBitRate; CFStringRef kVTCompressionPropertyKey_EncoderID; +CFStringRef kVTCompressionPropertyKey_SpatialAdaptiveQPLevel; CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder; CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder; @@ -208,6 +209,7 @@ static void loadVTEncSymbols(void){ "ReferenceBufferCount"); GET_SYM(kVTCompressionPropertyKey_MaxAllowedFrameQP, "MaxAllowedFrameQP"); GET_SYM(kVTCompressionPropertyKey_MinAllowedFrameQP, "MinAllowedFrameQP"); +GET_SYM(kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, "SpatialAdaptiveQPLevel"); } #define H264_PROFILE_CONSTRAINED_HIGH (AV_PROFILE_H264_HIGH | AV_PROFILE_H264_CONSTRAINED) @@ -279,6 +281,7 @@ typedef struct VTEncContext { int max_slice_bytes; int power_efficient; int max_ref_frames; +int spatialaq; } VTEncContext; static void vtenc_free_buf_node(BufNode *info) @@ -1599,6 +1602,13 @@ static int vtenc_create_encoder(AVCodecContext *avctx, } } +if (vtctx->spatialaq >= 0) { +set_encoder_int_property_or_log(avctx, + compat_keys.kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, +"spatialaq", +vtctx->spatialaq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable); These constants aren't available if building with an older SDK, so this would break building in such cases. For other similar cases of compile time constants that may or may not be available, we have configure checks and provide the constants ourselves - that seems to be reasonable here too. With the following changes on top, it seems to build successfully even for older versions: diff --git a/configure b/configure index 32fbe58126..020c2af843 100755 --- a/configure +++ b/configure @@ -2490,6 +2490,7 @@ TYPES_LIST=" kCVImageBufferColorPrimaries_ITU_R_2020 kCVImageBufferTransferFunction_ITU_R_2020 kCVImageBufferTransferFunction_SMPTE_ST_428_1 +kVTQPModulationLevel_Default socklen_t struct_addrinfo struct_group_source_req @@ -6748,6 +6749,7 @@ enabled videotoolbox && { check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferColorPrimaries_ITU_R_2020 "-framework CoreVideo" check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_ITU_R_2020 "-framework CoreVideo" check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo" +check_func_headers VideoToolbox/VTCompressionProperties.h kVTQPModulationLevel_Default "-framework CoreVideo" } enabled metal && test_cmd $metalcc -v || disable metal diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index fb2de7b960..950a29d9fa 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -54,6 +54,11 @@ enum { kCVPixelFormatType_420YpCbCr10BiPlanarFullRange = 'xf20' }; enum { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange = 'x420' }; #endif +#if !HAVE_KVTQPMODULATIONLEVEL_DEFAULT +enum { kVTQPModulationLevel_Default = -1 }; +enum { kVTQPModulationLevel_Disable = 0 }; +#endif + #ifndef TARGET_CPU_ARM64 # define TARGET_CPU_ARM64 0 #endif If you don't mind these changes, I could push the patch with these changes squashed in. // Martin ___ 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] examples/transcoding: Fix time_base handling
To be clear, i want to give an example, i use a 10s duration, 30fps video. The ifmt_ctx->streams[stream_index]->time_base is same as ofmt_ctx->streams[stream_index]->time_base after initializing. The stream->dec_ctx->time_base is default 0,60 but stream->enc_ctx->time_base is set to av_inv_q(dec_ctx->framerate) so it's 0,30 174 /* video time_base can be set to whatever is handy and supported by encoder */ 175 enc_ctx->time_base = av_inv_q(dec_ctx->framerate); so the twice rescale is this: input pkt in_tb: 15360 out_tb: 60 output pkt in_tb: 30 out_tb: 15360 so i get one 20s duration and 15fps video(audio duration is normal because the input's audio sample ratio is 44100) So i think the problem is that the enc_ctx->time_base shouldn't set to av_inv_q(dec_ctx->framerate) On Wed, Feb 5, 2025 at 10:29 AM Jack Lau wrote: > > AVCodecContext.time_base is not used for decoding. > > > > Thank you for your reply. I understand that time_base is not used during > decoding, but the transcoding code calls av_packet_rescale_ts twice, once > before decoding and once after encoding, as shown below: > > 540 if (filter_ctx[stream_index].filter_graph) { > 541 StreamContext *stream = &stream_ctx[stream_index]; > 542 > 543 av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the > frame\n"); > 544 > 545 av_packet_rescale_ts(packet, > > > 546 > ifmt_ctx->streams[stream_index]->time_base, > 547 stream->dec_ctx->time_base); > 548 ret = avcodec_send_packet(stream->dec_ctx, packet); > > 448 /* prepare packet for muxing */ > > > 449 enc_pkt->stream_index = stream_index; > 450 av_packet_rescale_ts(enc_pkt, > 451 stream->enc_ctx->time_base, > 452 > ofmt_ctx->streams[stream_index]->time_base); > 453 > 454 av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n"); > 455 /* mux encoded frame */ > 456 ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); > > If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can > lead to incorrect packet duration, which in turn causes issues with the > output file's duration. > ___ 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] Replace broken Web IRC link
On 2025-02-05 01:17 am, Gyan Doshi wrote: On 2025-02-04 11:58 pm, Marth64 wrote: Thank you Timo for removing the flag. Now users should be able to join correctly. Patch LGTM. I don't have access to merge to web. Will push tomorrow morning, if no one else has. Pushed as e99836bf11abbe38c64c08b1cd84ffd61542c207 Regards, Gyan ___ 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] avcodec/hevc/hevcdec: simplify creating a new reference to HDR10 side data
Signed-off-by: James Almer --- libavcodec/hevc/hevcdec.c | 11 +++ 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index cf4062c75c..24d801c39f 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3081,16 +3081,11 @@ static int set_side_data(HEVCContext *s) } if (s->sei.common.dynamic_hdr_plus.info) { -AVBufferRef *info_ref = av_buffer_ref(s->sei.common.dynamic_hdr_plus.info); -if (!info_ref) -return AVERROR(ENOMEM); - ret = ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, - &info_ref, 0); -if (ret < 0) { -av_buffer_unref(&info_ref); + &s->sei.common.dynamic_hdr_plus.info, + AV_FRAME_SIDE_DATA_FLAG_NEW_REF); +if (ret < 0) return ret; -} } if (s->rpu_buf) { -- 2.48.1 ___ 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 1/2] avcodec/decode: make ff_frame_new_side_data_from_buf behave like the function it's a wrapper for
It's less confusing to have ff_frame_new_side_data_from_buf() be a drop in replacement for av_frame_side_data_add(), and the addition of the missing flags field will make it more versatile, as will be seen in the following commit. Signed-off-by: James Almer --- libavcodec/av1dec.c | 6 -- libavcodec/decode.c | 13 + libavcodec/decode.h | 11 +++ libavcodec/h2645_sei.c| 12 libavcodec/hevc/hevcdec.c | 7 +-- libavcodec/hevc/refs.c| 6 -- libavcodec/libdav1d.c | 6 -- libavcodec/libjxldec.c| 6 -- libavcodec/mpeg12dec.c| 6 -- 9 files changed, 45 insertions(+), 28 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 7c54e36220..11b6100f9f 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -983,9 +983,11 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, if (!ret) break; -ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_A53_CC, &buf); -if (ret < 0) +ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_A53_CC, &buf, 0); +if (ret < 0) { +av_buffer_unref(&buf); return ret; +} #if FF_API_CODEC_PROPS FF_DISABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/decode.c b/libavcodec/decode.c index cac7e620d2..794e84c1a2 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2118,29 +2118,26 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, -AVBufferRef **buf) +AVBufferRef **buf, int flags) { int ret = 0; if (side_data_pref(avctx, sd, nb_sd, type)) -goto finish; +return 0; -if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0)) +if (!av_frame_side_data_add(sd, nb_sd, type, buf, flags)) ret = AVERROR(ENOMEM); -finish: -av_buffer_unref(buf); - return ret; } int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, -AVBufferRef **buf) +AVBufferRef **buf, int flags) { return ff_frame_new_side_data_from_buf_ext(avctx, &frame->side_data, &frame->nb_side_data, - type, buf); + type, buf, flags); } int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, diff --git a/libavcodec/decode.h b/libavcodec/decode.h index 2c3719a8d0..dc2802d782 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -168,12 +168,15 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, /** * Similar to `ff_frame_new_side_data`, but using an existing buffer ref. * - * *buf is ALWAYS consumed by this function and NULL written in its place, even - * on failure. + * @param buf Pointer to AVBufferRef to add to the array. On success, + * the function takes ownership of the AVBufferRef and *buf is + * set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set + * in which case the ownership will remain with the caller. + * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. */ int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, -AVBufferRef **buf); +AVBufferRef **buf, int flags); /** * Same as `ff_frame_new_side_data_from_buf`, but taking a AVFrameSideData @@ -182,7 +185,7 @@ int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, -AVBufferRef **buf); +AVBufferRef **buf, int flags); struct AVMasteringDisplayMetadata; struct AVContentLightMetadata; diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index 2494daaf3c..d48a9b5f2c 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -610,10 +610,12 @@ static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, } ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd, - AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, &buf)
Re: [FFmpeg-devel] [PATCH 2/2] avformat/hls: .ts is always ok even if its a mov/mp4
On 1/28/25 4:44 PM, Michael Niedermayer wrote: Hi On Tue, Jan 28, 2025 at 10:12:30PM +0200, Jan Ekström wrote: On Tue, Jan 28, 2025 at 4:24 PM Michael Niedermayer wrote: Maybe fixes: 11435 Do I understand correctly that the root issue that's being attempted to be fixed by the initial patch set is that unusual demuxers were possible to have been probed and opened through the HLS meta demuxer? In that case I would say that instead of trying to make very nebulous and easily breakable extension based checking, maybe this demuxer should just limit its default usable input formats? To my knowledge the officially utilized container formats for HLS are MPEG-TS, MP4-likes (fragmented mp4) and raw audio formats such as AAC, MP3 or AC-3. One could check what hls.js or ExoPlayer support, and that should be a generally mostly encompassing thing that does not depend on what extensions are in use. Adding an AVOption to add additional formats without code changes would then allow for some outliers to be added by users. there is extended M3U https://en.wikipedia.org/wiki/M3U that allows a wide range of things in it our hls demuxer can read these, if we limit to mpeg-ts/mp4 we would remove support for these. From reading this, it seems like we're using the same demuxer for both HLS streams (specified informationally in RFC 8216) as well as for generic m3u playlists, and changes to the HLS implementation for security reasons also change the M3U demuxer. Why don't we just separate this into two different demuxers/protocols? - Leo Izen (Traneptora) ___ 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/hls: .ts is always ok even if its a mov/mp4
On Tue, 28 Jan 2025 at 22:44, Michael Niedermayer wrote: > > Hi > > On Tue, Jan 28, 2025 at 10:12:30PM +0200, Jan Ekström wrote: > > On Tue, Jan 28, 2025 at 4:24 PM Michael Niedermayer > > wrote: > > > > > > Maybe fixes: 11435 > > > > > > > Do I understand correctly that the root issue that's being attempted > > to be fixed by the initial patch set is that unusual demuxers were > > possible to have been probed and opened through the HLS meta demuxer? > > In that case I would say that instead of trying to make very nebulous > > and easily breakable extension based checking, maybe this demuxer > > should just limit its default usable input formats? > > > > To my knowledge the officially utilized container formats for HLS are > > MPEG-TS, MP4-likes (fragmented mp4) and raw audio formats such as AAC, > > MP3 or AC-3. One could check what hls.js or ExoPlayer support, and > > that should be a generally mostly encompassing thing that does not > > depend on what extensions are in use. Adding an AVOption to add > > additional formats without code changes would then allow for some > > outliers to be added by users. > > there is extended M3U > https://en.wikipedia.org/wiki/M3U > > that allows a wide range of things in it > > our hls demuxer can read these, if we limit to mpeg-ts/mp4 we would remove > support for these. > > having an AVOption that is needed for some files is bad because > then people turn it on and if that makes it insecure ... > > > > > > Finally, the `-f` format definition option and whatever logic > > underneath it is just splitting the name on comma and then matching. > > There probably is a helper function for this in the code base. This > > enables just matching against "mp4" or so. While I consider it > > yeah, you are correct thats ugly, ill fix that > > michaelni: alternatively I feel like since we've had meta demuxers > have these issues having demuxers utilized that just read text from input, > maybe we should just have some general meta demuxer logic which allows or > disallows specific formats. allowlist is simpler since even if someone adds a > new one it will not automatically be allowed (thus not enabling possible new > "holes"), but on the other hand if > we can notice such formats as new ones happen to get added then a > blocklist based on a "not allowed in meta demuxers" or "may easily cause > information exfiltration" per-format flag might also be quite possible > > there are many things that can be done, iam not against this > the CVE IIRC explicitly suggested extension checks > > > dont we already have tons of whitelists for things, having a > demuxer whitelist sounds a lot better then doing it on extension, which is > meaningless in msot cases - as seen here, ts is just used for anything > > we have tons of whitelists and i have suggested their use everywhere including > the commit messages > > They have some problem though and that is they are unflexible if set to > a fixed value by hand > if you get a unknown generic input what whitelist do you use ? > you need to have the demuxer on it that that file needs but you dont know > which that is. > > I dont like hls and i dont like how our hls demuxer is "shared" with more > generic EXTM3U code. I think these 2 should be seperate AVInputFormat > in the same hls.c > Where the true HLS should be more locked down like you describe by default > > but still teh more generic code benefits from simple checks we can > throw at it. > Simply blacklisting tty "demuxers" feels like a risky fix though > because tty is used by an attacker because its simple not because its the only > way to exfiltrate data. If you just run a raw decoder or pcm decoder or > even something simple like a RLE decoder you can likely achieve the same > its just an extra layer of work > > Iam not sure and iam not feeling confident on any hls fix. This is all > more incremental improvments. Even if you can only run a TS demuxer or > MOV demuxer over /etc/passwd, i would not feel safe Hi, I think the main point here is that FFmpeg is being forced to implement "layers" of security that, at best, provide a false sense of assurance. You should never run a large media processing library, one that relies on dozens of third-party dependencies, without proper sandboxing and strict access controls for relevant files. That said, I do see some merit in extension filtering as a way to reduce the scope of what FFmpeg attempts to read. However, we must ensure that it aligns with the HLS specification and the practices of major media providers. In #11435, I provided another example (Twitter/X) that is currently being filtered in HEAD (88a8ba5c). (and I'm sure there are servers that feeds files without extension and only mime type) I believe changes like this create more friction for users than actual security benefits. I get it. Someone needed to hit their KPI by submitting CVEs, and they found a marginally applicable case of a highly unrealistic attack scenario. Bu
Re: [FFmpeg-devel] [PATCH v2 1/2] Parse ogg/flac header again after processing a new chained ogg bitstream.
Le jeu. 30 janv. 2025 à 08:08, Romain Beauxis a écrit : > > > > > Le mer. 29 janv. 2025 à 17:40, Marvin Scholz a écrit : > > > > > > > > On 29 Jan 2025, at 15:40, Romain Beauxis wrote: > > > > > This patch makes sure that ogg/flac headers are parsed again when > > > encountering a new logic stream inside a chained ogg bistream[1]. > > > > > > This patches makes it possible to retrieve metadata in chained ogg/flac > > > bitstreams. It is particularly important because ogg/flac is one of the > > > only (if not the only one) lossless container supported over HTTP/icecast. > > > > > > The patch has been tested with various ogg/flac encoders and appears to > > > work fine with ffmpeg. > > > > > > Changes since last version: > > > * Make sure to clear the stream's metadata before parsing again. > > > > > > 1: https://xiph.org/ogg/doc/oggstream.html > > > > > > > Hi, thanks a lot for trying to solve this, see remarks inline below: > > > > > --- > > > libavformat/oggdec.c | 7 +-- > > > libavformat/oggparseflac.c | 2 ++ > > > 2 files changed, 7 insertions(+), 2 deletions(-) > > > > > > diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c > > > index 5339fdd32c..d986e19817 100644 > > > --- a/libavformat/oggdec.c > > > +++ b/libavformat/oggdec.c > > > @@ -239,8 +239,11 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic, > > > os->start_trimming = 0; > > > os->end_trimming = 0; > > > > > > -/* Chained files have extradata as a new packet */ > > > -if (codec == &ff_opus_codec) > > > +/* Parse opus and flac header on new chained bitstream. > > > + * For opus, header contains required extradata as new packet > > > + * For both formats, this makes it possible to read chained metadata. */ > > > +if (codec == &ff_opus_codec || > > > +codec == &ff_flac_codec) > > > os->header = -1; > > > > > > return i; > > > diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c > > > index f25ed9cc15..932907fa1a 100644 > > > --- a/libavformat/oggparseflac.c > > > +++ b/libavformat/oggparseflac.c > > > @@ -72,6 +72,8 @@ flac_header (AVFormatContext * s, int idx) > > > > > > avpriv_set_pts_info(st, 64, 1, samplerate); > > > } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) { > > > +/* New metadata packet; release old data. */ > > > +av_dict_free(&st->metadata); > > > > I do not think it’s fine to change this mid-demuxing, as the caller > > has no way to know this changed „behind its back“ so may still hold > > on to the old pointer and run into invalid memory access. > > > > I checked with James and he suggested that maybe propagating the new > > metadata with AVPacket’s side_data might be a better approach, similar > > to AV_PKT_DATA_NEW_EXTRADATA. > > Thank you for the review! > > Do you mean the st->metadata dictionary? > > The nature of `av_dict` is to be an ever-changing pointer; each time a value is changed, the underlying pointer is changed so I think keeping a long-term pointer on it is a programming error. > > It's also worth noting that this is the same method used currently by the vorbis decoder. > > That being said, updating the AVStream is not natural and requires the user to constantly check on it. > > It would be more natural to have: > * The headers packets flow out of the demuxer as it is now so anyone operating at this level can see them and act accordingly. > * Have the decoded frame carry the new metadata, which is a more natural place for it. > > I'll look into this. Hopefully this is a better approach and also one that could be generalized to all ogg-encapsulated formats.. I'm sending another version of the patch. It pushes the metadata decoding to the codec decoding. This makes sense from separation of concern perspective: packets keep seeing the full encoded data and decoded frames see the decoded metadata. However, this adds a dependency on libavformat to libavcodec. I also looked at moving the vorbis comment parsing to libavutil but there's a lot of metadata definitions and utils that at located in libavformat at the moment so perhaps it makes sense this way. -- Romain ___ 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 0/3] Properly decode ogg metadata in ogg/flac chained bitstreams
This is a series of 3 patches to allow proper decoding of ogg metadata in chained ogg/flac streams. ogg/flac streams are pretty important because there are perhaps the only combination of lossless audio codec and open-source container that allows for proper transmittion of lossless audio data accross systems such as Icecast, browser media tags and more. In the context of long-running audio streams, the ogg bitstream specs[1] have historically been very badly implemented. For each new track and each new metadata, the specs require the logical bitstream to come to a full EOF and then start with a full new logical stream. These specs have often been confused with a gobal EOF by most implementations. Furtunately, FFmpeg is a little better at that in that it is capable to parsing chained logical ogg bitstreams and properly output either encoded ogg packets or decoded audio. Chained bitstreams with more than one underlying type of content (audio+video, etc) is not yet supported though this is a much less needed feature. The purpose of these changes is to also allow proper decoding of metadata associated with subsequent streams in chained ogg/flac bitstream. This is done by simply intercepting ogg packets with comments in the flac decoded, parsing the comment block and retaining it to be attached with the next decoded audio frame. Along with the changes is a new FATE test validating the implementation. This solution keeps a proper separation of concerns: ogg packets are sill output by the demuxer (as shown in the test) but consumer of decoded data see decoded metadata in the decoded frames. Only drawback is that this adds a dependency on libavformat to libavcodec. I have looked at moving the vorbis metadata parsing to libavutil but a lot of definitions and utilities related to metadata are in fact located in libavformat so perhaps this makes sense. Follow-up work not addressed in this series of patch: * Ensure valid PTS in decoded frames of subsequent streams? * Generalize this approach to other chained ogg codec. Thanks, -- Romain Romain Beauxis (3): libavformat/oggdec: Allow first parameter in ff_vorbis_comment to be a generic AVClass struct libavcodec/flacdec: parse vorbis metadata from ogg packets, add them to the next decoded frame. Add stream dump test with test for ogg/flac. libavcodec/flacdec.c | 12 +- libavformat/oggdec.h | 5 +- libavformat/oggparsevorbis.c | 4 +- tests/Makefile| 2 + tests/api/Makefile| 2 +- tests/api/api-dump-stream-meta-test.c | 169 ++ tests/fate/api.mak| 5 + tests/fate/ogg-flac.mak | 11 ++ 8 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 tests/api/api-dump-stream-meta-test.c create mode 100644 tests/fate/ogg-flac.mak -- 2.39.5 (Apple Git-154) ___ 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 3/3] Add stream dump test with test for ogg/flac.
This is the new FATE test. Test samples are available here: https://www.dropbox.com/scl/fo/fxt2edwkyj2mjc9qubku5/AICHxJyxMMAK8MIJqWLcvk4?rlkey=mlt12lsu741ejukz0p5qtn9rq&dl=0 Output prior to the changes is: Stream ID: 0, codec name: flac, metadata: encoder=Lavc61.19.100 flac:title=First Stream Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: Output after the changes: Stream ID: 0, codec name: flac, metadata: encoder=Lavc61.19.100 flac:title=First Stream Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: encoder=Lavc61.19.100 flac:title=Second Stream Stream ID: 0, packet PTS: 4608, packet DTS: 4608 Stream ID: 0, frame PTS: 4608, metadata: --- tests/Makefile| 2 + tests/api/Makefile| 2 +- tests/api/api-dump-stream-meta-test.c | 169 ++ tests/fate/api.mak| 5 + tests/fate/ogg-flac.mak | 11 ++ 5 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/api/api-dump-stream-meta-test.c create mode 100644 tests/fate/ogg-flac.mak diff --git a/tests/Makefile b/tests/Makefile index f9f5fc07f3..66e5189e6d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -219,6 +219,7 @@ include $(SRC_PATH)/tests/fate/mpeg4.mak include $(SRC_PATH)/tests/fate/mpegps.mak include $(SRC_PATH)/tests/fate/mpegts.mak include $(SRC_PATH)/tests/fate/mxf.mak +include $(SRC_PATH)/tests/fate/ogg-flac.mak include $(SRC_PATH)/tests/fate/oma.mak include $(SRC_PATH)/tests/fate/opus.mak include $(SRC_PATH)/tests/fate/pcm.mak @@ -277,6 +278,7 @@ $(FATE_FFPROBE) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FF $(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF) $(FATE_SAMPLES_DUMP_DATA) $(FATE_SAMPLES_DUMP_DATA-yes): tools/venc_data_dump$(EXESUF) $(FATE_SAMPLES_SCALE_SLICE): tools/scale_slice_test$(EXESUF) +$(FATE_SAMPLES_DUMP_STREAM_META): tests/api/api-dump-stream-meta-test$(EXESUF) ifdef SAMPLES FATE += $(FATE_EXTERN) diff --git a/tests/api/Makefile b/tests/api/Makefile index c96e636756..a2cb06a729 100644 --- a/tests/api/Makefile +++ b/tests/api/Makefile @@ -1,7 +1,7 @@ APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264-slice -APITESTPROGS-yes += api-seek +APITESTPROGS-yes += api-seek api-dump-stream-meta APITESTPROGS-$(call DEMDEC, H263, H263) += api-band APITESTPROGS-$(HAVE_THREADS) += api-threadmessage APITESTPROGS += $(APITESTPROGS-yes) diff --git a/tests/api/api-dump-stream-meta-test.c b/tests/api/api-dump-stream-meta-test.c new file mode 100644 index 00..4ffdfe8213 --- /dev/null +++ b/tests/api/api-dump-stream-meta-test.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2025 Romain Beauxis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Dump stream metadata + */ + +#include "libavcodec/avcodec.h" +#include "libavformat/avformat.h" +#include "libavutil/timestamp.h" + +static int dump_stream_meta(const char *input_filename) +{ +const AVCodec *codec = NULL; +AVPacket *pkt = NULL; +AVFrame *fr = NULL; +AVFormatContext *fmt_ctx = NULL; +AVCodecContext *ctx = NULL; +AVCodecParameters *origin_par = NULL; +int audio_stream; +int result; +char
[FFmpeg-devel] [PATCH v2 1/3] libavformat/oggdec: Allow first parameter in ff_vorbis_comment to be a generic AVClass struct
Firt argument in these function is only used to pass to av_log. This makes it possible to re-use them with any type of AVClass struct. --- libavformat/oggdec.h | 5 - libavformat/oggparsevorbis.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h index 43df23f4cb..6177254fd2 100644 --- a/libavformat/oggdec.h +++ b/libavformat/oggdec.h @@ -136,8 +136,11 @@ extern const struct ogg_codec ff_vp8_codec; *so it needs to be writable. Furthermore it must be padded *by a single byte (not counted in size). *All changes will have been reverted upon return. + * + * @param avcl A pointer to an arbitrary struct of which the first field is a + *pointer to an AVClass struct. */ -int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, +int ff_vorbis_comment(void *avcl, AVDictionary **m, const uint8_t *buf, int size, int parse_picture); /** diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 9f50ab9ffc..62eb8bbf70 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -88,7 +88,7 @@ int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st, * and reverts its changes before return. The input buffer needs to have * at least one byte of padding. */ -static int vorbis_parse_single_comment(AVFormatContext *as, AVDictionary **m, +static int vorbis_parse_single_comment(void *as, AVDictionary **m, const uint8_t *buf, uint32_t size, int *updates, int parse_picture) { @@ -146,7 +146,7 @@ end: return 0; } -int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m, +int ff_vorbis_comment(void *as, AVDictionary **m, const uint8_t *buf, int size, int parse_picture) { -- 2.39.5 (Apple Git-154) ___ 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/3] libavcodec/flacdec: parse vorbis metadata from ogg packets, add them to the next decoded frame.
This is the main patch. Parse ogg comments in ogg packets with comment, keep them in pending_metadata and copy them to the next decoded audio frame. --- libavcodec/flacdec.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index ad921a1bd1..03a68cdfef 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -37,6 +37,7 @@ #include "libavutil/crc.h" #include "libavutil/mem.h" #include "libavutil/opt.h" +#include "libavformat/oggdec.h" #include "avcodec.h" #include "codec_internal.h" #include "get_bits.h" @@ -68,6 +69,8 @@ typedef struct FLACContext { unsigned int decoded_buffer_size_33bps; int buggy_lpc; ///< use workaround for old lavc encoded files +AVDictionary *pending_metadata; + FLACDSPContext dsp; } FLACContext; @@ -728,7 +731,8 @@ static int flac_decode_frame(AVCodecContext *avctx, AVFrame *frame, } if (buf_size > 0 && (*buf & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) { -av_log(s->avctx, AV_LOG_DEBUG, "skipping vorbis comment\n"); +av_dict_free(&s->pending_metadata); +ff_vorbis_comment(avctx, &s->pending_metadata, buf + 4, buf_size - 4, 1); return buf_size; } @@ -788,6 +792,11 @@ static int flac_decode_frame(AVCodecContext *avctx, AVFrame *frame, buf_size - bytes_read, buf_size); } +if (s->pending_metadata) { +av_dict_copy(&frame->metadata, s->pending_metadata, AV_DICT_APPEND); +av_dict_free(&s->pending_metadata); +} + *got_frame_ptr = 1; return bytes_read; @@ -799,6 +808,7 @@ static av_cold int flac_decode_close(AVCodecContext *avctx) av_freep(&s->decoded_buffer); av_freep(&s->decoded_buffer_33bps); +av_dict_free(&s->pending_metadata); return 0; } -- 2.39.5 (Apple Git-154) ___ 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".