Commit Graph

1456 Commits

Author SHA1 Message Date
Anton Khirnov 2f1bc3b424 fftools/cmdutils: include OPT_PERFILE in OPT_OFFSET
And analogously OPT_OFFSET in OPT_SPEC. Previously the inclusion would
be implicit and required all code to remember this.
2023-12-22 11:39:57 +01:00
Anton Khirnov 66fcfc0009 fftools/cmdutils: renumber option flags sequentially
Also, document them.
2023-12-22 11:39:57 +01:00
Anton Khirnov 5b1b132072 fftools/cmdutils: rename HAS_ARG to OPT_FUNC_ARG
For consistent namespacing with other option flags. Also, document and
enforce that it can only be set for func-type options.
2023-12-22 11:39:57 +01:00
Anton Khirnov d2e479a429 fftools: split off option types from other flags
These values are not actually flags, as only one of them can be
meaningfully set.
2023-12-22 11:39:57 +01:00
Anton Khirnov 074abeb57e fftools/ffmpeg_opt: move deprecated options to the end of the list
This way they don't clutter this already-cluttered code even further.
2023-12-22 11:39:57 +01:00
Anton Khirnov b472c46a70 fftools/cmdutils: simplify handling of the HAS_ARG option flag
This option flag only carries nontrivial information for options that
call a function, in all other cases its presence can be inferred from
the option type (bool options do not have arguments, all other types do)
and is thus nothing but useless clutter.

Change the option parsing code to infer its value when it can, and drop
the flag from options where it's not needed.
2023-12-22 11:39:57 +01:00
Anton Khirnov 25c98566e8 fftools/ffmpeg_opt: drop HAS_ARG from auto{scale,rotate}
It causes those options to be parsed as either
* -autofoo 0/1 (with an argument)
* -noautofoo   (without an argument)
This is unnecessary, confusing, and against the documentation; these are
also the only two bool options that take an argument.

This should not affect the users, as these options are on by default,
and are supposed to be used as -nofoo per the documentation.
2023-12-22 11:39:57 +01: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
Anton Khirnov 6916105b11 fftools/ffmpeg_demux: set discard on the AVStream directly
Avoid taking an ugly detour through the decoder AVCodecContext.
2023-12-22 11:39:21 +01:00
James Almer fa961bb383 ffmpeg_mux_init: use strtoll() to parse stream and group indexes
Long is 32 bits signed on Windows, and nb_stream{s,_groups} are both unsigned
int. In a realistic scenario this wont make a difference, but it's still
proper.

Also ensure the parsed string is an integer while at it.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-12-21 10:32:53 -03:00
Zhao Zhili f72d781339 fftools/ffmpeg_enc: assert necessary frame fields before create encoder
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-12-21 19:30:25 +08: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
James Almer ed670b9b98 ffmpeg: add support for muxing AVStreamGroups
Starting with IAMF support.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-12-18 15:18:09 -03:00
Anton Khirnov 2ad0b8e0ea fftools/ffmpeg: use a mutex for enc_stats_write()
It may be called concurrently from different threads to write into the
same file.
2023-12-18 08:50:02 +01:00
Anton Khirnov 244d2fcc49 fftools/ffmpeg_mux: deduplicate uniniting EncStats 2023-12-18 08:50:02 +01:00
Anton Khirnov 02a4393647 fftools/ffmpeg: print keyframe information with -stats_* 2023-12-18 08:50:02 +01:00
Anton Khirnov 23c00d8c89 fftools/ffmpeg_mux_init: change 1-bit bitfields from int to unsigned
They cannot store 1 as signed, only 0 and -1.

Avoids warnings such as:
  implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
2023-12-18 08:50:02 +01:00
Anton Khirnov ca6f0192f2 fftools/cmdutils: change option flags to (1 << N) style
It is easier to read.
2023-12-18 08:50:02 +01:00
Anton Khirnov 7a7550ec28 fftools/ffmpeg_mux: factor timestamps processing out of write_packet() 2023-12-18 08:50:02 +01: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 8a11724a02 fftools/ffmpeg_mux: stop logging to AVFormatContext
Only the muxer itself is supposed to do that. Log to OutputStream
instead.

Drop now-redundant information from the logged string.
2023-12-18 08:50:02 +01:00
Anton Khirnov 5c5140ded2 fftools/ffmpeg_sched: track dts+duration as last_dts
This should be slightly (probably negligibly) more accurate for
scheduling, but mainly it improves the final reported time.

Reported-by: Paul B Mahol
2023-12-14 20:16:54 +01:00
Anton Khirnov 2305091a3a fftools/ffmpeg: update the reported timestamp at the end
Reported-by: microchip
2023-12-14 20:16:54 +01:00
Anton Khirnov 98d706b818 fftools/ffmpeg_sched: move trailing_dts() higher up
Will be useful in following commit.
2023-12-14 20:16:54 +01:00
Anton Khirnov 4549f20222 fftools/ffmpeg: drop OutputFile.sq_encode
It is unused since d119ae2fd8
2023-12-14 20:16:54 +01:00
Anton Khirnov 0d01e61807 fftools/ffmpeg_mux: move OutputStream.sq_idx_mux to private data
It should not be accessed outside of ffmpeg_mux*
2023-12-14 20:16:54 +01:00
Anton Khirnov 2c54097614 fftools/ffmpeg_demux: move InputFile.readrate to private data
It is not used outside of ffmpeg_demux.
2023-12-14 20:16:53 +01:00
Anton Khirnov 116bc5a9f3 fftools/ffmpeg: drop unused InputFile.eof_reached 2023-12-14 20:16:53 +01:00
Anton Khirnov 882bc8049d fftools/ffmpeg: move InputStream.codec_desc to private data
It is not used outside of ffmpeg_demux.
2023-12-14 20:16:53 +01:00
Anton Khirnov 9afe3f5274 fftools/ffmpeg: move InputStream.discard to private data
It is not used outside of ffmpeg_demux.
2023-12-14 20:16:53 +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 06d5dc11db fftools/ffmpeg_sched: actually initialize/destroy schedule_lock 2023-12-14 10:16:39 +01:00
Anton Khirnov 5256b2fbe6 fftools/ffmpeg_mux: print latency information in -debug_ts muxing output 2023-12-14 08:11:05 +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 c9f38210fc fftools/ffmpeg: merge DemuxPktData into FrameData
This way we can propagate arbitrary data from the demuxer all the way
into the muxer, using a single struct.
2023-12-14 08:11:05 +01:00
James Almer 7cc4b306eb ffmpeg_sched: initialize have_unchoked
Should fix valgrind warnings about Conditional jump or move depends on uninitialised value.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-12-12 16:10:28 -03: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
Anton Khirnov ee2a8cbfd1 fftools/ffmpeg_enc: move encoding to a separate thread
As for the analogous decoding change, this is only a preparatory step to
a fully threaded architecture and does not yet make encoding truly
parallel. The main thread will currently submit a frame and wait until
it has been fully processed by the encoder before moving on. That will
change in future commits after filters are moved to threads and a
thread-aware scheduler is added.

This code suffers from a known issue -  if an encoder with a sync queue
receives EOF it will terminate after processing everything it currently
has, even though the sync queue might still be triggered by other
threads. That will be fixed in following commits.
2023-12-12 08:24:18 +01:00
Anton Khirnov 66e78e9680 fftools/ffmpeg_demux: switch from AVThreadMessageQueue to ThreadQueue
* the code is made shorter and simpler
* avoids constantly allocating and freeing AVPackets, thanks to
  ThreadQueue integration with ObjPool
* is consistent with decoding/filtering/muxing
* reduces the diff in the future switch to thread-aware scheduling

This makes ifile_get_packet() always block. Any potential issues caused
by this will be resolved by the switch to thread-aware scheduling in
future commits.
2023-12-12 08:24:18 +01:00
Anton Khirnov 75efe530ce fftools/ffmpeg_mux: move bitstream filtering to the muxer thread
This will be the appropriate place for it after the rest of transcoding
is switched to a threaded architecture.
2023-12-12 08:24:18 +01:00
Anton Khirnov 1983507b6e fftools/ffmpeg_mux: add muxing thread private data
To be used for data that never needs to be visible outside of the muxer
thread. Start by moving the muxed AVPacket in there.
2023-12-12 08:24:18 +01:00
Anton Khirnov f37a741f42 fftools/ffmpeg_filter: reindent 2023-12-12 08:24:18 +01:00
Anton Khirnov 40e1cf1cd2 fftools/ffmpeg_filter: buffer sub2video heartbeat frames like other frames
Otherwise they'd be silently ignored if received by the filtering thread
before the filtergraph can be initialized, which would make the output
dependent on the order in which frames from different inputs arrive.
2023-12-12 08:24:18 +01:00
Anton Khirnov d35c05cb9e fftools/ffmpeg_filter: move filtering to a separate thread
As previously for decoding, this is merely "scaffolding" for moving to a
fully threaded architecture and does not yet make filtering truly
parallel - the main thread will currently wait for the filtering thread
to finish its work before continuing. That will change in future commits
after encoders are also moved to threads and a thread-aware scheduler is
added.
2023-12-12 08:24:18 +01:00
Anton Khirnov 4b8a171beb fftools/ffmpeg_filter: make sub2video heartbeat more robust
Avoid making decisions based on current graph input state, which makes
the output dependent on the order in which the frames from different
inputs are interleaved.

Makes the output of fate-filter-overlay-dvdsub-2397 more correct - the
subtitle appears two frames later, which is closer to its PTS as stored
in the file.
2023-12-12 08:24:18 +01:00
Anton Khirnov 99d2fa38ad fftools/ffmpeg: make sure FrameData is writable when we modify it
Also, add a function that returns const FrameData* for cases that only
read from it.
2023-12-06 10:30:28 +01:00
Anton Khirnov 1d536e0283 fftools/ffmpeg_filter: track input/output index in {Input,Output}FilterPriv
Will be useful in following commits.
2023-12-06 10:01:21 +01:00
Leo Izen 36980179a0 fftools/ffplay_renderer: declare function argument as const
Declaring the function argument as const fixes a warning down the line
that the const parameter is stripped. We don't modify this argument.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-11-27 23:39:48 +08:00
Zhao Zhili a1a6a328f0 fftools/ffplay: add hwaccel decoding support
Add vulkan renderer via libplacebo.

Simple usage:
$ ffplay -hwaccel vulkan foo.mp4

Use cuda to vulkan map:
$ ffplay -hwaccel cuda foo.mp4

Create vulkan instance by libplacebo, and enable debug:
$ ffplay -hwaccel vulkan \
	-vulkan_params create_by_placebo=1:debug=1 foo.mp4

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-11-15 01:20:11 +08:00
Anton Khirnov 889a022cce fftools/ffmpeg: rework keeping track of file duration for -stream_loop
Current code tracks min/max pts for each stream separately; then when
the file ends it combines them with last frame's duration to compute the
total duration of each stream; finally it selects the longest of those
durations as the file duration.

This is incorrect - the total file duration is the largest timestamp
difference between any frames, regardless of the stream.

Also change the way the last frame information is reported from decoders
to the muxer - previously it would be just the last frame's duration,
now the end timestamp is sent, which is simpler.

Changes the result of the fate-ffmpeg-streamloop-transcode-av test,
where the timestamps are shifted slightly forward. Note that the
matroska demuxer does not return the first audio packet after seeking
(due to buggy interaction betwen the generic code and the demuxer), so
there is a gap in audio.
2023-11-14 18:18:26 +01:00
Anton Khirnov 87016e031f fftools/thread_queue: count receive-finished streams as finished
This ensures that tq_receive() will always return EOF after all streams
were receive-finished, even though the sending side might not have
closed them yet. This may allow the receiver to avoid manually tracking
which streams it has already closed.
2023-11-14 18:18:26 +01:00
Anton Khirnov 4f7b91a698 fftools/thread_queue: do not return elements for receive-finished streams
It does not cause any issues in current callers, but still should not
happen.
2023-11-14 18:18:26 +01:00
Anton Khirnov 7c97a0c63f fftools/ffmpeg: move a few inline function into a new header
Will allow to use them in future commits without including the whole
ffmpeg.h.
2023-11-14 18:18:26 +01:00
Anton Khirnov 26ebd96371 fftools/ffmpeg_filter: return an error on ofilter_alloc() failure 2023-11-09 11:25:17 +01:00
Anton Khirnov 5db07311a0 fftools/ffmpeg_filter: fail on ifilter_alloc() failure 2023-11-09 11:25:17 +01:00
Anton Khirnov ed0a50923a fftools/cmdutils: only set array size after allocation succeeded 2023-11-09 11:25:17 +01:00
Andreas Rheinhardt 02064ba3a3 fftools/ffmpeg_mux_init: Restrict disabling automatic copying of metadata
Fixes ticket #10638 (and should also fix ticket #10482)
by restoring the behaviour from before
3c7dd5ed37.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-11-02 13:24:21 +01:00
James Almer ef01ab2627 ffprobe: print the non-diegetic stream disposition flag
Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-25 21:55:01 -03:00
Martin Storsjö ff5a3575fe fftools: Check HAVE_GETSTDHANDLE before using GetStdHandle
GetStdHandle is unavailable outside of the desktop API subset.

This didn't use to be a problem with earlier WinSDKs, as kbhit also
used to be available only for desktop apps, and this whole section is
wrapped in #if HAVE_KBHIT. With newer WinSDKs, kbhit() is available also
for non-desktop apps, while GetStdHandle still isn't.

Signed-off-by: Martin Storsjö <martin@martin.st>
2023-10-23 13:08:39 +03:00
Stefano Sabatini 7bf414408e ffprobe: add -output_format as an alias of -of
Currently we have -of and -print_format, which is a bit confusing. Add
-output_format as an alias of -of to match the short name.
2023-10-20 18:42:41 +02:00
Stefano Sabatini bf84ec0049 ffprobe: factorize xml_print_str and xml_print_int
Introduce xml_print_value to avoid logic duplication.
2023-10-20 18:42:41 +02:00
Stefano Sabatini 9dc834e71f ffprobe: reindent after 2b0973d 2023-10-20 18:42:12 +02:00
Stefano Sabatini 2b0973dedb ffprobe: fix XML rendering, review XML layout
Fix rendering of int values within a side data element, which was
broken since commit d2d3a83ad9, where the side data element was
correctly marked as a variable fields element. Logic to render a
string variable was implemented already, but it was not implemented
for the int fields path, which was enabled by that commit.

Also, code and schema is changed in order to account for multiple
variable-fields elements - such as side data, contained within the
same parent. Previously it was assumed that a single variable-fields
element was contained within the parent, which was the case for tags,
but is not the case for side-data.

Previously data was rendered as:
<side_data_list>
    <side_data side_data_type="CPB properties" max_bitrate="0" min_bitrate="0" avg_bitrate="0" buffer_size="327680" vbv_delay="-1"/>
</side_data_list>

Now as:
<side_data_list>
   <side_data type="CPB properties">
       <side_datum key="side_data_type" value="CPB properties"/>
       <side_datum key="max_bitrate" value="0"/>
       <side_datum key="min_bitrate" value="0"/>
       <side_datum key="avg_bitrate" value="0"/>
       <side_datum key="buffer_size" value="49152"/>
       <side_datum key="vbv_delay" value="-1"/>
   </side_data>
</side_data_list>

Variable-fields elements are rendered as a containing element wrapping
generic key/values elements, enabling use of strict XML schema.

Fix trac issue:
https://trac.ffmpeg.org/ticket/10613
2023-10-20 18:42:01 +02:00
Andreas Rheinhardt c06d3d2404 fftools/ffmpeg_demux: Fix leak on error
An AVFormatContext leaks on errors that happen before it is attached
to its permanent place (an InputFile). Fix this by attaching
it earlier.

Given that it is not documented that avformat_close_input() is usable
with an AVFormatContext that has only been allocated with
avformat_alloc_context() and not opened with avformat_open_input(),
one error path before avformat_open_input() had to be treated
specially: It uses avformat_free_context().

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 14:30:07 +02:00
Andreas Rheinhardt d98dfcecad fftools/ffmpeg_demux: Don't use fake object with av_opt_eval
The av_opt_eval family of functions emits errors messages on error
and can therefore not be used with fake objects when the AVClass
has a custom item_name callback. The AVClass for AVCodecContext
has such a custom callback (it searches whether an AVCodec is set
to use its name). In practice it means that whatever is directly
after the "cc" pointer to the AVClass for AVCodec in the stack frame
of ist_add() will be treated as a pointer to an AVCodec with
unpredictable consequences.

Fix this by using an actual AVCodecContext instead of a fake object.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 14:29:54 +02:00
Anton Khirnov 33f058f2ec fftools/ffmpeg_enc: constify the frame passed to enc_open() 2023-10-10 12:41:31 +02:00
Anton Khirnov 2ef50c17ab fftools/ffmpeg_filter: fail on filtering errors
These should be considered serious errors - don't just print a log
message and continue as if nothing happened.
2023-10-10 12:41:31 +02:00
Anton Khirnov 9196be2fb1 fftools/ffmpeg_enc: move fps conversion code to ffmpeg_filter
Its function is analogous to that of the fps filter, so filtering is a
more appropriate place for this.

The main practical reason for this move is that it places the encoding
sync queue right at the boundary between filters and encoders. This will
be important when switching to threaded scheduling, as the sync queue
involves multiple streams and will thus need to do nontrivial
inter-thread synchronization.

In addition to framerate conversion, the closely-related
* encoder timebase selection
* applying the start_time offset
are also moved to filtering.
2023-10-10 12:41:31 +02:00
Anton Khirnov f0f6d6d0e1 fftools/ffmpeg_enc: move framerate conversion state into a separate struct
Makes it more clear what state is specific to framerate conversion,
which will be useful in the following commit.
2023-10-10 12:41:31 +02:00
Anton Khirnov 61777c62d7 fftools/ffmpeg: stop accessing OutputStream.last_dropped in print_report()
That field is used by the framerate code to track whether any output has
been generated for the last input frame(*). Its use in the last
invocation of print_report() is meant to account for the very last
filtered frame being dropped in the number of dropped frames printed in
the log. However, that is a highly inappropriate place to do so, as it
makes assumptions about vsync logic in completely unrelated code. Move
the increment to encoder flush instead.

(*) the name is misleading, as the input frame has not yet been dropped
    and may still be output in the future
2023-10-10 12:41:31 +02:00
Anton Khirnov d2c416fdf1 fftools/ffmpeg_enc: merge -force_key_frames source/source_no_drop
Always use the functionality of the latter, which makes more sense as it
avoids losing keyframes due to vsync code dropping frames.

Deprecate the 'source_no_drop' value, as it is now redundant.
2023-10-10 12:41:31 +02:00
Anton Khirnov 735b082231 fftools/ffmpeg_enc: unbreak -force_key_frames source_no_drop
Unlike the 'source' mode, which preserves source keyframe-marking as-is,
the 'source_no_drop' mode attempts to keep track of keyframes dropped by
framerate conversion and mark the next output frame as key in such
cases. However,
* c75be06148 broke this functionality entirely, and made it equivalent
  to 'source'
* even before it would only work when the frame immediately following
  the dropped keyframe is preserved and not dropped as well

Also, drop a redundant check for 'frame' in setting dropped_keyframe, as
it is redundant with the check on the above line.
2023-10-10 12:41:31 +02:00
Anton Khirnov e35d36eb72 ffools/ffmpeg_filter: stop trying to handle an unreachable state
ifilter_send_eof() will fail if the input has no real or fallback
parameters, so there is no need to handle the case of some inputs being
in EOF state yet having no parameters.
2023-10-10 12:41:31 +02:00
Anton Khirnov 99567ee870 fftools/ffmpeg_enc: simplify adjust_frame_pts_to_encoder_tb() signature
It does not need an OutputFile and an OutputStream, only the target
timebase and the timestamp offset.
2023-10-10 12:41:31 +02:00
Anton Khirnov 096d88dcc6 fftools/ffmpeg_enc: move remaining vsync-related code to video_sync_process() 2023-10-10 12:41:31 +02:00
Anton Khirnov a9b9e771b3 fftools/ffmpeg_enc: move handling video frame duration to video_sync_process()
That is a more appropriate place for this.
2023-10-10 12:41:31 +02:00
James Almer 27fcc8dd9f fftools/ffplay: stop injecting stream side data in packets
This is no longer needed as the side data is available for decoders in the
AVCodecContext.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:19 -03:00
James Almer d372c2f3d3 fftools/ffmpeg: stop injecting stream side data in packets
This is no longer needed as the side data is available for decoders in the
AVCodecContext.
The tests affected reflect the removal of useless CPB and Stereo 3D side
data in packets.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:19 -03:00
James Almer d76b0c4a35 fftools/ffprobe: stop using AVStream.side_data
Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:18 -03:00
James Almer 235a66a143 fftools/ffplay: stop using AVStream.side_data
Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:18 -03:00
James Almer 3fd37b5268 fftools/ffmpeg: stop using AVStream.side_data
Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:00 -03:00
Stefano Sabatini d2d3a83ad9 ffprobe: introduce section type, use for the compact output
Also, avoid spurious end-of-line after side data entries, and improve
rendering of compact output, by adding an indication of the side data
type for each entry.

Also fixes issue:
http://trac.ffmpeg.org/ticket/9266
2023-10-06 00:17:02 +02:00
Stefano Sabatini 8eecd52d8b ffprobe: correct section name for side data piece 2023-10-06 00:17:01 +02:00
Stefano Sabatini 01edb505c6 ffprobe: factorize side data printing to dedicated function 2023-10-06 00:17:01 +02:00
Anton Khirnov 8d12762b42 fftools/ffmpeg: move derivation of frame duration from filter framerate
From ffmpeg_enc to ffmpeg_filter, which is a more appropriate
place for it.
2023-10-03 16:57:02 +02:00
Anton Khirnov 9d4ca76c08 fftools/ffmpeg_enc: do not round frame durations prematurely
Changes the results of fate-idroq-video-encode and fate-lavf* tests,
where different frames now get duplicated by framerate conversion code.
2023-10-03 16:57:02 +02:00
Anton Khirnov 303f10d4dd fftools/ffmpeg_dec: disregard demuxer timestamps for NOTIMESTAMPS formats
In this case any timestamps are guessed by compute_pkt_fields() in
libavformat. Since we are decoding the stream, we have more accurate
information from the decoder and do not need any guesses.

Eliminates spurious PTS gaps in a number of FATE tests.

Also avoids dropping the majority of frames in fate-dirac*
2023-10-03 16:57:02 +02:00
Anton Khirnov 5d58a35f98 fftools/ffmpeg: deprecate the -top option
It is badly named (should have been -top_field_first, or at least -tff),
underdocumented and underspecified, and (most importantly) entirely
redundant with the setfield filter.
2023-09-18 17:16:06 +02:00
Anton Khirnov 43a0004b5c fftools/ffmpeg_enc: apply -top to individual encoded frames
Fixes #9339.
2023-09-18 17:15:53 +02:00
Anton Khirnov 74b643a51e fftools/ffmpeg_enc: refactor setting encoding field_order
Merge three blocks with slightly inconsistent checks into one, treating
encoder input as interlaced when either:
* at least one of ilme/ildct flags is set
* the first frame in the stream is marked as interlaced
* the user specified the -top option

Stop modifying the frame passed to enc_open().
2023-09-18 17:15:53 +02:00
Anton Khirnov ced62a0c01 fftools/ffmpeg: do not fail on AVERROR(EAGAIN) from choose_output()
This is not an error condition, but would be treated like one if the
program terminates on the next transcode loop iteration because of a
signal or keyboard input.

Fixes #10504
Tested-by: https://github.com/0Ky
2023-09-14 10:44:05 +02:00
Andreas Rheinhardt 8238bc0b5e avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* defines
These defines are also used in other contexts than just AVCodecContext
ones, e.g. in libavformat. Furthermore, given that these defines are
public, the AV-prefix is the right one, so deprecate (and not just move)
the FF-macros.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:39:02 +02:00
Lynne 4acd08be6c
ffplay: port to lavu/tx 2023-09-01 23:59:11 +02:00
Leo Izen 60be62d293
fftools/ffmpeg_mux: replace monotonous with monotonic
The word "monotonous" means "spoken in a monotone" which is not what we
mean here. We mean "monotonic" i.e. nondecreasing.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2023-09-01 03:36:24 -04:00
Anton Khirnov 3c397a1d46 fftools/ffmpeg: move sending filtergraph commands to a separate function
Stop accessing filtergraph internals from keyboard reading code.
2023-08-30 11:53:50 +02:00
Anton Khirnov bff48e8d69 fftools/ffmpeg_mux: rename of_close() to of_free()
This function is primarily a destructor for OutputFile, the underlying
AVIOContext is normally closed earlier (right after writing the
trailer).
2023-08-30 11:53:50 +02:00
Anton Khirnov d55262704e fftools/ffmpeg_filter: shorten a variable name 2023-08-30 11:53:50 +02:00
Anton Khirnov fbcecdec8a fftools/ffmpeg_filter: reindent after previous commit 2023-08-30 11:53:50 +02:00
Anton Khirnov d9c862b57f fftools/ffmpeg_filter: factor processing a single frame out of reap_filters()
This is easier to read.
2023-08-30 11:53:50 +02:00
Anton Khirnov 82dd4dbe3f fftools/ffmpeg_filter: sanitize framerate retrieved from the filtergraph
Lavfi uses 1/0 to signal unknown/VFR, which should not be passed to
encoders.
2023-08-30 11:53:50 +02:00
Anton Khirnov d65d0f4df1 fftools/ffmpeg_enc: reindent after previous commit 2023-08-30 11:53:50 +02:00
Anton Khirnov 411ada649f fftools/ffmpeg_enc: only use fallback framerate when encoding CFR
When no output video framerate is specified by the user with -r or can
be inferred from the filtergraph, encoder setup will arbitrarily decide
that the framerate is 25fps. However, making up any framerate value for
VFR encoding is at best unnecessary.

Changes the results of the sub2video tests, where the input timebase is
now used instead of 1/25.
2023-08-30 11:53:50 +02:00
Anton Khirnov 8b6b2518fa fftools/ffmpeg_enc: reindent after previous commit 2023-08-30 11:53:50 +02:00
Anton Khirnov d1a2cd1e13 fftools/ffmpeg_enc: factor out setting encoder timebase
Mainly this fixes handling special values of -enc_time_base ('demux' or
'filter') for audio. It also prints a warning if -enc_time_base is
specified for subtitles, instead of ignoring it silently (current
subtitle encoding API only works with AV_TIME_BASE_Q).
2023-08-30 11:53:50 +02:00
Anton Khirnov 8ecbb1f9af fftools/ffmpeg_mux: stop rescaling timestamps in of_streamcopy()
This function converts packet timestamps from the input stream timebase
to OutputStream.mux_timebase, which may or may not be equal to the
actual output AVStream timebase (and even when it is, this may not
always be the optimal choice due to bitstream filtering).

Just keep the timestamps in input stream timebase, they will be rescaled
as needed before bitstream filtering and/or sending the packet to the
muxer.

Move the av_rescale_delta() call for audio (needed to preserve accuracy
with coarse demuxer timebases) to write_packet.

Drop now-unused OutputStream.mux_timebase.
2023-08-30 11:53:46 +02:00
Anton Khirnov ed5caaaf22 fftools/ffmpeg_mux: use correct timebases for bitstream filtering
Bitstream filtering input timebase is not always necessarily equal to
OutputStream.mux_timebase. Also, set AVPacket.time_base correctly for
packets output by bitstream filters

Do not rescale at all in of_output_packet() when not doing bitstream
filtering, as it's unnecessary - write_packet() will rescale to the
actual muxer timebase.
2023-08-30 11:51:42 +02:00
Anton Khirnov b39b6b7456 fftools/ffmpeg: simplify handling input -t for streamcopy
Output stream will be closed implicitly after a NULL packet is sent to
it, there is no need to explicitly call close_output_stream().
2023-08-30 11:51:42 +02:00
Anton Khirnov 8f2e7e9dcf fftools/ffmpeg: stop explicitly closing output streams on input EOF
Sending an empty packet already does that implicitly.
2023-08-30 11:51:42 +02:00
Andreas Rheinhardt 9583a2c8eb fftools/ffprobe: Use proper enum type
This is a bit cleaner as int need not be the underlying type
of an enum if a smaller type can hold all its values.
Also declare the children_ids array as const as it never changes.

Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-08 20:20:36 +02:00
Andreas Rheinhardt 739f24d833 fftools/opt_common: Don't add unnecessary " "
Before:
D.AIL. smackaudio           Smacker audio (decoders: smackaud )
After:
D.AIL. smackaudio           Smacker audio (decoders: smackaud)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-02 18:15:34 +02:00
Andreas Rheinhardt 41409405d4 fftools/opt_common: Use %c instead of %s to write single char
Also combine multiple printfs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-02 18:15:34 +02:00
Andreas Rheinhardt 0e9956a06e fftools/ffprobe: Fix memleak
Fixes Coverity issue #1524491.
Regression since e6126abc69.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-01 16:31:13 +02:00
Anton Khirnov e8777221f2 fftools/ffprobe: fix handling parse_options() return value
Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-07-28 09:11:26 -03:00
Andreas Rheinhardt 071c625ad7 fftools/ffmpeg_opt: Reduce scope of variables for deprecated code
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-23 17:55:38 +02:00
Andreas Rheinhardt 8bb1bcf47d fftools/ffmpeg_opt: Fix leak on error
Fixes Coverity id #1539096.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-23 17:55:38 +02:00
Andreas Rheinhardt 0368ded1a9 fftools/opt_common: Fix leak on error
Fixes Coverity issue #743443.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-23 17:55:38 +02:00
Andreas Rheinhardt 2654347d7a fftools/ffmpeg_opt: Fix leak on error
Fixes Coverity issue #1539097.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-23 17:55:38 +02:00
Andreas Rheinhardt 2a44c4bc9e fftools/ffmpeg_mux_init: Fix leak on error
Fixes Coverity issue #1539098.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-23 17:55:38 +02:00
Anton Khirnov ccc6849932 fftools/ffmpeg: stop calling exit_program()
Remove exit_program() and register_exit(), as they are no longer used.
2023-07-20 20:47:46 +02:00
Anton Khirnov a81d9231b9 fftools/ffprobe: stop calling exit_program()
Inline the relevant part of ffprobe_cleanup() into main() and drop the
rest.
2023-07-20 20:47:46 +02:00
Anton Khirnov be49c48282 fftools/ffprobe: inline opt_output_file() into its only caller
There is no reason to keep them separate.

Also, replace exit_program() with returning an error code.
2023-07-20 20:47:46 +02:00
Anton Khirnov 411e183360 fftools/opt_common: replace report_and_exit() with returning an error code
Remove report_and_exit(), as it has no more users.
2023-07-20 20:47:46 +02:00
Anton Khirnov 78699923ac fftools/ffplay: replace report_and_exit() with returning an error code 2023-07-20 20:47:46 +02:00
Anton Khirnov 140cb5a742 fftools/ffprobe: replace report_and_exit() with returning error codes 2023-07-20 20:47:46 +02:00
Anton Khirnov 83ace80bfd fftools/ffmpeg: return an error from MATCH_PER_STREAM_OPT() instead of aborting 2023-07-20 20:47:46 +02:00
Anton Khirnov 2f155b18a1 fftools/ffmpeg: return an error from assert_avoptions() instead of aborting
Rename it to check_avoptions().
2023-07-20 20:47:46 +02:00
Anton Khirnov eda1fac27a fftools/cmdutils: return AVERROR_EXIT for OPT_EXIT options instead of aborting() 2023-07-20 20:47:46 +02:00
Anton Khirnov 8173623e39 fftools/ffmpeg: consolidate exiting from main() on error 2023-07-20 20:47:46 +02:00
Anton Khirnov c56fabde27 fftools/ffmpeg_opt: consolidate printing errors in ffmpeg_parse_options() 2023-07-20 20:47:46 +02:00
Anton Khirnov 87f0333af1 fftools/cmdutils: add error handling to filter_codec_opts() 2023-07-20 20:47:46 +02:00
Anton Khirnov 6b8cf2505a fftools/cmdutils: constify the first parameter of filter_codec_opts() 2023-07-20 20:47:46 +02:00
Anton Khirnov 39d5104332 fftools: handle errors in parse_options() 2023-07-20 20:47:46 +02:00
Anton Khirnov 49ac7fc485 fftools: remove parse_time_or_die()
Replace it with calling av_parse_time() directly, which provides
graceful error handling and more accurate error messages.
2023-07-20 20:47:46 +02:00
Anton Khirnov 9cb47c78d6 fftools: return errors from parse_number_or_die() instead of aborting
Rename the function to just parse_number().
2023-07-20 20:47:40 +02:00
Anton Khirnov 4adbe2d219 fftools/opt_common: replace exit_program() with returning error codes 2023-07-20 20:40:26 +02:00
Anton Khirnov a50f90f1c2 fftools/ffmpeg_opt: replace exit_program() with returning error codes 2023-07-20 20:40:26 +02:00
Anton Khirnov 6c6f13baf3 fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting
Rename the function to just find_codec().
2023-07-20 20:40:26 +02:00
Anton Khirnov 2e6afa799e fftools/cmdutils: add error handling to GROW_ARRAY() 2023-07-20 20:40:26 +02:00
Anton Khirnov b23abb7c48 fftools/cmdutils: add error handling to grow_array() 2023-07-20 20:40:26 +02:00
Anton Khirnov 6be4a29397 fftools/cmdutils: add error handling to allocate_array_elem() 2023-07-20 20:40:26 +02:00
Anton Khirnov 8eb5adeab8 fftools/cmdutils: drop unused ALLOC_ARRAY_ELEM() 2023-07-20 20:40:26 +02:00
Anton Khirnov 26e1e80152 fftools/ffmpeg_opt: reimplement -streamid using a dictionary
This does not require an arbitrary limit on the number of streams.

Also, return error codes from opt_streamid() instead of aborting.
2023-07-20 20:40:26 +02:00
Anton Khirnov 37abb3a419 fftools/cmdutils: return error codes from setup_find_stream_info_opts() instead of aborting 2023-07-20 20:40:26 +02:00
Anton Khirnov 13ebc9a0a9 fftools/ffmpeg_filter: replace remaining report_and_exit() with error codes 2023-07-20 20:40:26 +02:00
Anton Khirnov cb8242db8d fftools/ffmpeg_filter: return error codes from set_channel_layout() instead of aborting 2023-07-20 20:40:26 +02:00
Anton Khirnov 5ba7aa2ce8 fftools/ffmpeg_filter: return error codes from fg_create() instead of aborting 2023-07-20 20:40:26 +02:00
Anton Khirnov 8db96808bc fftools/ffmpeg_filter: return error codes from choose_pix_fmts() instead of aborting 2023-07-20 20:40:26 +02:00
Anton Khirnov 8815adfe75 fftools/ffmpeg_filter: replace remaining exit_program() with error codes 2023-07-20 20:39:42 +02:00
Anton Khirnov a52ee1aa47 fftools/ffmpeg_filter: return error codes from init_input_filter() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov ab16e324ea fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov 6298dd683b fftools/ffmpeg_dec: drop redundant handling of AVERROR_EXPERIMENTAL
Normal error handling does the job just as well.
2023-07-20 20:30:13 +02:00
Anton Khirnov 518b49a735 fftools/ffmpeg_dec: return error codes from dec_packet() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov e0f4259689 fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov 2b4afe8169 fftools/ffmpeg_enc: return errors from encode_frame() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov 43bcf631d0 fftools/ffmpeg_enc: return errors from enc_flush() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov dde3de0170 fftools/ffmpeg_enc: return errors from do_*_out() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov aa1173feee fftools/ffmpeg_enc: return errors from enc_open() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov 80a64800ea fftools/ffmpeg_enc: return errors from enc_frame() instead of aborting 2023-07-20 20:30:13 +02:00
Anton Khirnov c4b074676a fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions()
This function assumes AVMEDIA_* are always positive, while in fact it
can also handle AVMEDIA_TYPE_UNKNOWN, which is -1.
2023-07-20 20:30:13 +02:00
Anton Khirnov 3a89e6d352 fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph
This is more natural, as all except one of its callers require
processing only one filtergraph.
2023-07-20 20:30:13 +02:00
Anton Khirnov 9d44eb8af5 fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection
ffmpeg CLI pixel format selection for filtering currently special-cases
MJPEG encoding, where it will restrict the supported list of pixel
formats depending on the value of the -strict option. In order to get
that value it will apply it from the options dict into the encoder
context, which is a highly invasive action even now, and would become a
race once encoding is moved to its own thread.

The ugliness of this code can be much reduced by moving the special
handling of MJPEG into ofilter_bind_ost(), which is called from encoder
init and is thus synchronized with it. There is also no need to write
anything to the encoder context, we can evaluate the option into our
stack variable.

There is also no need to access AVCodec at all during pixel format
selection, as the pixel formats array is already stored in
OutputFilterPriv.
2023-07-20 20:30:13 +02:00
Anton Khirnov 037d364797 fftools/ffmpeg_filter: move "smart" pixfmt selection to ffmpeg_mux_init
This code works on encoder information and has no interaction with
filtering, so it does not belong in ffmpeg_filter.
2023-07-20 20:30:04 +02:00
Anton Khirnov 249bca763d fftools/ffmpeg_mux_init: handle pixel format endianness
When -pix_fmt designates a BE/LE pixel format, it gets translated into
the native one by av_get_pix_fmt(). This may not always be the best
choice, as the encoder might only support one endianness. In such a
case, explicitly choose the endianness supported by the encoder.

While this is currently redundant with choose_pixel_fmt() in
ffmpeg_filter.c, the latter code will be deprecated in following commits.
2023-07-20 20:30:04 +02:00
Andreas Rheinhardt 463a472426 fftools/ffmpeg_enc: Reindentate after the last commit
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-17 16:18:12 +02:00
Andreas Rheinhardt bfe15b81b3 fftools/ffmpeg_enc: Remove always-true checks
frame is always != NULL for audio and video here
(this is checked by an assert and the frame is already dereferenced
before it reaches this code here).
Fixes Coverity issue #1538858.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-07-17 16:14:41 +02:00
Anton Khirnov 153cf85b24 fftools/ffmpeg_mux_init: fix an array declaration
map_func is supposed to be an array of const pointer to function
returning int, not an array of pointer to function returning const int.

Reported-By: Martin Storsjö
2023-07-16 11:10:00 +02:00
Anton Khirnov dff3a283cd fftools/ffmpeg: rework -enc_time_base handling
Read the timebase from FrameData rather than the input stream. This
should fix #10393 and generally be more reliable.

Replace the use of '-1' to indicate demuxing timebase with the string
'demux'. Also allow to request filter timebase with
'-enc_time_base filter'.
2023-07-15 11:02:11 +02:00
Anton Khirnov 4d06742b93 fftools/ffmpeg: add more structure to FrameData
It now contains data from multiple sources, so group those items that
always come from the decoder. Also, initialize them to invalid values,
so that frames that did not originate from a decoder can be
distinguished.
2023-07-15 11:02:11 +02:00
Anton Khirnov 75d0af388f fftools/ffmpeg_filter: make OutputFilter.filter private
It should not be accessed from outside of filtering code.
2023-07-15 11:02:11 +02:00
Anton Khirnov 9a97f9cf3a fftools/ffmpeg_enc: initialize audio/video encoders from frame parameters
This is possible now that enc_open() is always called with a non-NULL
frame for audio/video.

Previously the code would directly reach into the buffersink, which is a
layering violation.
2023-07-15 11:02:11 +02:00
Anton Khirnov b295ec31f3 fftools/ffmpeg_filter: only flush vsync code if encoding actually started
Otherwise this has no effect.

Will be useful in following commits.
2023-07-15 11:02:11 +02:00
Anton Khirnov 0a6751a78a fftools/ffmpeg: rework initializing encoders with no frames
When no frames were passed from a filtergraph to an encoder, but the
filtergraph is configured (i.e. has output parameters), encoder flush
code will use those parameters to initialize the encoder in a last-ditch
effort to produce some useful output.

Rework this process so that it is triggered by the filtergraph, which
now sends a dummy frame with parameters, but no data, to the encoder,
rather than the encoder reaching backwards into the filter.

This approach is more in line with the natural data flow from filters to
encoders and will allow to reduce encoder-filter interactions in
following commits.

This code is tested by fate-adpcm-ima-cunning-trunc-t2-track1, which (as
confirmed by Zane) is supposed to produce empty output.
2023-07-15 11:02:11 +02:00
Anton Khirnov 20c42213ea fftools/ffmpeg_mux_init: drop an obsolete assignment
This line was added in c30a4489b4 along with
AVStream.sample_aspect_ratio. However, configuring SAR for video
encoding is now done after this code (specifically in enc_open(), which
is called when the first video frame to be encoded is obtained), so this
line cannot have any meaningful effect.
2023-07-15 11:02:11 +02:00
Anton Khirnov c328bff4da fftools/ffmpeg_enc: return errors from enc_subtitle() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 2e742a2c3c fftools/ffmpeg_mux: return errors from of_streamcopy() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 464a5e8e76 fftools/ffmpeg: handle error codes from process_input_packet()
None are returned for now, but that will change in future commits.
2023-07-15 11:02:11 +02:00
Anton Khirnov 5fe3914c39 fftools/ffmpeg: return an error instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 858b635613 fftools/ffmpeg_mux_init: replace all remaining aborts with returning error codes
Mainly concerns new_stream_*() and their callees.
2023-07-15 11:02:11 +02:00
Anton Khirnov 45473258ff fftools/ffmpeg_mux_init: return error codes from metadata processing instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov dd44871eb9 fftools/ffmpeg_mux_init: improve of_add_programs()
Replace duplicated(!) and broken* custom string parsing with
av_dict_parse_string(). Return error codes instead of aborting.

* e.g. it treats NULL returned from av_get_token() as "separator not
  found", when in fact av_get_token() only returns NULL on memory
  allocation failure
2023-07-15 11:02:11 +02:00
Anton Khirnov fd40197170 fftools/ffmpeg_mux_init: return error codes from validate_enc_avopt() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 4e3557aadb fftools/ffmpeg_mux_init: return error codes from parse_forced_key_frames() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 6691d131d8 fftools/ffmpeg_mux_init: return error codes from copy_meta() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 54cbe6f57d fftools/ffmpeg_mux_init: return error codes from ost_add() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 38a2fc2c29 fftools/ffmpeg_mux_init: move allocation out of prologue
ost_add() has a very large variable declaration prologue, performing
"active" actions that can fail in there is confusing.
2023-07-15 11:02:11 +02:00
Anton Khirnov 4e366100e9 fftools/ffmpeg_mux_init: return error codes from map_*() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov eee09cdf39 fftools/ffmpeg_mux_init: improve error handling in of_add_attachments()
* return error codes instead of aborting
* avoid leaking the AVIOContext on failure
* check the return code of avio_read()
2023-07-15 11:02:11 +02:00
Anton Khirnov b3eedca5e5 fftools/ffmpeg_mux_init: return errors from create_streams() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov c23cff5a8a fftools/ffmpeg_demux: return errors from ist_add() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov cce294638b fftools/ffmpeg: return errors from assert_file_overwrite() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 2d59873fc1 fftools/ffmpeg_demux: add logging for -dump_attachment
Makes it more clear what was written where.
2023-07-15 11:02:11 +02:00
Anton Khirnov 63e4e8e4f4 fftools/ffmpeg_demux: forward errors from dump_attachment() instead of aborting
Also, check the return code of avio_close().
2023-07-15 11:02:11 +02:00
Anton Khirnov ff0160cb37 fftools/ffmpeg_demux: drop a redundant avio_flush()
It is immediately followed by avio_close(), which is documented to flush
the buffers.
2023-07-15 11:02:11 +02:00
Anton Khirnov ad80857a97 fftools/ffmpeg_demux: return errors from ifile_open() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov c313cdd70c fftools/ffmpeg_mux_init: return errors from of_open() instead of aborting 2023-07-15 11:02:11 +02:00
Anton Khirnov 9a2335444b fftools/ffmpeg_mux: forward EOF from the sync queue
EOF from sq_receive() means no packets will ever be output by the sync
queue. Since the muxing sync queue is always used by all interleaved
(i.e. non-attachment) streams, this means no further packets can make
it to the muxer and we can terminate muxing now.
2023-07-13 13:08:56 +02:00
Anton Khirnov 6a9d3f46c7 fftools/ffmpeg: drop an obsolete debug log
The value it prints has not been cur_dts from lavf for a very long time,
so it's misleading.
2023-07-11 19:28:18 +02:00
Anton Khirnov 57a42a714b fftools/ffmpeg_filter: consolidate calling avfilter_graph_set_auto_convert()
Do not call it from choose_pix_fmts(), as that function is not supposed
to modify random filtergraph properties.
2023-07-11 19:28:18 +02:00
Anton Khirnov 432399780a fftools/ffmpeg_filter: make OutputFile.{formats,ch_layouts,sample_rates} private
They are not used outside of the filtering code.
2023-07-11 19:28:18 +02:00
Anton Khirnov a3ab5bf80d fftools/ffmpeg_filter: make OutputFile.width,height private
They are not used outside of the filtering code.
2023-07-11 19:28:18 +02:00
Anton Khirnov c19aa9c28f fftools/ffmpeg_filter: make OutputFile.ch_layout private
It is not used outside of the filtering code.
2023-07-11 19:28:18 +02:00
Anton Khirnov 42f3f54cf4 fftools/ffmpeg_filter: make OutputFile.format/sample_rate private
They are not used outside of the filtering code.
2023-07-11 19:28:18 +02:00
Anton Khirnov c9a99ffe51 fftools/ffmpeg_filter: make sure no input or output is bound twice 2023-07-11 19:28:18 +02:00
Marton Balint 7357012bb5 fftools/ffmpeg: fix negative timestamps at the beginning of the encoding
Also fix a couple of possible overflows while at it.

Fixes the negative initial timestamps in ticket #10358.

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-07-09 19:50:15 +02:00
QiTong Li 79f41a0760 fftools/ffplay: fix typo in frame_queue_destory
Not sure if the function naming frame_queue_destory is intended because
"destory" is not really a word. Changing it to "destroy" makes more sense.

Signed-off-by: QiTong Li <liqitong@163.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-07-06 21:24:47 +02:00
James Almer 50f34172e0 fftools/ffplay: remove usage of internal AVInputFormat.read_seek field
It's an internal field, so it should not be touched.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-07-02 19:04:25 -03:00
Anton Khirnov 1617d1a752 fftools/ffmpeg: pass subtitle decoder dimensions to sub2video
Restores behavior from before 20cacfe493.
Eventually this should be handled similarly to audio/video - with a
filtergraph reset or a manual scaler.
2023-06-19 09:48:56 +02:00
Anton Khirnov 88f80977eb fftools/ffmpeg: use AVFrame to pass subtitles from decoders to filters
Allows to use the same buffering code for all media types. Will also be
important for the following commit.
2023-06-19 09:48:56 +02:00
Anton Khirnov fa717baaa5 fftools/ffmpeg_enc: constify the subtitle passed to enc_subtitle() 2023-06-19 09:48:56 +02:00
Anton Khirnov e89a6d1089 fftools/ffmpeg_dec: move InputStream.prev_sub to Decoder
It does not need to be visible outside of decoding code.
2023-06-19 09:48:56 +02:00
Anton Khirnov a45b9d35b9 fftools/ffmpeg: move fix_sub_duration_heartbeat() to ffmpeg_dec
This way ffmpeg.c does not need to access InputStream.prev_sub and it
can be made private.
2023-06-19 09:48:55 +02:00
Anton Khirnov 01897c1788 fftools/ffmpeg_dec: move decoding to a separate thread
This is only a preparatory step to a fully threaded architecture and
does not yet make decoding truly parallel - the main thread will
currently submit a packet and wait until it has been fully processed by
the decoding thread before moving on. Decoder behavior as observed by
the rest of the program should remain unchanged. That will change in
future commits after encoders and filters are moved to threads and a
thread-aware scheduler is added.
2023-06-19 09:48:55 +02:00
Anton Khirnov 5293adb1a7 fftools/ffmpeg: attach bits_per_raw_sample information to frames
This way avoids encoders reaching into filters or decoders for this
information.
2023-06-19 09:48:55 +02:00
Anton Khirnov 7d4e00ccf0 fftools/ffmpeg_dec: stop using Decoder.pkt
It is only used for flushing the subtitle decoder, so allocate a
dedicated packet for that.

Keep Decoder.pkt unused for now, it will be repurposed in future
commits.
2023-06-19 09:48:55 +02:00
Anton Khirnov 1bdd53e2f9 fftools/ffmpeg_filter: make configure_filtergraph() static
It is no longer used outside of ffmpeg_filter.
2023-06-19 09:48:55 +02:00
Anton Khirnov b1a213ab5d fftools/ffmpeg_filter: reject filtergraphs with zero outputs
Nothing useful can be done with them currently.
2023-06-19 09:48:55 +02:00
Anton Khirnov a7aa05c599 fftools/ffmpeg_filter: add an AVClass to FilterGraph
Use it for logging.
2023-06-19 09:48:55 +02:00
Anton Khirnov a934392db0 fftools/ffmpeg_enc: move dup_warning global variable to Encoder 2023-06-19 09:48:55 +02:00
Anton Khirnov 1adad44fc7 fftools/ffmpeg_dec: move InputStream.hwaccel_pix_fmt to Decoder
It is purely decoder-internal state.
2023-06-19 09:48:55 +02:00
Anton Khirnov 174cb3accf fftools/ffmpeg_dec: remove pointless InputStream.hwaccel_retrieve_data
It is always set to hwaccel_retrieve_data() from ffmpeg_hw.c, so that
function can just be called directly instead.
2023-06-19 09:48:55 +02:00
Anton Khirnov 25d96ab6c0 fftools/ffmpeg_hw: inline hwaccel_decode_init() into its caller
The function is now trivial and cannot fail, so all error handling in
its caller can be removed.
2023-06-19 09:48:55 +02:00
Anton Khirnov 6c9cbf7507 fftools/ffmpeg_demux: reindent after previous commit 2023-06-19 09:48:55 +02:00
Anton Khirnov 98766dbbd7 fftools/ffmpeg_demux: move the loop out of add_input_streams()
Make the function process just one input stream at a time and save an
indentation level. Also rename it to ist_add() to be consistent with an
analogous function in ffmpeg_mux_init.
2023-06-19 09:48:55 +02:00
Anton Khirnov df81fb46ee fftools/ffmpeg_dec: simplify process_subtitle()
Its got_output argument always points to 1.
2023-06-19 09:48:55 +02:00
Anton Khirnov e9eb44ed88 fftools/ffmpeg_dec: drop always-0 InputStream.prev_sub.ret 2023-06-19 09:48:55 +02:00
Anton Khirnov 141d11cb3c fftools/ffmpeg_mux: make OutputStream.pkt private
It is no longer used outside of muxing code.
2023-06-05 16:16:13 +02:00
Anton Khirnov 730a2221af fftools/ffmpeg_enc: use a private AVPacket instance for encoding
The code currently uses OutputStream.pkt, which complicates its
ownership semantics.
2023-06-05 16:16:12 +02:00
Anton Khirnov f94957e8f4 fftools/ffmpeg_mux: simplify calling of_output_packet()
Use NULL packets to signal EOF instead of a separate variable. This is
made possible by the previous commit.
2023-06-05 16:16:12 +02:00
Anton Khirnov 96e1325d91 fftools/ffmpeg_mux: use a dedicated packet for BSF output
Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
2023-06-05 16:16:12 +02:00
Anton Khirnov c803b36b8f fftools/ffmpeg_enc: stop using OutputStream.initialized
It is set by the muxing code, which will not be synchronized with
encoding code after upcoming threading changes. Use an encoder-private
variable instead.
2023-06-05 16:15:04 +02:00
Anton Khirnov 568d414074 fftools/ffmpeg: attach filter framerate to frames
This way the encoder does not need to reach backward into the filter.
2023-06-05 16:15:04 +02:00
Anton Khirnov 9630341073 fftools/ffmpeg: factor out attaching FrameData to a frame
Will be useful in following commits.
2023-06-05 16:15:04 +02:00
Anton Khirnov d7781cfb95 fftools/ffmpeg: convert timestamps inside the muxer
Packets submitted to the muxer now have their timebase attached to them,
so the muxer can do conversion to muxing timebase and avoid exposing it
to callers.
2023-06-05 16:15:04 +02:00
Anton Khirnov cf121592c5 fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding
The values currently written into it are not used after
enc_open(), so it is better to confine them to that function.
2023-06-05 16:15:04 +02:00
Anton Khirnov 5bea8daa78 fftools/ffmpeg_enc: do not guess frame durations from output framerate
There is no reason to expect input frame durations to match output
framerate.
2023-06-05 16:15:04 +02:00
Anton Khirnov 2f92650c5d fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers
The function now reduces to a ternary operator, so it is shorter and
clearer to eliminate it.
2023-06-05 16:15:04 +02:00
Anton Khirnov 93e26a4db7 fftools/ffmpeg: handle -enc_time_base -1 during stream creation
There is no reason to postpone it until opening the encoder. Also, abort
when the input stream is unknown, rather than disregard an explicit
request from the user.
2023-06-05 16:15:04 +02:00
Anton Khirnov 58a64e3d54 fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded
It has no effect otherwise.
2023-06-05 16:15:04 +02:00
Anton Khirnov 2baae6434b fftools/ffmpeg_enc: merge two adjacent video-specific blocks
There is no meaningful reason for them to be separated.
2023-06-05 16:15:04 +02:00
Anton Khirnov c8a85d1b2f fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy
The values currently written into it are not used after
streamcopy_init(), so it is better to confine them to that function.
2023-06-05 16:15:04 +02:00
Anton Khirnov ccf219e361 fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code
The code will currently add a small offset to avoid exact midpoints, but
this can cause inexact results when a float timestamp is exactly
representable as an integer.

Fixes off-by-one in the first frame duration in multiple FATE tests.
2023-06-05 16:15:04 +02:00
Anton Khirnov c7a05ac117 fftools/ffmpeg_demux: do not set AVCodecContext.framerate
For decoding, this field is used by the decoder to export information
to the caller; it does not make sense for the caller to set it.
2023-06-05 16:15:04 +02:00
Anton Khirnov d8c61ba723 fftools/ffmpeg_filter: drop a block disabled since 2012 2023-06-05 16:15:04 +02:00
Anton Khirnov ad14bdbcfd fftools/ffmpeg_filter: drop a write-only variable 2023-06-05 16:15:04 +02:00
Anton Khirnov 57021a68d9 fftools/ffmpeg_mux: set stream duration after the timebase is certainly known
Stop assuming the encoder knows the muxing timebase, which does not
always have to hold (e.g. due to bitstream filters).
2023-06-05 16:15:04 +02:00
Anton Khirnov ba1141d8a9 fftools/ffmpeg_enc: move nb_frames{dup,drop} globals into OutputStream 2023-06-05 16:15:04 +02:00