summaryrefslogtreecommitdiffstats
path: root/libavformat/img2enc.c
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2015-10-27 12:50:56 +0100
committerHendrik Leppkes <h.leppkes@gmail.com>2015-10-27 12:50:56 +0100
commit7daac50067cbc3b6a4d677ac3f3574258659c2f6 (patch)
tree0ce9bb2914b04ccbbe2d95332984695bef76ca06 /libavformat/img2enc.c
parente7a57d4873e1123b9a42c4f8d7aefb4b1e8f1b61 (diff)
parent22f4d9c303ede1a240538fd105c97047db40dc86 (diff)
downloadffmpeg-streaming-7daac50067cbc3b6a4d677ac3f3574258659c2f6.zip
ffmpeg-streaming-7daac50067cbc3b6a4d677ac3f3574258659c2f6.tar.gz
Merge commit '22f4d9c303ede1a240538fd105c97047db40dc86'
* commit '22f4d9c303ede1a240538fd105c97047db40dc86': img2enc: Make sure the images are atomically written Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
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 48454fe..efc9304 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -38,6 +38,7 @@ typedef struct VideoMuxData {
int is_pipe;
int split_planes; /**< use independent file for each Y, U, V plane */
char path[1024];
+ char tmp[1024];
int update;
int use_strftime;
const char *muxer;
@@ -50,6 +51,7 @@ static int write_header(AVFormatContext *s)
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codec->pix_fmt);
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)
@@ -100,9 +102,9 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EINVAL);
}
for (i = 0; i < 4; 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);
}
@@ -167,6 +169,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
avio_flush(pb[0]);
if (!img->is_pipe) {
avio_closep(&pb[0]);
+ ff_rename(img->tmp, filename, s);
}
img->img_number++;
OpenPOWER on IntegriCloud