summaryrefslogtreecommitdiff
path: root/libavformat/segment.c
Commit message (Collapse)AuthorAge
* avformat/segment: Avoid duplicating string when parsing frames listAndreas Rheinhardt2020-09-10
| | | | | Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Fix error messagesAndreas Rheinhardt2020-09-10
| | | | | Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Remove redundant code for freeing in write_trailerAndreas Rheinhardt2020-09-10
| | | | | | | | This code mostly duplicates code in the deinit function; the only exception is av_opt_free(): The options are freed generically lateron. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Free SegmentListEntries in deinit, not write_trailerAndreas Rheinhardt2020-09-10
| | | | | | | This fixes leaks when the trailer is never written. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Fix leak and invalid free of AVIOContextAndreas Rheinhardt2020-09-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | seg_init() and seg_write_header() currently contain a few error paths in which an already opened AVIOContext for the child muxer leaks (namely if there are unrecognized options for the child muxer or if writing the header of the child muxer fails); the reason for this is that this AVIOContext is not closed in the deinit function. If all goes well, it is closed when writing the trailer. From this it also follows that the AVIOContext also leaks when the trailer is never written, even when writing the header succeeds. But simply freeing said AVIOContext in the deinit function is complicated by the fact that the AVIOContext may or may not have been opened via the io_open callback: If options are set to discard header and trailer, said AVIOContext can also be a null context which must not be closed via the io_close callback. This may lead to crashes, as io_close may presume the AVIOContext's opaque to be set. It currently works with the default io_close callback which simply calls avio_close(), because avio_close() doesn't care about opaque being NULL since commit 6e8e8431e15a58aa44cfdd8c11f9ea096837c0fa. Therefore this commit records which of the two kinds of AVIOContext is currently in use to use the right way to close it. Finally there was one instance (namely if initializing the child muxer fails with no unrecognized options) where the AVIOContext was always closed via the io_close callback. The above remark applies to this; it has been fixed, too. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Fix leak of string on errorAndreas Rheinhardt2020-09-10
| | | | | | | | | | | A string containing the segment's filename that the segment muxer allocates got only freed in its write_trailer function. This implies that it leaks if write_trailer is never called, e.g. if initializing the child muxer fails. This commit fixes this by freeing the string in the deinit function instead. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Fix segfault when error happens and segment list is outputAndreas Rheinhardt2020-09-10
| | | | | | | | | | | | | | | | | | | | | | | The segment muxer has an option to output a file containing a list of the segments written. The AVIOContext used for writing this file is opened via the main AVFormatContext's io_open callback; seg_free() meanwhile unconditionally closes this AVIOContext by calling ff_format_io_close() with the child muxer (the one for the actual output format) as AVFormatContext. The problem hereby is that the child AVFormatContext need not exist, even when the AVIOContext does. This leads to a segfault in ff_format_io_close() when the child muxer's io_close callback is called. Situations in which the AVFormatContext can be NULL range from an invalid reference stream parameter to an unavailable/bogus/unsupported output format to inability to allocate the AVFormatContext. The solution is to simply close the AVIOContext with the AVFormatContext that was used to open it: The main AVFormatContext. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Fix segfault on allocation error, avoid allocationAndreas Rheinhardt2020-09-10
| | | | | | | | | | | | | | | If the user has set none of the options specifying the segments' durations, a default value of 2s is used by duplicating a "2" string and using av_parse_time() on it. Yet duplicating the string was unchecked and if the allocation failed, one would get a segfault in av_parse_time(). This commit solves this by turning said option into an option of type AV_OPT_TYPE_DURATION (which also uses av_parse_time() internally), avoiding duplicating the string altogether. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Fix leak of duration/framenumber lists upon errorAndreas Rheinhardt2020-09-10
| | | | | | | | | | | | | | | The code to free them is not in the segment muxer's deinit function, but in its write_trailer function which means that these lists leak if write_trailer isn't called after their allocation. This happens e.g. if the given lists are invalid (e.g. consisting only of ',' (which delimit entries)), so that parsing them fails and so does the muxer's init function; write_trailer is then never called. This has been fixed by moving the code to free them to the deinit function. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Don't overwrite AVCodecParameters after initAndreas Rheinhardt2020-09-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The segment muxer copies the user-provided AVCodecParameters to the newly created child streams in its init function before initializing the child muxer; and since commit 8e6478b723affe4d44f94d34b98e0c47f6a0b411, it does this again before calling avformat_write_header() if that is called from seg_write_header(). The reason for this is complicated: At that time writing the header was delayed, i.e. it was not triggered by avformat_write_header() (unless the AVFMT_FLAG_AUTO_BSF was unset), but instead by writing the very first packet. The rationale behind this was to allow to run bitstream filters on the packets in the interleavement queue in order to generate missing extradata from them before the muxer's write_header function is actually called. The segment muxer went even further: It initialized the child muxer and ran the child muxer's check_bitstream functions on the packets in its own muxing queue and stole any bitstream filters that got inserted. The reason for this is that the segment muxer has an option to write the header to a separate file and for this it is needed to write the child muxer's header without delay, but with correct extradata. Unsetting AVFMT_FLAG_AUTO_BSF for the child muxer accomplished the first goal and stealing the bitstream filters the second; and in order for the child muxer to actually use the updated extradata, the old AVCodecParameters (set before avformat_init_output()) were overwritten with the new ones. Updating the extradata proceeded as follows: The bitstream filter itself simply updated the AVBSFContext's par_out when processing a packet, in violation of the new BSF API (where par_out may only be set in the init function); the muxing code then simply forwarded the updated extradata, overwriting the par_in of the next BSF in the BSF chain with the fresh par_out of the last one and the AVStream's par with the par_out of the last BSF. This was an API violation, too, of course, but it made remuxing ADTS AAC into mp4/matroska work. But this no longer serves a useful purpose since the aac_adtstoasc BSF was updated to propagate new extradata via packet side data in commit f63c3516577d605e51cf16358cbdfa0bc97565d8; the next commit then removed the code in mux.c passing new extradata along the filter chain. This alone justifies removing the code for setting the AVCodecParameters a second time. But there is even another reason to do so: It is harmful. The ogg muxer parses the extradata of Theora and Vorbis in its init function and keeps pointers to parts of it. Said pointers become dangling when the extradata is overwritten by the segment muxer, leading to use-after-frees as has happened in ticket #8881 which this commit fixes. Ticket #8517 is about another issue caused by this: Immediately after having overwritten the old AVCodecParameters the segment muxer checks whether the codec_tag is ok (the codec_tag is set generically when initializing the child muxer based upon muxer-specific lists). The check used is: If the child output format has such a list and if the codec tag of the non-child stream does not match the codec id given the list of codec tags and if there is a match for the codec id in the codec tag list, then set the codec tag to zero (and not to the existing match), otherwise set the codec tag of the child stream to the codec tag of the corresponding stream of the main AVFormatContext (which is btw redundant given that the child AVCodecParameters have just been overwritten with the AVCodecParameters of the corresponding stream of the main AVFormatContext). Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec, avformat: Remove unnecessary initializations of side data sizeAndreas Rheinhardt2020-06-22
| | | | | Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Propagate dispositionAndreas Rheinhardt2020-05-23
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/segment: Access AVStream more directlyAndreas Rheinhardt2020-05-23
| | | | | | | by storing s->streams[i] in a pointer instead of constantly using s->streams[i]->... Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@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/segment: always use interleaved writes for formats with custom ↵Marton Balint2020-04-08
| | | | | | interleaving Signed-off-by: Marton Balint <cus@passwd.hu>
* remove CHAR_MIN/CHAR_MAX usagePaul B Mahol2020-03-17
| | | | It is not needed at all.
* avformat/segment: Don't set extradata size twiceAndreas Rheinhardt2020-03-02
| | | | | | | | | ff_alloc_extradata() already sets the size of the extradata so doing it again is unnecessary. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Gyan Doshi <ffmpeg@gyani.pro> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/segment: use AV_OPT_TYPE_DICT for segment_format_optionsMarton Balint2020-01-01
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat/segment: fix muxing tmcd tracks in MOVGyan Doshi2019-06-20
| | | | | | avformat/movenc still relies on AVCodecContext time_base to mux tmcd tracks and segment muxer did not copy that field to inner streams leading to SIGFPE in the child muxer instance.
* avformat/segment: fix increment_tcGyan Doshi2019-06-18
| | | | | | inner stream avg_frame_rate wasn't populated, so tc formation failed. Also, extended increment_tc to cover individual stream timecode.
* avformat/segment: populate empty outer stream extradata from packetGyan Doshi2019-05-28
| | | | | | | | | | | | | | At present, if the outer stream extradata is empty but first packet has extradata as a side data element, then only the first segment's muxer instance may be able to extract this side data and use it. For all other segments, extradata in packet side data could be missing and generated segments may be invalid or unplayable in some apps e.g. for an ADTS AAC stream segmented to MP4, the adtstoasc BSF will add extradata to the first packet. The MOV muxer for the first segment will add this to codecpar for the inner stream and write Decoder Specific Information within the esds box. For other segments, their esds' will not have this decSpecificInfo and they can't be opened in Quicktime player or by services like nginx-vod-module.
* lavf: Constify AVOutputFormat pointer.Carl Eugen Hoyos2019-03-20
|
* avformat/segment: fix segment_time_delta option min/max valueMarton Balint2018-10-07
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avformat: fix stream_segment muxer build dependenciesJames Almer2018-02-07
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: migrate to AVFormatContext->urlMarton Balint2018-01-28
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* Fix several typosLou Logan2017-09-21
| | | | | | | "apix_fmts" found by Marc Péchaud. "speedloss" found by Mikhail V. Signed-off-by: Lou Logan <lou@lrcd.com>
* Use the new AVIOContext destructor.Anton Khirnov2017-09-01
| | | | | (cherry picked from commit 6f554521afdf7ab4edbfaa9536660a1dca946b19) Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: remove obsolete commented-out DEBUG defineTobias Rapp2017-07-07
| | | | | Signed-off-by: Tobias Rapp <t.rapp@noa-archive.com> Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
* avformat/segment: remove last_cut check when detecting a new segmentMarton Balint2017-02-04
| | | | | | | | | Not starting a new segment if the elapsed microsecs since the start of the day equals the the elapsed microsecs since the start of the day at the time of the last cut seems plain wrong to me, Deti do you remember the original reason behind this check? Signed-off-by: Marton Balint <cus@passwd.hu>
* lavf/segment: fix crash when failing to open segment listRodger Combs2017-01-23
| | | | | | | | | | | | | | | This happens because segment_end() returns an error, so seg_write_packet never proceeds to segment_start(), and seg->avf->pb is never re-set, so we crash with a null pb when av_write_trailer flushes the packet queue. This doesn't seem to be clearly recoverable, so I'm just failing more gracefully. Repro: ffmpeg -i input.ts -f segment -c copy -segment_list /noaxx.m3u8 test-%05d.ts (assuming you don't have write access to /)
* lavf/segment: fix autobsfRodger Combs2016-11-02
|
* lavf/segment: fix writing separate header with auto BSFRodger Combs2016-10-24
|
* lavf/segment: add deinit functionRodger Combs2016-10-24
|
* lavf/segment: decide whether to rename based on list URIRodger Combs2016-10-21
| | | | | This fixes the case of writing segments to local files, but the list over a network protocol.
* avformat/segment: give a warning message for remove initial_offset optionSteven Liu2016-09-09
| | | | | | | ffmpeg have a generic solution working with all muxer named output_ts_offset, output_ts_offset will instead of initial_offset Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/segment: remove the check_bitstream from segmentSteven Liu2016-07-14
| | | | | | | | because the BSF logic was re-factored into a shareable function and both av_write_frame and av_interleaved_write_frame use it it Signed-off-by: LiuQi <liuqi@gosun.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavf: update auto-bsf to new BSF APIRodger Combs2016-06-25
|
* avformat/segment: Pass flags to child contextMichael Niedermayer2016-04-11
| | | | | | This is needed as the bitexact flag is not in the codecpar context, and thus not copied Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Merge commit '9200514ad8717c63f82101dc394f4378854325bf'Derek Buitenhuis2016-04-10
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '9200514ad8717c63f82101dc394f4378854325bf': lavf: replace AVStream.codec with AVStream.codecpar This has been a HUGE effort from: - Derek Buitenhuis <derek.buitenhuis@gmail.com> - Hendrik Leppkes <h.leppkes@gmail.com> - wm4 <nfxjfg@googlemail.com> - Clément Bœsch <clement@stupeflix.com> - James Almer <jamrial@gmail.com> - Michael Niedermayer <michael@niedermayer.cc> - Rostislav Pehlivanov <atomnuker@gmail.com> Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
| * lavf: replace AVStream.codec with AVStream.codecparAnton Khirnov2016-02-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, AVStream contains an embedded AVCodecContext instance, which is used by demuxers to export stream parameters to the caller and by muxers to receive stream parameters from the caller. It is also used internally as the codec context that is passed to parsers. In addition, it is also widely used by the callers as the decoding (when demuxer) or encoding (when muxing) context, though this has been officially discouraged since Libav 11. There are multiple important problems with this approach: - the fields in AVCodecContext are in general one of * stream parameters * codec options * codec state However, it's not clear which ones are which. It is consequently unclear which fields are a demuxer allowed to set or a muxer allowed to read. This leads to erratic behaviour depending on whether decoding or encoding is being performed or not (and whether it uses the AVStream embedded codec context). - various synchronization issues arising from the fact that the same context is used by several different APIs (muxers/demuxers, parsers, bitstream filters and encoders/decoders) simultaneously, with there being no clear rules for who can modify what and the different processes being typically delayed with respect to each other. - avformat_find_stream_info() making it necessary to support opening and closing a single codec context multiple times, thus complicating the semantics of freeing various allocated objects in the codec context. Those problems are resolved by replacing the AVStream embedded codec context with a newly added AVCodecParameters instance, which stores only the stream parameters exported by the demuxers or read by the muxers.
* | lavf/segment: add option to write empty filler segments as neededRodger Combs2016-04-02
| |
* | lavf/segment: slight refactor to seg_write_packetRodger Combs2016-04-02
| | | | | | | | | | This reduces some code duplication, and ensures that cur_entry.last_duration is always set.
* | lavf/segment: style nitRodger Combs2016-04-02
| |
* | lavf/segment: support automatic bitstream filteringRodger Combs2016-04-02
| | | | | | | | | | Most useful for MPEG-TS. Works by having the underlying muxer configure the bitstream filters, then moving them to our own AVStreams.
* | avformat/segment: set format options for all segmentsMarton Balint2016-03-26
| | | | | | | | | | | | | | Fixes ticket #5318. Reviewed-by: Stefano Sabatini <stefasab@gmail.com> Signed-off-by: Marton Balint <cus@passwd.hu>
* | avformat/segment: Fix "occured" typoMichael Niedermayer2016-03-17
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | lavf/segment: change type of increment_tc to BOOLStefano Sabatini2016-03-15
| |
* | lavf/segment: add increment_tc optionMartin Vignali2016-03-15
| | | | | | | | | | | | | | | | | | For example you can split a file, keeping a continuous timecode between each segment: ffmpeg -i src.mov -timecode 10:00:00:00 -vcodec copy -f segment \ -segment_time 2 -reset_timestamps 1 -increment_tc 1 target_%03d.mov Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
* | avformat/segment: Fix header_filename handlingMichael Niedermayer2016-02-10
| | | | | | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | Merge commit '9f61abc8111c7c43f49ca012e957a108b9cc7610'Derek Buitenhuis2016-02-10
|\| | | | | | | | | | | | | | | | | This also deprecates our old duplicated callbacks. * commit '9f61abc8111c7c43f49ca012e957a108b9cc7610': lavf: allow custom IO for all files Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>