Commit 1b82a005 authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/img2enc: Fix img2enc atomic implementation to work with split planes

Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 9ec2b9fc
......@@ -38,7 +38,8 @@ typedef struct VideoMuxData {
int is_pipe;
int split_planes; /**< use independent file for each Y, U, V plane */
char path[1024];
char tmp[1024];
char tmp[4][1024];
char target[4][1024];
int update;
int use_strftime;
const char *muxer;
......@@ -53,7 +54,6 @@ static int write_header(AVFormatContext *s)
const char *proto = avio_find_protocol_name(s->filename);
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)
......@@ -90,6 +90,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(codec->pix_fmt);
int i;
int nb_renames = 0;
if (!img->is_pipe) {
if (img->update) {
......@@ -111,9 +112,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EINVAL);
}
for (i = 0; i < 4; i++) {
if (avio_open2(&pb[i], img->use_rename ? img->tmp : filename, AVIO_FLAG_WRITE,
snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename);
av_strlcpy(img->target[i], filename, sizeof(img->target[i]));
if (avio_open2(&pb[i], img->use_rename ? img->tmp[i] : filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL) < 0) {
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->use_rename ? img->tmp : filename);
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->use_rename ? img->tmp[i] : filename);
return AVERROR(EIO);
}
......@@ -121,6 +124,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
break;
filename[strlen(filename) - 1] = "UVAx"[i];
}
if (img->use_rename)
nb_renames = i + 1;
} else {
pb[0] = s->pb;
}
......@@ -178,8 +183,9 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
avio_flush(pb[0]);
if (!img->is_pipe) {
avio_closep(&pb[0]);
if (img->use_rename)
ff_rename(img->tmp, filename, s);
for (i = 0; i < nb_renames; i++) {
ff_rename(img->tmp[i], img->target[i], s);
}
}
img->img_number++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment