2

ユーザーが指定したムービー ファイルを取得し、それを特定の形式に変換し、すべてのフレームを画像としてハード ドライブに保存する、社内用の Mac アプリを作成しようとしています。すばらしい Handbrake 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 または Handbrake CLI を使用したいので、アプリに ffmpeg と Handbrake の両方を追加する必要はありません。

どんなアイデアでも大歓迎です!

4

2 に答える 2

3

これを試してください(25をビデオの1秒あたりのフレーム数に置き換えます)

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

次に、NSTask を使用して、xcode プロジェクトからこのコマンドを実行します。

Mac osx 用の FFMPEG O.11.1 をダウンロード

Mac osx 用の FFMPEG git バージョンをダウンロードする

于 2012-10-12T19:33:57.703 に答える
2

そのため、IRC チャンネルで議論した結果、Handbrake ではできないことがわかりました。

ただし、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];

だから、私は(ビデオを変換するために)Handbrakeのタスクを使用してから、静止画を保存するために別のタスクを使用しています。ffmpeg だけでもいいのですが、私は Handbrake が好きなので、この 2 つを活用します。

これが誰にでも役立つことを願っています。

于 2012-10-23T11:24:36.837 に答える