Commit Graph

108 Commits

Author SHA1 Message Date
Derek Buitenhuis
6f69f7a8bf Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* 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>
2016-04-10 20:59:55 +01:00
Adam Kent
77e355ffb1 avformat/hlsenc: Add support for HLS PLAYLIST types EVENT and VOD
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-03-12 22:22:08 +01:00
Michael Niedermayer
b2ab3398f5 avformat/hlsenc: Fix passing options, regression since bc9a5965c8
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-03-11 00:45:28 +01:00
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
Johan Ström
6c31c99289 hlsenc: add use_localtime_mkdir option to automatically create time-based directory
Use with -use_localtime, and set -hls_segment_filename to a path which
contains a subdirectory i.e. /some/path/%Y%m%d/%Y%m%dT%H%M%S-%s.ts
This will mkdir the %Y%m%d-part of the path if it does not already
exist.
In addition, each filename in the playlist output will be prefixed with
this subdirectory (if playlist and segment shares the same base path).

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-17 16:17:58 +01:00
Michael Niedermayer
a73b23e3df avformat/hlsenc: Fix filename and options
Regression since bc9a5965c8

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-10 19:14:53 +01:00
Derek Buitenhuis
bc9a5965c8 Merge commit '9f61abc8111c7c43f49ca012e957a108b9cc7610'
This also deprecates our old duplicated callbacks.

* commit '9f61abc8111c7c43f49ca012e957a108b9cc7610':
  lavf: allow custom IO for all files

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-02-10 14:42:41 +00:00
Michael Niedermayer
fe3fed0b14 Update demuxers and protocols for protocol whitelist support
Reviewed-by: Andreas Cadhalpun <andreas.cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-02 04:16:50 +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
Ganesh Ajjanagadde
18bc3dc768 lavf/hlsenc: replace round by lrint
Mainly cosmetic here.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-19 09:33:49 -08:00
Michael Niedermayer
c62d1780ff avformat/hlsenc: Check the return code of avformat_write_header()
Fixes: segfault
Fixes: Ticket5067

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-13 02:28:13 +01:00
Clément Bœsch
43ecec0f03 avformat: use AV_OPT_TYPE_BOOL in a bunch of places 2015-12-04 15:43:33 +01:00
Derek Buitenhuis
9ae73d0644 hlsenc: Only write PAT/PMT once per segment
This saves a lot of muxing overhead, especially on lower bitrate
segments.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2015-11-02 14:35:28 +00:00
DHE
76e3f8242d libavformat/hlsenc: Use of uninitialized memory unlinking old files
Fixes ticket#4900

Signed-off-by: DHE <git@dehacked.net>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-10-03 23:52:19 +02:00
Michael Niedermayer
8b47e10651 avformat/hlsenc: Fix the method command line parameter
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-09-14 21:07:37 +02:00
Michael Niedermayer
4cad4bd4ca avformat/hlsenc: Fix memleak of path
Fixes: CID1322343
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-09-03 11:28:29 +02:00
Michael Niedermayer
e3d8504fd0 avformat/hlsenc: Initialize vtt_oc to help static analyzers
This is also more robust in case it ever is used

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-09-03 11:28:29 +02:00
LiuQi
a4055d3e5d avformat/hlsenc: add a use_localtime option to expand the segment filename with localtime
test examples:

./ffmpeg -re -i ~/Movies/objectC/facebook.mp4 -v verbose -c copy -f hls -hls_segment_filename test-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb aaa.m3u8

[StevenLiu@localhost ffmpeg]$ cat aaa.m3u8;ll test-*.ts
test-1441052221.ts
test-1441052231.ts
test-1441052235.ts
test-1441052243.ts
test-1441052249.ts
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:15 test-1441052131.ts
-rw-r--r--  1 StevenLiu  staff   495192  9  1 04:15 test-1441052141.ts
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:17 test-1441052212.ts
-rw-r--r--  1 StevenLiu  staff  1067840  9  1 04:17 test-1441052221.ts
-rw-r--r--  1 StevenLiu  staff   235564  9  1 04:17 test-1441052231.ts
-rw-r--r--  1 StevenLiu  staff  1187220  9  1 04:17 test-1441052235.ts
-rw-r--r--  1 StevenLiu  staff   694848  9  1 04:17 test-1441052243.ts
-rw-r--r--  1 StevenLiu  staff   526588  9  1 04:17 test-1441052249.ts
[StevenLiu@localhost ffmpeg]$

./ffmpeg -re -i ~/Movies/objectC/facebook.mp4 -v verbose -c copy -f hls -hls_segment_filename test-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb aaa.m3u8

[StevenLiu@localhost ffmpeg]$ cat aaa.m3u8;ll aaa-*.ts
aaa-1441052417.ts
aaa-1441052427.ts
aaa-1441052437.ts
aaa-1441052440.ts
aaa-1441052449.ts
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:19 aaa-1441052382.ts
-rw-r--r--  1 StevenLiu  staff   277300  9  1 04:19 aaa-1441052392.ts
-rw-r--r--  1 StevenLiu  staff  1310736  9  1 04:20 aaa-1441052417.ts
-rw-r--r--  1 StevenLiu  staff  1067840  9  1 04:20 aaa-1441052427.ts
-rw-r--r--  1 StevenLiu  staff   235564  9  1 04:20 aaa-1441052437.ts
-rw-r--r--  1 StevenLiu  staff  1187220  9  1 04:20 aaa-1441052440.ts
-rw-r--r--  1 StevenLiu  staff   338776  9  1 04:20 aaa-1441052449.ts
[StevenLiu@localhost ffmpeg]$

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-09-02 04:31:32 +02: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
Michael Niedermayer
29a43bd588 avformat/hlsenc: Fix wording in comment
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-26 22:06:19 +02:00
Anshul Maheshwari
379ddc6af4 avformat/hlsenc: Add WebVtt support in hls
Signed-off-by: Anshul Maheshwari <er.anshul.maheshwari@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-26 05:59:43 +02:00
Christian Suloway
7e871d6999 avformat/hlsenc: removed empty/unused print_encryption_tag function
Signed-off-by: Christian Suloway <csuloway@globaleagleent.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-16 16:52:38 +02:00
Christian Suloway
907ac20aa2 avformat/hlsenc: added HLS encryption
Added HLS encryption with -hls_key_info_file <key_info_file> option. The
first line of key_info_file specifies the key URI written to the
playlist. The key URL is used to access the encryption key during
playback. The second line specifies the path to the key file used to
obtain the key during the encryption process. The key file is read as a
single packed array of 16 octets in binary format. The optional third
line specifies the initialization vector (IV) as a hexadecimal string to
be used instead of the segment sequence number (default) for encryption.
Changes to key_info_file will result in segment encryption with the new
key/IV and an entry in the playlist for the new key URI/IV.

Key info file format:
<key URI>
<key file path>
<IV> (optional)

Example key URIs:
http://server/file.key
/path/to/file.key
file.key

Example key file paths:
file.key
/path/to/file.key

Example IV:
0123456789ABCDEF0123456789ABCDEF

Example:
ffmpeg -f lavfi -i testsrc -c:v h264 -hls_key_info_file file.keyinfo
foo.m3u8

file.keyinfo:
http://server/file.key
/path/to/file.key
0123456789ABCDEF0123456789ABCDEF

Example shell script:
BASE_URL=${1:-'.'}
openssl rand 16 > file.key
echo $BASE_URL/file.key > file.keyinfo
echo file.key >> file.keyinfo
echo $(openssl rand -hex 16) >> file.keyinfo
ffmpeg -f lavfi -re -i testsrc -c:v h264 -hls_flags delete_segments \
  -hls_key_info_file file.keyinfo out.m3u8
--

Signed-off-by: Christian Suloway <csuloway@globaleagleent.com>
Signed-off-by: Dan Dennedy <dan@dennedy.org>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-16 03:25:31 +02:00
MrBoogs
4f2fcac290 avformat/hlsenc: do not append an endlist tag when the stream ends
Reviewed-by: Thomas Volkert <silvo@gmx.net>
2015-05-17 17:15:03 +02:00
MrBoogs
572a8292cb avformat/hlsenc: Add hls flag for starting a playlist with a discontinuity on startup
Reviewed-by: Thomas Volkert <silvo@gmx.net>
2015-05-17 17:14:00 +02:00
MrBoogs
8fd01b4a79 avformat/hlsenc: Add hls flag for rounding m3u8 durations to whole numbers, problems with floats on some devices
Reviewed-by: Thomas Volkert <silvo@gmx.net>
2015-05-17 17:11:44 +02:00
Michael Niedermayer
6c9537b807 avformat/hlsenc: Warn if a non file protocol is used
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-23 16:53:36 +01:00
Michael Niedermayer
e78a729163 avformat/hlsenc: Use ff_rename() only for local files
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-21 01:50:26 +01:00
Hendrik Leppkes
da97e4c64a hlsenc: write playlist into a temp file and replace the original atomically
Reviewed-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-21 01:50:06 +01: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
Hendrik Leppkes
28bf05e7b5 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: Michael Niedermayer <michaelni@gmx.at>
2015-02-20 13:13:19 +01:00
Michael Niedermayer
aa6545e1f3 avformat/hlsenc: more robust error tests
errors are negative throughout ffmpeg

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-11 05:17:44 +01:00
Michael Niedermayer
bf3126db6a avformat/hlsenc: Use avio_closep() to avoid leaving stale pointers in memory
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-08 14:51:04 +01:00
Michael Niedermayer
b8eb8b0310 avformat/hlsenc: Use av_freep() to avoid leaving stale pointers in memory
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-16 15:37:04 +01:00
Christian Suloway
92a596f13b avformat/hlsenc: fix hls_write_trailer() on hls_start() failure
Close segment I/O context and append segment in hls_write_trailer() only
when segment I/O context is allocated.

Signed-off-by: Christian Suloway <csuloway@globaleagleent.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-16 03:57:58 +01:00
Christian Suloway
97b65f6126 avformat/hlsenc: added segment file deletion
This option flag deletes segment files removed from the playlist after a
period of time equal to the duration of the segment plus the duration of
the playlist.

Signed-off-by: Christian Suloway <csuloway@globaleagleent.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-10 23:49:25 +01:00
Christian Suloway
1c639fa6e0 avformat/hlsenc: added segment filename option
This option allows segment filenames to be specified. Unless -hls_flags
single_file is set the filename is used as a string format with the
segment number.

Example:
ffmpeg -f lavfi -i testsrc -c:v h264 -map 0 -hls_segment_filename
bar%03d.ts foo.m3u8

Signed-off-by: Christian Suloway <csuloway@globaleagleent.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-06 02:28:23 +01:00
Michael Niedermayer
530eb6acf8 avformat/hlsenc: Free context after hls_append_segment
Fixes reading uninitialized memory

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-16 04:32:54 +01:00
Mika Raento
75c8d7c2b4 hlsenc.c, segment.c: propagate defaults to mpegts
This fixes the abnormally high ts overhead in the files produced by the
HLS and segments muxers. See https://trac.ffmpeg.org/ticket/2857 . For
example makes it much more likely that it can produces streams that fit
under the 64kb App store limit.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-17 21:31:25 +02:00
Michael Niedermayer
3726d07a2a Merge commit '28816050e47b6dba430a52e429d21a864cffda8e'
* commit '28816050e47b6dba430a52e429d21a864cffda8e':
  lavf: Set the stream time base hint properly for chained muxers

Conflicts:
	libavformat/segment.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-07 02:51:08 +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
Michael Niedermayer
883bc7d2e7 Merge commit '55f03d872640175a00bfa262da4652b7312b905f'
* commit '55f03d872640175a00bfa262da4652b7312b905f':
  hlsenc: Add parameter -hls_allow_cache

Conflicts:
	doc/muxers.texi
	libavformat/hlsenc.c
	libavformat/version.h

See: 3edb9aaea6
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-03 21:46:40 +02: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
Michael Niedermayer
3f5095f213 avformat/hlsenc: fix outter typo
Found-by: beastd
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-29 00:19:43 +02:00
Michael Niedermayer
b1a0fccd02 avformat/hlsenc: export inner muxer timebase
Fixes "Non-monotonous DTS in output stream 0:0"
Fies Ticket 3797

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-28 22:27:33 +02:00
Joakim Roubert
3edb9aaea6 avformat/hlsenc: Added 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: Michael Niedermayer <michaelni@gmx.at>
2014-09-28 03:09:05 +02:00
Steven Liu
2c21e8b1a4 lavf/hls: add hls_ts_option
Same as COMMITID 4f5493fe23.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2014-09-16 16:30:03 +02:00
Mika Raento
f685f7d7a8 hlsenc: single_file, support HLS ver 4 byteranges
This adds a new option -hls_flags single_file that creates one .ts file
for HLS and adds byteranges to the .m3u8 file, instead of creating one
.ts file for each segment.

This is helpful at least for storing large number of videos, as the
number of files per video is drastically reduced and copying and storing
those files takes less requests and inodes.

This is based on work by Nicolas Martyanoff, discussed on ffmpeg-devel
in July 2014. That patch seems abandoned by the author, and contained
unrelated changes. This patch tries to add the minimum amount of code to
support the byterange playlists.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-15 22:16:44 +02:00