Commit graph

65 commits

Author SHA1 Message Date
Zhao Zhili
44ad73031d avcodec/bsf/lcevc_metadata: fix copy-paste typo in chroma loc setup
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-03-25 12:19:46 +00:00
James Almer
d61d724905 avcodec/bsf/lcevc_metadata: write Aditional Info blocks after the Global Config block
Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-24 11:14:17 -03:00
Andreas Rheinhardt
9d97771bc6 avcodec/bsf/extract_extradata: Remove pointless checks
It doesn't hurt to keep track of filtered_size:
The end result will be ignored if extradata is not removed
from the bitstream.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-21 15:05:17 +00:00
Andreas Rheinhardt
1dd853010a avcodec/bsf/extract_extradata: Redo extracting LCEVC extradata
Changes compared to the current version include:
1. We no longer use a dummy PutByteContext on the first pass
for checking whether there is extradata in the NALU. Instead
the first pass no longer writes anything to any PutByteContext
at all; the size information is passed via additional int*
parameters. (This no longer discards const when initializing
the dummy PutByteContext, fixing a compiler warning.)
2. We actually error out on invalid data in the first pass,
ensuring that the second pass never fails.
3. The first pass is used to get the exact sizes of both
the extradata and the filtered data. This obviates the need
for reallocating the buffers lateron. (It also means
that the extradata side data will have been allocated with
av_malloc (ensuring proper alignment) instead of av_realloc().)
4. The second pass now writes both extradata and (if written)
the filtered data instead of parsing the NALUs twice.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-21 15:05:17 +00:00
Andreas Rheinhardt
548b9f5ca7 avcodec/bsf/extract_extradata: Inline constants
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-03-21 15:05:17 +00:00
James Almer
2556db6173 avcodec/bsf/extract_extradata: don't use a NULL pointer to initialize an empty PutByteContext
Fixes UB in the form or adding a 0 offset to a NULL pointer, and substracting a
NULL pointer from another.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:27:07 -03:00
James Almer
5ebd50415f avcodec/bsf/extract_extradata: reallocate buffers with the final used size
The buffers are allocated using the worst case scenario of the entire NALU
being written, when this is in many times not the case.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:27:01 -03:00
James Almer
1434d99b19 avcodec/bsf/extract_extradata: write correct length start codes for LCEVC
The specification for LCEVC states that start codes may be three or four bytes
long except for the first NALU in an AU, which must be four bytes long.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:20:06 -03:00
James Almer
d1431d3f50 avcodec/bsf/extract_extradata: write correct length start codes for h26x
The specification for H.26{4,5,6} states that start codes may be three or four
bytes long long except for the first NALU in an AU, and for NALUs of parameter
set types, which must be four bytes long.
This is checked by ff_cbs_h2645_unit_requires_zero_byte(), which is made
available outside of CBS for this change.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-15 19:20:06 -03:00
Michael Niedermayer
f84c859ec5 avcodec/bsf/extract_extradata: Replace incorrect size accounting
Fixes: out of array writes
Fixes: 492054712/clusterfuzz-testcase-minimized-ffmpeg_BSF_EXTRACT_EXTRADATA_fuzzer-5705993148497920

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-13 02:03:59 +00:00
James Almer
125bb2e045 avcodec/lcevc_parser: Check that block_size is not negative
Based on 248b481c33

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-09 18:39:33 -03:00
Michael Niedermayer
248b481c33 avcodec/bsf/extract_extradata: Check that block_size is not negative
Fixes: out of array access
Fixes: 490576036/clusterfuzz-testcase-minimized-ffmpeg_BSF_EXTRACT_EXTRADATA_fuzzer-4605696279904256

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-08 23:34:14 +00:00
James Almer
863c748144 avcodec/bsf/extract_extradata: remove extradata blocks from supported LCEVC NALUs
Given we rewrite these NALUs to remove the encoded data blocks to export as extradata,
we need to do the inverse to remove SC, GC and AI blocks to export as filtered data in
packes.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-03 09:05:45 -03:00
James Almer
3607a10dc3 avcodec/bsf/extract_extradata: simplify a switch statement
And use named defines. Will come in handy the following commit.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-03 09:05:45 -03:00
James Almer
c893117048 avcodec/bsf/extract_extradata: fix writing filtered LCEVC NALUs when removing extradata
write_lcevc_nalu() is meant only for IDR and NON_IDR NALUs. For everything else, just
copy it unchanged.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-03-03 09:05:45 -03:00
James Almer
e869426a8c avcodec/bsf/extract_extradata: remove dead code
Applied accidentally in 3dba9eb806.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-02-28 19:42:06 -03:00
James Almer
e245f4d5cf avcodec/bsf: add a LCEVC metadata bitstream filter
Signed-off-by: James Almer <jamrial@gmail.com>
2026-02-28 16:14:40 -03:00
James Almer
3dba9eb806 avcodec/bsf/extract_extradata: add support for LCEVC
Signed-off-by: James Almer <jamrial@gmail.com>
2026-02-28 16:12:33 -03:00
Zhao Zhili
86d2fae59f avcodec: use int instead of enum for AVOption fields
AVOption with AV_OPT_TYPE_INT assumes the field is int (4 bytes),
but enum size is implementation-defined and may be smaller.
This can cause memory corruption when AVOption writes 4 bytes
to a field that is only 1-2 bytes, potentially overwriting
adjacent struct members.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-02-26 11:40:09 +08:00
Kacper Michajłow
fa36645f7e avcodec/bsf/dovi_rpu: fix typo
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-02-12 00:56:21 +00:00
Gyan Doshi
43dbc011fa avcodec/bsf/setts: add option prescale
When prescale is enabled, time fields are converted to the output
timebase before expression evaluation. This allows option specification
even if the input timebase is unknown.
2026-01-19 16:51:47 +05:30
Gyan Doshi
1ccd2f6243 avcodec/bsf/setts: rescale TS when changing TB
The setts bsf has an option to change TB. However the filter only
changed the TB and did not rescale the ts and duration, so it
effectively and silently stretched or squeezed the stream.

The pts, dts and duration are now rescaled to maintain temporal fidelity.
2026-01-19 16:51:31 +05:30
Zhao Zhili
2d241202ff avcodec/bsf/dts2pts: add hevc support 2025-11-05 15:13:54 +00:00
Zhao Zhili
5f15734d92 avcodec/bsf/dts2pts: fix return 0 on error path 2025-11-05 15:13:54 +00:00
Zhao Zhili
91b2fe71cc avcodec/bsf/dts2pts: remove always true check 2025-11-05 15:13:54 +00:00
Andreas Rheinhardt
635cb4543f avcodec/bsf/ahx_to_mp2: Don't output uninitialized data
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-27 17:57:15 +02:00
Paul B Mahol
b2e821310b avcodec: add AHX decoder
(cherry picked from commit 039dc23d185214b8b0ef2bbccae197ceb5ad42a2)
2025-09-22 23:46:29 +00:00
Andreas Rheinhardt
0ba0cf94db avcodec/bsf/noise: Avoid allocation for string
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-13 20:45:42 +00:00
Jacob Lifshay
925fad499d lavc/bsf/smpte436m_to_eia608: fix memory leak -- forgot to free input av_packet
Signed-off-by: Jacob Lifshay <programmerjake@gmail.com>
2025-08-10 01:21:44 +00:00
Jacob Lifshay
f0a53917e3 lavc/bsf/eia608_to_smpte436m: fix memory leak -- forgot to free input av_packet
reported in https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20024#issuecomment-2405

Reported-by: Sean McGovern <gseanmcg@gmail.com>
Signed-off-by: Jacob Lifshay <programmerjake@gmail.com>
2025-08-10 01:21:44 +00:00
Jacob Lifshay
0271d0423a
lavc: add eia608_to_smpte436m bitstream filter
Signed-off-by: Jacob Lifshay <programmerjake@gmail.com>
2025-08-08 03:04:42 -07:00
Jacob Lifshay
aa5b9db7bd
lavc: add smpte436m_to_eia608 bitstream filter
Signed-off-by: Jacob Lifshay <programmerjake@gmail.com>
2025-08-08 03:04:42 -07:00
Timo Rothenpieler
262d41c804 all: fix typos found by codespell 2025-08-03 13:48:47 +02:00
Andreas Rheinhardt
8d45dc858e avcodec/dovi_rpuenc: Avoid intermediate codec par in ff_dovi_configure()
It invalidates (removes by duplicates)  AVCodecContext.extradata
and AVCodecContext.coded_side_data which is quite surprising
and leads to bugs like #11617 where an AVCPBProperties
is used after it has been freed in ff_dovi_configure().

Reported-by: Ayose
Reviewed-by: Niklas Haas <ffmpeg@haasn.xyz>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-05-30 19:35:06 +02:00
Zhao Zhili
25812d3033 avcodec/bsf/h264_mp4toannexb: Fix mixed bitstream format
This bsf converts AV_PKT_DATA_NEW_EXTRADATA side data in avcc format
to in-band annexb format. However, the side data wasn't been removed
and copied from input packet to output packet. So the output packet
has mixed bitstream format. We don't support mixed bitstream format.
For example, h264_metadata report error in the following case:

ffmpeg -i foo.flv \
  -bsf:v "h264_mp4toannexb,h264_metadata" \
  -c copy -f null

This patch removed NEW_EXTRADATA side data after process.

This patch also add a check so only NEW_EXTRADATA in avcc format is
processed. NEW_EXTRADATA in annexb format is copied to output as is.

Reported-by: jiangjie <jiangjie618@gmail.com>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2025-04-29 15:25:08 +08:00
Mark Thompson
de42e06b5b lavc: APV metadata bitstream filter 2025-04-27 15:52:30 +01:00
James Almer
75ade2dd49 avcodec/hevc_mp4toannexb: prepend extradata before the leading PS for an IRAP
Parameter sets may be coded in the packet before an IRAP (as is the case for
the hev1 ISO-BMFF brand), and they should have priority as they may override
the extradata ones.
As such, prepend the extradata PS NALUs to the packet PS NALUs if they are
present before an IRAP, instead of prepending them to the IRAP slice.

Should fix ticket #11458.

Signed-off-by: James Almer <jamrial@gmail.com>
2025-02-14 00:21:19 -03:00
Anton Khirnov
56ba57b672 lavc/refstruct: move to lavu and make public
It is highly versatile and generally useful.
2024-12-15 14:03:47 +01:00
gnattu via ffmpeg-devel
248832dd5b avcodec/bsf/dovi_rpu: remove EL when stripping dovi metadata
When RPU is removed EL should also be removed. This only applies to
HEVC as AV1 based Profile 10 does not support EL at all.

Signed-off-by: Gnattu OC <gnattuoc@me.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-11-28 14:15:50 +01:00
James Almer
2eef902d38 avcodec/bsf/dts2pts: don't zero the node buffers when allocating them
It's unnecessary as the entire struct is written to immediately after it's
allocated.
Restores the behavior prior to fec6a8df31.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-09-19 23:23:14 -03:00
James Almer
fec6a8df31 avcodec/bsf/dts2pts: use a RefStruct pool to allocate nodes
Signed-off-by: James Almer <jamrial@gmail.com>
2024-09-16 16:45:00 -03:00
Zhao Zhili
40dda881d6 avcodec/filter_units: Fix extradata and packets can have different bitstream format
Filter init can change extradata from avcc/hvcc to annexb format.
With different passthrough logic, packets can still in avcc/hvcc
format. Use same passthrough logic for init and filter.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-08-24 00:27:15 +08:00
James Almer
a754ee0844 avcodec/h2645_parse: replace three bool arguments in ff_h2645_packet_split with a single flags one
Signed-off-by: James Almer <jamrial@gmail.com>
2024-08-19 20:23:20 -03:00
Niklas Haas
b3d33f11fa avcodec/bsf/dovi_rpu: add new bitstream filter
This can be used to strip dovi metadata, or enable/disable dovi
metadata compression. Possibly more use cases in the future.
2024-08-16 11:48:02 +02:00
Michael Niedermayer
a0f22218f7
bsf/media100_to_mjpegb: Clear output buffer padding
Fixes: use-of-uninitialized-value
Fixes: 70855/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MEDIA100_fuzzer-5537446610141184

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-08-14 18:20:59 +02:00
Josh Allmann
374824cbc7 avcodec/h264_mp4toannexb: Prepend SPS/PPS to buffering period SEI
Encoders may emit a buffering period SEI without a corresponding
SPS/PPS if the SPS/PPS is carried out-of-band, eg with avcc.

During Annex B conversion, this may result in the SPS/PPS being
inserted *after* the buffering period SEI but before the IDR NAL.

Since the buffering period SEI references the SPS, the SPS/PPS
needs to come first.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2024-08-14 13:20:56 +02:00
James Almer
d059ea5663 avcodec/bsf/showinfo: print packet data checksum
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2024-07-13 23:48:34 -03:00
Zhao Zhili
680b3cee1f avcodec/h265_metadata: Add options to set width/height after crop
It's a common usecase to request a video size after crop. Before
this patch, user must know the video size before crop, then set
crop_right/crop_bottom accordingly. Since HEVC can have different
CTU size, it's not easy to get/deduce the video size before crop.
With the new width/height options, there is no such requirement.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-06-07 13:14:46 +08:00
Anton Khirnov
e4601cc339 lavc/hevc*: move to hevc/ subdir 2024-06-04 11:46:27 +02:00
Andreas Rheinhardt
12ded9cd85 avcodec/adts_header: Add ff_adts_header_parse_buf()
Most users of ff_adts_header_parse() don't already have
an opened GetBitContext for the header, so add a convenience
function for them.
Also use a forward declaration of GetBitContext in adts_header.h
as this avoids (implicit) inclusion of get_bits.h in some of
the users that now no longer use a GetBitContext of their own.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-20 12:06:31 +02:00