summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBela Bodecs <bodecsb@vivanet.hu>2018-02-19 21:36:25 +0100
committerSteven Liu <lq@chinaffmpeg.org>2018-02-23 21:36:11 +0800
commit85e6a33bdfddfc9532dc10079368649a23c2b6c4 (patch)
treed03275ee9e140680aa670cfb82d289663aab5d73
parentb6652f5100af48141dadcc45b087cf75eadc145e (diff)
downloadffmpeg-streaming-85e6a33bdfddfc9532dc10079368649a23c2b6c4.zip
ffmpeg-streaming-85e6a33bdfddfc9532dc10079368649a23c2b6c4.tar.gz
hlsenc: Fixing HLS_TEMP_FILE usage with HLS_SECOND_LEVEL_SEGMENT_...
Currently using HLS_TEMP together with HLS_SECOND_LEVEL_SEGMENT_DURATION or HLS_SECOND_LEVEL_SEGMENT_SIZE gives error at end of each segment writing and the final segment file names do not contain the desired data. This patch fixes this bug by delaying the initilization of original segment filename after actual temp file renaming will skip the interfering. Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
-rw-r--r--libavformat/hlsenc.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index cc13c94..ff06473 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2168,13 +2168,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
if (vs->packets_written && can_split && av_compare_ts(pkt->pts - vs->start_pts, st->time_base,
end_pts, AV_TIME_BASE_Q) >= 0) {
int64_t new_start_pos;
- char *old_filename = av_strdup(vs->avf->url);
+ char *old_filename = NULL;
int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size > 0);
- if (!old_filename) {
- return AVERROR(ENOMEM);
- }
-
av_write_frame(vs->avf, NULL); /* Flush any buffered data */
new_start_pos = avio_tell(vs->avf->pb);
@@ -2215,17 +2211,21 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Failed to open file '%s'\n",
vs->avf->url);
- av_free(old_filename);
return ret;
}
write_styp(vs->out);
ret = flush_dynbuf(vs, &range_length);
if (ret < 0) {
- av_free(old_filename);
return ret;
}
ff_format_io_close(s, &vs->out);
}
+
+ old_filename = av_strdup(vs->avf->url);
+ if (!old_filename) {
+ return AVERROR(ENOMEM);
+ }
+
ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
vs->start_pos = new_start_pos;
if (ret < 0) {
@@ -2316,6 +2316,12 @@ failed:
if ((hls->flags & HLS_TEMP_FILE) && oc->url[0]) {
hls_rename_temp_file(s, oc);
+ av_free(old_filename);
+ old_filename = av_strdup(vs->avf->url);
+
+ if (!old_filename) {
+ return AVERROR(ENOMEM);
+ }
}
/* after av_write_trailer, then duration + 1 duration per packet */
OpenPOWER on IntegriCloud