1

I'm trying to call ffmpeg from NSTask in objective-c. I execute the ffmpeg command in terminal and it works flawlessly every time. I make the same command using NSTask, and it never gives me the whole output. It cuts it off half way through the output, at a seemingly random spot every time. Here is my code.

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSString* ffmpegPath = [[NSBundle mainBundle] pathForResource:@"ffmpeg" ofType:@""];
    NSString* path = @"test.mov";

    NSTask *task = [[NSTask alloc] init];
    NSArray *arguments = [NSArray arrayWithObjects: @"-i", path, nil];
    NSPipe *pipe = [NSPipe pipe];
    NSFileHandle * read = [pipe fileHandleForReading];

    [task setLaunchPath: ffmpegPath];
    [task setArguments: arguments];
    [task setStandardOutput: pipe];
    [task launch];
    [task waitUntilExit];

    NSData* data = [read readDataToEndOfFile];
    NSString* stringOutput = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];


    NSLog(@"%@", stringOutput);
    NSLog(@"%i", [task terminationStatus]);
    NSLog(@"DONE");
}
Morgan
  • 1,765
  • 2
  • 19
  • 26
  • what is this "ffmpeg" that you saved in your resource bundle, i can find only the libraries (.a) like libavcodec.a etc.. – Swati Dec 27 '12 at 12:25
  • 1
    It is the compiled ffmpeg application http://www.ffmpeg.org/ – Morgan Feb 12 '13 at 02:32

1 Answers1

1

And just like that I figured it out. Apparently the output had non UTF8Characters in it. Switched it over to NSASCIIStringEncoding and voila. Magic.

Morgan
  • 1,765
  • 2
  • 19
  • 26