Commit Graph

45 Commits

Author SHA1 Message Date
Andreas Rheinhardt
04133eb2d5 fftools/ffmpeg_filter: Avoid inserting hflip filter
The transpose filter has modes equivalent to "rotation by 90°/270°"
followed by horizontal flips.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-23 18:09:46 +01:00
Andreas Rheinhardt
4e21fff19d fftools/ffmpeg_filter: Fix autorotation
In case of an orthogonal transformation av_display_rotation_get()
returns the (anticlockwise) degree that the unit vector in x-direction
gets rotated by; get_rotation in cmdutils.c makes a clockwise degree
out of this. So if one inserts a transpose filter corresponding to
this degree, then the x-vector gets mapped correctly and there are
two possibilities for image of the y-vector, namely the two unit
vectors orthogonal to the image of the x-vector.

E.g. if the x-vector gets rotated by 90° clockwise, then the two
possibilities for the y-vector are the unit vector in x direction
or its opposite. The latter case is a simple 90° rotation for both
vectors* whereas the former is a simple 90° clockwise rotation followed
by a horizontal flip. These two cases can be distinguished by looking
at the x-coordinate of the image of the y-vector, i.e. by looking
at displaymatrix[3]. Similarly for the case of a 270° clockwise
rotation.

These two cases were previously wrong (they were made to match
wrongly parsed exif rotation tag values).

*: For display matrices, the y-axis points downward.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-23 18:09:46 +01:00
Andreas Rheinhardt
2e7ef008e3 fftools/cmdutils: Make allocate_array_elem() return ptr to new element
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-05 13:27:38 +01:00
Andreas Rheinhardt
9d73967b40 fftools/ffmpeg_(filter|opt): Use dedicated pointer for array elem access
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-05 13:27:37 +01:00
Andreas Rheinhardt
3ca1e31e63 fftools/cmdutils: Atomically add elements to list of pointers, fix crash
Currently, adding a (separately allocated) element to a list of pointers
works by first reallocating the array of pointers and (on success)
incrementing its size and only then allocating the new element.
If the latter allocation fails, the size is inconsistent, i.e.
array[nb_array_elems - 1] is NULL. Our cleanup code crashes in such
scenarios.

Fix this by adding an auxiliary function that atomically allocates
and adds a new element to a list of pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-05 13:27:37 +01:00
Anton Khirnov
ab3ef54c8c ffmpeg: only copy bits_per_sample from decoder when it remains valid
I.e. when the only filters that are applied do not modify the frame
data.
2021-12-04 14:08:17 +01:00
Andreas Rheinhardt
efc323062c fftools/ffmpeg_filter: Avoid DynBuf API to improve error checks
choose_pix_fmts() used the dynamic buffer API to write strings;
as is common among uses of this API, only opening the dynamic buffer
was checked, but not the end result, leading to crashes in case
of allocation failure.
Furthermore, some static strings were duplicated; the allocations
performed here were not properly checked: Allocation failure would
be treated as "could not determine pixel format".
The first issue is fixed by switching to the AVBPrint API which allows
to easily perform checks at the end. Furthermore, the internal buffer
avoids almost all allocations in case the AVBPrint is used.
The AVBPrint also allows to solve the second issue in an elegant way,
because it allows to return the static strings directly.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-03 16:12:52 +01:00
Andreas Rheinhardt
cf8925a096 fftools/ffmpeg_filter: Avoid DynBuf-API for writing strings
It is not really natural, it requires internal allocations
of its own and its error handling is horrible (i.e. the implicit
(re)allocations here are unchecked).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-03 16:11:01 +01:00
Anton Khirnov
d013453caa ffmpeg: drop the -deinterlace option
It is undocumented and has been deprecated since 2013.
2021-11-23 11:36:59 +01:00
Chad Fraleigh
a185b526a9 fftools: Constify values from av_dict_get()
Treat values returned from av_dict_get() as const, since they are
internal to AVDictionary.

Signed-off-by: Chad Fraleigh <chadf@triularity.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-18 19:43:32 +01:00
James Almer
ed1a70469e ffmpeg_filter: don't try to autorotate frames with hwaccel pixel formats
The transpose, rotate, hflip, and vflip filters don't support them.
Fixes ticket #9432.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-21 10:41:16 -03:00
James Almer
42fce6fffe ffmpeg: take into account image flipping in the display matrix
This covers only standard rotations.
Fixes part of ticket #6945.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-16 12:57:06 -03:00
James Almer
535a835e51 ffmpeg: use display matrix frame side data for autorotation
And give it priority over stream side data when present.
Fixes part of ticket #6945.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-16 12:46:07 -03:00
James Almer
7453d3482a ffmpeg: let AVFilterGraph parse the filter_threads option
This way the CLI accepts for "filter_threads" the same values as for the
libavcodec specific option "threads".

Fixes FATE with THREADS=auto which was broken in bdc1bdf3f5.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-04 10:35:07 -03:00
Andreas Rheinhardt
f3f9041302 fftools: Remove remnants of resample_opts
These were intended to pass options to auto-inserted avresample
resampling filters. Yet FFmpeg uses swresample for this purpose
(with its own AVDictionary swr_opts similar to resample_opts).
Therefore said options were not forwarded any more since commit
911417f0b34e611bf084319c5b5a4e4e630da940; moreover since commit
420cedd497 avresample options are
not even recognized and ignored any more. Yet there are still
remnants of all of this. This commit gets rid of them.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-03 16:08:19 +02:00
Linjie Fu
7352c370fa Revert "fftools/ffmpeg_filter: fix the flags parsing for scaler"
This reverts commit b3a0548a98.

This breaks the usage of swscale options, scale_sws_opts should be
passed to auto-inserted scale-filters.

Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
2021-08-30 21:27:50 +08:00
Anton Khirnov
834b8ad8a3 ffmpeg_filter: do not override -filter_threads with -threads
When both -filter_threads and -threads are specified, the latter takes
effect. Since -threads is an encoder option and -filter_threads is a
filter option, it makes sense for the -filter_threads to take
precedence.
2021-08-29 18:44:09 +02:00
Anton Khirnov
4a0d918c9e ffmpeg: reset the dict iterator before use 2021-08-29 18:43:01 +02:00
Paul B Mahol
8cbed82b2a fftools/ffmpeg_filter: silence valgrind warning 2021-08-25 22:51:32 +02:00
James Almer
d708add98c fftools/ffmpeg_filter: add a return at the end of non-void functions
Fixes compilation with GCC 11 when configured with --disable-optimizations

Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-06 21:22:49 -03:00
Linjie Fu
b3a0548a98 fftools/ffmpeg_filter: fix the flags parsing for scaler
Scaler relys on "-sws_flags" option to pass the flags to swscale
and scale filter. Currently passing "sws_flags=xxx" as a filter
option to scaler leads to an incorrect option parsing.

Check and change the string to "flags=xxx" and dumped flags information.
(Refer to parse_sws_flags())

CMD:
$ffmpeg -v verbose -i input.mp4 -sws_flags lanczos+bitexact+accurate_rnd \
        -vf format=yuv420p,scale=800x600 -an -vframes 10 -f md5 -

Before:
[auto_scaler_0 @ 0x7f96c3808680] w:iw h:ih flags:'' interl:0
[auto_scaler_0 @ 0x7f96c3808680] w:1920 h:1080 fmt:yuvj420p sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0x0
[Parsed_scale_1 @ 0x7f96c3806e40] w:1920 h:1080 fmt:yuv420p sar:0/1 -> w:800 h:600 fmt:yuv420p sar:0/1 flags:0x0
MD5=ff1d6091690c6fcd36d458d2a9f648ce

After:
[auto_scaler_0 @ 0x7fe94563b4c0] w:iw h:ih flags:'lanczos+bitexact+accurate_rnd' interl:0
[auto_scaler_0 @ 0x7fe94563b4c0] w:1920 h:1080 fmt:yuvj420p sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0xc0200
[Parsed_scale_1 @ 0x7fe945639d00] w:1920 h:1080 fmt:yuv420p sar:0/1 -> w:800 h:600 fmt:yuv420p sar:0/1 flags:0xc0200
MD5=ff1d6091690c6fcd36d458d2a9f648ce

Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
2021-08-05 22:23:49 +08:00
Andreas Rheinhardt
420cedd497 libavresample: Remove deprecated library
Deprecated in c29038f304.
The resample filter based upon this library has been removed as well.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:13 -03:00
Andreas Rheinhardt
4e39cd67b7 fftools/ffmpeg_filter: Fix check for mjpeg encoder
The MJPEG encoder supports some pixel format/color range combinations
only when strictness is set to unofficial or less. Before commit
059fc2d9da said encoder's pix_fmts array
only included the pixel formats supported with default strictness.
When strictness was <= unofficial, fftools/ffmpeg_filter.c used
an extended list of pixel formats instead of the encoder's including
the pixel formats only supported when strictness <= unofficial.

Said commit turned the logic around: The encoder's pix_fmts array now
included all pixel formats and fftools/ffmpeg_filter.c instead used
a small list of all pixel formats supported when strictness is >
unofficial and the encoder's pixel formats instead. In particular,
the codec's pix_fmt is not used when strictness is normal.

This works for the mjpeg encoder; yet it did not work for other
(hardware-based) mjpeg encoders, because the check for whether one is
using the MJPEG encoder is wrong: It just checks the codec id.
So if one used strict unofficial with a hardware-accelerated MJPEG
encoder before commit 059fc2d9da, the unofficial (non-hardware)
pixel formats of the MJPEG encoder would be used; since said commit
the codec's pixel formats are overridden at ordinary strictness
by the ordinary MJPEG pixel formats. This leads to format conversion
errors lateron which were reported in #9186.

The solution to this is to check AVCodec.name instead of its id.

Fixes ticket #9186.

Tested-by: Eoff, Ullysses A <ullysses.a.eoff@intel.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-13 21:58:25 +02:00
Andreas Rheinhardt
4782124b90 fftools/ffmpeg_filter: Don't needlessly copy string
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:53:40 +02:00
Andreas Rheinhardt
6b72410e01 fftools/ffmpeg_filter: Don't write string that is never used
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:53:33 +02:00
Andreas Rheinhardt
80399c7910 fftools/ffmpeg_filter: Avoid allocations when configuring output filters
Use an AVBPrint to handle the (typically short) strings involved here.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:51:50 +02:00
Andreas Rheinhardt
059fc2d9da avcodec/mjpegenc: Include all supported pix_fmts in mpegenc pix_fmts
Currently said list contains only the pixel formats that are always
supported irrespective of the range and the value of
strict_std_compliance. This makes the MJPEG encoder an outlier as all
other codecs put all potentially supported pixel formats into said list
and error out if the chosen pixel format is unsupported. This commit
brings it therefore in line with the other encoders.

The behaviour of fftools/ffmpeg_filter.c has been preserved. A more
informed decision would be possible if colour range were available
at this point, but it isn't.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-10 03:48:41 +02:00
Andreas Rheinhardt
5ad0eb936c fftools/ffmpeg_filter: Don't use deprecated function
avcodec_find_best_pix_fmt_of_2 has been moved to libavutil in
617e866e25.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-26 18:28:26 +01:00
Andreas Rheinhardt
2367affc2c fftools/ffmpeg_filter: Make functions only used locally static
Also remove some declarations of inexistent functions while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-02 23:53:30 +01:00
Andreas Rheinhardt
2166d8d6b2 fftools/ffmpeg_filter: Remove ist_in_filtergraph
Unused since af1761f7b5.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-02 23:53:30 +01:00
Andreas Rheinhardt
a40c158eda fftools/ffmpeg_filter: Remove choose_sample_fmt
Unused since 6b35a83214.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-02-02 23:53:30 +01:00
Gyan Doshi
d16b0a4bf0 ffmpeg: remove dead code for -vol
It is applied via configure_input_audio_filter()
2021-01-31 17:21:32 +05:30
Andreas Rheinhardt
0086432fc7 fftools, libavcodec, libavfilter: Add const to some AVCodec *
The user has no business modifying the underlying AVCodec.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-11 14:42:36 +02:00
Nicolas George
697fb09e3d ffmpeg: add auto_conversion_filters option. 2020-09-08 14:16:08 +02:00
Linjie Fu
0b511bd9a5 fftools/ffmpeg_filter: add -autoscale to disable/enable the default scale
Currently, ffmpeg inserts scale filter by default in the filter graph
to force the whole decoded stream to scale into the same size with the
first frame. It's not quite make sense in resolution changing cases if
user wants the rawvideo without any scale.

Using autoscale/noautoscale as an output option to indicate whether auto
inserting the scale filter in the filter graph:
    -noautoscale or -autoscale 0:
    disable the default auto scale filter inserting.

ffmpeg -y -i input.mp4 out1.yuv -noautoscale out2.yuv -autoscale 0 out3.yuv

Update docs.

Suggested-by:  Mark Thompson <sw@jkqxz.net>
Reviewed-by:   Nicolas George <george@nsup.org>
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2020-06-18 16:31:09 +08:00
James Almer
0a3ba58b44 fftools/ffmpeg_filter: check the codec's descriptor to see if it's lossless
Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-21 12:32:15 -03:00
Mark Thompson
e254212405 ffmpeg: Make filter hardware device selection clearer
Also move it into a dedicated function in the hardware file.
2020-04-26 18:38:25 +01:00
Jan Ekström
7ba3ea212f ffmpeg: explicitly handle sub2video subpicture initialization
Each time the sub2video structure is initialized, the sub2video
subpicture is initialized together with the first received heartbeat.
The heartbeat's PTS is utilized as the subpicture start time.

Additionally, add some documentation on the stages.
2020-03-16 19:35:17 +02:00
Zhao Zhili
609285af51 fftools/ffmpeg_filter: remove sws_param option from buffersrc
The option is deprecated and ignored by buffersrc.
2019-12-31 14:24:34 +01:00
Jan Ekström
8cf757ee8d ffmpeg_filter: initialize sub2video.end_pts together with last_pts
This way re-initializations properly update end_pts, enabling
sub2video_heartbeat to call sub2video_update as expected to re-init
the sub2video AVFrame's contents and to feed a frame into the filter
chain.

This then fixes memory usage ballooning due to framesync waiting
for secondary input in case of no actual subtitle samples being present
for a while in source after a re-init occurs.
2019-02-21 20:13:21 +02:00
Gyan Doshi
54109b1d14 ffmpeg: skip disabled streams
Fully discarded streams can't be selected for output or mapped or filtered.
Previously, a few packets from such streams, probably buffered for
stream probing, would get smuggled into output files.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-01-02 22:29:11 +01:00
Jun Zhao
df9fe79b3c fftools/ffmpeg_filter: Replace the number by macro for bprint init
Replace the number by macro for bprint init.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
2018-06-17 09:59:33 +08:00
Marton Balint
7033654f7f Use AV_PIX_FMT_FLAG_ALPHA for detecting transparency where nb_components was used
Temporarily keep the old method for ffmpeg_filters.c choose_pix_fmt and
avfiltergraph.c pick_format() until a paletted pixel format without alpha is
introduced.

Signed-off-by: Marton Balint <cus@passwd.hu>
2018-04-30 21:51:31 +02:00
DHE
ae61bcbdf8 ffmpeg_filter: use nb_threads=1 on unused filtergraph
Signed-off-by: DHE <git@dehacked.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-19 04:38:29 +01:00
James Almer
fd5f4ac081 Merge commit 'c95169f0ec68bdeeabc5fde8aa4076f406242524'
* commit 'c95169f0ec68bdeeabc5fde8aa4076f406242524':
  build: Move cli tool sources to a separate subdirectory

Merged-by: James Almer <jamrial@gmail.com>
2017-10-01 18:26:36 -03:00