Commit Graph

598 Commits

Author SHA1 Message Date
Anton Khirnov d02ae31fb2 fftools/ffmpeg: use pre-BSF DTS for choosing next output
The following commits will add a new buffering stage after bitstream
filters, which should not be taken into account for choosing next
output.

OutputStream.last_mux_dts is also used by the muxing code to make up
missing DTS values - that field is now moved to the muxer-private
MuxStream object.
2022-07-23 11:53:19 +02:00
Anton Khirnov b2b9e9ccee fftools/ffmpeg: use last filter output pts to choose next output stream
This will be needed in following commits that will add new buffering
stages after encoding and bitstream filtering.
2022-07-23 11:53:19 +02:00
Anton Khirnov f52d045e34 fftools/ffmpeg: do not send spurious EOF for streamcopy when looping 2022-07-23 11:53:19 +02:00
Anton Khirnov 481b27e850 fftools/ffmpeg: use refcounted packets for encoded subtitles 2022-07-23 11:53:19 +02:00
Anton Khirnov dceccd4aeb fftools/ffmpeg: move freeing 2pass input stats to a better place
The current placement of this free is historical - it used to be
followed by avcodec_close(), since removed.

The proper place for freeing the stats is currently right before the
encoder context itself is freed.
2022-07-23 11:53:19 +02:00
Anton Khirnov 52fee96ae9 fftools/ffmpeg: move output file opts into private context
It is private to the muxer, no reason to access it from outside.
2022-07-23 11:53:19 +02:00
Anton Khirnov ec00b005f9 fftools/ffmpeg_mux: split of_write_packet()
It is currently called from two places:
- output_packet() in ffmpeg.c, which submits the newly available output
  packet to the muxer
- from of_check_init() in ffmpeg_mux.c after the header has been
  written, to flush the muxing queue

Some packets will thus be processed by this function twice, so it
requires an extra parameter to indicate the place it is called from and
avoid modifying some state twice.

This is fragile and hard to follow, so split this function into two.
Also rename of_write_packet() to of_submit_packet() to better reflect
its new purpose.
2022-07-23 11:53:19 +02:00
Anton Khirnov 6999a3cb18 fftools/ffmpeg_mux: split queuing packets into a separate function 2022-07-23 11:53:19 +02:00
Anton Khirnov 9c2b800203 fftools/ffmpeg: move the mux queue into muxer private data
The muxing queue currently lives in OutputStream, which is a very large
struct storing the state for both encoding and muxing. The muxing queue
is only used by the code in ffmpeg_mux, so it makes sense to restrict it
to that file.

This makes the first step towards reducing the scope of OutputStream.
2022-07-23 11:53:19 +02:00
Anton Khirnov 35bfcff07f fftools/ffmpeg: do not log to the muxer context
All other logging goes to NULL context.
2022-07-23 11:53:19 +02:00
Anton Khirnov 48989efb76 fftools/ffmpeg: access output file chapters through a wrapper
Avoid accessing the muxer context directly, as this will become
forbidden in future commits.
2022-07-23 11:53:19 +02:00
Anton Khirnov 4877842bb5 fftools/ffmpeg: refactor the code checking for bitexact output
Figure out earlier whether the output stream/file should be bitexact and
store this information in a flag in OutputFile/OutputStream.

Stop accessing the muxer in set_encoder_id(), which will become
forbidden in future commits.
2022-07-23 11:53:19 +02:00
Anton Khirnov cc1cc2c65e fftools/ffmpeg: move closing the file into of_write_trailer()
The current code postpones closing the files until after printing the
final report, which accesses the output file size. Deal with this by
storing the final file size before closing the file.
2022-07-23 11:53:19 +02:00
Anton Khirnov cc49646077 fftools/ffmpeg: write the header for stream-less outputs when initializing the muxer
There is no reason to delay this.
2022-07-23 11:53:19 +02:00
Anton Khirnov 12e9e50219 fftools/ffmpeg: set want_sdp when initializing the muxer
Allows making the variable local to ffmpeg_mux.
2022-07-23 11:53:19 +02:00
Anton Khirnov d8e944c238 fftools/ffmpeg: refactor limiting output file size with -fs
Move the file size checking code to ffmpeg_mux. Use the recently
introduced of_filesize(), making this code consistent with the size
shown by print_report().
2022-07-23 11:53:19 +02:00
Anton Khirnov 81af4dec27 fftools/ffmpeg: fix the type of limit_filesize
The option is parsed as INT64 (signed). It is also compared to the
output of avio_tell(), which is also int64_t.
2022-07-23 11:53:19 +02:00
Anton Khirnov 9fe62a545f fftools/ffmpeg: add a helper function to access output file size
Stop accessing muxer internals from outside of ffmpeg_mux.
2022-07-23 11:53:19 +02:00
Anton Khirnov 6a23be92d2 fftools/ffmpeg_mux: add private muxer context
Move header_written into it, which is not (and should not be) used by
any code outside of ffmpeg_mux.

In the future this context will contain more muxer-private state that
should not be visible to other code.
2022-07-23 11:53:19 +02:00
Anton Khirnov de3a135e0f ffmpeg: use AVFrame.duration instead of AVFrame.pkt_duration 2022-07-19 12:27:18 +02:00
Anton Khirnov ccb94ec5cf ffprobe: print AVFrame.duration 2022-07-19 12:27:18 +02:00
Timo Rothenpieler 91a95e19c9 fftools/ffmpeg: make debug_ts print raw filter output 2022-07-18 00:32:14 +02:00
Gyan Doshi 882aac99d2 ffmpeg: add option -isync
This is a per-file input option that adjusts an input's timestamps
with reference to another input, so that emitted packet timestamps
account for the difference between the start times of the two inputs.

Typical use case is to sync two or more live inputs such as from capture
devices. Both the target and reference input source timestamps should be
based on the same clock source.

If either input lacks starting timestamps, then no sync adjustment is made.
2022-07-14 15:48:24 +05:30
Andreas Rheinhardt c6134ce65f fftools/ffprobe: Improve description of AFD side data
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-09 20:21:31 +02:00
Andreas Rheinhardt dc977f94d5 fftools/ffprobe: Add const to AVPacket data pointers
These packets need not be writable (and are not modified by us),
so it is best to access them via const uint8_t*.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-09 19:37:53 +02:00
Nicolas Gaullier d3cf7be5a4 fftools: Fix preset search pathes
regression since 13350e81fd

Fix looking for .ffmpeg subfolder in FFMPEG_DATADIR and inversely not in HOME.
Fix search order (documentation).

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2022-07-08 13:58:49 +02:00
Marton Balint 20e2aa940c fftools/ffmpeg: change frame counters to 64 bit
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 are always
using 64 bit values for them.

A live stream can easily run for more than a year and the framedup logic breaks
on an overflow.

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-06-27 20:37:43 +02:00
Niklas Haas a526f0cc3a fftools/ffplay: fix YUV conversion mode
GL and Metal cache the state at time of texture creation. GLES2 and
Direct3D 11 use the state at time of the render copy call.

So the only way we can get the correct behavior consistently is by
making sure the state is set for both the upload *and* the draw call.
This probably isn't our bug to fix (upstream should make itself behave
consistently and also document its functions), but as it stands,
`ffplay` is misrendering BT.709 as BT.601 on my stock Linux system, and
that leaves a bad taste in my mouth.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-06-27 12:17:59 +02:00
Nil Admirari 13350e81fd fftools: Remove MAX_PATH limit and switch to UTF-8 versions of fopen() and getenv()
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-06-21 13:27:46 +03:00
Marton Balint c11fb46731 fftools/ffprobe: report avio errors
Signed-off-by: Marton Balint <cus@passwd.hu>
2022-06-20 23:51:54 +02:00
softworkz fee765c207 fftools/fopen_utf8: support long paths on Windows for fftools
Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-06-19 01:38:23 +03:00
Stefano Sabatini ff07492cd8 ffprobe: add -o option
This enables printing to a resource specified with -o OUTPUT.

In case the output is not specified, prints to stdout as usual.

Address issue: http://trac.ffmpeg.org/ticket/8024

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-06-13 22:42:55 +02:00
Gyan Doshi 09c53a04c5 ffmpeg: add option fps_mode
fps_mode sets video sync per output stream. Overrides vsync for matching
streams.

vsync is deprecated.
2022-06-11 09:47:27 +05:30
Stefano Sabatini 605b4016b3 ffmpeg: drop undocumented -d option
Option was added in commit 39aafa5ee9 but was never documented.

Also does not seem there are current use cases for it,
tests for which it was introduced are still working therefore we drop
it altogether.

Indirectly fix trac issue: http://trac.ffmpeg.org/ticket/1698

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-06-09 21:12:16 +02:00
Stefano Sabatini 7adeeff91f ffprobe: update entry index after printing packet/media type
Fix JSON output in case a frame or packet section contains a nested section.

Fix trac issue http://trac.ffmpeg.org/ticket/8680.

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-06-09 00:10:17 +02:00
Anton Khirnov b033913d1c fftools/ffmpeg: move processing AV_PKT_DATA_QUALITY_STATS to do_video_stats()
This is a more appropriate place for this code, since the values we read
from AV_PKT_DATA_QUALITY_STATS side data are primarily written into
video stats. This ensures that the values written into stats actually
apply to the right packet.

Rename the function to update_video_stats() to better reflect its new
purpose.
2022-05-24 13:46:57 +02:00
Anton Khirnov 0c914ebd53 fftools/ffmpeg: merge variable declaration and initialization 2022-05-24 13:46:57 +02:00
Anton Khirnov 9acce2afcf fftools/ffmpeg: stop using av_stream_get_end_pts() in do_video_stats()
It retrieves libavformat's internal dts value (contrary to the
function's name), which is not only incorrect in general, but also
unnecessary because we can access the packet directly.
2022-05-24 13:46:57 +02:00
Anton Khirnov 3d4d355375 fftools/ffmpeg: stop using AVStream.nb_frames in do_video_stats()
Its use for muxing is not documented, in practice it is incremented per
each packet successfully passed to the muxer's write_packet(). Since
there is a lot of indirection between ffmpeg receiving a packet from the
encoder and it actually being written (e.g. bitstream filters, the
interleaving queue), using nb_frames here is incorrect.

Add a new counter for packets received from encoder instead.
2022-05-24 13:46:57 +02:00
Anton Khirnov 19d1e1fb06 fftools/ffmpeg: move do_video_stats() to avoid a forward declaration 2022-05-24 13:46:57 +02:00
Anton Khirnov 1753fbd095 fftools/ffmpeg: drop a useless check and reduce indentation
do_video_stats() is only ever called for video.
2022-05-24 13:46:57 +02:00
Anton Khirnov 9f4437a4eb fftools/ffmpeg: reindent after previous commit 2022-05-24 13:46:57 +02:00
Anton Khirnov 2ecb333fe4 fftools/ffmpeg: reuse the encoding code for flushing encoders 2022-05-24 13:46:57 +02:00
Anton Khirnov a11ab64730 fftools/ffmpeg: share the code encoding a single frame between video and audio
Call do_video_stats() for every video packet produced by the encoder,
rather than for every frame sent to the encoder.
2022-05-24 13:46:57 +02:00
Anton Khirnov e53940186a fftools/ffmpeg: fix 2pass log file names
Use the global stream index rather than an unrelated variable in the
filename.

Broken in 6d5d924604.
2022-05-24 13:35:16 +02:00
Martin Storsjö 4cdc14aa95 libavutil: Deprecate av_fopen_utf8, provide an avpriv version
Since every DLL can use an individual CRT on Windows, having
an exported function that opens a FILE* won't work if that
FILE* is going to be used from a different DLL (or from user
application code).

Internally within the libraries, the issue can be worked around
by duplicating the function in all libraries (this already happened
implicitly because the function resided in file_open.c) and renaming
the function to ff_fopen_utf8 (so that it doesn't end up exported from
the DLLs) and duplicating it in all libraries that use it.

This makes the avpriv_fopen_utf8 / ff_fopen_utf8 function work in
the exact same way as the existing avpriv_open / ff_open, with the
same setup as introduced in e743e7ae6e.

That mechanism doesn't work for external users, thus deprecate the
existing function.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-05-23 13:52:26 +03:00
Martin Storsjö 3fb9244642 fftools: Stop using av_fopen_utf8
Provide a header based inline reimplementation of it.

Using av_fopen_utf8 doesn't work outside of the libraries when built
with MSVC as shared libraries (in the default configuration, where
each DLL gets a separate statically linked CRT).

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-05-23 13:35:59 +03:00
Gyan Doshi 9ab20b1614 opt_common: note D and T type streams for completeness.
Addresses #9784
2022-05-20 23:42:23 +05:30
softworkz b8ede4d637 fftools/opt_common: add includes of avf headers for clarity
Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-18 18:01:51 +02:00
Stefano Sabatini 83e1a1de88 doc/ffprobe: clarify that the input file is not optional
Fix trac issue http://trac.ffmpeg.org/ticket/9562
2022-04-21 12:34:04 +05:30
Anton Khirnov 4a7c8bb3d8 fftools/ffmpeg: store output format separately from the muxer context
Allows accessing it without going through the muxer context. This will
be useful in the following commits, where the muxer context will be
hidden.
2022-04-13 12:07:54 +02:00
Anton Khirnov 5c66ee6351 fftools/ffmpeg: move freeing the output file to ffmpeg_mux.c 2022-04-13 12:07:54 +02:00
Anton Khirnov 5bc644ea8a fftools/ffmpeg: move writing the trailer to ffmpeg_mux.c 2022-04-13 12:07:54 +02:00
Anton Khirnov 288aa37387 fftools/ffmpeg: move some muxing-related code into a separate file
This is a first step towards making muxers more independent from the
rest of the code.
2022-04-13 12:07:54 +02:00
Anton Khirnov b1a984cb49 fftools/ffmpeg: store the output file index in OutputFile
Use it to simplify check_init_output_file(). Will allow further
simplifications in the following commits.
2022-04-13 12:07:54 +02:00
Anton Khirnov 16aea9a38b fftools/ffmpeg: pass the muxer context explicitly to some functions
Stop accessing OutputFile.ctx. This will be useful in the following
commits, where it will become hidden.
2022-04-13 12:07:54 +02:00
Anton Khirnov 662364b2ef fftools/ffmpeg: stop using OutputStream.frame_number for streamcopy
This field is currently used by checks
- skipping packets before the first keyframe
- skipping packets before start time
to test whether any packets have been output already. But since
frame_number is incremented after the bitstream filters are applied
(which may involve delay), this use is incorrect. The keyframe check
works around this by adding an extra flag, the start-time check does
not.

Simplify both checks by replacing the seen_kf flag with a flag tracking
whether any packets have been output by do_streamcopy().
2022-04-13 12:07:54 +02:00
Anton Khirnov 86e1c0303c fftools/ffmpeg: move a comment to a more appropriate place 2022-04-13 12:07:54 +02:00
Anton Khirnov a8c95e1feb fftools/ffmpeg: drop an obsolete hack
Introduced in 05741d70c7. All encoders should set the timestamps
properly now, so it should never be necessary.
2022-04-13 12:07:54 +02:00
James Almer b04f14136e fftools/opt_cmdutils: fix printing known channel layouts
Look for the generic "USR" labels instead of "?" to skip channels with no
known names, and actually print the decomposition of standard channel layouts.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-25 08:42:45 -03:00
Jaakko Perttilä b1cbeabf5e ffmpeg: add packet duration to AVPacket logging
Especially useful when debugging subtitle output, but also shows
if values are set or not for demux and encoding.

Co-authored-by: Jan Ekström <jan.ekstrom@24i.com>

Signed-off-by: Jan Ekström <jan.ekstrom@24i.com>
2022-03-23 17:26:20 +02:00
Anton Khirnov 1728ad8293 fftools/cmdutils: drop redundant code
It allocates a dummy sws/swr context and tries setting options on it,
apparently to check if they are valid. This is redundant, since the
options will be checked if/when they are later applied on a context that
is actually used for conversion.
2022-03-22 18:49:43 +01:00
Anton Khirnov bd0cbebf3e fftools: drop the fake "default" option from ffplay/ffprobe
It tries to process any unhandled options as AVOptions. Handle this
directly in cmdutils.c, without resorting to a confusing fake option
definition (which is currently visible to the users in -help output).
2022-03-22 18:49:43 +01:00
Anton Khirnov 1dd6363581 fftools/ffprobe: drop -show_format_entry
Deprecated since 2012.
2022-03-22 18:49:43 +01:00
Anton Khirnov 6fd1cd6053 fftools/ffplay: drop options deprecated since 2011 2022-03-22 18:49:43 +01:00
Anton Khirnov 8d293918b5 fftools/ffmpeg: drop mistakenly added empty line 2022-03-22 18:49:43 +01:00
Anton Khirnov 00da464658 fftools: move opt_timelimit from cmdutils to ffmpeg
This option is only supported by ffmpeg.
2022-03-22 18:49:43 +01:00
Anton Khirnov a545cb2b9d fftools/cmdutils: split common option handlers into their own file 2022-03-22 18:49:43 +01:00
Anton Khirnov c99b93c5d5 fftools: drop useless indirection 2022-03-22 18:49:43 +01:00
Anton Khirnov 5e51f5af33 fftools/cmdutils: drop extern declarations for nonexistent variables 2022-03-22 18:49:43 +01:00
Anton Khirnov e46d8c53a3 fftools/cmdutils: drop prototypes for nonexistent functions 2022-03-22 18:49:43 +01:00
James Almer e78173557d ffmpeg: make the ac option set the demuxer's ch_layout AVOption
channels is deprecated on all supported raw demuxers.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-22 08:45:39 -03:00
James Almer 639c2f0049 ffmpeg: add a ch_layout option as an alias to channel_layout
This ensures it's parsed as a CLI option instead of the AVCodecContext AVOption.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-22 08:45:38 -03:00
James Almer bc99e3a9d6 ffmpeg: replace custom channel_layout code with an SpecifierOpt based one
This is cleaner and allows fine tuning which stream the option is applied to.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-22 08:45:38 -03:00
Zhao Zhili 117672c814 ffplay: don't shadow global variable
Signed-off-by: Marton Balint <cus@passwd.hu>
2022-03-21 00:48:30 +01:00
Zhao Zhili 269ed0a413 ffplay: check AVFMT_NO_BYTE_SEEK flag for seek_by_bytes
Signed-off-by: Marton Balint <cus@passwd.hu>
2022-03-21 00:48:30 +01:00
James Almer 11c4f4b455 ffmpeg: remove usage of internal deprecation macro
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-16 13:00:42 -03:00
Martin Storsjö a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00
Martin Storsjö 288313a8b2 libavfilter: Split version.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:05:26 +02:00
Martin Storsjö 6cd2ac388d libswscale: Split version.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:05:26 +02:00
Martin Storsjö 4332d6c4d5 libswresample: Split version.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:05:26 +02:00
Martin Storsjö 0f8b0b9ce2 libpostproc: Split version.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:05:26 +02:00
Martin Storsjö 884c597659 libavdevice: Split version.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:05:26 +02:00
Martin Storsjö 4eb9232c6e libavformat: Split version.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:05:26 +02:00
Martin Storsjö f2da2e1458 libavcodec: Split version.h
This avoids including version.h in all source files, avoiding
unnecessary rebuilds when the version number is bumped. Only
version_major.h is included by the main header, which defines
availability of e.g. FF_API_* macros, and which is bumped much
less often.

This isn't done for libavutil/version.h, because that header needs
to be included essentially everywhere due to LIBAVUTIL_VERSION_INT
being used wherever an AVClass is constructed.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:04:35 +02:00
James Almer 0995e1f1b3 ffplay: convert to new channel layout-API
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:46 -03:00
James Almer a8b885f294 ffprobe: convert to new channel layout-API
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:46 -03:00
James Almer 987763ac35 ffmpeg: convert to new channel layout-API
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:46 -03:00
Andreas Rheinhardt f497731260 fftools/ffmpeg_opt: Apply copyinkf for all stream types
The earlier code has ignored it for all stream types except
video and subtitles, probably because audio was presumed
to only consist of keyframes. Yet this assumption is not true
for e.g. TrueHD.

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-04 21:39:42 +01:00
Andreas Rheinhardt 6559858de9 fftools/ffmpeg: Don't presume frame_queue to have been allocated
Fixes segfaults upon allocation failure.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-03 03:48:04 +01:00
Andreas Rheinhardt 88b02e5829 fftools/ffmpeg_opt: Simplify adding complex filtergraph
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-03 03:48:04 +01:00
Andreas Rheinhardt 09e532c575 fftools/ffmpeg_opt: Simplify adding new input/output streams
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-03 03:48:04 +01:00
Limin Wang 316e0ff752 fftool/ffprobe: support for CUVA HDR Vivid metadata
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2022-03-01 09:08:43 +08:00
James Almer d75e7a9a83 ffmpeg: ensure a keyframe was not seen before skipping packets
A keyframe could be buffered in the bsf and not be output until more packets
had been fed to it.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-28 12:11:24 -03:00
James Almer afe485ee6b ffmpeg: flush delayed frames in codec copy scenarios
Bitstream filters inserted between the input and output were never drained,
resulting in packets being lost if the bsf had any buffered.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-28 12:10:51 -03:00
Andreas Rheinhardt 047a4e580e fftools/ffprobe: Remove redundant checks
A decoder is only opened if there is a decoder for the codec,
so every AVCodecContext here has AVCodecContext.codec set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-23 11:50:48 +01:00
Andreas Rheinhardt 26cce232d7 fftools/ffprobe: Flush decoder after draining
This is a prerequisite to continue using the decoder at all
to decode the next interval (if any).
This fixes a regression introduced in commit
2a88ebd096 and reported in ticket #8657.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-23 11:50:48 +01:00
Anton Khirnov e85958ece8 fftools/ffmpeg: fix (a)buffer src names 2022-02-15 10:16:16 +01:00
Danny Wu 68595b46cb fftools/ffmpeg: Restore DTS correction for VP9 copies
Fixes ticket 9086.

Since early 2021, some of YouTube's VP9 encodes have non-monotonous DTS.
This makes ffmpeg fatally fail when trying to copy or encode the V9 video.

ffmpeg already includes functionality to correct this, however it was
disabled without explanation for VP9 stream copies in
2e6636aa87

This patch restores the DTS correction logic, and allows ffmpeg to correctly
encode (invalid) videos produced by youtube.com. I have verified that frames
are NOT being cut (so it does not re-introduce 4313).

Reviwed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-13 10:46:47 -03:00
Anton Khirnov e6469e68cc ffmpeg: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov bdf9ed41fe ffplay: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Gyan Doshi e1a14479a8 ffprobe: allow side-data selection by element
At present, side data printing forces display for all levels i.e.
stream, packets and frames. This can bloat output and also force
decode of all frames in selected streams.

Now, stream_side_data[=type], packet_side_data[=type] &
frame_side_data[=type] can be used with -show_entries to specify carrier
element.
2022-02-03 16:04:24 +05:30
Andreas Rheinhardt bbf00916e4 fftools/cmdutils: Fix undefined 1 << 31
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-11 00:20:35 +01:00
Anton Khirnov 1b24a1ea14 ffmpeg: remove a redundant assignment of interrupt_callback
It is already set in open_output_file().
2022-01-10 15:57:22 +01:00
Jan Ekström a3f4148319 ffprobe: Support AV_FRAME_DATA_DOVI_METADATA
Co-authored-by: Niklas Haas <git@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 11:59:41 +01:00
Diederick Niehorster 5c90c13a56 fftools: provide media type info for devices
fftools now print info about what media type(s), if any, are provided by
sink and source avdevices.

Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
Reviewed-by: Roger Pack <rogerdpack2@gmail.com>
2021-12-24 14:06:56 +05:30
Andreas Rheinhardt 04133eb2d5 fftools/ffmpeg_filter: Avoid inserting hflip filter
The transpose filter has modes equivalent to "rotation by 90°/270°"
followed by horizontal flips.

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

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

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

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

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-23 18:09:46 +01:00
James Almer 131dbb9a7a ffprobe: add missing separator when printing side data in compact output
Should fix ticket #7153

Signed-off-by: James Almer <jamrial@gmail.com>
2021-12-22 09:41:13 -03:00
Yu Yang a4580bf959 fftools/cmdutils: Avoid crash when opts could not be allocated
If 'opts' could not be allocated, exiting the program to avoid crash when release it.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Yu Yang <yuyang14@kuaishou.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-16 11:56:00 +01:00
Marton Balint 8d66a07d65 fftools/ffmpeg: close output files before cleanup
This allows us to check the return value of avio_closep().

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-12-12 00:32:20 +01:00
Anton Khirnov 9f717ca92f ffmpeg: handle errors in print_sdp()
Do not continue as if nothing happened.
2021-12-07 11:23:45 +01:00
Anton Khirnov 9145c6d3b2 ffmpeg: move setting video sync method to new_video_stream()
do_video_out() is the wrong place for it, since the necessary
information is already known when creating the stream and its value
should never change.
2021-12-07 11:23:45 +01:00
Anton Khirnov 6ce9546428 ffmpeg: deprecate passing numbers to -vsync
There is never a reason to do this, using symbolic names is always
preferred.
2021-12-07 11:23:45 +01:00
Anton Khirnov 011114f3e1 ffmpeg: change vsync value to an enum
Stop explicitly defining VSCFR and DROP values, which were never
documented.
2021-12-07 11:23:45 +01:00
Anton Khirnov bb6f591c49 ffmpeg: drop useless framerate assignments
If the input stream framerate is known, it will be configured on the
relevant filtergraph input and get propagated to the output stream in
the above line. That makes these assignments redundant.
2021-12-07 11:23:45 +01:00
Andreas Rheinhardt 6fc0fc5441 fftools/ffmpeg_opt: Improve alloc/truncation checks when reading lines
Do this by switching from the dynamic buffer API to the AVBPrint API;
the former has no defined way to check for errors.
This also avoids allocating an AVIOContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-07 10:01:41 +01:00
Andreas Rheinhardt f3a8d208c0 fftools/ffmpeg_opt: Improve checks for truncation/alloc error
Do this by switching from the dynamic buffer API to the AVBPrint API;
the former has no defined way to check for errors.
This also avoids allocating an AVIOContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-07 10:01:34 +01:00
Andreas Rheinhardt fc01a703de fftools/ffmpeg: Avoid creating unnecessary reference
The only caller of do_video_out() doesn't need the frame afterwards,
ergo one can replace an av_frame_ref() by av_frame_move_ref().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-05 13:27:38 +01:00
Andreas Rheinhardt b886512ef2 fftools/ffmpeg: Avoid allocating+freeing frame, check allocations
Fixes a potential crash upon av_frame_alloc() failure.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-05 13:27:38 +01:00
Andreas Rheinhardt 2d0bfbd0fa fftools/cmdutils: Use av_dynarray_add_nofree()
Simplifies code and reduces the number of allocations a bit
by overallocating.

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

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

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

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

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-03 16:11:01 +01:00
James Almer c1818cb947 ffmpeg: fix usage of -shortest in codec copy scenarios
Don't mark all streams as finished, instead make sync_opts keep track of the
stream's duration, and set recording_time to it, same as in transcoding paths.

Fixes tickets #9512 and #9513.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-12-01 18:16:56 -03:00
Andreas Rheinhardt e22dff43e7 fftools/ffmpeg_opt: Don't set source_index redundantly
It is already set in new_output_stream().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-30 12:06:02 +01:00
Andreas Rheinhardt 4913f05ccf fftools/ffmpeg_opt: Don't duplicate array unnecessarily
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-30 11:53:22 +01:00
softworkz 939711905a fftools/ffprobe: print size of attachment streams (extradata_size)
Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-11-29 21:30:11 +01:00
rcombs 4b54818981 ffmpeg: remove ffmpeg_videotoolbox
This was almost completely redundant. The only functionality that's no longer
available after this removal is the videotoolbox_pixfmt arg, which has been
obsolete for several years.
2021-11-28 16:40:43 -06:00
Andreas Rheinhardt 81be19b906 fftools/ffmpeg: Take type limitations of AVFifo API into account
The types used by the AVFifo API are inconsistent:
av_fifo_(space|size)() returns an int; av_fifo_alloc() takes an
unsigned, other parts use size_t. This commit therefore ensures
that the size of the muxing_queue FIFO never exceeds INT_MAX.

While just at it, also make sure not to call av_fifo_size()
unnecessarily often.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-26 18:55:58 +01:00
Anton Khirnov 9dd104f6e2 ffmpeg: drop obsolete rotation API remnants
No demuxers export the "rotate" metadata tag anymore.
2021-11-23 11:36:59 +01:00
Anton Khirnov 823cea5197 ffmpeg: drop -isync, which did nothing since 2012 2021-11-23 11:36:59 +01:00
Anton Khirnov 84cb255c20 ffmpeg: drop -sameq/-samequant options
They did nothing but return an error since 2012.
2021-11-23 11:36:59 +01:00
Anton Khirnov 5ebdf9bb50 ffmpeg: drop the -tvstd option
It is undocumented and has been deprecated since 2012.
2021-11-23 11:36:59 +01:00
Anton Khirnov a44098152b ffmpeg: drop the -vc option
It is undocumented and has been deprecated since 2012.
2021-11-23 11:36:59 +01:00
Anton Khirnov d013453caa ffmpeg: drop the -deinterlace option
It is undocumented and has been deprecated since 2013.
2021-11-23 11:36:59 +01:00
Anton Khirnov 9d4e290ec4 ffmpeg: drop the -intra option
It is undocumented and has been marked as deprecated since 2012.
2021-11-23 11:36:59 +01:00
Anton Khirnov e8380bbae6 ffmpeg: do not copy chroma_sample_location from the input stream
It will be set from the supplied AVFrame later on.
2021-11-23 11:36:59 +01:00
Andreas Rheinhardt a132614bba fftools/ffmpeg: Avoid temporary frame
send_frame_to_filters() sends a frame to all the filters that
need said frame; for every filter except the last one this involves
creating a reference to the frame, because
av_buffersrc_add_frame_flags() by default takes ownership of
the supplied references. Yet said function has a flag which
changes its behaviour to create a reference itself.
This commit uses this flag and stops creating the references itself;
this allows to remove the spare AVFrame holding the temporary
references; it also avoids unreferencing said frame.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-20 00:07:47 +01:00
James Almer 405685dec7 ffmpeg: remove unused hw_frames_ctx AVBufferRef from InputStream
Signed-off-by: James Almer <jamrial@gmail.com>
2021-11-19 15:26:11 -03:00
James Almer 379f8b8ec6 ffmpeg: remove unused hwaccel_get_buffer function pointer
As well as the custom get_buffer2() implementation which would become a
redundant wrapper for avcodec_default_get_buffer2() after this

Signed-off-by: James Almer <jamrial@gmail.com>
2021-11-19 15:26:11 -03:00
James Almer e7f3279ba0 ffmpeg: Allocate InputStream.decoded_frame early
Based on a commit by Andreas Rheinhardt.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-11-19 11:21:04 -03:00
James Almer ee3d6a20f6 ffmpeg: Allocate (In|Out)putStream.filter_frame early
Based on a commit by Andreas Rheinhardt.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-11-19 11:21:04 -03:00
Chad Fraleigh a185b526a9 fftools: Constify values from av_dict_get()
Treat values returned from av_dict_get() as const, since they are
internal to AVDictionary.

Signed-off-by: Chad Fraleigh <chadf@triularity.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-18 19:43:32 +01:00
Paul B Mahol e5367b481b ffmpeg: fix loosing gaps between audio frame timestamps when filtering 2021-11-18 12:54:17 +01:00
Anton Khirnov bd55552d69 ffmpeg: rewrite setting the stream disposition
Currently, the code doing this is spread over several places and may
behave in unexpected ways. E.g. automatic 'default' marking is only done
for streams fed by complex filtergraphs. It is also applied in the order
in which the output streams are initialized, which is effectively
random.

Move processing the dispositions at the end of open_output_file(), when
we already have all the necessary information.

Apply the automatic default marking only if no explicit -disposition
options were supplied by the user, and apply it to the first stream of
each type (excluding attached pics) when there is more than one stream
of that type and no default markings were copied from the input streams.

Explicitly document the new behavior.

Changes the results of some tests, where the output file gets a default
disposition, while it previously did not.
2021-11-16 10:51:32 +01:00