summaryrefslogtreecommitdiff
path: root/libavformat/mux.c
Commit message (Collapse)AuthorAge
* avformat/mux: Remove unnecessary unreferencing of AVPacketAndreas Rheinhardt2020-05-23
| | | | | | | | Since commit c5324d92c5f206dcdc2cf93ae237eaa7c1ad0a40 all custom interleave_packet() functions always return clean packets (even on error), so that unreferencing manually can be removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Call check_packet() more directlyAndreas Rheinhardt2020-05-16
| | | | | | | Call it directly from write_packets_common() instead of indirectly through prepare_input_packet(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Check pkt->stream_index before using itAndreas Rheinhardt2020-05-16
| | | | | | | | | | | This commit stops using pkt->stream_index as index in an AVFormatContext's streams array before actually comparing the value with the count of streams in said array. 96e5e6abb9851d7a26ba21703955d5826ac857c0 used pkt->stream_index in prepare_input_packet() before checking and 64063512227c4c87a7d16a1076481dc6baf19841 did likewise in write_packets_common(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: add proper support for full N:M bitstream filteringMarton Balint2020-05-07
| | | | | | | | | | | Previously only 1:1 bitstream filters were supported, the end of the stream was not signalled to the bitstream filters and time base changes were ignored. This change also allows muxers to set up bitstream filters regardless of the autobsf flag during write_header instead of during check_bitstream and those bitstream filters will always be executed. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mux: factorize writing a packetMarton Balint2020-05-07
| | | | | | In preparation for N:M bsf support. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mux: factorize interleaved write_packetMarton Balint2020-05-07
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mux: move interleaved packet functions upwardsMarton Balint2020-05-07
| | | | | | Will be needed later to avoid a forward declaration. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mux: Set AV_PKT_FLAG_KEY for is_intra_only packetLimin Wang2020-05-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch will make audio and subtitle packets be marked as AV_PKT_FLAG_KEY. For audio, it'll caused the audio sample to be sync sample. To verify ref/fate/movenc results: 1. Get the movenc test data [lmwang@vpn ffmpeg]$ libavformat/tests/movenc -w && mkdir -p audio_old && mv *.mp4 audio_old_ After applied the patch: [lmwang@vpn ffmpeg]$ make fate-movenc SAMPLES=../fate-suite [lmwang@vpn ffmpeg]$ libavformat/tests/movenc -w && mkdir -p audio_key && mv *.mp4 audio_key 2. Get l-smash and build boxdumper https://github.com/l-smash/l-smash.git 3. dump the box of crc change mp4 and diff -u [lmwang@vpn ffmpeg]$ ../l-smash/cli/boxdumper --box audio_key/non-empty-moov-no-elst.mp4 > audio_key/non-empty-moov-no-elst.log [lmwang@vpn ffmpeg]$ ../l-smash/cli/boxdumper --box audio_old/non-empty-moov-no-elst.mp4 > audio_old/non-empty-moov-no-elst.log [lmwang@vpn ffmpeg]$ diff -u audio_key/non-empty-moov-no-elst.log audio_old/non-empty-moov-no-elst.log - default_sample_flags = 0x02000000 - independent - sync sample + default_sample_flags = 0x01010000 + dependent + non-sync sample 4. have checked the change of crc are caused by default_sample_flags non-empty-moov.mp4, non-empty-moov-elst.mp4, non-empty-moov-no-elst.mp4, empty-moov.mp4, delay-moov-content.mp4, empty-moov-second-frag.mp4, empty-moov-second-frag-discont.mp4, delay-moov-second-frag-discont.mp4, delay-moov-elst-second-frag.mp4 etc 5 For subtitle, it'll effect for tests/ref/fate/binsub-movtextenc and tests/ref/fate/sub2video, that's expecting result for the subtitle is marked as keyframe. Below is the checking result of binsub-movtextenc: [lmwang@vpn ffmpeg]$ ./ffmpeg -i ../fate-suite/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov audio_key/binsub-movtextenc.mp4 [lmwang@vpn ffmpeg]$ ./ffmpeg -i ../fate-suite/sub/MovText_capability_tester.mp4 -map 0 -scodec mov_text -f mp4 -flags +bitexact -fflags +bitexact -movflags frag_keyframe+empty_moov audio_old/binsub-movtextenc.mp4 [lmwang@vpn ffmpeg]$../l-smash/cli/boxdumper audio_key/binsub-movtextenc.mp4 > audio_key/binsub-movtextenc.log [lmwang@vpn ffmpeg]$../l-smash/cli/boxdumper audio_old/binsub-movtextenc.mp4 > audio_old/binsub-movtextenc.log [lmwang@vpn ffmpeg]$ diff -u audio_key/binsub-movtextenc.log audio_old/binsub-movtextenc.log .... // the key difference is the flag for sync sample - flags = 0x000701 + flags = 0x000301 data-offset-present sample-duration-present sample-size-present - sample-flags-present sample_count = 6 - data_offset = 188 + data_offset = 164 sample[0] sample_duration = 1570000 sample_size = 21 - sample_flags = 0x02000000 - independent - sync sample - degradation_priority = 0 sample[1] sample_duration = 510000 sample_size = 2 - sample_flags = 0x01010000 - dependent - non-sync sample - degradation_priority = 0 sample[2] sample_duration = 1690000 sample_size = 9 - sample_flags = 0x02000000 - independent - sync sample - degradation_priority = 0 Suggested-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Suggested-by: Nicolas George <george@nsup.org> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avformat: only allow a single bitstream filter when muxingMarton Balint2020-04-26
| | | | | | | | | | | | Current muxers only use a single bitstream filter, so there is no need to maintain code which operates on a list of bitstream filters. When multiple bitstream filters are needed muxers can simply use a list bitstream filter. If there is a use case in the future when different bitstream filters should be added at subsequent packets then a new API possibly involving reconfiguring the list bitstream filter can be added knowing the exact requirements. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mux: Remove unnecessary headersAndreas Rheinhardt2020-04-24
| | | | | | | | | | | mux.c was split from utils.c in 55f9037f38bc3beacb2f5a17408c1d24c077d7fd and during this split all headers were simply copied without checking if they were only needed in the part that stayed in utils.c (or whether these haeders were needed at all). As a result quite a lot of headers in mux.c are unnecessary. This commit removes them. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* libavformat/mux, mxfenc: Don't initialize unnecessarilyAndreas Rheinhardt2020-04-18
| | | | | | | | | | | When no packet could be output, the interleavement functions nevertheless initialized the packet destined for output (with the exception of the data and size fields, making the initialization pointless), although it will not be used at all. So remove the initializations. Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Remove pointless timestamp backupsAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | write_packet() currently saves the original timestamps of the packet it got and restores them in case writing fails. This is unnecessary as we are no longer working directly with the user-supplied AVPacket here; and it is also pointless because the timestamps may already have been altered before write_packet(). So remove this and add a general comment to the function that timestamps may be modified; also remove a long outdated comment about side data. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Don't modify packets we don't ownAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation of av_write_frame() explicitly states that the function doesn't take ownership of the packets sent to it; while av_write_frame() does not directly unreference the packets after having written them, it nevertheless modifies the packet in various ways: 1. The timestamps might be modified either by prepare_input_packet() or compute_muxer_pkt_fields(). 2. If a bitstream filter gets applied, it takes ownership of the reference and the side-data in the packet sent to it. In case of do_packet_auto_bsf(), the end result is that the returned packet contains the output of the last bsf in the chain. If an error happens, a blank packet will be returned; a packet may also simply not lead to any output (vp9_superframe). This also implies that side data needs to be really copied and can't be shared with the input packet. The method choosen here minimizes copying of data: When the input isn't refcounted and no bitstream filter is applied, the packet's data will not be copied. Notice that packets that contain uncoded frames are exempt from this because these packets are not owned by and returned to the user. This also moves unreferencing the packets containing uncoded frames to av_write_frame() in the noninterleaved codepath; in the interleaved codepath, these packets are already freed in av_interleaved_write_frame(), so that unreferencing the packets in write_uncoded_frame_internal() is no longer needed. It has been removed. Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Remove redundant resettingAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | Now that ff_interleave_add_packet() always returns blank packets, the input packet to ff_interleave_packet_per_dts() will always be blank on return as well (if supplied) and the same goes for interleave_packet() in mux.c. Document these facts and remove the redundant resetting that happened in av_interleaved_write_frame(). The last reference to the (long removed) destruct field that AVPackets once had has been removed as well when updating the documentation of ff_interleave_packet_per_dts(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Fix leak when adding packet to interleavement queue failsAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | When an error happened in ff_interleave_add_packet() when adding a packet to the packet queue, said packet would not be unreferenced in ff_interleave_add_packet(), but would be zeroed in av_interleaved_write_frame(), which results in a memleak. This has been fixed: ff_interleave_add_packet() now always unreferences the input packet on error; as a result, it always returns blank packets which has been documented. Relying on this a call to av_packet_unref() in ff_audio_rechunk_interleave() can be removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Fix leaks on error when writing noninterleaved uncoded framesAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | If writing uncoded frames in noninterleaved mode fails at the preparatory steps (i.e. before it reaches write_packet()), the packet would not be unreferenced and the frame would leak. This is fixed by unreferencing the packet in write_uncoded_frame_internal() instead. This also makes it possible to remove the unreferencing in write_packet() itself: In noninterleaved mode frames are now freed in write_uncoded_frame_internal(), while they are freed in interleaved mode when their containing packet gets unreferenced (like normal packets). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Make uncoded frames av_packet_unref() compatibleAndreas Rheinhardt2020-04-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently uncoded frames (i.e. packets whose data actually points to an AVFrame) are not refcounted. As a consequence, calling av_packet_unref() on them will not free them, but may simply make sure that they leak by losing the pointer to the frame. This commit changes this by actually making uncoded frames refcounted. In order not to rely on sizeof(AVFrame) (which is not part of the public API and so must not be used here in libavformat) the packet's data is changed to a (padded) buffer containing just a pointer to an AVFrame. Said buffer is owned by an AVBuffer with a custom free function that frees the frame as well as the buffer. Thereby the pointer/the AVBuffer owns the AVFrame. Said ownership can actually be transferred by copying and resetting the pointer, as might happen when actually writing the uncoded frames in AVOutputFormat.write_uncoded_frame() (although currently no muxer makes use of this possibility). This makes packets containing uncoded frames compatible with av_packet_unref(). This already has three advantages in interleaved mode: 1. If an error happens at the preparatory steps (before the packet is put into the interleavement queue), the frame is properly freed. 2. If the trailer is never written, the frames still in the interleavement queue will now be properly freed by ff_packet_list_free(). 3. The custom code for moving the packet to the packet list in ff_interleave_add_packet() can be removed. It will also simplify fixing further memleaks in future commits. Suggested-by: Marton Balint <cus@passwd.hu> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Only prepare input packet if there is a packetAndreas Rheinhardt2020-04-01
| | | | | | | | | It is unnecessary to call prepare_input_packet if there is no packet as it doesn't do anything, except when the currently inactive code guarded by !FF_API_COMPUTE_PKT_FIELDS2 || !FF_API_LAVF_AVCTX becomes active: Then attempting to access pkt->stream_index will crash. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/mux: Unify setting number of muxed packetsAndreas Rheinhardt2020-03-14
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/mux: Remove redundant checks for write errorsAndreas Rheinhardt2020-03-14
| | | | | | | | | | | | | | | If writing a packet didn't directly return an error, the AVIOContext's error flag is checked for errors (if existing) by write_packet(). And if write_packet() didn't indicate an error, its callers checked the error flag of the AVIOContext (if existing). The latter check is redundant. The reason for checking twice lies in the FFmpeg-Libav split: The check in write_packet() has been added in 9ad1e0c1 in Libav. FFmpeg already had the other checks (since aec9390a), but when 9ad1e0c1 was merged (in 1f1c1008), no one noticed the redundant checks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/mux: CosmeticsAndreas Rheinhardt2020-02-25
| | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/mux: Don't use av_ prefix for static functionsAndreas Rheinhardt2020-01-27
| | | | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: Don't unnecessarily zero-initialize AVPacketListAndreas Rheinhardt2020-01-26
| | | | | | | | | If no error occurs and this AVPacketList is used at all, its packet substructure will be overwritten and its next pointer explicitly set, so every field will still be initialized even when using av_malloc. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/mux: Move packet referencesAndreas Rheinhardt2020-01-26
| | | | | | | | | | | | | | | | | | | In the common case that the input packet was already refcounted, ff_interleave_add_packet would allocate a new AVPacketList, use av_packet_ref to create a new reference to the buffer for the AVPacketList's packet, interleave the packet and finally unreference the original input packet. This commit changes this: It uses av_packet_move_ref to transfer the packet to its destination. In case the input packet is refcounted, this saves an allocation and a free (of an AVBufferRef); if not, the packet is made refcounted before moving it. When the input packet has side data, one saves even more than one allocation+free. Furthermore, when the packet is in reality an uncoded frame, a hacky ad-hoc variant of av_packet_move_ref has been employed. Not any more. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: call AVOutputFormat->deinit() when freeing the contextJames Almer2019-10-21
| | | | | | | | | | | | Despite the doxy stating that it's called when the muxer is destroyed, this was not true in practice. It's only called by av_write_trailer() and on init() failure. An AVFormatContext may be closed without writing the trailer if errors ocurred while muxing packets, so in order to prevent memory leaks, it should effectively be called when freeing the muxer. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: Use av_packet_rescale_tsAndreas Rheinhardt2019-08-15
| | | | | | | | | ff_write_chained essentially duplicated the functionality of av_packet_rescale_ts. This has been changed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/mux: Use const AVPacket * in compare functionsAndreas Rheinhardt2019-08-15
| | | | | | | | | There is no reason for these functions to modify the given packets at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/mux: correct error msg for when BSF filtering failsGyan Doshi2019-07-20
|
* libavformat/mux: Fix mixed delarations and codeAndreas Rheinhardt2019-06-27
| | | | | | This commit fixes mixed declarations and code introduced in 1889e316. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* libavformat/mux: Fix audio_preloadAndreas Rheinhardt2019-06-26
| | | | | | | | | | | | | | | | | Commit 31f9032b added the audio_preload feature; its goal is to interleave audio earlier than the rest. Unfortunately, it has never ever worked, because the check for whether a packet should be interleaved before or after another packet was completely wrong: When audio_preload vanishes, interleave_compare_dts returns 1 if the new packet should be interleaved earlier than the packet it is compared with and that is what the rest of the code expects. But the codepath used when audio_preload is set does the opposite. Also fixes potential undefined behaviour (namely signed integer overflow). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavf: Constify AVOutputFormat pointer.Carl Eugen Hoyos2019-03-20
|
* avformat: correct fdebug loglevelGyan Doshi2018-08-14
| | | | | fftools/cmdutils sets loglevel for fdebug to DEBUG but all fdebug output except for two were emitted at TRACE.
* avformat: deprecate AVFormatContext filename fieldMarton Balint2018-01-28
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat: add url field to AVFormatContextMarton Balint2018-01-28
| | | | | | | | | This will replace the 1024 character limited filename field. Compatiblity for output contexts are provided by copying filename field to URL if URL is unset and by providing an internal function for muxers to set both url and filename at once. Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/mux: factorize AVFormatContext->avoid_negative_ts initializationJames Almer2017-12-12
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: stop delaying writing the headerJames Almer2017-12-06
| | | | | | | Every bitstream filter behaves as intended now, so there's no need to wait for the first packet of every stream. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: move priv_pts from AVStream to an internal structJames Almer2017-11-07
| | | | | | | It has no reason to be in a public header, even if defined as private. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/mux: be less strict with bitstream filter failuresJames Almer2017-11-01
| | | | | | | | | | | This makes the autobsf feature behave the same as the manual bitstream filtering in ffmpeg.c Fixes ticket #6794 Reviewed-by: rcombs Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: remove ABI portion of the side data merging APIJames Almer2017-10-22
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* Merge commit '63fe79a3368cc53e6faf7fa265a9a1a8bec46a88'James Almer2017-10-21
|\ | | | | | | | | | | | | * commit '63fe79a3368cc53e6faf7fa265a9a1a8bec46a88': lavf: Drop deprecated hint to set muxer timebase Merged-by: James Almer <jamrial@gmail.com>
| * lavf: Drop deprecated hint to set muxer timebaseVittorio Giovara2017-03-23
| | | | | | | | Deprecated in 05/2014.
* | Merge commit '5e71299758d3aa7c93c3cca618a8e048a9483794'James Almer2017-10-21
|\| | | | | | | | | | | | | * commit '5e71299758d3aa7c93c3cca618a8e048a9483794': lavf: Drop deprecated bitexact functionality Merged-by: James Almer <jamrial@gmail.com>
| * lavf: Drop deprecated bitexact functionalityVittorio Giovara2017-03-23
| | | | | | | | Deprecated in 05/2014.
| * Use correct printf conversion specifiers for POSIX integer typesDiego Biurrun2016-12-23
| |
* | avformat: make flush_packets a tri-state and set it to -1 (auto) by defaultMarton Balint2017-06-24
| | | | | | | | | | | | | | | | | | If flushing is not disabled, then mux.c will signal the end of the packets with an AVIO_DATA_MARKER_FLUSH_POINT, and aviobuf will be able to decide to flush or not based on the preferred minimum packet size set by the used protocol. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Marton Balint <cus@passwd.hu>
* | avformat/mux: Fix copy an paste typoMichael Niedermayer2017-05-27
| | | | | | | | | | Found-by: Roger Scott <rscott@grammatech.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avformat/mux: remove autobsf extradata propagation hackJames Almer2017-05-24
| | | | | | | | | | | | The offending bitstream filter was fixed, so this is no longer needed. Signed-off-by: James Almer <jamrial@gmail.com>
* | Merge commit 'cdcfa97dc49d83b5eefd0a651db6bb0a6f98e8f2'Clément Bœsch2017-04-26
|\| | | | | | | | | | | | | * commit 'cdcfa97dc49d83b5eefd0a651db6bb0a6f98e8f2': libavformat: Fix a faulty api deprecation guard in prepare_input_packet Merged-by: Clément Bœsch <u@pkh.me>
| * libavformat: Fix a faulty api deprecation guard in prepare_input_packetMartin Storsjö2016-12-15
| | | | | | | | | | | | | | | | | | | | | | This seems to have been added by mistake in 11de006b, by not noticing the negation for the existing condition. This block does not contain any code that accesses the codec field in AVStream. This function is meant to serve as a complement to compute_pkt_fields2, which is guarded by FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX. Signed-off-by: Martin Storsjö <martin@martin.st>
* | avformat: do not use AVFrame accessorMuhammad Faiz2017-04-23
| | | | | | | | | | Reviewed-by: wm4 <nfxjfg@googlemail.com> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>