1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

418 Commits

Author SHA1 Message Date
Steven Liu
73fe0cbb94 avformat/hlsenc: check fragment size plus start_pos large than hls_segment_size
if vs->size + vs->start_pos > hls->max_seg_size, should split segment.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-07-07 14:32:00 +08:00
Andrey Semashev
93a435dd4b libavformat/hlsenc: Remove duplicate close of the output stream.
The result of the first close attempt is ignored and may be lost. By removing
it we ensure the close result code is properly analyzed.
2020-07-06 15:16:45 +08:00
Limin Wang
0e10f54585 avformat/hlsenc: simplify code to pass s directly
Suggested-by:  Nicolas George <george@nsup.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-02 21:12:37 +08:00
Limin Wang
fdda832603 avformat/hlsenc: fix av_bprint_finalize() usage
Don't need to do double check by the description of the API.

Reviewed-by:   Nicolas George <george@nsup.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-02 21:12:37 +08:00
Limin Wang
db92efd83e avformat/hlsenc: use proper error codes
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-02 21:12:37 +08:00
Andreas Rheinhardt
19a876fd69 avformat/hlsenc: Always treat numbers as decimal
c801ab43c3 caused a regression: The stream
number is now parsed with strtoll without a fixed basis; as a
consequence, the "010" in a variant stream mapping like "a:010" is now
treated as an octal number (i.e. as eight, not ten). This was not
intended and may break some scripts, so this commit restores the old
behaviour.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-06-15 05:09:07 +02:00
Andreas Rheinhardt
6c70f89813 avformat/hlsenc, hlsplaylist: Cosmetics
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-28 11:18:53 +02:00
Andreas Rheinhardt
4fbcb69707 avformat/hlsenc: Avoid duplicating strings when parsing
Up until now, the HLS muxer uses av_strtok() to split an input string
controlling parameters of the VariantStreams and then duplicates
parts of this string containing parameters such as the language or the
name of the VariantStream. But these parts are proper zero-terminated
strings of their own that are never modified lateron, so one can simply
use the substring as-is without creating a copy. This commit implements
this.

The same also happened for the string controlling the closed caption
groups.

Furthermore, add const to indicate that the pointers to these substrings
are not used to modify them and also to indicate that these strings are
not allocated on their own.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-28 11:18:53 +02:00
Andreas Rheinhardt
c1638bfae1 avformat/hlsenc: Don't unnecessarily duplicate baseurl string
Up until now, the HLS muxer duplicated a string for every VariantStream,
although neither the original nor the copies are ever modified. So use
the original directly and stop copying.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-28 11:18:53 +02:00
Andreas Rheinhardt
3ab6a923d1 avformat/hlsenc: Don't segfault on uncommon names
The parsing process of the AVOpt-enabled string controlling the mapping
of input streams to variant streams is roughly as follows: Space and tab
separate variant stream group maps while the entries in each variant
stream group map are separated by ','.

The parsing process of each variant stream group proceeded as follows:
At first the number of occurences of "a:", "v:" and "s:" in each variant
stream group is calculated so that one can can allocate an array of
streams with this number of entries. Then the string is split along ','
and each substring is parsed. If such a substring starts with "a:", "s:"
or "v:" it is treated as stream specifier and (if there is a correct
number after ':') a stream of the variant stream is mapped to one of the
actual input streams.

Nothing actually guarantees that the number of streams allocated initially
equals the number of streams that are mapped to an actual input stream.
These numbers can differ if e.g. the name, the sgroup, agroup or ccgroup
of the variant stream contain "a:", "s:" or "v:".

The problem hereby is that the rest of the code presumes these numbers
to be equal and segfaults if it isn't (because the corresponding input
stream is NULL).

This commit fixes this by modifying the initial counting process to only
count occurences of "a:", "s:" or "v:" that are at the beginning or that
immediately follow a ','.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-17 22:55:18 +02:00
Steven Liu
ba436c1586 avformat/hlsenc: free options fix memleak in hls_write_trailer
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-12 22:32:08 +08:00
Steven Liu
76eaca43be avformat/hlsenc: fix filename memleak in hls_write_packet
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-12 22:32:04 +08:00
Steven Liu
e684d07ac6 avformat/hlsenc: move number out of hls_start
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-12 22:31:57 +08:00
Andreas Rheinhardt
6db81e93a9 avformat/hlsenc: Simplify setting base_output_dirname
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-10 22:30:43 +02:00
Andreas Rheinhardt
21553d2082 avformat/hlsenc: Simplify setting basename with av_asprintf()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-10 22:23:28 +02:00
Andreas Rheinhardt
6b44f6839d avformat/hlsenc: Simplify setting subtitle basename with av_asprintf
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-10 21:41:22 +02:00
Andreas Rheinhardt
940601616e avformat/hlsenc: Don't cast const away
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-10 21:40:56 +02:00
Andreas Rheinhardt
d41c93d155 avformat/hlsenc: Remove redundant initializations
For every variantstream vs, vs->packets_written is set to one, only to be
set to zero a few lines below. Given that the relevant structure has
been zeroed during the allocation, this commit removes both assignments.
A redundant initialization for vs->init_range_length has been removed as
well a few lines below. Given that the relevant structure has been
zeroed during the allocation, this commit removes both assignments. A
redundant initialization for vs->init_range_length has been removed as
well.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-10 21:40:41 +02:00
Andreas Rheinhardt
a90f2265fa avformat/hlsenc: Don't reset AVIOContext pointer manually a second time
ff_format_io_close() already does it for us.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-10 21:40:13 +02:00
Andreas Rheinhardt
345158aea1 avformat/hlsenc: Cosmetics
Mainly includes reindentation and returning directly (i.e. without
a goto fail when possible).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 15:51:43 +02:00
Andreas Rheinhardt
4effcc399a avformat/hlsenc: Factor check out of loop
The check will be true at most once anyway.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 15:40:04 +02:00
Andreas Rheinhardt
e1dfb5128b avformat/hlsenc: Localize initialization of subtitle streams
Before this commit, the checks were unnecessarily scattered.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 15:35:06 +02:00
Andreas Rheinhardt
191b51254c avformat/hlsenc: Unconditionally free some strings
hls_init() would at first allocate the vtt_basename string, then
allocate the vtt_m3u8_name string followed by several operations that
may fail and then open the subtitles' output context. Yet upon freeing,
these strings were only freed when the subtitles' output context
existed, ensuring that they leak if something goes wrong between their
allocation and the opening of the subtitles' output context. So drop the
check for whether this output context exists.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 15:30:56 +02:00
Andreas Rheinhardt
2fcfc16dd2 avformat/hlsenc: Check some unchecked allocations
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 15:22:03 +02:00
Andreas Rheinhardt
fdb6f55209 avformat/hlsenc: Add deinit function
This fixes memleaks in instances such as:
a) When an allocation fails at one of the two places in hls_init() where
the error is returned immediately without goto fail first.
b) When an error happens when writing the header.
c) When an allocation fails at one of the three places in
hls_write_trailer() where the error is returned immediately without goto
fail first.
d) When one decides not to write the trailer at all (e.g. because of
errors when writing packets).
Furthermore, it removes code duplication and allows to return
immediately, without goto fail first.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 15:17:46 +02:00
Andreas Rheinhardt
de20f6cb70 avformat/hlsenc: Avoid setting unused variables
Several variables which are only used when the HLS_SINGLE_FILE flag is
unset have been set even when this flag is set. This has been changed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-08 14:02:53 +02:00
Andreas Rheinhardt
1ec0fb56a7 avformat/hlsenc: Remove redundant setting of output format
avformat_alloc_output_context2() already sets the oformat member, so
that there is no reason to overwrite it again with the value it already
has.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-07 16:06:51 +02:00
Andreas Rheinhardt
c801ab43c3 avformat/hlsenc: Improve checks for invalid stream mappings
The mapping of streams to the various variant streams to be created by
the HLS muxer is roughly as follows: Space and tab separate variant
stream group maps while the entries in each variant stream group map are
separated by ','.

The parsing process of each variant stream group proceeded as follows:
At first the number of occurences of "a:", "v:" and "s:" in each variant
stream group is calculated so that one can can allocate an array of
streams with this number of entries. Then each entry is checked and the
check for stream numbers was deficient: It did check that there is a
number beginning after the ":", but it did not check that the number
extends until the next "," (or until the end).

This means that an invalid variant stream group like v:0_v:1 will not be
rejected; the problem is that the variant stream in this example is
supposed to have two streams associated with it (because it contains two
"v:"), yet only one stream is actually associated with it (because there
is no ',' to start a second stream specifier). This discrepancy led to
segfaults (null pointer dereferencing) in the rest of the code (when the
nonexistent second stream associated to the variant stream was inspected).

Furthermore, this commit also removes an instance of using atoi() whose
behaviour on a range error is undefined.

Fixes ticket #8652.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-06 08:47:35 +02:00
Steven Liu
666dbe7aac avformat/hlsenc: resend full url of the init fragment mp4
fix ticket: 8651
because the init fragment mp4 file name is without base url name,
so just modify it use the full url which splice after init function.

Tested-by: matclayton
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-06 11:56:58 +08:00
Yaroslav Pogrebnyak
7f0200d0d2 libavformat/hlsenc: Allow usage of 'periodic-rekey' with multi-variant streams
This patch adds possibility to use 'periodic-rekey' option with
multi-variant streams to hlsenc muxer. All streams variants
use parameters from the same key_info_file.

There are 2 sets of encryption options that kind of overlaps and add
complexity, so I tried to do the thing without changing too much code.

There is a little duplication of the key_file, key_uri, iv_string, etc
in the VariantStream since we copy it from hls to each variant stream,
but generally all the code remains the same to minimise appearing
of unexpected bugs. Refactoring could be done as a separate patch then as needed.

Signed-off-by: Yaroslav Pogrebnyak <yyyaroslav@gmail.com>
2020-05-06 11:53:23 +08:00
Steven Liu
a7bab199e5 avformat/hlsenc: compute segment duration use current pts minus last segment end pts
segment duration is using vs duration which compute by frame per second,
that can not fix problem of VFR video stream, so compute the duration
when split the segment, set the segment target duration use
current packet pts minus the prev segment end pts..

Reported-by: Zhao Jun <barryjzhao@tencent.com>
Reviewed-by: Zhao Jun <barryjzhao@tencent.com>
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-05-06 11:32:26 +08:00
Marton Balint
d695762949 avformat/hlsenc: add support for microseconds since epoch based sequence number
Sequence numbers of segments should be unique, if an encoder is using shorter
than 1 second segments and it is restarted, then future segments will be using
already used sequence numbers if initial sequence number is based on the number
of seconds since epoch and not microseconds.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-01 17:22:58 +02:00
Steven Liu
152f61e29b avformat/hlsenc: add hls_fmp4_init_resend option
add option for resend init file after m3u8 refresh everytime.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-04-15 12:45:16 +08:00
Limin Wang
df08db0711 avformat/hlsenc: return media_url directly if failed to get seperator
Fix ticket: 8606
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-04-10 11:44:36 +08:00
Limin Wang
99ebb033d2 avformat/hlsenc: use av_asprintf()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-04-08 23:54:55 +08:00
Andreas Rheinhardt
d7780636df avformat/hlsenc: Factor out deleting files from deleting segments
Removes code duplication.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-08 17:06:21 +02:00
Limin Wang
cd8c5e89ba avformat: add subtitle support in master playlist m3u8
Test with the following command for the webvtt subtitle:
$ ./ffmpeg -y -i input_with_subtitle.mkv \
 -b✌️0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
 -b🅰️0 256k \
 -c:s webvtt -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0🅰️0 -map 0:s:0 \
 -f hls -var_stream_map "v:0,a:0,s:0,sgroup:subtitle" \
 -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 -hls_list_size \
 10 -master_pl_publish_rate 10  -hls_flags \
 delete_segments+discont_start+split_by_time ./tmp/video.m3u8

Check the master m3u8:
$ cat tmp/master.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitle",NAME="subtitle_0",DEFAULT=YES,URI="video_vtt.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33",SUBTITLES="subtitle"
video.m3u8

Check the result by convert to mkv:
$ ./ffmpeg -strict experimental -i ./tmp/master.m3u8 -c:v copy -c:a mp2 -c:s srt ./test.mkv

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-04-08 23:02:41 +08:00
Limin Wang
e2e8ef5076 avformat/hlsenc: remove the first slash of the relative path line in the master m3u8 file
Please testing with the following command:
./ffmpeg -y -i input.mkv \
 -b✌️0 5250k -c:v h264 -pix_fmt yuv420p -profile:v main -level 4.1 \
 -b🅰️0 256k \
 -c:a mp2 -ar 48000 -ac 2 -map 0:v -map 0🅰️0\
 -f hls -var_stream_map "v:0,a:0" \
 -master_pl_name master.m3u8 -t 300 -hls_time 10 -hls_init_time 4 -hls_list_size \
 10 -master_pl_publish_rate 10  -hls_flags \
 delete_segments+discont_start+split_by_time ./tmp/video.m3u8

then cat ./tmp/master.m3u8
before:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33"
/video.m3u8

$ ./ffmpeg -i  ./tmp/master.m3u8 -c:v copy -c:a mp2 ./test.mkv
[hls @ 0x7f82f9000000] Skip ('#EXT-X-VERSION:3')
[hls @ 0x7f82f9000000] Opening '/video.m3u8' for reading
[hls @ 0x7f82f9000000] parse_playlist error No such file or directory [/video.m3u8]
./tmp/master.m3u8: No such file or directory

after:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=6056600,RESOLUTION=1280x720,CODECS="avc1.4d4829,mp4a.40.33"
video.m3u8

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-04-08 23:02:36 +08:00
Andreas Rheinhardt
c9cd0a20b2 avformat/hlsenc: Use AVBPrint to avoid allocations of strings
when deleting old segments.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-08 16:47:19 +02:00
Andreas Rheinhardt
de8f6a4033 avformat/hlsenc: Fix memleak when deleting old segments
if the directory name of the segments contains "%v".

This memleak is caused by masking the pointer that will eventually
be freed by a variable of the same name in a smaller scope.
Therefore the pointer that gets freed is always NULL when it is
freed and the allocated data leaks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-08 16:30:45 +02:00
Steven Liu
31bc1c44d6 avformat/hlsenc: set the options when open the key info files
make the options same as segments for the http put method

Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
2020-03-12 14:00:45 +08:00
Hongcheng Zhong
5c72bb62a9 avformat/hlsenc: Fix initial setting for start_pts
This patch fixes Bug #8469
If x264 baseline profile is used with other profiles,
start_pts will be initialized to audio stream's first pts,
while the duration is calculated based on video stream's pts.
In this patch the start_pts is initialized with the correct stream's first pts.

Signed-off-by: Hongcheng Zhong <sj.hc_Zhong@sjtu.edu.cn>
Reviewed-by: Steven Liu <liuqi05@kuaishou.com>
2020-03-12 13:00:29 +08:00
Marton Balint
a8a05340de avformat/hlsenc: allow a custom SDT and PAT period
The default is not to write SDT and PAT periodically, only in the beginning of
every segment. After this patch the user might override this if needed.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-05 21:27:30 +01:00
Marton Balint
73aab08d9d avformat/hlsenc: fix hls_ts_options with mpegts
Was broken since cdbf8847ea.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-31 22:49:55 +01:00
Bela Bodecs
8c3e9c9cbb avformat/hlsenc: fix default AES key file url with variant streams
Currently when hls_enc is active and there are multiple variant stream
outputs, default key file url construction does not work, because it is
based on the FormatContext' url field. But in case of multiple variant
streams, it contains the variant m3u8 output playlist url that contains
the %v placeholder. So the result key file url will hold the %v
placeholder causing run time error message about "could not write the
key file".
This patch correct this behaviour, and use the master playlist url for
constructing the output key file url when master playlist is vailable.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2020-01-20 14:34:30 +08:00
Bela Bodecs
dd5c7378bb avformat/hlsenc: program_date_time and append_list flags conflict
When program_date_time flag is present, in m3u8 playlist file each
segment has a corresponding EXT-X-PROGRAM-DATE-TIME value. The intial
program-date-time value is the actual current time at init and
each new segment increments this value by its duration. When append_list
flags is also present, existing playlist parsing by hls_append_segment
treats existing segments as new segments regarding the program-date-time
calculation. But it should not do that, because this way all real the
new segments' EXT-X-PROGRAM-DATE-TIME values will be shifted erroneously
by the sum duration of existing segments. Instead it should have
decremented the initial program-date-time value by its duration. This
would ensure that
the first new segment's program-date-time value had the current time as
it is expected.
This patch corrects this behaviour and prevent existing segments to
increment the value of initial_prog_date_time variable but decrements
it.

Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2020-01-20 14:34:26 +08:00
Steven Liu
bc0bedf3c9 avformat/hlsenc: compare without the last directory separator in get_relative_url
fix ticket: 8461
there is no problem before commit 75aea52a10

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2020-01-20 14:23:56 +08:00
Marton Balint
4d7f8254ac avformat: remove unneeded avio_flush() calls before calling avio_close_dyn_buf()
avio_close_dyn_buf() also does avio_flush().

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-07 21:51:45 +01:00
Marton Balint
5d35a6e8e2 avformat/hlsenc: use AV_OPT_TYPE_DICT for hls_ts_options
Simplifies code and avoids memory leaks.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-01-01 20:41:34 +01:00
Andreas Rheinhardt
74a8be3546 avformat/hlsenc: Fix check for presence of webvtt muxer
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:54 +08:00
Andreas Rheinhardt
5ba3a8958c avformat/hlsenc: Fix memleaks with repeating parameters
When a parameter like e.g. language is contained more than once in the
part of var_stream_map pertaining to a single VariantStream, the later
one just overwrites the pointer to the earlier one, leading to a
memleak. This commit changes this by handling the situation gracefully:
The earlier string is silently freed first, so that the last one wins.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:51 +08:00
Andreas Rheinhardt
53c1458bf2 avformat/hlsenc: Fix return value from localtime_r failure
"If an error is detected, localtime_r() shall return a null pointer
and set errno to indicate the error." Yet in case this happened in
hls_init(), AVERROR(ENOMEM) has been returned.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:47 +08:00
Andreas Rheinhardt
149ee954a3 avformat/hlsenc: Fix potential segfault upon allocation failure
The hls muxer allocates an array of VariantStreams, a structure that
contains pointers to objects that need to be freed on their own. This
means that the number of allocated VariantStreams needs to be correct
when they are freed; yet the number of VariantStreams is set in
update_variant_stream_info() resp. parse_variant_stream_mapstring()
before the allocation has been checked for success, so that upon error
an attempt would be made to free the objects whose pointers are
positioned at position NULL (the location of VariantStreams) +
offsetof(VariantStream, the corresponding pointer).

Furthermore d1fe1344 added another possibility for the first function
to leave an inconsistent state behind: If an allocation of one of the
objects referenced by the VariantStream fails, the VariantStream will be
freed, but the number of allocated VariantStreams isn't reset, leading
to the same problem as above. (This was done in the mistaken belief that
the VariantStreams array would leak otherwise.)

Essentially the same also happens for the number of cc-streams. It has
been fixed, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:43 +08:00
Andreas Rheinhardt
bd131b64bc avformat/hlsenc: Fix leak of options when writing packets
Under certain circumstances hls_write_packet() would add options to an
AVDictionary. Said dictionary was never explicitly freed, instead it was
presumed that these options would be consumed when opening a new
IO-context. This left several possibilities for memleaks:

a) When no new IO-context would be opened at all. This is possible when
using both the flags temp_file and single_file together with a file
output.
b) When an error happens before one actually tries to open the new
IO-context.
c) When the new IO-context does not consume all options.

All three have been fixed; furthermore, the AVDictionary has been put
into a smaller scope (namely the only part of hls_write_packet() where
it is actually used).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:40 +08:00
Andreas Rheinhardt
9e4b3ccbb6 avformat/hlsenc: Fix leak of options when initializing muxing fails
hls_mux_init() currently leaks an AVDictionary if opening a dynamic
buffer fails or if avformat_init_output fails. This has been fixed by
moving the initialization resp. the freeing of the dictionary around:
In the former case to a place after opening the dynamic buffer, in the
latter to a place before the check for initialization failure so that it
is done unconditionally.

Furthermore, the dictionary is now only copied and freed if the options
in it are actually used (namely when in SEGMENT_TYPE_FMP4 mode).

Finally, a similar situation in hls_start() has been fixed, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:37 +08:00
Andreas Rheinhardt
ae84305036 avformat/hlsenc: Only allocate when data is known to be needed
hls_init() would allocate a buffer, although it is only needed in one of
two branches that follow. This commit moves the allocation to the branch
that actually needs the buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:33 +08:00
Andreas Rheinhardt
728c44b861 avformat/hlsenc: Fix typo in error message
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:30 +08:00
Andreas Rheinhardt
7d6637bcc4 avformat/hlsenc: Fix leak of child AVFormatContext
Before ed897633, the hls muxer would free its child AVFormatContexts
and reset the pointer to these contexts to NULL immediately afterwards;
ed897633 moved the former to later (into a separate function), but kept
the resetting, ensuring that the child context leaks.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Steven Liu <lq@onvideo.cn>
2019-12-23 14:05:26 +08:00
Steven Liu
ed89763336 avformat/hlsenc: remove duplicate code block
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-12-11 15:19:19 +08:00
Michael Niedermayer
a0ae4b7df9 Remove redundant ;
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-10 16:09:14 +01:00
Steven Liu
59d264b0a1 avformat/hlsenc: set strict_std_compliance from the parent AVFormatContext
fix ticket: 8388

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-11-26 11:32:03 +08:00
Limin Wang
09afddf04e avformat/hlsenc: free the original malloc pointer to avoid error when system function used in the following patch
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-11-13 17:01:34 +08:00
Limin Wang
7c872df3e1 avformat/hlsenc: fix the av_dirname path isn't include separator in the end of string
Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-10-31 14:13:00 +08:00
Steven Liu
1a109fba54 avformat/hlsenc: move freep segment from sls_flags_filename_process after caller failed
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-10-28 14:26:04 +08:00
Steven Liu
17d96c15d2 avformat/hlsenc: check av_strdup() return value
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-10-19 06:48:49 +02:00
Jun Zhao
feaec3bc31 lavf/hlsenc: fix memory leak
fix memory leak

Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-10-18 09:58:50 +08:00
Limin Wang
afab93ccd0 avformat/hlsenc: replace with av_freep for all av_free
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-10-08 14:12:56 +08:00
Limin Wang
28bb73cee7 avformat/hlsenc: replace with av_dirname to get the directory
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-10-08 14:12:53 +08:00
Limin Wang
61aa77272a avformat/hlsenc: remove the unnecessary null pointer check
Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-10-08 14:12:49 +08:00
Steven Liu
db99b32a1b avformat/hlsenc: add logging context to log
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-10-08 13:46:32 +08:00
Steven Liu
8efc9fcc56 avformat/hlsenc: make fix code style of hls_write_trailer
change vs->avf to oc
2019-09-14 13:09:16 +08:00
Andreas Rheinhardt
1a066d87e3 avformat/hlsenc: Fix memleak when using single_file
This commit fixes a memleak in the hls muxer when one uses a single file
as output. It has been forgotten to free the temporary buffers used to write
the packets so that the size of the leaks basically amounts to the size
of the output file. This commit adds the necessary free.

Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-09-14 09:55:49 +08:00
Daniel Oberhoff
88a26abcc6 hlsenc: flush segments to guarantuee atomic single file hls 2019-09-14 09:53:22 +08:00
Steven Liu
9ff8fbda65 avformat/hlsenc: fix memleak at hls_write_trailer
Found-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-12 10:40:41 +08:00
Steven Liu
5b809a8d4b avformat/hlsenc: print warning at the end when upload the last segment failed
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-12 10:39:15 +08:00
Steven Liu
307e0627db avformat/hlsenc: merge fmp4 and mpegts segment type m3u8 list AVIOConext
hlsenc has been merge fmp4 and mpegts workflow before
so it can merge m3u8 list AVIOContext now.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-12 10:38:47 +08:00
Steven Liu
db92a3e463 avformat/hlsenc: fix compiling error of hlsenc 2019-09-06 12:47:15 +08:00
Steven Liu
fe77cad3a4 avformat/hlsenc: fix code style
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-06 12:30:04 +08:00
Steven Liu
07b4bf5f11 avformat/hlsenc: move the warning message from every segment upload to init part
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-06 12:29:56 +08:00
Steven Liu
f267a2ac9c avformat/hlsenc: avformat/hlsenc: reopen new http session for http_persistent
fix ticket: 7975

Tested-by: Ian Klassen <ian@virtualfunc.com>
Suggested-by: Ian Klassen <ian@virtualfunc.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-09-06 10:26:23 +08:00
Limin Wang
75aea52a10 lavf/hlsenc: refine the get_relative_url function to avoid extra malloc for relation path
Reviewed-by: Steven Liu <lq@chinaffmpeg.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-09-02 13:28:08 +08:00
Steven Liu
17576fda65 avformat/hlsenc: remove unused value
CID: 1452644
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-26 11:06:48 +08:00
Steven Liu
80d2a7f5c6 avformat/hlsenc: fix memleak of filename
CID: 1452445
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-26 11:06:36 +08:00
Steven Liu
4ba82ecc12 avformat/hlsenc: fix memleak in hls_write_trailer
fix CID: 1426931

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-26 11:06:24 +08:00
Steven Liu
c66d468795 avformat/hlsenc: avformat/hlsenc: simplified code
simplified code for get dirname string in hls_delete_old_segments

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-21 16:46:35 +08:00
Steven Liu
fa78a6abb3 avformat/hlsenc: simplified code of use_localtime in hls_init
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-21 16:46:31 +08:00
Steven Liu
d1fe1344ea avformat/hlsenc: fix memleak in update_variant_stream_info
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-21 16:46:28 +08:00
Steven Liu
3708a2a909 avformat/hlsenc: reindent code
and remove redundant empty line
2019-08-20 09:56:38 +08:00
Steven Liu
939c17fcb3 avformat/hlsenc: remove unuse comment of the code 2019-08-20 09:45:47 +08:00
Jun Zhao
f36925201c lavf/hlsenc: free the old_filname to avoid memory leak
free the old_filname to avoid memory leak in error handle
path.

Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-08-20 08:44:42 +08:00
Limin Wang
eccb94c3ba lavf/hlsenc: fix one warning: unused variable 'filename' [-Wunused-variable]
Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2019-08-20 08:23:53 +08:00
Steven Liu
cff309097a avformat/hlsenc: merge mpegts and fmp4 workflow to one workflow
write mpegts or fmp4 context into buffer, and flush the buffer into
output file when split fragment. merge two format split workflow into
one workflow

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-08-18 08:22:32 +08:00
Steven Liu
23678462c0 avformat/hlsenc: Fix overflow of int for durations compute
Fix ticket: 8037

Reported-by: DusanBrejka
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-07-29 19:48:06 +08:00
Steven Liu
234a5e058d avformat/hlsenc: use old way for fragment mp4 in HLS PUT method
fix ticket: 8015

Reported-by: Jun Zhao
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-07-15 21:56:04 +08:00
Steven Liu
33a8cd5925 avformat/hlsenc: use one handler for m3u8 and segments
Use one handler for m3u8 and segments.
Use two handler in byterange mode.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2019-07-11 09:38:39 +08:00
Bela Bodecs
1476d82e73 avformat/hlsenc: changing all filename length to MAX_URL_SIZE
Throughout hlsenc code, all filename related buffer lengths are set
hardcoded as 1024. This PATCH change it to general value as MAX_URL_SIZE
in internal.h

Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2019-07-01 10:24:21 +08:00
Bela Bodecs
098ab93257 avformat/hlsenc: temp_file usage for master playlist and vtt playlist
currently master playlist and subtitle playlist creation does not use
temporary files even when temp_file flag is set. Most of the use cases
it is not a problem because master playlist creation happens once on the
beginning of the whole process. But if master playlist is periodically
re-created because of master_pl_refresh_rate is set, non-atomic playlist
creation may cause problems in case of live streaming. This patch
correct this behavior by adding this functionality.

Reviewed-by: Steven Liu <lq@onvideo.cn>
Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2019-06-28 13:54:27 +08:00
Derek Buitenhuis
025fcee6fa hlsenc: Add option to set custom HTTP headers
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2019-06-27 12:16:14 +01:00
Bela Bodecs
2045dd0050 avformat/hlsenc: better error log message for var_stream_map content
When multiple variant streams are specified by var_stream_map option,
%v is expected either in the filename or in the last sub-directory name,
but only in one of them. When both of them contains %v string, current
error message only states half of the truth.
And even %v may appears several times inside the last sub-directory name
or in filename pattern.
This patch clarifies this in the log message and in the doc also.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
2019-06-24 17:43:39 +08:00
Bela Bodecs
1beeb3b877 avformat/hlsenc: better checking var_stream_map content
When multiple variant streams are specified by var_stream_map option,
implementation assumes that each elementary stream is assigned only once
to any variant. But this is not checked. This patch makes this checking.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
Reviewed-by: Steven Liu<lq@onvideo.cn>
2019-06-22 18:02:42 +08:00