简体   繁体   中英

OSX/Cocoa app crashing when finished running ffmpeg terminal command

I'm running ffmpeg within my Mac app and it's actually creating the output file successfully. The problem is that the app crashes as soon as the ffmpeg command is finished. Any ideas on how to prevent the crash?

Here's the code I'm using to run ffmpeg in my Mac app:

char ffm_cmd[512];
NSString *command = [NSString stringWithFormat:@"%@%@ \\\n-filter_complex '[0:0][1:0][2:0][3:0]concat=n=%d:v=0:a=1[out]' \\\n-map '[out]' %@/output.wav", escapedPath, concatFiles, count, self.outputFolderPath];
const char *cString = [command cStringUsingEncoding:NSASCIIStringEncoding];
sprintf(ffm_cmd,cString);
system(ffm_cmd);

Figured it out. My command was longer than 512 characters, so I just needed to change the size of my ffm_cmd character property.

This sounds like a sandboxing issue, can you have a look at console when you run the app (not via Xcode) but via finder..

ie find your app and double click it whilst console is open.

If you've never used console:

1) Press CMD + Space so spotlight pops up 2) Type in: console [press enter] 3) With All Messages high-lighted on the left, click clear display at the top 4) Run your app

What comes up in there?

Quite often libs can access some areas that are "off bounds" and sandbox (taskgated)throws a hissy fit killing the thread.

Cheers,

A

There's no need for ffm_cmd at all in the following sequence:

char ffm_cmd[512];
…
const char *cString = [command cStringUsingEncoding:NSASCIIStringEncoding];
sprintf(ffm_cmd,cString);
system(ffm_cmd);

The string you get back from -[NSString cStringUsingEncoding:] is already perfectly good:

const char *cmd = [command cStringUsingEncoding:NSASCIIStringEncoding];
system(cmd);

This rids you of the buffer overflow that was causing your issue, and will also make your code work correctly with filenames containing % characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM