NSTask和FFMpeg输出失败 [英] NSTask and FFMpeg losing output

查看:225
本文介绍了NSTask和FFMpeg输出失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从目标c中的NSTask调用ffmpeg。我在终端中执行ffmpeg命令,每次都完美无缺地运行。我使用NSTask做同样的命令,它从不给我整个输出。它每次在一个看似随机的地方将其切断输出。这是我的代码。

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");
}


推荐答案

就像我想到的出来。显然输出中有非UTF8Characters。切换到NSASCIIStringEncoding和瞧。魔术。

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

这篇关于NSTask和FFMpeg输出失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆