Commit Graph

333 Commits

Author SHA1 Message Date
Andreas Rheinhardt 4a4dcde339 avformat/internal: Move FF_FMT_INIT_CLEANUP to demux.h
and rename it to FF_INFMT_INIT_CLEANUP. This flag is demuxer-only,
so this is the more appropriate place for it.
This does not preclude adding internal flags common to both
demuxer and muxer in the future.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-26 06:36:43 +01:00
Andreas Rheinhardt 53a51e70f2 avformat/internal: Remove declaration for ff_format_io_close_default()
Forgotten in d6799ee0e4.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-14 22:53:50 +01:00
Andreas Rheinhardt b800327f4c avformat/avformat: Add FFInputFormat, hide internals of AVInputFormat
This commit does for AVInputFormat what commit
59c9dc82f4 did for AVOutputFormat:
It adds a new type FFInputFormat, moves all the internals
of AVInputFormat to it and adds a now reduced AVInputFormat
as first member.

This does not affect/improve extensibility of both public
or private fields for demuxers (it is still a mess due to lavd).

This is possible since 50f34172e0
(which removed the last usage of an internal field of AVInputFormat
in fftools).

(Hint: tools/probetest.c accesses the internals of FFInputFormat
as well, but given that it is a testing tool this is not considered
a problem.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-07 08:53:31 -03:00
James Almer 41e349c24a avformat/mov: add support for tile HEIF still images
Export each tile as its own stream, and the grid information as a Stream Group
of type TILE_GRID.
This also enables exporting other stream items like thumbnails, which may be
present in non tiled HEIF images too. For those, the primary stream will be
tagged with the default disposition.

Based on a patch by Swaraj Hota

Signed-off-by: James Almer <jamrial@gmail.com>
2024-02-26 12:21:12 -03:00
Andreas Rheinhardt 71e1da4522 avformat/mux: Don't allocate priv_pts separately
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-07 10:22:18 +01:00
Andreas Rheinhardt 569ad285a5 avformat/options: Only allocate AVCodecContext for demuxers
The muxer's AVCodecContext is currently used for exactly one thing:
To store a time base in it that has been derived via heuristics
in avformat_transfer_internal_stream_timing_info(); said time base
can then be read back via av_stream_get_codec_timebase().
But one does not need a whole AVCodecContext for that, a simple
AVRational is enough.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-07 10:22:18 +01:00
James Almer 89215237dd avformat: remove ff_remove_stream_group()
It's unused.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-12-20 00:17:59 -03:00
James Almer 556b596d1d avformat: introduce AVStreamGroup
Signed-off-by: James Almer <jamrial@gmail.com>
2023-12-18 15:18:05 -03:00
James Almer 5432d2aaca avformat/avformat: use the side data from AVStream.codecpar
Deprecate AVStream.side_data and its helpers in favor of the AVStream's
codecpar.coded_side_data.

This will considerably simplify the propagation of global side data to decoders
and from encoders. Instead of having to do it inside packets, it will be
available during init().
Global and frame specific side data will therefore be distinct.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:03:57 -03:00
Anton Khirnov 85e075587d lavf: deprecate AVFMT_FLAG_SHORTEST
It was added in cb114ed464 with the comment
"This will allow fixing several bugs with the -shortest option".

Since
* there is no explanation of what these bugs are
* libavformat is not the place to work around ffmpeg CLI bugs
* there is no indication that this feature is actually in use
deprecate it without replacement.
2023-09-18 17:10:59 +02:00
Andreas Rheinhardt 185d0acdc7 avformat/internal: Avoid casting const away
Fixes many warnings when using -Wcast-qual.

Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-10 11:18:48 +02:00
Andreas Rheinhardt 0c6e5f321b avformat/avformat: Avoid including codec.h, frame.h
AVCodec is only ever used as an incomplete type (i.e. via a pointer
to an AVCodec) in avformat.h and it is not really part of the core
of avformat.h or libavformat; almost none of our internal users
make use of it (and none make use of hwcontext.h, which is implicitly
included). So switch to use struct AVCodec, but continue to include
codec.h for external users for compatibility.

Also, do the same for AVFrame and frame.h, which is implicitly included
by codec.h (via lavu/hwcontext.h).

Also, remove an unnecessary inclusion of <time.h>.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:30:08 +02:00
Andreas Rheinhardt ee485b4051 avformat/internal: Don't auto-include os_support.h
It includes various Windows-specific headers when compiling
for Windows and these sometimes cause issues: E.g. winbase.h
defines IGNORE, which clashes with a macro used in the Matroska
muxer (since 884653ee5b) and demuxer.

This header provides fallback defines for various stuff that is
mostly not used directly by (de)muxers at all:
mkdir, rename, rmdir, unlink, access, poll, pollfd, nfds_t,
closesocket, socklen_t, fstat, stat, lseek, SHUT_(RD|WR|RDWR)
and various POLL* constants.

Ergo fix this issue by not auto-including this header in lots
of places via an inclusion in internal.h and instead include
it everywhere where the above stuff is used (most of these
translation units already included os_support.h).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-02 10:36:11 +02:00
Andreas Rheinhardt 76f244b84e avformat/internal: Use forward declaration for AVCodecDescriptor
This avoids including lavc/codec_desc.h everywhere and thereby
forces users to include it directly instead of lazily and potentially
unknowingly relying on indirect inclusions.

Also add the proper inclusion to libavformat/demux.c, one of the
two files that actually use the new field.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-05 09:40:06 +02:00
Anton Khirnov e930b834a9 lavf: use AV_CODEC_PROP_FIELDS where appropriate
H.264 and mpeg12 parsers need to be adjusted at the same time to stop
using the value of AVCodecContext.ticks_per_frame, because it is not set
correctly unless the codec has been opened. Previously this would result
in both the parser and lavf seeing the same incorrect value, which would
cancel out.
Updating lavf and not the parsers would result in correct value in lavf,
but the wrong one in parsers, which would break some tests.
2023-05-15 10:31:55 +02:00
Michael Niedermayer a7b06bfc5d
avformat: add ff_match_url_ext()
Match url against a list of extensions similar to av_match_ext()

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-05-15 03:02:28 +02:00
Andreas Rheinhardt 59c9dc82f4 avformat/avformat: Move AVOutputFormat internals out of public header
This commit does for AVOutputFormat what commit
20f9727018 did for AVCodec:
It adds a new type FFOutputFormat, moves all the internals
of AVOutputFormat to it and adds a now reduced AVOutputFormat
as first member.

This does not affect/improve extensibility of both public
or private fields for muxers (it is still a mess due to lavd).

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
Andreas Rheinhardt 2b41463b87 avformat/internal: Don't include avcodec.h
The general demuxing API uses parsers and decoders. Therefore
FFStream contains pointers to AVCodecContexts and
AVCodecParserContext and lavf/internal.h includes lavc/avcodec.h.

Yet actually only a few files files really use these; and it is best
when this number stays small. Therefore this commit uses opaque
structs in lavf/internal.h for these contexts and stops including
avcodec.h.
This also avoids including lavc/codec_desc.h implicitly. All other
headers are implicitly included as now (mostly through codec.h).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-26 03:02:50 +02:00
Andreas Rheinhardt 1a8309e954 avformat/mux: Allow muxers to set custom min timestamp
Matroska requires pts to be >= 0 with a slight exception:
It has a mechanism to deal with codec delay, i.e. with
the data added at the beginning that does not correspond
to actual input data and should be discarded by the player.
Only the audio actually intended to be output needs to have
a timestamp >= 0.
In order to avoid unnecessary timestamp shifting, this patch
allows muxers to inform the shifting code about this so that
it can take it into account.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-05 20:36:01 +02:00
Pierre-Anthony Lemieux f2403d1530 avformat: refactor ff_stream_encode_params_copy() to stream_params_copy()
Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299726.html

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-12 18:54:19 +02:00
Andreas Rheinhardt 439ca8b5f4 avformat/internal: Hide BSF stuff only used by the core APIs
The general demuxing API uses bitstream filters to extract extradata
and the muxing API uses them in order to transform packets into
the format desired by the target format. Therefore FFStream contains
pointers to AVBSFContexts and lavf/internal.h includes lavc/bsf.h.

Yet actually, only a few files files are supposed to use these,
namely avformat.c, demux.c and mux.c. For all the other files,
it should be an opaque type that they should not touch and that
they need not know anything about. This can be achieved by not
including these headers and using the structs instead of the
corresponding typedefs.
This also forces translation units that really use the BSF API
themselves to include lavc/bsf.h directly instead of relying on
indirect inclusions (a few other files also use the BSF API;
they already abided by this).
Of course, it also avoids unnecessary rebuilds when bsf.h changes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-12 08:52:59 +02:00
Andreas Rheinhardt aaeb37f385 avformat/internal: Move FFERROR_REDO to demux.h
It is demuxer-only.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-12 08:52:59 +02:00
Andreas Rheinhardt 9825d488d6 avformat/utils: Move ff_find_stream_index to demux_utils.c
It is only used by demuxers (and it is generally demuxers
who have to translate format-specific IDs to stream indices).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:49:01 +02:00
Andreas Rheinhardt a085cfa654 avformat/utils: Move ff_get_extradata to demux_utils.c
It is only used by demuxers (although it is hypothetically
possible that some day e.g. a protocol might need it, but
that is unlikely given that they don't deal with AVCodecParameters).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:45:58 +02:00
Andreas Rheinhardt aef16886dd avformat/internal: Make AVFormatContext* a logctx in ff_get_extradata
I.e. use void* instead of AVFormatContext*, because it is only used
for logging.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:43:26 +02:00
Andreas Rheinhardt 7803825cfc avformat/utils: Move ff_generate_avci_extradata to demux_utils.c
Only used by demuxers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:43:25 +02:00
Andreas Rheinhardt f104352b91 avformat/utils: Move ff_add_param_change to demux_utils.c
Only demuxers have a need to add side-data to a packet.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:42:46 +02:00
Andreas Rheinhardt 92a43ad384 avformat/utils: Move ff_add_attached_pic to demux_utils.c
It is demuxer-only: It potentially adds an AVStream and it sets
AVStream.attached_pic.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:42:22 +02:00
Andreas Rheinhardt ff0e8e14c3 avformat/utils: Move avpriv_new_chapter to demux_utils.c
It is demuxer-only: Muxers deal only with chapters given to them;
they don't create any of their own.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:42:07 +02:00
Andreas Rheinhardt 284313c664 avformat/utils: Move parser functions to a new file, demux_utils.c
This file is both for the various public APIs that are demuxer-only
as well as for the demuxer-only internal functions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:50 +02:00
Andreas Rheinhardt 3cfae9e038 avformat/internal: Move definition of FFStream->info to demux.h
It is only used by avformat_find_stream_info().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:43 +02:00
Andreas Rheinhardt 35ec5c819b avformat/demux: Add new demux.h header
And move those stuff already in demuxer-only files to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:38 +02:00
Andreas Rheinhardt 20ca491664 avformat/utils: Move ff_stream_encode_params_copy() to mux_utils.c
Only used by muxers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:32:16 +02:00
Andreas Rheinhardt 437484a66a avformat/utils: Move ff_format_output_open() to mux_utils.c
It is obviously a muxing-only function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:31:47 +02:00
Andreas Rheinhardt d78838414b avformat/utils: Move creation-time functions to mux_utils
Only used by muxers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:30:31 +02:00
Andreas Rheinhardt 533836b8e0 avformat/utils: Move ff_get_packet_palette() to rawutils.c
ff_get_packet_palette() and ff_reshuffle_raw_rgb() belong together:
E.g. the former takes the return value of the latter as argument.
So move ff_get_packet_palette() to rawutils.c (which consists solely
of ff_reshuffle_raw_rgb()).
Also add a separate header for these two functions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:29:32 +02:00
Andreas Rheinhardt ba49acf143 avformat/mux_utils: Move ff_format_shift_data to new file for mux utils
It is only used by muxers. Given that it is not part of
the core muxing code and given that mux.c is already big enough,
it is moved to a new file for utility functions for muxing.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:29:15 +02:00
Andreas Rheinhardt b9f6d416ec avformat/utils: Move stream_options, avformat_new_stream to options.c
This is the appropriate place given that AVStream is about to
become an AVOpt-enabled struct.
Also move av_disposition_(to|from)_string, as these are tied
to the disposition stream option.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:28:54 +02:00
Andreas Rheinhardt 7547f13548 avformat/utils: Move ff_stream_add_bitstream_filter to mux.c
It is muxing-only; in fact, it should be considered part of
the core muxing code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:27:36 +02:00
Andreas Rheinhardt 5130bbb7ef avformat/mux: Move ff_choose_chroma_location to mxfenc, its only user
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:27:26 +02:00
Andreas Rheinhardt 107bdd97a9 avformat/mux: Move ff_choose_timebase to nutenc, its only user
(This function does not seem to abide by its documentation.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:27:09 +02:00
Andreas Rheinhardt f4a2d722aa avformat/internal: Move muxing-only functions to new mux.h header
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:27:01 +02:00
Michael Niedermayer 6265f0b4e1 avformat: Do not search through the AVOption table for a option not in it repeatedly on each packet
This search takes alot of time especially when compared with small packets

46631 decicycles -> 15719 decicycles in read_frame_internal() for amr-nb in 3gp

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-27 11:58:54 +02:00
Pierre-Anthony Lemieux b172c0f8c5
avformat/seek: add ff_rescale_interval() function
Refactors a function used by avformat/concat and avformat/imf.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2022-03-19 21:34:00 +10:00
Andreas Rheinhardt c602deb138 avformat/mux: Preserve sync even if later packet has negative ts
write_packet() has code to shift the packets timestamps
to make them nonnegative or even make them start at ts zero;
this code inspects every packet that is written and if a packet
with negative timestamp (whether this is dts or pts depends upon
another flag; basically: Matroska uses pts, everyone else dts)
is encountered, this is offset to make the timestamp zero.
All further packets will be offset accordingly (with the offset
converted according to the streams' timebases).

This is based around an assumption, namely that the timestamps
are indeed non-decreasing, so that the first packet with negative
timestamps is the first packet with timestamps. This assumption
is often fulfilled given that the default interleavement function
by default interleaves per dts; yet there are scenarios in which
it may not be fulfilled:
a) av_write_frame() instead of av_interleaved_write_frame() is used.
b) The audio_preload option is used.
c) When the timestamps that are made nonnegative/zero are pts
(i.e. with Matroska), because the packet with the smallest dts
is not necessarily the packet with the smallest pts.
d) Possibly with custom interleavement functions.
In these cases the relative sync of the first few packet(s) is offset
relative to the later packets. This contradicts the documentation
("When shifting is enabled, all output timestamps are shifted by
the same amount").

Therefore this commit changes this: As soon as the first packet
with valid timestamps is output, it is checked and recorded whether
the timestamps need to be shifted. Further packets are no longer
checked for needing to be offset; instead they are simply offset.
In the cases above this leads to packets with negative timestamps
(and the appropriate warnings) instead of desync. This will mostly
be fixed in the next commit.

This commit also factors handling the avoid_negative_ts stuff out
of write_packet() in order to be able to return immediately.

Tickets #4536 and #5784 as well as the matroska-avoid-negative-ts-test
are examples of c); as has been said, some timestamps are now negative,
yet the ref file update does not show it because ffmpeg.c sanitizes
the timestamps (-copyts disables it; ffprobe and mkvinfo also show
the original timestamps).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-21 16:47:38 +01:00
Andreas Rheinhardt d61240f8c9 avcodec/packet_internal: Add proper PacketList struct
Up until now, we had a PacketList structure which is actually
a PacketListEntry; a proper PacketList did not exist
and all the related functions just passed pointers to pointers
to the head and tail elements around. All these pointers were
actually consecutive elements of their containing structs,
i.e. the users already treated them as if they were a struct.

So add a proper PacketList struct and rename the current PacketList
to PacketListEntry; also make the functions use this structure
instead of the pair of pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 13:16:50 +01:00
Marton Balint 76e062322c avformat/movenc: factorize data shifting
And move data shift function from movenc to utils.

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-01-03 22:54:12 +01:00
Gerard Sole 18ad360648 libavformat: add side_data copy in concat demuxer
Adds support for concat demuxer to copy the side data information
from the input file to the resulting file. It will behave like the
metadata copy, where the metadata of the first file is kept in the
the output file.

Extract the current code that already performs the stream side_data
copy into a separate method and reuse the method in the concat demuxer.

Signed-off-by: Gerard Sole <g.sole.ca@gmail.com>
2021-12-22 12:05:41 +01:00
Anton Khirnov fe31708eaa lavf/sdp: add more thorough error handling
Return error codes when constructing a stream config fails, rather than
just disregarding the failure and continuing.
Propagate the error codes from av_sdp_create().
2021-12-17 10:23:07 +01:00
Anton Khirnov 230646751d lavf/sdp: add const qualifiers where appropriate
Declares that these structs are read-only for this code.
2021-12-17 10:22:41 +01:00