shithub: aacenc

Download patch

ref: 5d1b42fc53252961b3ea25526723d6cb95401c65
parent: 4b298a9b06e46a6779676f50fc9263621dc5c49d
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Wed Aug 16 06:55:22 EDT 2017

check if output file exists; --overwrite option added

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -102,7 +102,8 @@
     HELP_QUAL,
     HELP_IO,
     HELP_MP4,
-    HELP_ADVANCED
+    HELP_ADVANCED,
+    OVER_FLAG
 };
 
 typedef struct {
@@ -163,6 +164,7 @@
     "\t\tin your multichannel input files if they haven't been reordered\n"
     "\t\talready).\n"},
     {"--ignorelength\tIgnore wav length from header (useful with files over 4 GB)\n"},
+    {"--overwrite\t\tOverwrite existing output file"},
     {0}
 };
 
@@ -483,6 +485,7 @@
     char *faac_copyright_string;
     int ignorelen = FALSE;
     int verbose = 1;
+    int overwrite = 0;
 
 #ifndef _WIN32
     // install signal handler
@@ -535,6 +538,7 @@
             {"pcmswapbytes", 0, 0, 'X'},
             {"ignorelength", 0, 0, IGNORELEN_FLAG},
             {"tag", 1, 0, TAG_FLAG},
+            {"overwrite", 0, 0, OVER_FLAG},
             {0, 0, 0, 0}
         };
         int c = -1;
@@ -735,6 +739,9 @@
         case IGNORELEN_FLAG:
             ignorelen = TRUE;
             break;
+        case OVER_FLAG:
+            overwrite = TRUE;
+            break;
         case MPEGVERS_FLAG:
             mpegVersion = atoi(optarg);
             switch (mpegVersion)
@@ -955,7 +962,7 @@
             return 1;
         }
 
-        if (mp4atom_open(aacFileName))
+        if (mp4atom_open(aacFileName, overwrite))
         {
             fprintf(stderr, "Couldn't create output file %s\n", aacFileName);
             return 1;
--- a/frontend/mp4write.c
+++ b/frontend/mp4write.c
@@ -25,6 +25,7 @@
 #endif
 #include <string.h>
 #include <time.h>
+#include <unistd.h>
 
 enum ATOM_TYPE
 {
@@ -840,13 +841,20 @@
     return 0;
 }
 
-int mp4atom_open(char *name)
+int mp4atom_open(char *name, int over)
 {
     mp4atom_close();
 
-    g_fout = fopen(name, "wb");
-    if (!g_fout)
+    if (!access(name, W_OK) && !over)
+    {
+        fprintf(stderr, "output file exists, use --overwrite option\n");
         return 1;
+    }
+    if (!(g_fout = fopen(name, "wb")))
+    {
+        perror(name);
+        return 1;
+    }
 
     mp4config.mdatsize = 0;
     mp4config.frame.bufsize = BUFSTEP;
--- a/frontend/mp4write.h
+++ b/frontend/mp4write.h
@@ -79,7 +79,7 @@
 
 extern mp4config_t mp4config;
 
-int mp4atom_open(char *name);
+int mp4atom_open(char *name, int over);
 int mp4atom_head(void);
 int mp4atom_tail(void);
 int mp4atom_frame(uint8_t * bitbuf, int bytesWritten, int frame_samples);