aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2015-02-20 12:54:58 +0100
committerMartin Storsjö <martin@martin.st>2015-02-20 23:55:28 +0200
commit3fe26bb60858951710a42065c8183cce100d632a (patch)
treedff186d4aada9db50825dcad3d944b3eb10d3dd6
parentff48ae94f90f6862dbe5b1e7397a1bda3150e200 (diff)
downloadffmpeg-3fe26bb60858951710a42065c8183cce100d632a.tar.gz
hlsenc: write playlist into a temp file and replace the original atomically
Signed-off-by: Martin Storsjö <martin@martin.st>
-rw-r--r--libavformat/hlsenc.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d8fd2546ef..21c952630d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -134,9 +134,11 @@ static int hls_window(AVFormatContext *s, int last)
int target_duration = 0;
int ret = 0;
AVIOContext *out = NULL;
+ char temp_filename[1024];
int64_t sequence = FFMAX(hls->start_sequence, hls->sequence - hls->size);
- if ((ret = avio_open2(&out, s->filename, AVIO_FLAG_WRITE,
+ snprintf(temp_filename, sizeof(temp_filename), "%s.tmp", s->filename);
+ if ((ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0)
goto fail;
@@ -168,6 +170,8 @@ static int hls_window(AVFormatContext *s, int last)
fail:
avio_closep(&out);
+ if (ret >= 0)
+ ff_rename(temp_filename, s->filename);
return ret;
}