[FFmpeg-cvslog] avformat/img2enc: Fix img2enc atomic implementation to work with split planes

Michael Niedermayer git at videolan.org
Tue Oct 27 21:39:48 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Tue Oct 27 21:21:17 2015 +0100| [1b82a0052ce1541a42de74e06890f3fecba96c99] | committer: Michael Niedermayer

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

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1b82a0052ce1541a42de74e06890f3fecba96c99
---

 libavformat/img2enc.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 339dfba..8a8e6e1 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -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++;



More information about the ffmpeg-cvslog mailing list