]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/img2enc.c
Merge commit '8958c5c64d05453204642b55a7b8b44c93023b17'
[ffmpeg] / libavformat / img2enc.c
index 2f0aec1f029415abddb7042118002c312b6216b0..ebbac2bf7b1a3c2e6b98344a0cef40b34e4e6e21 100644 (file)
@@ -51,7 +51,6 @@ static int write_header(AVFormatContext *s)
     VideoMuxData *img = s->priv_data;
     AVStream *st = s->streams[0];
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codec->pix_fmt);
-    const char *proto = avio_find_protocol_name(s->filename);
 
     av_strlcpy(img->path, s->filename, sizeof(img->path));
 
@@ -73,9 +72,6 @@ static int write_header(AVFormatContext *s)
                              && desc->nb_components >= 3;
     }
 
-    img->use_rename = img->use_rename < 0 ? proto && !strcmp(proto, "file")
-                                          : img->use_rename;
-
     return 0;
 }
 
@@ -111,8 +107,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         for (i = 0; i < 4; i++) {
             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) {
+            if (s->io_open(s, &pb[i], img->use_rename ? img->tmp[i] : filename, AVIO_FLAG_WRITE, NULL) < 0) {
                 av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->use_rename ? img->tmp[i] : filename);
                 return AVERROR(EIO);
             }
@@ -137,11 +132,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         avio_write(pb[0], pkt->data                , ysize);
         avio_write(pb[1], pkt->data + ysize        , usize);
         avio_write(pb[2], pkt->data + ysize + usize, usize);
-        avio_closep(&pb[1]);
-        avio_closep(&pb[2]);
+        ff_format_io_close(s, &pb[1]);
+        ff_format_io_close(s, &pb[2]);
         if (desc->nb_components > 3) {
             avio_write(pb[3], pkt->data + ysize + 2*usize, ysize);
-            avio_closep(&pb[3]);
+            ff_format_io_close(s, &pb[3]);
         }
     } else if (img->muxer) {
         int ret;
@@ -179,9 +174,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
     }
     avio_flush(pb[0]);
     if (!img->is_pipe) {
-        avio_closep(&pb[0]);
+        ff_format_io_close(s, &pb[0]);
         for (i = 0; i < nb_renames; i++) {
-            ff_rename(img->tmp[i], img->target[i], s);
+            int ret = ff_rename(img->tmp[i], img->target[i], s);
+            if (ret < 0)
+                return ret;
         }
     }
 
@@ -207,7 +204,7 @@ static const AVOption muxoptions[] = {
     { "update",       "continuously overwrite one file", OFFSET(update),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0,       1, ENC },
     { "start_number", "set first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT,  { .i64 = 1 }, 0, INT_MAX, ENC },
     { "strftime",     "use strftime for filename", OFFSET(use_strftime),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
-    { "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, ENC },
+    { "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
     { NULL },
 };