2011-11-16 3 views
1

목표 -c에서 NSTask에서 ffmpeg를 호출하려고합니다. 터미널에서 ffmpeg 명령을 실행하면 매번 완벽하게 작동합니다. 나는 NSTask를 사용하여 같은 명령을 내린다. 그것은 매번 겉으로보기에 무작위의 지점에서, 출력을 통하여 반 길을 자른다. 여기 내 코드가있다.NSTask 및 FFMpeg 출력 손실

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

자원 번들에 저장 한 "ffmpeg"는 무엇입니까? libavcodec.a 등의 라이브러리 (.a) 만 찾을 수 있습니다. – Swati

+1

컴파일 된 ffmpeg 응용 프로그램 http://www.ffmpeg.org / – Morgan

답변

1

그리고 나는 그것을 알아 냈습니다. 출력에는 UTF8 문자가 아닌 것 같습니다. 그것을 NSASCIIStringEncoding 및 Voila로 전환했습니다. 마법.