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.
Some (de)muxers open additional files beyond the main IO context.
Currently, they call avio_open() directly, which prevents the caller
from using custom IO for such streams.
This commit adds callbacks to AVFormatContext that default to
avio_open2()/avio_close(), but can be overridden by the caller. All
muxers and demuxers using AVIO are switched to using those callbacks
instead of calling avio_open()/avio_close() directly.
(de)muxers that use the URLProtocol layer directly instead of AVIO
remain unconverted for now. This should be fixed in later commits.
A failure in segment_end() or segment_start() would lead to freeing
a dangling pointer and in general further calls to seg_write_packet()
or to seg_write_trailer() would have the same faulty behaviour.
CC: libav-stable@libav.org
Reported-By: luodalongde@gmail.com
Since the pointer `oc' is NULL, oc->oformat->name will cause a null
pointer dereference. This patch changes it to seg->oformat->name.
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
avconv provides an option to set it externally and there isn't a way for
the outer demuxer to report the inner demuxer flag.
Solves a bad interaction between mpegts and x264, but requires
additional setting for the user.
This makes sure any buffered data is written to the segment, for
muxers that buffer up data internally (e.g. fragmented mp4).
Signed-off-by: Martin Storsjö <martin@martin.st>
This makes sure new inline headers are emitted when the next
packet is written. This allows segmenting mpegts without calling
write_header/write_trailer (nor freeing/reiniting the muxer)
for each segment.
Signed-off-by: Martin Storsjö <martin@martin.st>
Some segmented formats (such as fragmented mp4) are "bare", as in,
the segment files do not have the same headers/trailers as full normal
files of that format have.
Signed-off-by: Martin Storsjö <martin@martin.st>
This makes sure the muxers are set up in the way they expect
with no data left around from the previous run (which could
cause various issues including memory leaks, depending on the chaine
muxer).
This fixes memory leaks with the mpegts and flv muxers. It also
makes the usage of chained muxers correct.
Signed-off-by: Martin Storsjö <martin@martin.st>
With this change, the segmenter muxer doesn't rely on anything
not available/supported to libavformat external users, making
the segmenter muxer do things just like a normal segmenter
application using libavformat would do.
Signed-off-by: Martin Storsjö <martin@martin.st>
Before, the chained muxer reused the AVStreams array from
the outer muxer, which made it impossible to use the proper
public functions (such as av_write_frame) when calling the
chained muxer.
Signed-off-by: Martin Storsjö <martin@martin.st>
This might not be needed at the moment, but it's good practice to
pass it to all chained AVFormatContexts, if it would happen to be
used there at a later point.
Signed-off-by: Martin Storsjö <martin@martin.st>
Provide a way to wrap around the segment index so pseudostreaming
live through a web server and html5 browser is simpler.
Also ensure that 0 (disable) is a valid value across the options
providing wrap around.