Commit Graph

33 Commits

Author SHA1 Message Date
Anton Khirnov 9200514ad8 lavf: replace AVStream.codec with AVStream.codecpar
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.
2016-02-23 17:01:58 +01:00
Anton Khirnov 9f61abc811 lavf: allow custom IO for all files
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.
2016-01-24 16:45:32 +01:00
Luca Barbato 2157df425b hlsenc: Support outputting specific versions
Right now only version 2 and version 3 are supported.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2015-08-25 19:43:58 +02:00
Luca Barbato 72839fce64 hlsenc: Use AV_TIME_BASE units for all the computations
Do not risk mixing different timebases.

CC: libav-stable@libav.org

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2015-08-16 19:02:16 +02:00
Hendrik Leppkes 3fe26bb608 hlsenc: write playlist into a temp file and replace the original atomically
Signed-off-by: Martin Storsjö <martin@martin.st>
2015-02-20 23:55:28 +02:00
Hendrik Leppkes ff48ae94f9 hlsenc: remove the AVIOContext for the playlist from the muxer context
Its only used in one function, having it in the context serves no purpose.

Signed-off-by: Martin Storsjö <martin@martin.st>
2015-02-20 23:55:27 +02:00
Martin Storsjö 28816050e4 lavf: Set the stream time base hint properly for chained muxers
This avoids warnings about using the codec time base as time
base hint.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-06 23:30:52 +03:00
Joakim Roubert 55f03d8726 hlsenc: Add parameter -hls_allow_cache
The -hls_allow_cache parameter enables explicitly setting the
EXT-X-ALLOW-CACHE tag in the manifest file. That tag indicates
whether the client MAY or MUST NOT cache downloaded media
segments for later replay.

Valid values are 1 (=YES) or 0 (=NO) and the EXT-X-ALLOW-CACHE
will not show in the manifest for other values (or if
-hls_allow_cache is not used.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-03 20:20:28 +03:00
Martin Storsjö 34e2ce5dde hlsenc: Set the default codecs to AAC and H264
Most HLS implementation only support these codecs.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-05-17 01:34:16 +03:00
Luca Barbato 7266e24f17 hls: Sync the file number with the start sequence 2014-04-30 17:52:49 +02:00
Luca Barbato a16431034d hls: Factor the sequence computation 2014-04-30 17:52:33 +02:00
Luca Barbato c7603b3c24 hls: Print start_number as first sequence value
The option now behaves as expected.
2014-04-30 17:52:17 +02:00
Luca Barbato 344f7b5a7e hls: Report the current media sequence
Useful for debugging mostly.
2014-04-30 17:51:50 +02:00
Luca Barbato 5a70a783f0 hls: Add an option to prepend a baseurl to the playlist entries
Useful to generate playlists with absolute paths.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2014-04-29 12:14:11 +02:00
Diego Biurrun 8f8bc92365 Add missing #includes for *INT64_MAX and *INT64_C 2013-11-23 21:55:52 +01:00
Carl Eugen Hoyos 9d86bfc259 hlsenc: Don't reset the number variable when wrapping
The counter itself shouldn't be wrapped, since it is used for
determining end_pts for the next segment - only wrap the number
used for the segment file name.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-15 22:41:19 +03:00
Stefano Sabatini 09c93b1b95 hlsenc: Append the last incomplete segment when closing the output
Also avoid comparing NOPTS values.

Bug-id: 551
Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-15 22:41:18 +03:00
Anton Khirnov cf679b9476 hls, segment: fix splitting for audio-only streams.
CC:libav-stable@libav.org
2013-04-27 10:19:04 +02:00
Kanglin ba8cb33273 hlsenc: Make the start_number option set the right variable
Signed-off-by: Martin Storsjö <martin@martin.st>
2013-01-08 17:33:56 +02:00
Luca Barbato 30a7648730 hlsenc: make segment number unsigned
It will overflow if somebody keeps streaming for a time long enough.
2012-12-29 17:26:30 +01:00
Kanglin 27a15e0af6 hlsenc: make EXT-X-MEDIA-SEQUENCE always increase 2012-12-29 17:26:30 +01:00
Luca Barbato 9b1370aced hlsenc: do not add timestamps in different timebases
start_time is in stream timebase units while end_time is
in AV_TIME_BASE ones.
2012-12-29 17:26:30 +01:00
Kanglin 0d8cc7a3b2 hlsenc: use the correct AV_TIME_BASE macro
recording_time is in AV_TIME_BASE units.
2012-12-29 17:26:30 +01:00
Luca Barbato 0448f26c97 hlsenc: keep the playlist to the correct number of items
Consider the corner case with a list size larger than the wrap
number.
2012-12-29 17:26:30 +01:00
Luca Barbato ae85d6c9c0 hlsenc: use the segment filename in the playlist entry
Avoid calling av_get_frame_filename twice, once to generate the
segment filename and once to generate the playlist.
2012-12-29 17:26:29 +01:00
Luca Barbato 6dd93ee6f1 hlsenc: check append_entry return value 2012-12-29 17:26:29 +01:00
Luca Barbato 66f7b4862f hlsenc: use the basename to generate the list entries
The segment path is desumed from the playlist path, recording a
relative path in the playlist while serving the file could lead
to misleading results.
2012-12-29 17:26:29 +01:00
Martin Storsjö 4a9f7d2bf9 hlsenc: Don't duplicate a string constant
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-12-24 00:02:48 +02:00
Stefano Sabatini 3193b13aa1 hlsenc: Allocate enough space for the pattern string
If s->filename doesn't contain any period/filename extension to strip
away, the buffer will be too small to fit both strings. This isn't
any buffer overflow since the concatenation uses av_strlcat with
the right buffer size.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-12-24 00:02:45 +02:00
Luca Barbato 7e98956e72 hlsenc: correctly report target duration 2012-12-23 12:13:41 +01:00
Luca Barbato adbe03077d hls: use a meaningful long name 2012-12-08 17:04:22 +01:00
Luca Barbato 5fbceb2c63 hls: add start_number option 2012-12-08 17:04:22 +01:00
Luca Barbato 22a0827dff hlsenc: stand alone hls segmenter
Simplifies usage but has higher latency.
2012-11-13 01:37:05 +01:00