summaryrefslogtreecommitdiff
path: root/libavformat/mux.c
Commit message (Collapse)AuthorAgeFilesLines
* lavf/mux: clarify log messages when choosing oformat failsAnton Khirnov2023-04-041-3/+5
| | | | | | | | | Current log messages talk about 'suitable' output formats. This is confusing, because it suggests that some formats are suitable, while others are not, which is not the case. Also, suggest possible user actions when format cannot be guessed from a filename.
* avformat/mpegts: add support for preserving SMPTE 2038 when transcoding ↵Devin Heitmueller2023-03-261-2/+4
| | | | | | | | | | | | | | | | | MPEG-TS streams Add the appropriate descriptors to the MPEG-TS demux and mux to ensure that SMPTE 2038 VANC streams are properly preserved when using codec copy (including adding the appropriate PMT descriptors). The focus of this patch is TS input to TS output. A separate patch adds support for output of 2038 VANC over decklink SDI. Thanks to Marton Balint for feedback to preserve ABI compatibility. Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com> Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/avformat: Move AVOutputFormat internals out of public headerAndreas Rheinhardt2023-02-091-38/+39
| | | | | | | | | | | | | | This commit does for AVOutputFormat what commit 20f972701806be20a77f808db332d9489343bb78 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>
* avformat/mux: use only valid timestamps when calculating packet distanceJames Almer2023-01-031-0/+1
| | | | | | | | Fixes: signed integer overflow: 0 - -9223372036854775808 cannot be represented in type 'long int' Fixes: fate-cover-art-aiff-id3v2-remux, fate-cover-art-mp3-id3v2-remux and fate-mov-cover-image under ubsan. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: Constify validate_codec_tag()Andreas Rheinhardt2022-10-271-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Don't call ff_toupper4() unnecessarilyAndreas Rheinhardt2022-10-271-1/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Allow muxers to set custom min timestampAndreas Rheinhardt2022-09-051-2/+5
| | | | | | | | | | | | | | 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>
* lavf: use AVFrame.duration instead of AVFrame.pkt_durationAnton Khirnov2022-07-191-1/+8
|
* avformat/utils: Move ff_stream_add_bitstream_filter to mux.cAndreas Rheinhardt2022-05-101-0/+43
| | | | | | | 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>
* avformat/mux: Move ff_choose_chroma_location to mxfenc, its only userAndreas Rheinhardt2022-05-101-31/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Move ff_choose_timebase to nutenc, its only userAndreas Rheinhardt2022-05-101-15/+0
| | | | | | (This function does not seem to abide by its documentation.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/internal: Move muxing-only functions to new mux.h headerAndreas Rheinhardt2022-05-101-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* libavformat: Split version.hMartin Storsjö2022-03-161-0/+1
| | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* lavf: drop the channel layout compat layer for old-style (de)muxersAnton Khirnov2022-03-151-9/+0
| | | | | | All the (de)muxers have been converted to the new API. Signed-off-by: James Almer <jamrial@gmail.com>
* lavf: convert the generic layer to the new channel layoutAnton Khirnov2022-03-151-1/+17
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* lavf: add a temporary compat layer for the channel layout API changeAnton Khirnov2022-03-151-0/+10
| | | | | | | Mediates between old-style (de)muxers and new-style callers. Will be removed once all the (de)muxers are converted to the new API. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: Peek into the muxing queue for avoid_negative_tsAndreas Rheinhardt2022-01-211-2/+19
| | | | | | | | | | | Peeking into the muxing queue can improve the estimate of the lowest timestamp needed for avoid_negative_ts in case the lowest timestamp is in a packet other than the first packet to be muxed. This fixes tickets #4536 and #5784 as well as the output from the matroska-avoid-negative-ts FATE-test. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Preserve sync even if later packet has negative tsAndreas Rheinhardt2022-01-211-46/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* avformat/avformat: Add AVFMT_AVOID_NEG_TS_DISABLEDAndreas Rheinhardt2022-01-211-1/+1
| | | | | | And also don't use explicit constants in the movenc test. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Remove assert based on faulty assumptionsAndreas Rheinhardt2022-01-211-1/+0
| | | | | | | | | This assert is based upon the wrong assumption that the noninterleaved codepath is never used; if it is used, max_interleave_delta is irrelevant. It furthermore ignores audio_preload. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/packet_internal: Add proper PacketList structAndreas Rheinhardt2022-01-041-19/+19
| | | | | | | | | | | | | | | 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>
* avcodec/utils: Unavpriv avpriv_toupper4()Andreas Rheinhardt2022-01-041-1/+1
| | | | | | | | | | | | | | | | This function is quite small (96B with GCC 11.2 on x64 Ubuntu 21.10 at -O3), making it more economical to duplicate it into libavformat instead of exporting it as avpriv: Doing so saves 2x24B in .dynsim, 2x16B in .dynstr, 2x2B .gnu.version, 24B in .rela.plt, 16B in .plt, 16B in .plt.sec (if enabled), 4B .gnu.hash; besides the actual duplicated code this also adds 2x8B .eh_frame_hdr and 24B .eh_frame. In other words: Duplicating is neutral size-wise (it is also presumed neutral for other systems). Given that it avoids the runtime overhead of dynamic symbols, it is advantageouos to duplicate the function. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux, mxfenc: Don't use sizeof(AVPacket)Andreas Rheinhardt2022-01-041-7/+1
| | | | | | | | This removes one of the last usages of sizeof(AVPacket) in the generic muxing code. Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/avformat: Add AVStream parameter to check_bitstream() sigAndreas Rheinhardt2021-11-271-1/+1
| | | | | | | | | | For most check_bitstream() functions this just avoids having to dereference s->streams[pkt->stream_index] themselves; but for meta-muxers it will allow to forward the packet to stream with a different stream_index (belonging to a different AVFormatContext) without using a spare packet. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Avoid overhead of packet list in case of single streamsAndreas Rheinhardt2021-11-191-1/+9
| | | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Store pointer to interleavement func in FFFormatContextAndreas Rheinhardt2021-11-191-14/+5
| | | | | | | It avoids branches lateron and will allow to easily avoid the overhead of the linked list currently in use in case there is only one stream. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Remove unnecessary av_packet_unref()Andreas Rheinhardt2021-10-031-6/+4
| | | | | | AVFormatInternal.parse_pkt is always blank after having been used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/internal: Allow AVFormatInternal.pkt to be used by muxersAndreas Rheinhardt2021-10-031-0/+1
| | | | | | It is unused by the generic muxing code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Use AVFormatInternal.parse_pkt for temporary packetsAndreas Rheinhardt2021-10-031-3/+3
| | | | | | | | The documentation of said packet ("Every user has to ensure that this packet is blank after using it") perfectly fits how we use said packet in the generic muxing code. Better than the documentation of pkt. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Don't use stack packet when writing interleaved packetsAndreas Rheinhardt2021-10-031-25/+19
| | | | | | | | | | | | | | | | | | | Currently the interleave_packet functions use a packet for a new packet to be interleaved (may be NULL if there is none) and a packet for output; said packet is always a stack packet in interleaved_write_packet(). But all the interleave_packet functions in use first move the packet to the packet list and then check whether a packet can be returned, i.e. the effective lifetime of the new packet ends before the packet for output is touched. So one can use one packet both for input and output by adding a new parameter that indicates whether there is a packet to add to the packet list; there is just one complication: In case the muxer is flushed, there is no packet available. This can be solved by reusing one of the packets from AVFormatInternal. They are currently unused when flushing in av_interleaved_write_frame(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Sanitize packets without data and side-dataAndreas Rheinhardt2021-10-031-0/+7
| | | | | | | | | The BSF API treats such packets as signalling EOF and therefore such a packet might corrupt the BSF state. In such a case, the guarantee that av_interleaved_write_frame() always frees the packet is not upheld. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: Avoid allocation for AVStreamInternalAndreas Rheinhardt2021-09-171-17/+17
| | | | | | | | | | Do this by allocating AVStream together with the data that is currently in AVStreamInternal; or rather: Put AVStream at the beginning of a new structure called FFStream (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux, utils: Use dedicated pointer for AVStreamInternalAndreas Rheinhardt2021-09-171-57/+74
| | | | | | | This gets rid of ugly "->internal" and is in preparation for removing AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: Avoid allocation for AVFormatInternalAndreas Rheinhardt2021-09-171-12/+12
| | | | | | | | | | | | | Do this by allocating AVFormatContext together with the data that is currently in AVFormatInternal; or rather: Put AVFormatContext at the beginning of a new structure called FFFormatContext (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVFormatInternal altogether. The biggest simplifications occured in avformat_alloc_context(), where one can now simply call avformat_free_context() in case of errors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux, mxfenc, utils: Use dedicated pointer for AVFormatInternalAndreas Rheinhardt2021-09-171-47/+58
| | | | | | | This gets rid of ugly "->internal" and is in preparation for removing AVFormatInternal altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/asfenc, mux, utils: Use smaller scope for variablesAndreas Rheinhardt2021-09-171-36/+24
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Fix double-free when using AVPacket.opaque_refAndreas Rheinhardt2021-09-031-13/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, ff_write_chained() copied the packet (manually, not with av_packet_move_ref()) from a packet given to it to a stack packet whose timing and stream_index is then modified before being sent to another muxer via av_(interleaved_)write_frame(). Afterwards it is intended to sync the fields of the packet relevant to freeing again; yet this only encompasses buf, side_data and side_data_elems and not the newly added opaque_ref. The other fields are not synced so that the returned packet can have a size > 0 and data != NULL despite its buf being NULL (this always happens in the interleaved codepath; before commit fe251f77c80b0512ab8907902e1dbed3f4fe1aad it could also happen in the noninterleaved one). This leads to double-frees if the interleaved codepath is used and opaque_ref is set. This commit therefore changes this by directly reusing the packet instead of a spare packet. Given that av_write_frame() does not change the packet given to it, one only needs to restore the timing information to return it as it was; for the interleaved codepath it is not possible to do likewise*, because av_interleaved_write_frame() takes ownership of the packets given to it and returns blank packets. But precisely because of this users of the interleaved codepath have no legitimate expectation that their packet will be returned unchanged. In line with av_interleaved_write_frame() ff_write_chained() therefore returns blank packets when using the interleaved codepath. Making the only user of said codepath compatible with this was trivial. *: Unless one wanted to create a full new reference. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/mux: Don't access AVStream's internal AVCodecContextAndreas Rheinhardt2021-08-301-1/+1
| | | | | | | | | | An AVStream's internal AVCodecContext is pretty much unused for muxing: The only place where any of its fields are set is avformat_transfer_internal_stream_timing_info() where its time base is set based upon the desired output format. The max_b_frames field is never set at all, so don't read it in mux.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/avcodec: Stop including bsf.h in avcodec.hAndreas Rheinhardt2021-07-221-0/+1
| | | | | | Also include bsf.h directly wherever it is used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: move AVStream.{first,cur}_dts to AVStreamInternalJames Almer2021-06-091-9/+9
| | | | | | They are private fields, no reason to have them exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: remove deprecated AVStream.codecJames Almer2021-04-271-27/+0
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Remove deprecated filename field from AVFormatContextAndreas Rheinhardt2021-04-271-11/+0
| | | | | | | Deprecated in fa8308d3d4f27d6fb38ac2069887a7b259f1c6ab. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Constify the API wrt AV(In|Out)putFormatAndreas Rheinhardt2021-04-271-1/+1
| | | | | | | Also constify AVProbeData. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* lavf: postpone removal of FF_API_COMPUTE_PKT_FIELDS2Anton Khirnov2021-04-081-4/+4
| | | | | The infrastructure to fully handle generating timestamps e.g. for raw video streamcopy is still not present.
* avformat/mux: use av_packet_alloc() to allocate packetsJames Almer2021-03-171-20/+20
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/packet_internal: make avpriv_packet_list_* functions use an internal ↵James Almer2021-03-171-5/+6
| | | | | | | | | struct The next pointer is kept at the end for backwards compatability until the major bump, when it should ideally be moved at the front. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: return a pointer to the packet in ff_interleaved_peek()James Almer2021-02-131-17/+3
| | | | | | | And make it const, so the caller doesn't attempt to change it. ff_get_muxer_ts_offset() should be used to get the muxer timestamp offset. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: add ff_get_muxer_ts_offset()James Almer2021-02-131-0/+16
| | | | | | Will be useful in the next patch Signed-off-by: James Almer <jamrial@gmail.com>
* lavf/mux: rewrite guessing the packet durationAnton Khirnov2020-12-101-15/+34
| | | | | | Factor out the code into a separate muxing-specific function. Stop accessing the deprecated AVStream-embedded codec context, use the average framerate (if specified) instead.
* lavf: move AVStream.last_in_packet_buffer to AVStreamInternalAnton Khirnov2020-10-281-9/+9
| | | | | Those are private fields, no reason to have them exposed in a public header.