Commit Graph

230 Commits

Author SHA1 Message Date
Anton Khirnov 509afedaaf fftools/ffmpeg_filter: pass vsync method through OutputFilterOptions
Do not read it from OutputStream directly.

Will allow decoupling filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov bc206ed1b3 fftools/ffmpeg_filter: stop accessing encoder AVCodecContext
Pass all the necessary value through OutputFilterOptions.

Will allow decoupling filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov 17702c5f7b fftools/ffmpeg_filter: move the MJPEG format selection hack to muxer setup
That, if anywhere, is a more appropriate place for it.
2024-04-09 10:34:18 +02:00
Anton Khirnov 9d5bf2d69e fftools/ffmpeg_filter: pass enc_timebase through OutputFilterOptions
Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov e903c31fd1 fftools/ffmpeg_filter: pass keep_pix_fmt through OutputFilterOptions
Reduces the need to access OutputStream, which will allow decoupling
filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov b3864e7a08 fftools/ffmpeg_filter: pass ts offset through OutputFilterOptions
Reduces the need to access OutputFile, which will allow decoupling
filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov 651c79da36 fftools/ffmpeg_filter: check that filter type matches output stream type
For simple filtergraphs. For complex filtergraphs they always match.
2024-04-09 10:34:18 +02:00
Anton Khirnov 8e35e33d42 fftools/ffmpeg_filter: stop accessing AVCodecContext.codec
Instead pass the encoder through a newly-added output options struct,
analogous to previously added input options.

Will allow decoupling filtering from encoding in future commits.
2024-04-09 10:34:18 +02:00
Anton Khirnov 8c33085313 fftools/ffmpeg_filter: do not pass OutputStream to set_channel_layout()
It only needs a list of allowed layouts and the requested layout.
2024-04-09 10:34:18 +02:00
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Anton Khirnov 106131bb10 fftools/ffmpeg_filter: remove display matrix if we have applied it 2024-03-28 08:40:01 +01:00
James Almer 767e7d3d2b fftools/ffmpeg_filter: remove unused struct from InputFilterPriv
It's already in InputFilterOptions.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-25 23:23:27 -03:00
Anton Khirnov a9193f7b7d fftools/ffmpeg: add loopback decoding
This allows to send an encoder's output back to decoding and feed the
result into a complex filtergraph.
2024-03-13 08:01:27 +01:00
Anton Khirnov 2ee9362419 fftools/ffmpeg: remove unncessary casts for *_thread() return values
These functions used to be passed directly to pthread_create(), which
required them to return void*. This is no longer the case, so they can
return a plain int.
2024-03-13 08:01:15 +01:00
Anton Khirnov f5d03b972c fftools/ffmpeg: simplify propagating fallback parameters from decoders to filters
Current callstack looks like this:
* ifilter_bind_ist() (filter) calls ist_filter_add() (demuxer);
* ist_filter_add() opens the decoder, and then calls
  dec_add_filter() (decoder);
* dec_add_filter() calls ifilter_parameters_from_dec() (i.e. back into
  the filtering code) in order to give post-avcodec_open2() parameters
  to the filter.

This is unnecessarily complicated. Pass the parameters as follows
instead:
* dec_init() (which opens the decoder) returns post-avcodec_open2()
  parameters to its caller (i.e. the demuxer) in a parameter-only
  AVFrame
* the demuxer passes these parameters to the filter in
  InputFilterOptions, together with other filter options
2024-03-13 08:01:15 +01:00
Anton Khirnov cabeac9123 fftools/ffmpeg_filter: add logging for binding inputs to demuxer streams 2024-03-13 08:01:15 +01:00
Anton Khirnov cb0ec854fd fftools/ffmpeg_filter: move filtergraph input type check to a better place
Perform it right after we figure out what the type is.
2024-03-13 08:01:15 +01:00
Anton Khirnov 7b51523f12 fftools/ffmpeg_opt: merge init_complex_filters() and check_filter_outputs()
The first of these binds inputs of complex filtergraphs to demuxer
streams (with a misleading comment claiming it *creates* complex
filtergraphs).

The second ensures that all filtergraph outputs are connected to an
encoder.

Merge them into a single function, which simplifies the ffmpeg_filter
API, is shorter, and will also be useful in following commits.

Also, rename misleadingly-named init_input_filter() to
fg_complex_bind_input().
2024-03-13 08:01:15 +01:00
Anton Khirnov 6f2acd7a9c fftools/ffmpeg_filter: drop unused InputFilterPriv.ist
Outside of ifilter_bind_ist(), there are no longer any assumptions about
about filter inputs being fed by an InputStream.
2024-03-13 08:01:15 +01:00
Anton Khirnov daca5d1241 fftools/ffmpeg_filter: refactor setting input timebase
Treat it analogously to stream parameters like format/dimensions/etc.
This is functionally different from previous code in 2 ways:
* for non-CFR video, the frame timebase (set by the decoder) is used
  rather than the demuxer timebase
* for sub2video, AV_TIME_BASE_Q is used, which is hardcoded by the
  subtitle decoding API

These changes should avoid unnecessary and potentially lossy timestamp
conversions from decoder timebase into the demuxer one.

Changes the timebases used in sub2video tests.
2024-03-13 08:01:15 +01:00
Anton Khirnov f344277a88 fftools/ffmpeg_filter: merge block with the enclosing one
It has no reason to exist.
2024-03-12 09:47:56 +01:00
Anton Khirnov 639208cc6a fftools/ffmpeg_filter: don't forward EOF in close_output()
The caller does not need or expect it, and it can lead to terminating
filtering prematurely in case there is more than one output.
2024-03-12 09:47:56 +01:00
Anton Khirnov ce178be8b0 fftools/ffmpeg_filter: do not assume av_buffersrc_get_nb_failed_requests()>0
Apparently it can happen that avfilter_graph_request_oldest() returns
EAGAIN, yet av_buffersrc_get_nb_failed_requests() returns 0 for every
input.

Works around #10795, though the root issue is most likely in the
scale2ref filter.
2024-03-12 09:47:14 +01:00
James Almer b8fef7e9c5 avutil: remove deprecated FF_API_PKT_DURATION
Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-07 08:53:30 -03:00
Anton Khirnov e48055fdce fftools/ffmpeg: remove options deprecated before 6.0 2024-03-01 16:51:11 +01:00
Anton Khirnov a2fc86378a fftools/ffmpeg: declare loop indices inside loops 2024-02-24 11:51:41 +01:00
Anton Khirnov a3f69cdec7 fftools/ffmpeg: cosmetics, vertically align structs 2024-02-21 10:33:20 +01:00
Anton Khirnov 826cfd9997 fftools/ffmpeg_filter: pass framerate through InputFilterOptions
Rather than read it directly from InputStream.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.
2024-02-21 10:27:20 +01:00
Anton Khirnov fef3052df3 fftools/ffmpeg_filter: pass autorotate/reinit flags through InputFilterOptions
Rather than read them directly from InputStream.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.
2024-02-21 10:27:20 +01:00
Anton Khirnov 6315f78e0c fftools/ffmpeg_filter: pass sub2video canvas size through InputFilterOptions
Rather than read them directly from InputStream.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.
2024-02-21 10:27:20 +01:00
Anton Khirnov bd3c1c194b fftools/ffmpeg_filter: accept a name from its upstream input
Do not construct the name manually from input file/stream indices.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.
2024-02-21 10:27:20 +01:00
Anton Khirnov 8f592eb35f fftools/ffmpeg_filter: compute input trim start/end in demuxer
The computation is based on demuxer properties, so that is the more
appropriate place for it. Filter code just receives the desired
start time/duration.
2024-02-21 10:27:20 +01:00
Anton Khirnov 09438d6529 fftools/ffmpeg_filter: stop taking display matrix from global side data
It should never be necessary now that decoders propagate global side
data to frames.
2024-02-21 10:27:20 +01:00
Niklas Haas f7b1017d73 fftools/ffmpeg_filter: simplify buffersrc arg printing
There's no need to go through full string expansion here.
2024-02-02 13:24:27 +01:00
Anton Khirnov d47bb91f8b fftools/ffmpeg_filter: consolidate decoder/filter type checks
Also perform them earlier.
2024-01-30 09:52:00 +01:00
Anton Khirnov 1ea2e757f7 fftools/ffmpeg_filter: do not end filtering when a graph input EOFs
There may be other inputs or sources in the filtergraph. Propagate the
EOF to the scheduler and continue filtering.

Fixes #10803
2024-01-27 09:24:29 +01:00
Marton Balint 90bef6390f fftools/ffmpeg_filter: log an information message about filter graph reconfigurations
Filter graph reconfigurations can cause nontrivial issues, e.g. PTS
discontinuities, so it is better to warn the user about them.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-01-07 22:47:22 +01:00
Marton Balint 324be730fc fftools/ffmpeg_filter: honor -reinit_filters 0 even on changed display matrix
Not sure about honoring it also in case of a hwaccel change, so left that as is
for now.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-01-07 22:47:22 +01:00
Niklas Haas 9613ba95c1 fftools/ffmpeg_filter: configure buffersrc with csp/range
Propagates input metadata to the input filter graph.
2023-12-31 13:35:35 -08:00
Niklas Haas 9d0f361f7f fftools/ffmpeg_filter: don't clear buffersrc params
This memset is bogus, it accomplishes nothing in the best case and
regresses future additions to AVBufferSrcParameters in the worst case.
2023-12-31 13:35:17 -08:00
Anton Khirnov dc2fc5a919 fftools/ffmpeg_filter: only set framerate for video
Otherwise an unitialized stack value would be copied to FPSConvContext.
As it's then never used, it tends not to be a problem in practice,
however it is UB and some compilers warn about it.
2023-12-22 11:39:57 +01:00
Zhao Zhili 42a4c59e59 fftools/ffmpeg_filter: remove semicolon after code block
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-12-21 19:30:11 +08:00
Zhao Zhili 7cd416792a fftools/ffmpeg_filter: fix NULL pointer dereference
In close_output(), a dummy frame is created with format NONE passed
to enc_open(), which isn't prepared for it. The NULL pointer
dereference happened at
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth.

When fgt.graph is NULL, skip fg_output_frame() since there is
nothing to output.

frame #0: 0x0000005555bc34a4 ffmpeg_g`enc_open(opaque=0xb400007efe2db690, frame=0xb400007efe2d9f70) at ffmpeg_enc.c:235:44
frame #1: 0x0000005555bef250 ffmpeg_g`enc_open(sch=0xb400007dde2d4090, enc=0xb400007e4e2daad0, frame=0xb400007efe2d9f70) at ffmpeg_sched.c:1462:11
frame #2: 0x0000005555bee094 ffmpeg_g`send_to_enc(sch=0xb400007dde2d4090, enc=0xb400007e4e2daad0, frame=0xb400007efe2d9f70) at ffmpeg_sched.c:1571:19
frame #3: 0x0000005555bee01c ffmpeg_g`sch_filter_send(sch=0xb400007dde2d4090, fg_idx=0, out_idx=0, frame=0xb400007efe2d9f70) at ffmpeg_sched.c:2154:12
frame #4: 0x0000005555bcf124 ffmpeg_g`close_output(ofp=0xb400007e4e2d85b0, fgt=0x0000007d1790eb08) at ffmpeg_filter.c:2225:15
frame #5: 0x0000005555bcb000 ffmpeg_g`fg_output_frame(ofp=0xb400007e4e2d85b0, fgt=0x0000007d1790eb08, frame=0x0000000000000000) at ffmpeg_filter.c:2317:16
frame #6: 0x0000005555bc7e48 ffmpeg_g`filter_thread(arg=0xb400007eae2ce7a0) at ffmpeg_filter.c:2836:15
frame #7: 0x0000005555bee568 ffmpeg_g`task_wrapper(arg=0xb400007d8e2db478) at ffmpeg_sched.c:2200:21

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-12-21 19:29:53 +08:00
Anton Khirnov 3dc319587f fftools/ffmpeg: deprecate -fps_mode/vsync drop
It depends on the ability of muxers to generate timestamps, which is
itself deprecated.
2023-12-18 08:50:02 +01:00
Anton Khirnov 4224895a87 fftools/ffmpeg: replace OutputStream.file_index by a pointer
Reduces the need to use the output_files global array.
2023-12-14 20:16:53 +01:00
Anton Khirnov 0fcea80b2a fftools/ffmpeg: replace InputStream.file_index by a pointer
Reduces the need to use the input_files global array.
2023-12-14 20:16:53 +01:00
Anton Khirnov 84201d8af6 fftools/ffmpeg_filter: move FilterGraph.graph to FilterGraphThread
The AVFilterGraph is fully owned by the filtering thread and should
never be accessed outside of it.
2023-12-14 20:16:53 +01:00
Anton Khirnov 9d7000b1be fftools/ffmpeg: attach wallclock timing information to packets and frames
Will become useful in following commits.
2023-12-14 08:11:05 +01:00
Anton Khirnov d119ae2fd8 fftools/ffmpeg: convert to a threaded architecture
Change the main loop and every component (demuxers, decoders, filters,
encoders, muxers) to use the previously added transcode scheduler. Every
instance of every such component was already running in a separate
thread, but now they can actually run in parallel.

Changes the results of ffmpeg-fix_sub_duration_heartbeat - tested by
JEEB to be more correct and deterministic.
2023-12-12 08:24:18 +01:00
Anton Khirnov 9b8cc36ce0 fftools/ffmpeg: add thread-aware transcode scheduling infrastructure
See the comment block at the top of fftools/ffmpeg_sched.h for more
details on what this scheduler is for.

This commit adds the scheduling code itself, along with minimal
integration with the rest of the program:
* allocating and freeing the scheduler
* passing it throughout the call stack in order to register the
  individual components (demuxers/decoders/filtergraphs/encoders/muxers)
  with the scheduler

The scheduler is not actually used as of this commit, so it should not
result in any change in behavior. That will change in future commits.
2023-12-12 08:24:18 +01:00