diff --git a/android/app/src/main/java/com/arthenica/ffmpegkit/FFmpegKitConfig.java b/android/app/src/main/java/com/arthenica/ffmpegkit/FFmpegKitConfig.java index 0d2fb5a..6a32d25 100644 --- a/android/app/src/main/java/com/arthenica/ffmpegkit/FFmpegKitConfig.java +++ b/android/app/src/main/java/com/arthenica/ffmpegkit/FFmpegKitConfig.java @@ -509,10 +509,19 @@ public class FFmpegKitConfig { */ public static String registerNewFFmpegPipe(final Context context) { - // PIPES ARE CREATED UNDER THE CACHE DIRECTORY + // PIPES ARE CREATED UNDER THE PIPES DIRECTORY final File cacheDir = context.getCacheDir(); + final File pipesDir = new File(cacheDir, "pipes"); - final String newFFmpegPipePath = MessageFormat.format("{0}{1}{2}{3}", cacheDir, File.separator, FFMPEG_KIT_NAMED_PIPE_PREFIX, pipeIndexGenerator.getAndIncrement()); + if (!pipesDir.exists()) { + final boolean pipesDirCreated = pipesDir.mkdirs(); + if (!pipesDirCreated) { + android.util.Log.e(TAG, String.format("Failed to create pipes directory: %s.", pipesDir.getAbsolutePath())); + return null; + } + } + + final String newFFmpegPipePath = MessageFormat.format("{0}{1}{2}{3}", pipesDir, File.separator, FFMPEG_KIT_NAMED_PIPE_PREFIX, pipeIndexGenerator.getAndIncrement()); // FIRST CLOSE OLD PIPES WITH THE SAME NAME closeFFmpegPipe(newFFmpegPipePath); diff --git a/apple/src/FFmpegKitConfig.m b/apple/src/FFmpegKitConfig.m index 2a220e2..b4604e1 100644 --- a/apple/src/FFmpegKitConfig.m +++ b/apple/src/FFmpegKitConfig.m @@ -916,11 +916,21 @@ void callbackBlockFunction() { * @return the full path of named pipe */ + (NSString*)registerNewFFmpegPipe { + NSError *error = nil; + BOOL isDirectory; - // PIPES ARE CREATED UNDER THE CACHE DIRECTORY + // PIPES ARE CREATED UNDER THE PIPES DIRECTORY NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + NSString *pipesDir = [cacheDir stringByAppendingPathComponent:@"pipes"]; - NSString *newFFmpegPipePath = [NSString stringWithFormat:@"%@/%@%d", cacheDir, FFMPEG_KIT_PIPE_PREFIX, (++lastCreatedPipeIndex)]; + if (![[NSFileManager defaultManager] fileExistsAtPath:pipesDir isDirectory:&isDirectory]) { + if (![[NSFileManager defaultManager] createDirectoryAtPath:pipesDir withIntermediateDirectories:YES attributes:nil error:&error]) { + NSLog(@"Failed to create pipes directory: %@. Operation failed with %@.", pipesDir, error); + return nil; + } + } + + NSString *newFFmpegPipePath = [NSString stringWithFormat:@"%@/%@%d", pipesDir, FFMPEG_KIT_PIPE_PREFIX, (++lastCreatedPipeIndex)]; // FIRST CLOSE OLD PIPES WITH THE SAME NAME [FFmpegKitConfig closeFFmpegPipe:newFFmpegPipePath]; @@ -929,10 +939,7 @@ void callbackBlockFunction() { if (rc == 0) { return newFFmpegPipePath; } else { - int activeLogLevel = av_log_get_level(); - if ((activeLogLevel != AV_LOG_QUIET) && (AV_LOG_WARNING <= activeLogLevel)) { - NSLog(@"Failed to register new FFmpeg pipe %@. Operation failed with rc=%d.", newFFmpegPipePath, rc); - } + NSLog(@"Failed to register new FFmpeg pipe %@. Operation failed with rc=%d.", newFFmpegPipePath, rc); return nil; } }