2012-10-12 25 views
2

我想创建一个Mac应用程序供内部使用,即抓取用户指定的电影文件,将其转换为特定的格式并将每个帧保存为硬盘驱动器上的图像。 我已经完成了转换部分,使用真棒手刹CLI。视频图像序列与手刹CLI

现在我试图找到一种方法来保存每一帧作为图像,但我找不到一种方法。

看来ffmpeg有一个命令将帧提取到图像中。下面以拉一帧5秒:

ffmpeg -i "infile.mp4" -r 1 -ss 00:00:05 -t 00:00:01 -vframes 1 -f image2 -y "image.jpg" 

不过,我宁愿使用QTKit或手刹CLI,所以我不会有两个ffmpeg的和手刹添加到应用程序。

任何想法将不胜感激!

回答

1

所以,我已经确定你不能在Handbrake上讨论过他们的IRC频道。

然而,这里与ffmpeg的做这件事的是一个相对简单:

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; 
outputPipe = [NSPipe pipe]; 
taskOutput = [outputPipe fileHandleForReading]; 
current_task = [[NSTask alloc] init]; 

NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; 

NSString *stillName = [NSString stringWithFormat:@"%@_still%d.png", [MY_FILE substringToIndex:([draggedFile length]-4)], MY_STILL_NUMBER]; 

[current_task setLaunchPath: [NSString stringWithFormat:@"%@/ffmpeg", resourcePath]]; 

// save just frame at current time 
// by leaving -ss before the -i, we enable direct indexing within ffmpeg, which saves a still in about a second, rather than a minute or so on a long video file 
NSArray *arguments = [NSArray arrayWithObjects:@"-ss", currentFrameTime, @"-i", draggedFile, @"-vframes", @"1", @"-f", @"image2", stillName, nil]; 

[current_task setArguments:arguments]; 
[current_task setStandardInput:[NSPipe pipe]]; 
[current_task setStandardOutput:outputPipe]; 
[current_task setStandardError:outputPipe]; 

[defaultCenter addObserver:self selector:@selector(saveTaskCompleted:) name:NSTaskDidTerminateNotification object:current_task]; 

[current_task launch]; 
[taskOutput readInBackgroundAndNotify]; 

所以,我使用手刹任务(转换视频),然后另一个任务保存静态。 我只能使用ffmpeg,但我喜欢Handbrake,所以我会利用这2种方法。

希望这可以帮助那里的任何人。

0

试试这个(按帧的数量在您的视频替换25秒)

ffmpeg -i infile.mp4 -r 25 -f image2 /tmp/image-%4d.jpg 

然后用NSTask从您xcode项目运行此命令

Download FFMPEG O.11.1 for mac osx

Download FFMPEG git version for mac osx

+1

不知道你有什么我问的吗?我说我可以用ffmpeg来做,但是想用Handbrake(因为我已经在使用视频转换)或QTKit来找到一种方法。有任何想法吗? :) – Andre