Commit Graph

982 Commits

Author SHA1 Message Date
Anton Khirnov
710da200fc fftools/ffmpeg: move OutputStream.next_pts to Encoder
It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
2023-04-13 15:11:56 +02:00
Anton Khirnov
45202556cb fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder
It is video encoding-only and does not need to be visible outside of
ffmpeg_enc.c
2023-04-13 15:11:56 +02:00
Anton Khirnov
f098eaee56 fftools/ffmpeg_enc: factorize calling enc_init()
It is done in the same way for both audio and video, so can be moved to
enc_frame().
2023-04-09 15:47:45 +02:00
Anton Khirnov
2225134e7d fftools/ffmpeg: clean up #includes
Drop unneeded ctype.h and math.h.
Group all system headers together.
Sort unconditional includes alphabetically.
Group local includes by the library, sort alphabetically.
2023-04-09 15:47:45 +02:00
Anton Khirnov
a2a09932f2 fftools/ffmpeg: stop including os_support.h
It was added for usleep(), which
- is not used in ffmpeg
- is not handled in os_support.h anymore
2023-04-09 15:47:45 +02:00
Anton Khirnov
f30b620e98 fftools/ffmpeg: add encoder private data
Start by moving OutputStream.last_frame to it. In the future it will
hold other encoder-internal state.
2023-04-09 15:47:45 +02:00
Anton Khirnov
44accfef41 fftools/ffmpeg: move audio/video encoding code to ffmpeg_enc.c 2023-04-09 15:47:45 +02:00
Anton Khirnov
9de5dc74fd fftools/ffmpeg: move subtitle encoding to ffmpeg_enc.c 2023-04-09 15:47:45 +02:00
Anton Khirnov
b79448fa38 fftools/ffmpeg: replace ff_dlog() with av_log()
ff_dlog() is a lavu internal macro, and av_log() at trace level is just
as good here.
2023-04-09 15:47:45 +02:00
Anton Khirnov
a996478e8c fftools/ffmpeg: simplify output stream initialization call graph
Several places in the code currently call init_output_stream_wrapper(),
which in turn calls init_output_stream(), which then calls either
enc_open() or init_output_stream_streamcopy(), followed by
of_stream_init(), which tells the muxer the stream is ready for muxing.

All except one of these callers are in the encoding code, which will be
moved to ffmpeg_enc.c. Keeping this structure would then necessitate
ffmpeg_enc.c calling back into the common code in ffmpeg.c, which would
then just call ffmpeg_mux, thus making the already convoluted call chain
even more so.

Simplify the situation by using separate paths for filter-fed output
streams (audio and video encoders) and others (subtitles, streamcopy,
data, attachments).
2023-04-09 15:47:45 +02:00
Anton Khirnov
d96f2fbf76 fftools/ffmpeg: move initializing encoders to a new file
This file will contain more encoding-related code in the future.
2023-04-09 15:47:45 +02:00
Anton Khirnov
1dabd48519 fftools/ffmpeg: reindent after previous commit 2023-04-09 15:47:45 +02:00
Anton Khirnov
39291f19e2 fftools/ffmpeg: move encoder initialization to init_output_stream_encode
Encoder initialization is currently split rather arbitrarily between
init_output_stream_encode() and init_output_stream(). Move all of it to
init_output_stream_encode().
2023-04-09 15:47:45 +02:00
Anton Khirnov
e1fe6c5577 fftools/ffmpeg: use stack variables to shorten code 2023-04-09 15:47:45 +02:00
Anton Khirnov
e1e0c2c7f2 fftools/ffmpeg: drop unnecessary indirection
init_output_stream() can print log messages directly, there is no need
to ship them to the caller.
2023-04-09 15:47:45 +02:00
Anton Khirnov
237f9b9682 fftools/ffmpeg: stop handling AVMEDIA_TYPE_DATA in init_output_stream_encode()
We do not support data encoders, so this should never be reached.
2023-04-09 15:47:45 +02:00
Anton Khirnov
923c6ab170 fftools/ffmpeg: use sync queues for enforcing audio frame size
The code currently uses lavfi for this, which creates a sort of
configuration dependency loop - the encoder should be ideally
initialized with information from the first audio frame, but to get this
frame one needs to first open the encoder to know the frame size. This
necessitates an awkward workaround, which causes audio handling to be
different from video.

With this change, audio encoder initialization is congruent with video.
2023-04-09 15:47:45 +02:00
Anton Khirnov
f9d3c06533 fftools/sync_queue: allow requesting a specific number of audio samples
This will be made useful in following commits.
2023-04-09 15:47:45 +02:00
Anton Khirnov
81cca3dae3 fftools/sync_queue: make sure audio duration matches sample count
For audio AVFrames, nb_samples is typically more trustworthy than
duration. Since sync queues look at durations, make sure they match the
sample count.

The last audio frame in the fate-shortest test is now gone. This is more
correct, since it outlasts the last video frame.
2023-04-09 15:47:45 +02:00
Anton Khirnov
9a85245adf fftools/sync_queue: support operation with no limiting streams
ffmpeg CLI will not create such queues currently, but this will become
useful in following commits.
2023-04-09 15:47:45 +02:00
Anton Khirnov
98b41d0bd2 fftools/sync_queue: document overall design 2023-04-09 15:47:45 +02:00
Anton Khirnov
090950f832 fftools/sync_queue: use timebase from input frames/packets
They are always properly set now. Avoid a separate timebase-setting
call, which duplicates the knowledge of the timebase being used.
2023-04-09 15:47:45 +02:00
Anton Khirnov
87e9f5ad3c fftools/ffmpeg: move initializing next_[pd]ts to add_input_streams()
They are initialized to constants, so it makes most sense to do it as
soon as possible.
2023-04-09 15:47:45 +02:00
Anton Khirnov
8e23a62eff fftools/ffmpeg: drop InputStream.processing_needed
It is equivalent to !InputStream.discard.
2023-04-09 15:47:45 +02:00
Anton Khirnov
e1d12aaa45 fftools/ffmpeg: do not return finished streams from choose_output() 2023-04-09 15:47:45 +02:00
Anton Khirnov
416e2661ea fftools/ffmpeg: make sure non-lavfi streams are closed on input EOF 2023-04-09 15:47:45 +02:00
James Almer
20dade27d9 fftools/ffprobe: print crop_* frame fields
Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2023-03-26 16:39:59 -03:00
Thilo Borgmann
653ee3f159 fftools/ffmpeg_mux_init: Use all metadata selectors if none is specified.
Fixes regression from 3c7dd5ed37.
Fixes ticket #10157.
2023-03-25 20:28:41 +01:00
James Almer
6ee6dd93eb fftools/ffprobe: add support for HDR10+ packet side data
Signed-off-by: James Almer <jamrial@gmail.com>
2023-03-25 13:27:20 -03:00
Anton Khirnov
3f63685c35 fftools/ffmpeg: supply hw_device_ctx to filters before initializing them
This is more correct, but was not possible before the recently-added
filtergraph parsing API.

Also, only pass hw devices to filters that are flagged as capable of
using them.

Tested-by: Niklas Haas
2023-03-24 10:23:52 +01:00
rcombs
b68a6ba469 ffmpeg: send only one rect per packet when encoding ASS
The packet and rect formats are identical,
so there's no support for multiple rects per packet.
2023-03-21 14:24:31 -04:00
Anton Khirnov
1e406692e5 fftools/ffmpeg_mux_init: avoid invalid reads in forced keyframe parsing
Fixes #10243
2023-03-20 10:53:03 +01:00
Anton Khirnov
2fb3ee1787 fftools/ffplay: stop using AVFrame.pkt_pos
This field is ad-hoc and will be deprecated. Use the recently-added
AV_CODEC_FLAG_COPY_OPAQUE to pass arbitrary user data from packets to
frames.
2023-03-20 10:42:09 +01:00
Anton Khirnov
c29e5ab5c1 fftools/ffplay: depend on avfilter
Making lavfi optional adds a lot of complexity for very questionable
gain.
2023-03-20 10:42:09 +01:00
Anton Khirnov
9141c0cfd8 fftools/ffplay: drop an unused function argument 2023-03-20 10:42:09 +01:00
Anton Khirnov
e6126abc69 fftools/ffprobe: stop using AVFrame.pkt_{pos,size}
These fields are ad-hoc and will be deprecated. Use the recently-added
AV_CODEC_FLAG_COPY_OPAQUE to pass arbitrary user data from packets to
frames.

Changes the result of the flcl1905 test, which uses ffprobe to decode
wmav2 with multiple frames per packet. Such packets are handled
internally by calling the decoder's decode callback multiple times,
offsetting the internal packet's data pointer and decreasing its size
after each call. The output pkt_size value before this commit is then
the remaining internal packet size at the time of each internal decode
call.

After this commit, output pkt_size is simply the size of the full packet
submitted by the caller to the decoder. This is more correct, since
internal packets are never seen by the caller and should have no
observable outside effects.
2023-03-20 10:42:09 +01:00
Anton Khirnov
0ad64cdd92 fftools/ffmpeg_filter: initialize graph inputs/outputs
Avoids uninitialized free on error.

Found-by: Paul B Mahol
2023-03-20 10:41:26 +01:00
Zhao Zhili
13deb775cf fftools/ffprobe: fix print_dynamic_hdr_vivid
Don't print tone_mapping_param_num if tone_mapping_mode_flag is
disabled.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-03-17 18:52:36 +08:00
Zhao Zhili
8de8f1df77 fftools/ffprobe: fix HDR vivid info
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-03-17 18:52:31 +08:00
Jun Zhao
a0a0a80499 fftools/ffmpeg_filter: initialize the 'o' to silence the warning
silence the warning: variable 'o' is used uninitialized whenever
'&&' condition is false

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2023-03-01 06:49:13 +08:00
Stefano Sabatini
9998c31044 ffmpeg_demux: show fixed timestamps in ts_fixup
Help debugging.
2023-02-28 22:24:56 +01:00
Anton Khirnov
156ca86569 fftools/ffmpeg: move ts_scale to DemuxStream
It is not needed outside of ffmpeg_demux.
2023-02-20 19:22:22 +01:00
Anton Khirnov
66c1e956aa fftools/ffmpeg_demux: add an AVClass to DemuxStream/InputStream
Use it for logging. This makes log messages related to this input stream
more consistent.
2023-02-20 19:22:22 +01:00
Anton Khirnov
d9079f6700 fftools/ffmpeg_demux: move InputStream.guess_layout_max to stack
It is only needed while processing the stream in add_input_streams(), no
reason to store it in the context.
2023-02-20 19:22:22 +01:00
Anton Khirnov
8a7554a574 fftools/ffmpeg_demux: add InputStream private data
Move {min,max}_pts to it, which is not used outside of ffmpeg_demux.
2023-02-20 19:22:22 +01:00
Anton Khirnov
cd4cd95d5e fftools/ffmpeg_demux: add an AVClass to Demuxer/InputFile
Use it for logging. This makes log messages related to this input file
more consistent.
2023-02-20 19:22:22 +01:00
Marton Balint
2296078397 avutil/frame: deprecate AVFrame.coded_picture_number and display_picture_number
Their usefulness is questionable, very few decoders set them, and their type
should have been int64_t. A replacement field can be added later if a valid use
case is found.

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-02-13 00:37:50 +01:00
Marton Balint
6b6f7db819 avcodec: add AVCodecContext.frame_num as 64 bit variant to frame_number
Frame counters can overflow relatively easily (INT_MAX number of frames is
slightly more than 1 year for 60 fps content), so make sure we use 64 bit
values for them.

Also deprecate the old 32 bit frame_number attribute.

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-02-13 00:36:46 +01:00
Anton Khirnov
78f46065d8 fftools/ffmpeg: add special syntax for loading filter options from files
Many filters accept user-provided data that is cumbersome to provide as
text strings - e.g. binary files or very long text. For that reason such
filters typically provide a option whose value is the path from which
the filter loads the actual data.

However, filters doing their own IO internally is a layering violation
that the callers may not expect, and is thus best avoided. With the
recently introduced graph segment parsing API, loading option values
from files can now be handled by the caller.

This commit makes use of the new API in ffmpeg CLI. Any option name in
the filtergraph syntax can now be prefixed with a slash '/'. This will
cause ffmpeg to interpret the value as the path to load the actual value
from.
2023-02-12 10:34:45 +01:00
Anton Khirnov
2c4dcbd66b fftools/ffmpeg: rename -enc_stats* to -stats_enc*
This is consistent with -stats_mux*

As the options were added very recently, this should not break any
users.
2023-02-10 11:02:13 +01:00
Anton Khirnov
b40856c905 fftools/ffmpeg_mux: distinguish between sync queue and muxer EOF
Individual streams should be terminated in the former case, the whole
muxing process in the latter.

Reported-by: Gyan Doshi
2023-02-10 11:01:11 +01:00
James Almer
0a95e4af99 avutil/version: postpone the remaining API deprecations
They are too recent.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-02-09 15:35:14 +01:00
James Almer
6d6ae3595b avformat: remove FF_API_AVSTREAM_CLASS
Signed-off-by: James Almer <jamrial@gmail.com>
2023-02-09 15:35:14 +01:00
James Almer
e0786a8eeb avcodec: remove FF_API_THREAD_SAFE_CALLBACKS
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-02-09 15:24:16 +01:00
Andreas Rheinhardt
868a31b42d avcodec: Make avcodec_decode_subtitle2 accept a const AVPacket*
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-02-09 15:24:15 +01:00
Anton Khirnov
42a0dd6e7e fftools/ffmpeg: add an option for writing pre-muxing stats
Analogous to -enc_stats*, but happens right before muxing. Useful
because bitstream filters and the sync queue can modify packets after
encoding and before muxing. Also has access to the muxing timebase.
2023-02-09 15:24:15 +01:00
Anton Khirnov
6d4f3ae116 fftools/ffmpeg: store output packet timebases in the packet
Useful to keep track of what timebase the packet's timestamps are in.
2023-02-09 15:24:15 +01:00
Marth64
25f31929b6 ffmpeg_opt: move help text for -ab/-b:a to audio category
Since at least 4.4.3, -ab/-b:a help text was in the video section
of ffmpeg -h, but these are audio options.

Signed-off-by: Marth64 <marth64@proxyid.net>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-02-09 12:45:53 +01:00
rcombs
18cd65998b ffprobe: report the corrupt flag on packets
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-02-09 12:45:53 +01:00
Jan Ekström
9a820ec8b1 ffmpeg: add video heartbeat capability to fix_sub_duration
Splits the currently handled subtitle at random access point
packets that can be configured to follow a specific output stream.
Currently only subtitle streams which are directly mapped into the
same output in which the heartbeat stream resides are affected.

This way the subtitle - which is known to be shown at this time
can be split and passed to muxer before its full duration is
yet known. This is also a drawback, as this essentially outputs
multiple subtitles from a single input subtitle that continues
over multiple random access points. Thus this feature should not
be utilized in cases where subtitle output latency does not matter.

Co-authored-by: Andrzej Nadachowski <andrzej.nadachowski@24i.com>
Co-authored-by: Bernard Boulay <bernard.boulay@24i.com>

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-02-03 16:17:29 +02:00
Jan Ekström
746d27455b ffmpeg: move decoded frame counter from after post-processing to decode
This way we can call process_subtitles without causing the decoded
frame counter to get bumped.

Additionally, this now takes into mention all of the decoded
subtitle frames without fix_sub_duration latency/buffering, or filtering
out decoded reset/end subtitles without any rendered rectangles, which
matches the original intent in 4754345027
.

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-02-03 12:21:02 +02:00
Jan Ekström
fcc50674de ffmpeg: refactor post-decoding steps for subtitles into a function
This enables us to later call this when generating additional
subtitles for splitting purposes.

Co-authored-by: Andrzej Nadachowski <andrzej.nadachowski@24i.com>

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2023-02-03 12:21:02 +02:00
Anton Khirnov
806ecace91 fftools/ffmpeg: support input frame params in encoding stats 2023-01-31 09:09:23 +01:00
Anton Khirnov
61afbc2376 fftools/ffmpeg: use correct IO context for -enc_stats_post 2023-01-31 09:09:11 +01:00
Anton Khirnov
9b5036fabd fftools/ffmpeg: add an AVClass to MuxStream/OutputStream
Use it for logging. This makes log messages related to this output
stream more consistent.
2023-01-29 09:12:22 +01:00
Anton Khirnov
d2c983c213 fftools/ffmpeg: add an AVClass to Muxer/OutputFile
Use it for logging. This makes log messages related to this output file
more consistent.
2023-01-29 09:10:57 +01:00
Anton Khirnov
425b2c4a56 fftools/ffmpeg: add options for writing encoding stats
Similar to -vstats, but more flexible:
- works for audio as well as video
- frame and/or packet information
- user-specifiable format
2023-01-29 09:09:59 +01:00
Stefano Sabatini
843a446713 ffprobe: fix data hash rendering
Print data hash before side data list, fix wrong nesting level of data hash
element.

In particular, fix trac issue:
http://trac.ffmpeg.org/ticket/7217
2023-01-24 23:58:00 +01:00
Stefano Sabatini
b6219c9114 ffprobe: use pkt->dts to compute interval ts when pts is missing
For some samples the pkt->pts is always missing, use the pkt->dts
instead.

Fix trac issue:
http://trac.ffmpeg.org/ticket/4427
2023-01-24 23:58:00 +01:00
Jan Ekström
be76a9bd32 ffprobe: expose AVAmbientViewingEnvironment side data in AVFrames 2023-01-13 21:26:27 +02:00
Zhao Zhili
52eb2396d7 fftools/ffmpeg_demux: prefer fd over pipe for seek support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-11 18:50:36 +08:00
Zhao Zhili
244f3cfbe3 fftools/ffprobe: prefer fd over pipe for seek support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-11 18:50:36 +08:00
Zhao Zhili
c926140558 fftools/ffplay: prefer fd over pipe for seek support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-11 18:50:36 +08:00
Zhao Zhili
195ccf7ea8 fftools/ffmpeg_demux: disable stdin interaction for fd protocol
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-01-11 18:50:36 +08:00
Anton Khirnov
260f391893 fftools/ffmpeg: always generate CFR output when -r is used
Current code may, depending on the muxer, decide to use VSYNC_VFR tagged
with the specified framerate, without actually performing framerate
conversion. This is clearly wrong and against the documentation, which
states unambiguously that -r should produce CFR output for video
encoding.

FATE test changes:
* nuv-rtjpeg: replace -r with '-enc_time_base -1', which keeps the
  original timebase. Output frames are now produced with proper
  durations.
* filter-mpdecimate: just drop the -r option, it is unnecessary
* filter-fps-r: remove, this test makes no sense and actually
  produces broken VFR output (with incorrect frame durations).
2023-01-10 11:49:28 +01:00
Anton Khirnov
7655249f72 fftools/ffmpeg: reindent after previous commit 2023-01-10 11:49:28 +01:00
Anton Khirnov
a848a5a223 fftools/ffmpeg: move video frame dup/drop logic into its own function 2023-01-10 11:49:28 +01:00
Anton Khirnov
5874ca3650 fftools/ffmpeg: rename a variable to be more descriptive 2023-01-10 11:49:28 +01:00
Anton Khirnov
3b21f10639 fftools/ffmpeg: fix stream id in an error message.
Broken in 7ef7a22251
2023-01-10 11:49:28 +01:00
Anton Khirnov
c60941dfaf fftools/ffmpeg: stop using AVCodecContext.sample_rate in decode_audio()
Use the decoded frame's sample_rate instead, which is the authoritative
value.

Drop a now-obsolete check validating AVCodecContext.sample_rate.
2023-01-10 11:49:28 +01:00
Marvin Scholz
ece29ad0dc fftools: use av_dict_get_string
Instead of manually assembling the string, use av_dict_get_string
which handles things like proper escaping too (even though it is
not yet needed here).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-12-01 11:21:14 +01:00
Marvin Scholz
f1907faab4 fftools: use av_dict_iterate
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-12-01 11:21:14 +01:00
Anton Khirnov
becbb22eb0 fftools/ffmpeg: cosmetics
Reindent after previous commit and break/split some lines as
appropriate.
2022-11-28 10:28:14 +01:00
Anton Khirnov
d04ec7efe3 fftools/ffmpeg: remove a useless inner block
adjust_frame_pts_to_encoder_tb() is so small that this serves no useful
purpose.
2022-11-28 10:28:14 +01:00
Anton Khirnov
d60d6d819d fftools/ffmpeg: drop an always-false check 2022-11-28 10:28:14 +01:00
Anton Khirnov
8ee4365ad8 fftools/ffmpeg: only convert video frame pts if we have a frame
Calling adjust_frame_pts_to_encoder_tb() with a NULL frame does not
perform a meaningful action.
2022-11-28 10:28:14 +01:00
Anton Khirnov
617ea07c22 fftools/ffmpeg: call check_recording_time() with actual frame pts
Not its estimated value that will not necessarily be used.
2022-11-28 10:28:14 +01:00
Anton Khirnov
86a71d6b3c fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio
Almost none of that function's complexity is useful for audio, it can
be replaced by a simple av_rescale_q().
2022-11-28 10:28:14 +01:00
Anton Khirnov
a186360f27 fftools/ffmpeg: set AVFrame.time_base after filtering
Makes it easier to track what timebase are the frame timestamps in and
allows to stop accessing filters in code that shouldn't deal with
filtering.
2022-11-28 10:28:14 +01:00
Anton Khirnov
d9534ec84e fftools/ffmpeg: move logging filtered frame timestamps
Do it right after the frame is received from the filtergraph. This is a
more logical place for this and will simplify future commits.
2022-11-28 10:28:14 +01:00
Anton Khirnov
2fa2e146cc fftools/ffmpeg: avoid storing full forced keyframe spec
It is not needed after the spec is parsed. Also avoids ugly string
comparisons for each video frame.
2022-11-28 10:28:14 +01:00
Anton Khirnov
334e52e094 fftools/ffmpeg: parse forced keyframes in of_open()
Allows to remove the ugly of_get_chapters() wrapper.
2022-11-28 10:28:14 +01:00
Anton Khirnov
efe4423627 fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q
Rather than the encoder timebase. Since the times are parsed as
microseconds, this will not reduce precision, except possibly when
chapter times are used and the chapter timebase happens to be better
aligned with the encoder timebase, which is unlikely.

This will allow parsing the keyframe times earlier (before encoder
timebase is known) in future commits.
2022-11-28 10:28:14 +01:00
Anton Khirnov
b1143330c8 fftools/ffmpeg: move force-keyframe-related vars to a separate struct
There are 8 of them and they are typically used together. Allows to pass
just this struct to forced_kf_apply(), which makes it clear that the
rest of the OutputStream is not accessed there.
2022-11-28 10:28:14 +01:00
Anton Khirnov
630fbdcc52 fftools/ffmpeg: stop explicitly closing decoders
It serves no purpose, they will be closed and freed in
avcodec_free_context() called from ist_free().
2022-11-28 10:28:14 +01:00
Anton Khirnov
95af0bcc34 fftools/ffmpeg_mux_init: postpone matching -disposition to streams
Do it in set_dispositions() rather than during stream creation.

Since at this point all other stream information is known, this allows
setting disposition based on metadata, which implements #10015. This
also avoids an extra allocated string in OutputStream that was unused
after of_open().
2022-11-23 10:36:23 +01:00
Anton Khirnov
3da5c60aa9 fftools/ffmpeg: _-prefix variables in MATCH_PER_STREAM_OPT()
Avoids conflicts, e.g. when 'i' is used in the outvar expression.
2022-11-23 10:36:23 +01:00
Anton Khirnov
996fed5235 fftools/ffmpeg: declare loop variables inside loops in transcode_init() 2022-11-23 10:36:23 +01:00
Anton Khirnov
005f4e1caf fftools/ffmpeg: do not assume input streams exist
There can be zero input streams, with input provided by lavfi complex
filtergraphs.
2022-11-23 10:36:23 +01:00
Anton Khirnov
fd8bf8d3b5 fftools/ffmpeg: remove the input_streams global
Replace it with an array of streams in each InputFile. This is a more
accurate reflection of the actual relationship between InputStream and
InputFile.

Analogous to what was previously done to output streams in
7ef7a22251.
2022-11-23 10:36:23 +01:00
Anton Khirnov
86e2ffedfe fftools/ffmpeg_mux_init: simplify inner loop in map_auto_{video,audio}
Skip unusable streams early and do not compute any scores for them.
2022-11-23 10:36:23 +01:00
Anton Khirnov
4c40581614 fftools/ffmpeg: replace OutputStream.source_index with a pointer to InputStream
This is simpler. The indirection via an index exists for historical
reasons that longer apply.
2022-11-23 10:36:23 +01:00
Anton Khirnov
bda06c60fe fftools/ffmpeg: stop inventing fake source information
This code was supposed to affect copying stream dispositions, but it
does not achieve that after bd55552d69, since dispositions are set
earlier.
2022-11-23 10:36:23 +01:00
Anton Khirnov
50ecba7e84 fftools/ffmpeg: drop an arbitrary condition
Encoding init code will currently fall back to a 25fps default when no
framerate is known or specified, but only if there is a known source
input stream. There is no good reason for this condition, so drop it.
2022-11-23 10:36:23 +01:00
Anton Khirnov
9654df1336 fftools/ffmpeg: move freeing an input stream into a separate function 2022-11-23 10:36:23 +01:00
Zhao Zhili
c0c0a5f106 fftools/ffmpeg_demux: set default hwaccel_output_format for mediacodec
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-11-21 23:57:10 +08:00
Anton Khirnov
b58264217b fftools/ffmpeg_mux_init: drop an always-false check
It cannot be true since 1959351aec. Effectively reverts 6a3833e141.
2022-11-17 10:52:58 +01:00
Anton Khirnov
13947aff3f fftools/ffmpeg_mux_init: use av_dict_iterate() where appropriate 2022-11-17 10:52:58 +01:00
Anton Khirnov
19e192eae6 fftools/ffmpeg_mux_init: do not call av{codec,format}_get_class() repeatedly 2022-11-17 10:52:58 +01:00
Anton Khirnov
52380a055b fftools/ffmpeg_mux_init: move validating codec avoptions to a separate function 2022-11-17 10:52:58 +01:00
Anton Khirnov
0fb7d111e8 fftools/ffmpeg: move OutputStream.max_frames to MuxStream
It no longer needs to be visible outside of the muxing code.
2022-11-17 10:52:58 +01:00
Anton Khirnov
25620b69e0 fftools/ffmpeg: stop handling max_frames in do_video_out()
Frame limiting is now handled using sync queues. This code prevents the
sync queue from triggering EOF, resulting in unnecessarily many frames
being decoded, filtered, and then discarded.

Found-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2022-11-17 10:52:58 +01:00
Anton Khirnov
6a8145a4b1 fftools/ffmpeg_mux_init: move more code from of_open() to create_streams()
Specificaly, the of_add_attachments() call (which can add attachment
streams to the output) and the check whether the output file contains
any streams. They both logically belong in create_streams().
2022-11-17 10:52:58 +01:00
Anton Khirnov
1b076556c6 fftools/ffmpeg: simplify ost_iter()
The inner loop never goes through more than 1 iteration, and so can be
replaced by an if().

Found-by: Andreas Rheinhardt
2022-11-17 10:52:58 +01:00
Anton Khirnov
822da7a317 fftools/ffmpeg: make demuxing with one file always blocking 2022-11-16 08:41:14 +01:00
Anton Khirnov
c15eb2773a fftools/ffmpeg_[de]mux: constify all uses of OptionsContext 2022-11-16 08:41:14 +01:00
Anton Khirnov
4119480681 fftools/ffmpeg_mux_init: stop using OptionsContext as storage in copy_metadata()
It should be input-only to this code. Will allow making it const in
future commits.
2022-11-16 08:41:14 +01:00
Anton Khirnov
3c7dd5ed37 fftools/ffmpeg_mux_init: drop a duplicated block in copy_metadata()
It does the same thing as the block right below it.
2022-11-16 08:41:14 +01:00
James Almer
b119b3da1e fftools/ffprobe: support 2D arrays in print_list_fmt()
Should fix undefined behavior.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-11-15 23:18:48 -03:00
Derek Buitenhuis
d1366c4167 fftools/ffprobe: Loop over correct number of streams when flushing decoders
Some formats like FLV can dynamically add streams during packet reading.
FFprobe does check for this and reallocates the global stream info, but does
not reallocate InputFrame's streams and decoders when this happens, which,
as a result, could have caused flushing to occur on an out of bounds stream
index, since the flush loop iterates over fmt_ctx's nb_streams, and not
ifile's, despite using ifile's streams.

This fixes an out of bounds read and segfult.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2022-11-07 16:13:45 +00:00
Gyan Doshi
5ccd4d3060 ffmpeg: fix implementation of updated input start time
The current adjustment of input start times just adjusts the tsoffset.
And it does so, by resetting the tsoffset to nullify the new start time.
This leads to breakage of -copyts, ignoring of input_ts_offset, breaking
of -isync as well as breaking wrap correction.

Fixed by taking cognizance of these parameters, and by correcting start times
just before sync offsets are applied.
2022-11-03 14:38:42 +05:30
Gyan Doshi
93faba449c ffmpeg: shift start time correction to ffmpeg_opt
In preparation for applying start time correction that accounts for all
factors such as copyts, input_ts_offset ..etc
2022-11-03 14:38:24 +05:30
Anton Khirnov
7aa5ea237f fftools/ffmpeg_demux: stop modifying OptionsContext
It should be input-only to this code.
2022-10-25 11:13:03 +02:00
Anton Khirnov
0d821edb40 fftools/ffmpeg_mux_init: stop modifying OptionsContext.*_disable
The current code will override the *_disable fields (set by -vn/-an
options) when creating output streams for unlabeled complex filtergraph
outputs, in order to disable automatic mapping for the corresponding
media type.

However, this will apply not only to automatic mappings, but to manual
ones as well, which should not happen. Avoid this by adding local
variables that are used only for automatic mappings.
2022-10-25 11:12:22 +02:00
Anton Khirnov
69da53ade9 fftools/ffmpeg_mux_init: move code creating streams into a new function
Makes it easy to see where all the streams are created. Will also be
useful in the following commit.
2022-10-25 11:12:05 +02:00
Anton Khirnov
006df0b6fe fftools/ffmpeg_mux_init: stop modifying some OptionsContext fields
Specifically recording_time and stop_time - use local variables instead.
OptionsContext should be input-only to this code. Will allow making it
const in future commits.
2022-10-25 11:11:35 +02:00
Anton Khirnov
ccab823559 fftools/ffmpeg_mux_init: constify metadata specifier arguments 2022-10-25 11:04:42 +02:00
Anton Khirnov
aa0ce91f57 fftools/ffmpeg_mux_init: avoid modifying OptionsContext.chapters_input_file
Use a local variable instead. This will allow making OptionsContext
const in future commits.
2022-10-25 11:04:42 +02:00
Anton Khirnov
5ccc151bf2 fftools/ffmpeg: factor out copying metadata/chapters from of_open()
This code shares variables like OptionsContext.metadata_*_manual, so it
makes sense to group it together.
2022-10-25 11:04:42 +02:00
Anton Khirnov
21ef1f2cec fftools/ffmpeg_demux: log when the demuxer thread terminates
Similar to what is done for muxing, may be useful for debugging.
2022-10-25 11:04:42 +02:00
Anton Khirnov
5c1a096d02 fftools/ffmpeg: move nb_streams_warn from InputFile to Demuxer
It is private to the demuxer and do not need to be visible outside of
it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
d8f7ce38da fftools/ffmpeg_demux: do not log to the demuxer context
Only the demuxer itself is supposed to do that.
2022-10-25 11:04:42 +02:00
Anton Khirnov
541104f3a3 fftools/ffmpeg: move duration/time_base from InputFile to Demuxer
They are private to the demuxer and do not need to be visible outside of
it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
5bc1f177d3 fftools/ffmpeg: move threading fields from InputFile to Demuxer
They are private to the demuxer and do not need to be visible outside of
it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
c20977c4e0 fftools/ffmpeg: drop free_input_threads()
Stop demuxer threads in ifile_close() instead. Simplifies the demuxer
API.
2022-10-25 11:04:42 +02:00
Anton Khirnov
295848bacb fftools/ffmpeg: move closing the input file into a separate function
For now this is just closing the format context and freeing InputFile,
but will contain more in the future.
2022-10-25 11:04:42 +02:00
Anton Khirnov
09cd147dcc fftools/ffmpeg: drop init_input_threads()
Start threads implicitly when ifile_get_packet() is called. Simplifies
the demuxer API.
2022-10-25 11:04:42 +02:00
Anton Khirnov
6975320506 fftools/ffmpeg_demux: add demuxer private data
Move InputFile.loop into it.
2022-10-25 11:04:42 +02:00
Anton Khirnov
78efefa9a5 fftools/ffmpeg_opt: move opening input files to ffmpeg_demux.c
This is similar to what was done before for output files and will allow
introducing demuxer-private state in future commits

Unlike for muxing, the code is moved to existing ffmpeg_demux.c rather
than to a new file. The reason is just file size - the demuxing code is
much smaller than muxing.
2022-10-25 11:04:42 +02:00
Anton Khirnov
874a6f2090 fftools/ffmpeg: set thread names 2022-10-24 02:00:31 +02:00
Anton Khirnov
4cfffdd551 fftools/ffmpeg: rename read_file() to avoid conflict with libass
libass defines a non-static read_file() symbol, which causes conflicts
with static linking.
2022-10-21 10:13:16 +02:00
Jan Ekström
b9058765d7 ffmpeg: Deprecate display rotation override with a metadata key
Now that we have proper options for defining display matrix
overrides, this should no longer be required.

fftools does not have its own versioning, so for now the define is
just set to 1 and disables the functionality if set to zero.
2022-10-19 11:53:52 +02:00
Jan Ekström
c889248647 ffmpeg: Add display_{rotation, hflip, vflip} options
This enables overriding the rotation as well as horizontal/vertical
flip state of a specific video stream on the input side.

Additionally, switch the singular test that was utilizing the rotation
metadata to instead override the input display rotation, thus leading
to the same result.
2022-10-19 11:53:52 +02:00
Andreas Rheinhardt
ff2c37d449 fftools/ffmpeg_opt: Move stuff only used by ffmpeg_mux_init to it
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-18 14:19:11 +02:00
Anton Khirnov
c5d7b6f49b fftools/ffmpeg_mux: move muxing queue fields from OutputStream to MuxStream
They are private to the muxer and do not need to be visible outside of
it.
2022-10-18 14:19:11 +02:00
Anton Khirnov
f0cd68eea0 fftools/ffmpeg_mux: move bsf_ctx from OutputStream to MuxStream
It is private to the muxer and does not need to be visible outside of
it.
2022-10-18 14:19:11 +02:00
Anton Khirnov
2266e04834 fftools/ffmpeg_mux: embed OutputStream in a MuxStream
This is now possible since OutputStream is a child of OutputFile and the
code allocating it can access MuxStream. Avoids the overhead and extra
complexity of allocating two objects instead of one.

Similar to what was previously done for OutputFile/Muxer.
2022-10-18 14:19:11 +02:00
Anton Khirnov
709b47f8a4 fftools/ffmpeg: free output streams in of_close()
Output streams are now children of OutputFile, so it makes more sense to
free them there.
2022-10-18 14:19:11 +02:00
Anton Khirnov
fe304c0694 fftools/ffmpeg: remove a cleanup block at the end of transcode()
Some of it is already duplicated in ost_free() - those parts can be just
dropped. The rest is moved to ost_free(), as it properly belongs there.
2022-10-18 14:19:07 +02:00
Anton Khirnov
7ef7a22251 fftools/ffmpeg: remove the output_streams global
Replace it with an array of streams in each OutputFile. This is a more
accurate reflection of the actual relationship between OutputStream and
OutputFile. This is easier to handle and will allow further
simplifications in future commits.
2022-10-18 13:57:43 +02:00
Anton Khirnov
0baed07f74 fftools/ffmpeg_mux_init: pass Muxer to new_output_stream()
And intermediate functions. Will be useful in the following commit.
2022-10-18 13:57:43 +02:00
Anton Khirnov
18d96e8703 fftools/ffmpeg: reindent after previous commit 2022-10-18 13:57:43 +02:00
Anton Khirnov
2dcedd9af8 fftools/ffmpeg: move freeing an output stream into a separate function 2022-10-18 13:57:43 +02:00
Anton Khirnov
9f9bf8703b fftools/ffmpeg: move init_output_bsfs() to ffmpeg_mux
Bitstream filtering is done as a part of muxing, so this is the more
proper place for this.
2022-10-18 13:57:43 +02:00
Anton Khirnov
ee0a900e58 fftools/ffmpeg_mux: move sq_mux from OutputFile to Muxer
It is internal to ffmpeg_mux* and does not need to be visible to other
code.
2022-10-18 13:57:43 +02:00
Anton Khirnov
d6195c88e2 fftools/ffmpeg_mux: inline mux_free() into of_close()
mux_free() is no longer called from anywhere else.
2022-10-18 13:57:43 +02:00
Anton Khirnov
36ce335d46 fftools/ffmpeg_mux: inline of_muxer_init() into of_open()
A separate muxer init is no longer necessary, now that of_open() has
access to Muxer.
2022-10-18 13:57:43 +02:00
Anton Khirnov
a55ca682e2 fftools/ffmpeg_mux: allocate sq_pkt in setup_sync_queues()
This is now possible since setup_sync_queues() can interact with Muxer.
2022-10-18 13:57:43 +02:00
Anton Khirnov
65d106933a fftools/ffmpeg_mux: embed OutputFile in a Muxer
This is now possible since the code allocating OutputFile can see
sizeof(Muxer). Avoids the overhead and extra complexity of allocating
two objects instead of one.

Similar to what is done e.g. for AVStream/FFStream in lavf.
2022-10-18 13:57:43 +02:00
Anton Khirnov
24098c6c8d fftools/ffmpeg_mux: move Muxer and MuxStream to a new header
This will allow ffmpeg_mux_init.c to work with these structs.
2022-10-18 13:57:43 +02:00
Anton Khirnov
18d6c07267 fftools/ffmpeg_opt: move opening output files into a new file
ffmpeg_opt.c currently contains code for
- parsing the options provided on the command line
- opening and initializing input files based on these options
- opening and initializing output files based on these options

The code dealing with each of these is for the most part disjoint, so it
makes sense to move them to separate files. Beyond reducing the quite
considerable size of ffmpeg_opt.c, this will also allow exposing muxer
internals (currently private to ffmpeg_mux.c) to the initialization
code, thus removing the awkward separation currently in place.
2022-10-18 13:57:42 +02:00
Anton Khirnov
965bff37b6 fftools/ffmpeg: move some stream initialization code to ffmpeg_mux
The code in question is muxing-specific and so belongs there. This will
allow make some objects private to the muxer in future commits.
2022-10-18 13:57:42 +02:00
Anton Khirnov
731246ae8f fftools/ffmpeg_mux: drop the of_ prefix from of_submit_packet()
This function is now static.
2022-10-18 13:57:42 +02:00
Anton Khirnov
a7028d7fa8 fftools/ffmpeg_mux: rename submit_packet() to thread_submit_packet()
This is more descriptive, and the submit_packet() name will be reused in
following commits.
2022-10-18 13:57:42 +02:00
Anton Khirnov
d579a70291 fftools/ffmpeg: move output_packet() to ffmpeg_mux
This function is common to both transcoding and streamcopy, so it
properly belongs into the muxing code.
2022-10-18 13:57:42 +02:00
Anton Khirnov
072e3f710e fftools/ffmpeg_mux: do not unref a NULL packet
The packet submitted to of_submit_packet() may be NULL to signal EOF.
2022-10-18 13:57:42 +02:00
Marvin Scholz
fed841f6f9 fftools/ffmpeg_opt: Use av_err2str
This simplifies the code as there is no other place the error buffer
is needed, so the av_err2str helper macro can be used.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-14 12:19:13 +02:00
Marvin Scholz
88635c7f95 fftools/ffprobe: Use av_err2str
av_err2str which is a wrapper for av_strerror already calls
strerror_r if available and if not has a fallback for the other
error codes that would be handled by that, so manually calling
strerror again if it fails is not necessary.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-14 12:19:13 +02:00
Marvin Scholz
3eab2c1af1 fftools/cmdutils: Use av_err2str
av_err2str which is a wrapper for av_strerror already calls
strerror_r if available and if not has a fallback for the other
error codes that would be handled by that, so manually calling
strerror again if it fails is not necessary.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-14 12:19:13 +02:00
Marvin Scholz
3ce1616106 ffmpeg: Make find_stream_info behave like a normal per-file option
Currently it would essentially change the find_stream_info setting for
the file it was specified for and all following files, which is unusual
and somewhat unexpected behaviour for a per-file option and not even
documented to behave like this.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-13 10:19:13 +02:00
Anton Khirnov
044d70736e fftools/ffmpeg: move some code from init_output_stream() to init_output_stream_encode()
The code is subtitle-encoding-specific, so this is a more appropriate
place for it.
2022-10-04 11:55:03 +02:00
Anton Khirnov
29188f9c62 fftools/ffmpeg: rename OutputStream.sync_opts to next_pts
The current name is confusing.
2022-10-04 11:55:03 +02:00
Anton Khirnov
3c0f532cbc fftools/ffmpeg: pass the timestamp to check_recording_time()
Stop setting OutputStream.sync_opts for subtitle encoding, as it is now
unused.
2022-10-04 11:55:03 +02:00
Anton Khirnov
69f770f77c fftools/ffmpeg: stop setting OutputStream.sync_opts for streamcopy
It is not used for anything.
2022-10-04 11:55:03 +02:00
Anton Khirnov
76678b7137 fftools/ffmpeg: drop never-set OutputStream.first_pts 2022-10-04 11:55:03 +02:00
Anton Khirnov
5188aeaffb fftools/ffmpeg: cosmetics
Reindent after previous commit, apply some style fixes.
2022-10-04 11:55:03 +02:00
Anton Khirnov
c75be06148 fftools/ffmpeg: move forced keyframe processing into its own function 2022-10-04 11:55:03 +02:00
Anton Khirnov
7a994c8701 fftools/ffmpeg: drop always-true conditions
in_picture->pts cannot be AV_NOPTS_VALUE, as it is set to ost->sync_opts
a few lines above. ost->sync_opts is never AV_NOPTS_VALUE.
2022-10-04 11:55:03 +02:00
Anton Khirnov
3d86a13b47 fftools/ffmpeg: drop the -async option
It has been deprecated in favor of the aresample filter for almost 10
years.

Another thing this option can do is drop audio timestamps and have them
generated by the encoding code or the muxer, but
- for encoding, this can already be done with the setpts filter
- for muxing this should almost never be done as timestamp generation by
  the muxer is deprecated, but people who really want to do this can use
  the setts bitstream filter
2022-10-04 11:55:03 +02:00
Marvin Scholz
cc48454561 fftools/ffmpeg: Remove unused frame_bits_per_raw_sample variable
Unused since the bits_per_raw_sample was made a per-output-stream
option in 4258893961

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-02 11:59:25 +02:00
Marvin Scholz
793953f44a fftools/ffmpeg: Remove unused do_deinterlace variable
Unused since removal of the -deinterlace option in
d013453caa

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-02 11:59:25 +02:00
Marvin Scholz
1c8e95bd99 fftools: Remove unused videotoolbox_init declaration
The code that defined videotoolbox_init was removed in
4b54818981

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-02 11:59:25 +02:00
Marvin Scholz
d2cf6d1665 fftools: Remove unused qsv declarations
The code that uses these was removed in
ecee3b07cd

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-10-02 11:59:25 +02:00
Derek Buitenhuis
f5cd00bf52 ffprobe: Check for invalid matrix error when printing rotation
av_display_rotation_get will return NAN when the display matrix is invalid,
which would end up printing NAN as an integer in the rotation field. This
is poor for multiple reasons:

* Users of ffprobe have no way of discerning "valid but ugly rotation from
  display matrix" from "invalid display matrix".
* It can have unintended consequences on some platforms, such as Linux x86_64,
  where NAN is equal to INT64_MIN, which, for example, when printed as JSON,
  which uses floating point for all numbers, can end up as invalid JSON or wit
  a number that cannot be reserialized as an integer at all.

Since NAN is av_display_rotation_get's error case, just print 0 (no rotation)
when that happens.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2022-09-27 17:37:21 +01:00
Zhao Zhili
686096739b fftools/ffmpeg_filter: configure min_hard_comp unconditionally
There are two issues here. Firstly, the floating-point comparison
is always true. Seconly, the code depends on the default value of
min_hard_comp implicitly, which can be dangerous.

Partially fixes ticket 9859.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-09-23 19:58:08 +08:00
Zhao Zhili
af919cf780 fftools/ffmpeg: fix av_display_rotation_set() type cast
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-09-22 20:03:57 +08:00
Wang Yaqiang
3f0fac9303 fftools/ffplay: fix rotation incorrect when frame contains the displaymatrix
For example, if the jpeg contains exif information
and the rotation direction is included in the exif,
the displaymatrix will be set on the side_data of the frame when decoding.
However, when ffplay is used to play the image,
only the side data in the stream will be determined.
It does not check whether the frame also contains rotation information,
causing it to play in the wrong direction

Reviewed-by: Zhao Zhili <zhilizhao@tencent.com>
Signed-off-by: Wang Yaqiang <wangyaqiang03@kuaishou.com>
2022-09-15 16:16:16 +08:00
James Almer
130483449e fftools/opt_common: check the return value of av_hwdevice_get_type_name before printing it
It may be NULL, as is the case for D3D11VA_VLD.

Running "ffmpeg -h decoder=h264" on a Windows build

Before:
Decoder h264 [H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:
    Supported hardware devices: dxva2 (null) d3d11va cuda

After:
Decoder h264 [H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:
    Supported hardware devices: dxva2 d3d11va cuda

Signed-off-by: James Almer <jamrial@gmail.com>
2022-09-14 09:54:19 -03:00
Andreas Rheinhardt
5c16df1b92 fftools/ffprobe: Report initial and trailing padding
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-05 20:32:12 +02:00
Andreas Rheinhardt
90aa2a88f9 fftools/ffmpeg_opt: Check creation of new program
Fixes Coverity issue #1512413.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-01 14:26:01 +02:00
Andreas Rheinhardt
601faaed92 fftools: Use report_error_then_exit_program() for allocation failures
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-01 14:26:00 +02:00
Andreas Rheinhardt
e157b21a90 fftools/cmdutils: Add function to report error before exit
This is designed to improve and unify error handling for
allocation failures for the many (often small) allocations that we have
in the fftools. These typically either don't return an error message
or an error message that is not really helpful to the user
and can be replaced by a generic error message without loss of
information.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-01 14:21:56 +02:00
Anton Khirnov
4fce3bab64 fftools/ffmpeg: use a separate counter for encoded packet data size
update_video_stats() currently uses OutputStream.data_size to print the
total size of the encoded stream so far and the average bitrate.
However, that field is updated in the muxer thread, right before the
packet is sent to the muxer. Not only is this racy, but the numbers may
not match even if muxing was in the main thread due to bitstream
filters, filesize limiting, etc.

Introduce a new counter, data_size_enc, for total size of the packets
received from the encoder and use that in update_video_stats(). Rename
data_size to data_size_mux to indicate its semantics more clearly.

No synchronization is needed for data_size_mux, because it is only read
in the main thread in print_final_stats(), which runs after the muxer
threads are terminated.
2022-08-29 15:42:11 +02:00
Anton Khirnov
0dd7347963 fftools/ffmpeg: drop OutputStream.fps_mode
It is only used within new_video_stream(), so make it a local variable
there.
2022-08-29 15:42:11 +02:00
Anton Khirnov
d0f767f81f fftools/ffmpeg: drop OutputStream.enc
It is either equal to OutputStream.enc_ctx->codec, or NULL when enc_ctx
is NULL. Replace the use of enc with enc_ctx->codec, or the equivalent
enc_ctx->codec_* fields where more convenient.
2022-08-29 15:42:11 +02:00
Anton Khirnov
4a4a206304 fftools/ffmpeg_filter: remove an always-true check
ost->enc is always non-NULL here, since
- this code is never called for streamcopy
- opening the output file will fail if an encoder cannot be found, so
  filters are never initialized
2022-08-29 15:42:11 +02:00
Anton Khirnov
c97bb940c2 fftools/ffmpeg_filter: remove an always-false check
This code cannot be triggered, since after 90944ee3ab opening the
output file will abort if an encoder cannot be found and streamcopy was
not explicitly requested.
2022-08-29 15:42:11 +02:00
Anton Khirnov
7c8737548f fftools/ffmpeg: remove a stale extern declaration
Forgotten in 8cbf229c94
2022-08-29 15:42:11 +02:00
Anton Khirnov
8d26a21bf6 fftools/ffmpeg: stop accessing av_stream_get_parser() from the main thread
It races with the demuxing thread. Instead, send the information along
with the demuxed packets.

Ideally, the code should stop using the stream-internal parsing
completely, but that requires considerably more effort.

Fixes races, e.g. in:
- fate-h264-brokensps-2580
- fate-h264-extradata-reload
- fate-iv8-demux
- fate-m4v-cfr
- fate-m4v
2022-08-29 15:42:11 +02:00
James Almer
f5a663f2a9 fftools/ffmpeg_opt: try to propagate the requested output channel layout
Don't silently replace it with the default layout for the amount of channels
from the requested layout.

Should fix ticket #9869

Signed-off-by: James Almer <jamrial@gmail.com>
2022-08-23 13:03:56 -03:00
Anton Khirnov
f23e3ce858 fftools/ffmpeg: call av_guess_frame_rate() when opening the file
It is currently called when configuring the filter, which races with the
demuxer thread.
2022-08-22 11:36:43 +02:00
Gyan Doshi
d5544f6457 ffprobe: restore reporting error code for failed inputs
c11fb46731 led to a regression whereby the return code for missing
input or input probe is overridden by writer close return code and
hence not conveyed in the exit code.
2022-08-17 16:46:05 +05:30
Anton Khirnov
ab31473830 fftools/ffmpeg: store a separate copy of input codec parameters
Use it instead of AVStream.codecpar in the main thread. While
AVStream.codecpar is documented to only be updated when the stream is
added or avformat_find_stream_info(), it is actually updated during
demuxing. Accessing it from a different thread then constitutes a race.

Ideally, some mechanism should eventually be provided for signalling
parameter updates to the user. Then the demuxing thread could pick up
the changes and propagate them to the decoder.
2022-08-16 11:09:09 +02:00
Timo Rothenpieler
f85e0673c3 fftools: add DPI awareness manifest
Some filters, like gdigrab, rely on this to be set to see and report
proper dimensions.
2022-08-13 14:42:52 +02:00
Anton Khirnov
6ded80af92 fftools/ffmpeg: move packet timestamp processing to demuxer thread
Discontinuity detection/correction is left in the main thread, as it is
entangled with InputStream.next_dts and related variables, which may be
set by decoding code.

Fixes races e.g. in fate-ffmpeg-streamloop after
aae9de0cb2.
2022-08-13 12:41:05 +02:00
Anton Khirnov
3b2beceae1 fftools/ffmpeg: use a separate variable for discontinuity offset
This will allow to move normal offset handling to demuxer thread, since
discontinuities currently have to be processed in the main thread, as
the code uses some decoder-produced values.
2022-08-13 12:41:05 +02:00
Anton Khirnov
ca38fe927e fftools/ffmpeg: simplify conditions in ts_discontinuity_process 2022-08-13 12:41:05 +02:00
Anton Khirnov
aa6d4a53e3 fftools/ffmpeg: move inter-stream ts discontinuity handling to ts_discontinuity_process() 2022-08-13 12:41:05 +02:00
Anton Khirnov
e2d784a5b7 fftools/ffmpeg: move timestamp discontinuity correction out of process_input() 2022-08-13 12:41:05 +02:00
Anton Khirnov
274c8d5882 fftools/ffmpeg: pre-compute the streamcopy start pts before transcoding starts
InputFile.ts_offset can change during transcoding, due to discontinuity
correction. This should not affect the streamcopy starting timestamp.

Cf. bf2590aed3
2022-08-13 12:41:05 +02:00
Anton Khirnov
86e9cef77b fftools/ffmpeg: move stream-dependent starttime correction to transcode_init()
Currently this code is located in the discontinuity handling block,
where it does not belong.
2022-08-13 12:41:05 +02:00
Anton Khirnov
ee2092ddec fftools/ffmpeg_mux: avoid leaking pkt on errors 2022-08-13 12:41:05 +02:00
Anton Khirnov
5d499d3250 fftools/ffmpeg: mark all encode sync queues as done before flushing encoders 2022-08-13 12:41:05 +02:00
Anton Khirnov
a5e025e826 fftools/ffmpeg: move handling corrupt packets to the input thread 2022-08-08 16:20:58 +02:00
Anton Khirnov
61d9f34c70 fftools/ffmpeg_demux: do not store demux packet in the context
Its use is local to input_thread().
2022-08-08 16:20:58 +02:00
Anton Khirnov
de9fb9fba7 fftools/ffmpeg_demux: factorize signalling end of demuxing 2022-08-08 16:20:58 +02:00
Anton Khirnov
aae9de0cb2 fftools/ffmpeg: move -stream_loop handling to the demuxer thread
-stream_loop is currently handled by destroying the demuxer thread,
seeking, then recreating it anew. This is very messy and conflicts with
the future goal of moving each major ffmpeg component into its own
thread.

Handle -stream_loop directly in the demuxer thread. Looping requires the
demuxer to know the duration of the file, which takes into account the
duration of the last decoded audio frame (if any). Use a thread message
queue to communicate this information from the main thread to the
demuxer thread.
2022-08-08 16:20:58 +02:00
Anton Khirnov
b99462cd27 fftools/ffmpeg: move seek_to_start() to ffmpeg_demux.c
Reduces the diff in the following commit.
2022-08-08 16:20:58 +02:00
Anton Khirnov
57d75ca031 fftools/ffmpeg: move get_input_packet() to ffmpeg_demux.c
Also rename it to use the ifile_* namespace.
2022-08-08 16:20:58 +02:00
Anton Khirnov
07da07ddb0 fftools/ffmpeg: report new streams from the input thread
This avoids a potential race with the demuxer adding new streams. It is
also more efficient, since we no longer do inter-thread transfers of
packets that will be just discarded.
2022-08-08 16:20:58 +02:00
Anton Khirnov
9c16310fe5 fftools/ffmpeg: handle dumping input packets in input_thread()
This is a more appropriate place for this.
2022-08-08 16:20:58 +02:00
Anton Khirnov
b1f24afe7e fftools/ffmpeg: drop the 'h' key handling
This undocumented feature runtime-enables dumping input packets. I can
think of no reasonable real-world use case that cannot also be
accomplished in a different way. Keeping this functionality would
interfere with the following commit moving it to the input thread (then
setting the variable would require locking or atomics, which would be
unnecessarily complicated for a feature that probably nobody uses).
2022-08-08 16:20:58 +02:00
Anton Khirnov
7b6622705e fftools/ffmpeg: move the input thread into its own file
It will contain more demuxing-specific code in the future.
2022-08-08 16:20:58 +02:00
Anton Khirnov
c3b8d59d2f fftools/ffmpeg: drop a write-only variable 2022-08-08 16:20:58 +02:00
Anton Khirnov
d8bf53710f fftools/ffmpeg: always read input in a thread
This will be required by the following architecture changes.
2022-08-08 16:20:58 +02:00
Anton Khirnov
cc2b7f4625 fftools/ffmpeg: store the input file index in InputFile
Use it to simplify some code and fix two off-by-one errors.

Similar to what was previously done for OutputFile.
2022-08-08 16:20:58 +02:00
Anton Khirnov
9139ea4c8d fftools/ffmpeg: drop a superfluous stack variable 2022-08-08 16:20:58 +02:00
Anton Khirnov
fee249b30a fftools/ffmpeg: deprecate specifying a sync stream with -map
It has not had any effect whatsoever for over 10 years.
2022-08-08 16:20:58 +02:00
Anton Khirnov
49123dd058 fftools/ffmpeg: remove OutputStream.sync_ist
It is not actually used for anything.
2022-08-08 16:20:58 +02:00
Anton Khirnov
8e092c3eac fftools/ffmpeg: remove OutputStream.encoding_needed
It is unnecessary, as it is always exactly equivalent to !!ost->enc_ctx
2022-08-08 16:20:58 +02:00
Anton Khirnov
80e7feb48b fftools/ffmpeg: remove OutputStream.stream_copy
There are currently three possible modes for an output stream:
1) The stream is produced by encoding output from some filtergraph. This
   is true when ost->enc_ctx != NULL, or equivalently when
   ost->encoding_needed != 0.
2) The stream is produced by copying some input stream's packets. This
   is true when ost->enc_ctx == NULL && ost->source_index >= 0.
3) The stream is produced by attaching some file directly. This is true
   when ost->enc_ctx == NULL && ost->source_index < 0.

OutputStream.stream_copy is currently used to identify case 2), and
sometimes to confusingly (or even incorrectly) identify case 1). Remove
it, replacing its usage with checking enc_ctx/source_index values.
2022-08-08 16:20:58 +02:00
Anton Khirnov
4f2b946c19 fftools/ffmpeg_opt: drop redundant decoder selection
A decoder is already selected above, in choose_decoder().
2022-08-08 16:20:58 +02:00
Anton Khirnov
a1da77bd71 fftools/ffmpeg: stop accessing the decoder context unnecessarily
The same information is available from AVStream.codecpar. This will
allow to stop allocating a decoder unless decoding is actually
performed.
2022-08-08 16:20:58 +02:00
Anton Khirnov
04b340e6b8 fftools/ffmpeg_hw: stop logging to the decoder context
Only the decoder itself should do that. Use NULL as is done by all other
logging code in ffmpeg.
2022-08-08 16:20:58 +02:00
Anton Khirnov
20ba49c1a4 fftools/ffmpeg_opt: move adding metadata out of open_output_file() 2022-08-08 16:20:58 +02:00
Anton Khirnov
7cafea59bc fftools/ffmpeg_opt: move adding programs out of open_output_file() 2022-08-08 16:20:58 +02:00
Anton Khirnov
aad68ab0e0 fftools/ffmpeg_opt: move adding attachments out of open_output_file() 2022-08-08 16:20:58 +02:00
Haihao Xiang
ad67ea9eee ffmpeg_opt: consider HW acceleration method when selecting decoder
Usually a HW decoder is expected when user specifies a HW acceleration
method via -hwaccel option, however the current implementation doesn't
take HW acceleration method into account, it is possible to select a SW
decoder.

For example:
$ ffmpeg -hwaccel vaapi -i av1.mp4 -f null -
$ ffmpeg -hwaccel nvdec -i av1.mp4 -f null -
$ ffmpeg -hwaccel vdpau -i av1.mp4 -f null -
[...]
Stream #0:0 -> #0:0 (av1 (libdav1d) -> wrapped_avframe (native))

libdav1d is selected in this case even if vaapi, nvdec or vdpau is
specified.

After applying this patch, the native av1 decoder (with vaapi, nvdec or
vdpau support) is selected for decoding(libdav1d is still used for
probing format).
$ ffmpeg -hwaccel vaapi -i av1.mp4 -f null -
$ ffmpeg -hwaccel nvdec -i av1.mp4 -f null -
$ ffmpeg -hwaccel vdpau -i av1.mp4 -f null -
[...]
Stream #0:0 -> #0:0 (av1 (native) -> wrapped_avframe (native))

Tested-by: Mario Roy <marioeroy@gmail.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-08-03 11:10:57 +08:00
Haihao Xiang
df5defe15a ffmpeg_opt: select a decoder after getting values for per-stream hwdec options
After applying this patch, the desired HW acceleration method is known
before selecting decoder, so we may take HW acceleration method into
account when selecting decoder for input stream in the next commit

There should be no functional changes in this patch

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2022-08-03 09:54:20 +08:00
Andreas Rheinhardt
d9cd192ddd fftools/ffmpeg_opt: Fix copyinkf
Broken in 9c2b800203.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-02 09:02:11 +02:00
Anton Khirnov
6b12208646 fftools/ffmpeg_opt: reindent 2022-07-28 16:37:16 +02:00
Anton Khirnov
ac3e461348 fftools/ffmpeg_opt: factor manually mapping streams out of open_output_file() 2022-07-28 16:37:16 +02:00
Anton Khirnov
753195944a fftools/ffmpeg_opt: reindent 2022-07-28 16:37:16 +02:00
Anton Khirnov
85692aeecb fftools/ffmpeg_opt: factor auto-mapping data streams out of open_output_file() 2022-07-28 16:37:16 +02:00
Anton Khirnov
6bd98d9ed8 fftools/ffmpeg_opt: reduce indentation in map_auto_subtitle()
Fix indentation after the previous commit. Also use an early return to
save one extra indentation level.
2022-07-28 16:37:16 +02:00
Anton Khirnov
6ab412ef9c fftools/ffmpeg_opt: factor auto-mapping subtitles out of open_output_file() 2022-07-28 16:37:16 +02:00
Anton Khirnov
ff40d9e8ed fftools/ffmpeg_opt: reduce indentation in map_auto_audio()
Fix indentation after the previous commit. Also use an early return to
save one extra indentation level.
2022-07-28 16:37:16 +02:00
Anton Khirnov
b898dc8934 fftools/ffmpeg_opt: factor auto-mapping audio out of open_output_file() 2022-07-28 16:37:16 +02:00
Anton Khirnov
74176f3cd6 fftools/ffmpeg_opt: reduce indentation in map_auto_video()
Fix indentation after the previous commit. Also use an early return to
save one extra indentation level.
2022-07-28 16:37:16 +02:00
Anton Khirnov
1a464efae3 fftools/ffmpeg_opt: factor auto-mapping video out of open_output_file() 2022-07-28 16:37:16 +02:00