Commit Graph

103302 Commits

Author SHA1 Message Date
Andreas Rheinhardt
8be701d9f7 avfilter/avfilter: Add numbers of (in|out)pads directly to AVFilter
Up until now, an AVFilter's lists of input and output AVFilterPads
were terminated by a sentinel and the only way to get the length
of these lists was by using avfilter_pad_count(). This has two
drawbacks: first, sizeof(AVFilterPad) is not negligible
(i.e. 64B on 64bit systems); second, getting the size involves
a function call instead of just reading the data.

This commit therefore changes this. The sentinels are removed and new
private fields nb_inputs and nb_outputs are added to AVFilter that
contain the number of elements of the respective AVFilterPad array.

Given that AVFilter.(in|out)puts are the only arrays of zero-terminated
AVFilterPads an API user has access to (AVFilterContext.(in|out)put_pads
are not zero-terminated and they already have a size field) the argument
to avfilter_pad_count() is always one of these lists, so it just has to
find the filter the list belongs to and read said number. This is slower
than before, but a replacement function that just reads the internal numbers
that users are expected to switch to will be added soon; and furthermore,
avfilter_pad_count() is probably never called in hot loops anyway.

This saves about 49KiB from the binary; notice that these sentinels are
not in .bss despite being zeroed: they are in .data.rel.ro due to the
non-sentinels.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-20 12:53:58 +02:00
Andreas Rheinhardt
d53d48c799 fftools/cmdutils: Use avfilter_pad_count() for AVFilter's number of pads
Besides being nicer code this also has the advantage of not making
assumptions about the internal implementation: While it is documented
that the AVFilter.inputs and AVFilter.outputs arrays are terminated
by a zeroed sentinel, one is not allowed to infer that one can just
check avfilter_pad_get_name(padarray, i) to see whether one has reached
the sentinel:
It could be that the pointer to the string is contained
in a different structure than AVFilterPad that needs to be accessed
first: return pad->struct->string.
It could be that for small strings an internal buffer in
AVFilterPad is used (to avoid a relocation) whereas for longer strings
an external string is used; this is useful to avoid relocations:
return pad->string_ptr ? pad->string_ptr : pad->interal_string
Or it could be that the name has a default value:
return pad->name ? pad->name : "default"
(This actually made sense for us because the name of most of our
AVFilterPads is just "default"; doing so would save lots of relocations.)

The only thing one is allowed to infer from the existence of the
sentinel is that one is allowed to use avfilter_pad_count() to get
the number of pads. Therefore it is used.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-20 12:52:33 +02:00
Andreas Rheinhardt
c83a7dd25f avcodec/h264_parser: Fix undefined left shift
Use an uint32_t for the NAL unit size of an AVC H.264 NAL unit instead
of an int as a left shift of a signed value is undefined behaviour
if the result doesn't fit into the target type.

Also make the log message never output negative lengths.

Fixes: left shift of 16711968 by 8 places cannot be represented in type 'int'
Fixes: 36601/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-6581933285965824

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-20 12:19:12 +02:00
Andreas Rheinhardt
29bf3fafa0 avfilter/avfiltergraph: Don't use AVClass * for logcontext
Forgotten in 57fa314090.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-20 12:09:07 +02:00
Paul B Mahol
d5b3e0403e avfilter/vf_colorcorrect: fix average analyze mode and add minmax mode 2021-08-20 10:55:33 +02:00
Nicolas George
b06f12b68b lavfi/formats: document the negotiation process 2021-08-20 10:26:36 +02:00
Nicolas George
24de2b7618 lavfi/formats: rename AVFilterNegotiation.nb to nb_mergers 2021-08-20 10:26:36 +02:00
Nicolas George
703c3c4151 lavfi/formats: cosmetic: move negotiation stuff at the end
It was between AVFilterFormats and AVFilterChannelLayouts.
2021-08-20 10:26:36 +02:00
Paul B Mahol
7871b3ca5e avfilter/vf_signalstats: avoid doubles in calculations 2021-08-20 07:34:17 +02:00
Paul B Mahol
ed6ea4f9ca avfilter/vf_chromakey: fix diff scaling for chromahold filter 2021-08-20 07:25:16 +02:00
Christopher Degawa
8990c5869e get_cabac_inline_x86: Don't inline if 32-bit clang on windows
Fixes https://trac.ffmpeg.org/ticket/8903

relevant https://github.com/msys2/MINGW-packages/discussions/9258

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2021-08-19 22:29:23 +03:00
Steven Liu
c64d56a2f5 avformat/hlsenc: minus subtitle streams count when subtitle stream between video and audio streams
because subtitles streams will be written to webvtt m3u8 list
so the stream index should minus subtitles streams count when subtitle
between audio and video streams.
testcase:
before patch:
ffmpeg -i input -map 0🅰️0 -map 0:s:0 -map 0✌️0 -f hls aaaa.m3u8
will EXC_BAD_ACCESS

after patch:
ffmpeg -i input -map 0🅰️0 -map 0:s:0 -map 0✌️0 -f hls aaaa.m3u8
will ok

Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2021-08-19 18:24:15 +08:00
Steven Liu
5dc1b4b997 avformat/hlsenc: set http options before use delete http method
Fix ticket: 9338
Set options which set by user from parent options.

Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2021-08-19 18:24:12 +08:00
Paul B Mahol
79934cc702 avfilter/vf_paletteuse: do not use in dithering transparent palette 2021-08-19 09:45:09 +02:00
Paul B Mahol
6d09de90d1 avfilter/vf_paletteuse: fix some integer overflows 2021-08-19 09:45:09 +02:00
Paul B Mahol
835eb0a556 avfilter/vf_paletteuse: do not sort transparency color
Make last palette entry always transparent color.
Fixes wrong filtered output with new=1 option set.
2021-08-19 01:49:58 +02:00
Paul B Mahol
124eec942a avfilter/vf_palettegen: fix integer overflow 2021-08-19 01:29:11 +02:00
Hu Weiwen
4cdab8d022 movenc: Get rid of frag_start
"frag_start" is redundant, and every occurance can be replaced with cluster[0].dts - start_dts

The proof of no behaviour changes: (All line number below is based on commit bff7d662d7)

"frag_start" is read at 4 place (with all possible call stacks):

mov_write_packet
  ...
  mov_flush_fragment
    mov_write_moof_tag
      mov_write_moof_tag_internal
        mov_write_traf_tag
          mov_write_tfxd_tag (#1)
          mov_write_tfdt_tag (#2)
      mov_add_tfra_entries (#3)
      mov_write_sidx_tags
        mov_write_sidx_tag (#4)

mov_write_trailer
  mov_auto_flush_fragment
    mov_flush_fragment
      ... (#1 #2 #3 #4)
  mov_write_sidx_tags
    mov_write_sidx_tag (#4)
  shift_data
    compute_sidx_size
      get_sidx_size
        mov_write_sidx_tags
          mov_write_sidx_tag (#4)

All read happens in "mov_write_trailer" and "mov_write_moof_tag". So we need to prove no behaviour change in these two
functions.

Condition 1: for every track that have "trk->entry == 0", trk->frag_start == trk->track_duration.

Condition 2: for every track that have "trk->entry > 0", trk->frag_start == trk->cluster[0].dts - trk->start_dts.

Definition 1: "Before flush" means just before the invocation of "mov_flush_fragment", except for the auto-flush case in
"mov_write_single_packet", which means before L5934.

Lemma 1: If Condition 1 & 2 is true before flush, Condition 1 & 2 is still true after "mov_flush_fragment" returns.

    Proof:
    No update to the tracks that have "trk->entry == 0" before flushing, so we only consider tracks that have "trk->entry > 0":

    Case 1: !moov_written and moov will be written in this iteration
        trk->entry = 0                                                                    L5366
        trk->frag_start == trk->cluster[0].dts - trk->start_dts                           Lemma condition
        trk->frag_start += trk->start_dts + trk->track_duration - trk->cluster[0].dts;    L5363
        So trk->entry == 0 && trk->frag_start == trk->track_duration
    Case 2: !moov_written and moov will NOT be written in this iteration
        nothing changed
    Case 3: moov_written
        trk->entry = 0                                                                    L5445
        trk->frag_start == trk->cluster[0].dts - trk->start_dts                           Lemma condition
        trk->frag_start += trk->start_dts + trk->track_duration - trk->cluster[0].dts;    L5444
        So trk->entry == 0 && trk->frag_start == trk->track_duration

    Note that trk->track_duration may be updated for the tracks that have "trk->entry > 0" (mov_write_moov_tag will
    update track_duration of "tmcd" track, but it must have 1 entry). But in all case, trk->frag_start is also updated
    to consider the new value.

Lemma 2: If Condition 1 & 2 is true before "ff_mov_write_packet" invocation, Condition 1 & 2 is still true after it returns.

    Proof:
    Only the track corresponding to the pkt is updated, and no update to relevant variables if trk->entry > 0 before invocation.
    So we only need to prove "trk->frag_start == trk->cluster[0].dts - trk->start_dts" after trk->entry increase from 0 to 1.

    Case 1: trk->start_dts == AV_NOPTS_VALUE
        Case 1.1: trk->frag_discont && use_editlist
            trk->cluster[0].dts = pkt->dts        at L5741
            trk->frag_start = pkt->pts            at L5785
            trk->start_dts = pkt->dts - pkt->pts  at L5786
            So trk->frag_start == trk->cluster[0].dts - trk->start_dts
        Case 1.2: trk->frag_discont && !use_editlist
            trk->cluster[0].dts = pkt->dts        at L5741
            trk->frag_start = pkt->dts            at L5790
            trk->start_dts = 0                    at L5791
            So trk->frag_start == trk->cluster[0].dts - trk->start_dts
        Case 1.3: !trk->frag_discont
            trk->cluster[0].dts = pkt->dts        at L5741
            trk->frag_start = 0                   init
            trk->start_dts = pkt->dts             at L5779
            So trk->frag_start == trk->cluster[0].dts - trk->start_dts
    Case 2: trk->start_dts != AV_NOPTS_VALUE
        Case 2.1: trk->frag_discont
            trk->cluster[0].dts = pkt->dts                at L5741
            trk->frag_start = pkt->dts - trk->start_dts   at L5763
            So trk->frag_start == trk->cluster[0].dts - trk->start_dts
        Case 2.2: !trk->frag_discont
            trk->cluster[0].dts = trk->start_dts + trk->track_duration  at L5749
            trk->track_duration == trk->frag_start                      Lemma condition
            So trk->frag_start == trk->cluster[0].dts - trk->start_dts

Lemma 3: Condition 1 & 2 is true in all case before and after "ff_mov_write_packet" invocation, before flush and after
         "mov_flush_fragment" returns.

    Proof: All updates to relevant variable happen either in "ff_mov_write_packet", or during flush. And Condition 1 & 2
           is true initially. So with lemma 1 & 2, we can prove this use induction.

Noticed that all read of "frag_start" only happen in "trk->entry > 0" branch. Now we need to prove Condition 2 is true
before each read.

Because no update to variables relevant to Condition 2 between "before flush" and "mov_write_moof_tag" invocation, we
can conclude Condition 2 is true before every invocation of "mov_write_moof_tag". No behaviour change in
"mov_write_moof_tag" is proved.

In "mov_write_trailer", No update to relevant variables after the last flush and before the invocation of
"mov_write_sidx_tag". So no behaviour change to "mov_write_trailer" is proved.

Q.E.D.

Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>
Signed-off-by: Martin Storsjö <martin@martin.st>
2021-08-18 13:07:46 +03:00
Hu Weiwen
2b77a2f723 movenc: Ensure no separate moof written for empty track
track->mdat_buf can be not NULL while the track is still empty if the
last packet write failed.

Signed-off-by: Hu Weiwen <sehuww@mail.scut.edu.cn>
Signed-off-by: Martin Storsjö <martin@martin.st>
2021-08-18 13:07:46 +03:00
Jan Ekström
dbe40478e2 avcodec/libx265: improve full range flag setting logic
Unlike libx264, libx265 does not have a separate "unspecified"/"auto"
default for color range, so we do always have to specify it.
Thus, we are required to handle the RGB case on the libavcodec
side to enable the correct value to be written out in in case
of RGB content with unspecified color range being received.

In other words:
1. If the user has set color range specifically, follow that.
2. If the user has not set color range specifically, set full
   range by default in case of RGB and YUVJ pixel formats.
2021-08-18 12:09:37 +03:00
Jan Ekström
7ca71b79f2 avcodec/libx264: leave full range flag unchanged if unknown
By default the x264 full range flag is set to -1. By not setting
it to something else, we can let libx264 handle the RGB case.
Additionally, change the preference order to user-specified range
first, and then any fall-back logic left for the YUVJ pix_fmts.

Fixes the capture part of #9374
2021-08-18 12:09:37 +03:00
Paul B Mahol
ed47a4a842 avcodec: add SMC encoder 2021-08-18 08:55:56 +02:00
Andreas Rheinhardt
515e7fbce1 avfilter/avfilter: Remove unused feature to add pads in the middle
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17 21:20:59 +02:00
Andreas Rheinhardt
1e35744a4c avfilter/internal: Replace AVFilterPad.needs_writable by flags
It will be useful in the future when more flags are added.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17 21:10:45 +02:00
Andreas Rheinhardt
f60c3ca136 avfilter/audio: Don't call av_get_channel_layout_nb_channels twice
Also makes the assert-string shorter.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17 19:13:40 +02:00
Andreas Rheinhardt
1aa640c7d7 avfilter/internal: Combine get_(audio|video)_buffer into union
These fields are mutually exclusive, so putting them in a union
is possible and makes AVFilterPad smaller.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17 19:13:16 +02:00
Andreas Rheinhardt
90550856e5 avfilter/avfilter: Remove redundant assignment
av_frame_copy_props() already copies pts.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17 19:12:45 +02:00
Andreas Rheinhardt
8c53b14599 avutil/opt: Document actual behaviour of av_opt_copy a bit more
In particular, document that av_opt_copy() always disentangles
allocated options even on error; this guarantee is needed to e.g.
properly free duplicated thread contexts in libavcodec on error.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-17 19:11:57 +02:00
Haihao Xiang
51a80aacce ffmpeg_hw: Don't ignore key parameters when initializing a hw device
Currently user may use '-init_hw_device type=name' to initialize a hw
device, however the key parameter is ignored when use '-init_hw_device
type=name,key=value'. After applying this patch, user may set key
parameter if needed.

Reviewed-by: Soft Works <softworkz@hotmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-17 10:10:07 -03:00
Michael Niedermayer
7bba0dd638 avcodec/frame_thread_encoder: Free AVCodecContext structure on error during init
Fixes: MemLeak
Fixes: 8281
Fixes: PoC_option158.jpg
Fixes: CVE-2020-22037

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-08-17 10:34:10 +02:00
Nicolas George
318e184022 doc/git-howto: be more strict about commit message formatting.
Explain the format of the first line: "context: summary".
Add examples and explain bad practices.
Make it a section, so that we can link to it.
2021-08-17 10:11:44 +02:00
Paul B Mahol
376ac5b7a8 avfilter/vf_convolve: switch to TX FFT from avutil 2021-08-17 09:15:06 +02:00
Paul B Mahol
8567f1c392 avfilter: add (a)segment filters 2021-08-16 20:26:04 +02:00
Andreas Rheinhardt
7b0e63b7d5 avfilter: Remove init_opaque callback
The last init_opaque callback has been removed in commit
07ffdedf784e86b88074d8d3e08e55752869562a; the opaque argument has been
always NULL since 0acf7e268b.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-16 17:16:09 +02:00
Andreas Rheinhardt
8f51c12f87 avfilter/vf_(guided|program_opencl): Add missing dynamic inputs flag
The code for inserting inpads can't be reached by ff_vsrc_openclsrc
(unsurprising given that it is a source filter), so it didn't get
the flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-16 17:15:38 +02:00
Limin Wang
694ec84ae9 avdevice/decklink: support for more duplex mode for Decklink 8K Pro
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-08-16 10:00:39 +08:00
Limin Wang
13460af456 avdevice/decklink: add level_a configuration option
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-08-16 10:00:39 +08:00
Limin Wang
5f3df7afa6 avdevice/decklink: add sqd configuration option
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-08-16 10:00:39 +08:00
Limin Wang
b923bfc679 avdevice/decklink: add link configuration option
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2021-08-16 10:00:39 +08:00
Paul B Mahol
ca788d184c avfilter/vf_waveform: add option to control strechness of waveform 2021-08-16 01:19:19 +02:00
Paul B Mahol
e0de0aa585 avfilter/vf_colorcorrect: calculate imax/max once at config stage 2021-08-16 01:19:19 +02:00
Paul B Mahol
d42b49fc87 avfilter/vf_colorcorrect: add initial automatic filtering 2021-08-16 01:19:19 +02:00
Andreas Rheinhardt
1cc64146e3 avcodec/options_table: Treat (request_)channel_layout as channel layout
Also adapt some FATE tests to already cover this.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 23:19:35 +02:00
Andreas Rheinhardt
4049b34aca avfilter/vf_fieldorder: Simplify setting common pixel formats
by using ff_set_common_formats().

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 23:18:57 +02:00
Andreas Rheinhardt
c8b1c9f97a avfilter/vf_find_rect: Don't make frame writable unnecessarily
AVFrame.metadata is always owned by its AVFrame, it is not shared
in the first place, so one does not need to make the frame writable
to modify it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 22:49:06 +02:00
Andreas Rheinhardt
631c4db13b avfilter/vf_colorkey: Don't manually make frame writable
Instead, set AVFilterPad.needs_writable.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 22:48:46 +02:00
Andreas Rheinhardt
ce2a77b52e avfilter/vf_despill: Don't manually make frame writable
Instead, set AVFilterPad.needs_writable.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 22:47:45 +02:00
Andreas Rheinhardt
6140eb720e avfilter/vf_lumakey: Don't manually make frame writable
Instead, set AVFilterPad.needs_writable.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 22:47:10 +02:00
Andreas Rheinhardt
2f4b43a5a1 avfilter/vf_paletteuse: Remove redundant freeing code
AVFilter.uninit is called automatically if init fails.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 22:46:33 +02:00
Andreas Rheinhardt
1b20853fb3 avfilter/internal: Factor out executing a filter's execute_func
The current way of doing it involves writing the ctx parameter twice.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 21:33:25 +02:00