summaryrefslogtreecommitdiff
path: root/libavformat/img2enc.c
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2015-10-20 19:49:13 +0200
committerLuca Barbato <lu_zero@gentoo.org>2015-10-23 11:55:14 +0200
commit22f4d9c303ede1a240538fd105c97047db40dc86 (patch)
treee8a35bf3ea67e51b1f2652f9cb9fbdf7e12491f2 /libavformat/img2enc.c
parent1ec72c6c68dbc78bf4ebb6f06c13316dc488bdfa (diff)
downloadffmpeg-22f4d9c303ede1a240538fd105c97047db40dc86.tar.gz
img2enc: Make sure the images are atomically written
Users that want to generate a live-preview and serve it would otherwise get partial images.
Diffstat (limited to 'libavformat/img2enc.c')
-rw-r--r--libavformat/img2enc.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index eeb19c0e25..d5b664658f 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -33,6 +33,7 @@ typedef struct VideoMuxData {
int img_number;
int is_pipe;
char path[1024];
+ char tmp[1024];
int update;
} VideoMuxData;
@@ -41,6 +42,7 @@ static int write_header(AVFormatContext *s)
VideoMuxData *img = s->priv_data;
av_strlcpy(img->path, s->filename, sizeof(img->path));
+ snprintf(img->tmp, sizeof(img->tmp), "%s.tmp", s->filename);
/* find format */
if (s->oformat->flags & AVFMT_NOFILE)
@@ -70,9 +72,9 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EIO);
}
for (i = 0; i < 3; i++) {
- if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE,
+ if (avio_open2(&pb[i], img->tmp, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL) < 0) {
- av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", filename);
+ av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->tmp);
return AVERROR(EIO);
}
@@ -121,6 +123,7 @@ error:
avio_flush(pb[0]);
if (!img->is_pipe) {
avio_close(pb[0]);
+ ff_rename(img->tmp, filename);
}
img->img_number++;