AVAssetReader を介してサンプルを読み取るにはどうすればよいですか? AVAssetReader を使用して複製または混合する例を見つけましたが、これらのループは常に AVAssetWriter ループによって制御されます。AVAssetReader を作成し、それを読んで各サンプルを取得することは可能ですか?
ありがとう。
AVAssetReader を介してサンプルを読み取るにはどうすればよいですか? AVAssetReader を使用して複製または混合する例を見つけましたが、これらのループは常に AVAssetWriter ループによって制御されます。AVAssetReader を作成し、それを読んで各サンプルを取得することは可能ですか?
ありがとう。
ビデオサンプルについて話しているのか、オーディオサンプルについて話しているのか、あなたの質問からは不明です。ビデオ サンプルを読むには、次の手順を実行する必要があります。
AVAssetReader を構築します。
asset_reader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
(error checking goes here)
アセットからビデオ トラックを取得します。
NSArray* video_tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack* video_track = [video_tracks objectAtIndex:0];
目的のビデオ フレーム形式を設定します。
NSMutableDictionary* 辞書 = [[NSMutableDictionary alloc] init]; [辞書 setObject:[NSNumber numberWithInt:<CVPixelBuffer.h からのフォーマット コード>] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey];
特定のビデオ形式は機能しないことに注意してください。また、リアルタイムで何かを行っている場合、特定のビデオ形式は他のものよりもパフォーマンスが優れています (たとえば、BGRA は ARGB よりも高速です)。
実際のトラック出力を構築し、アセット リーダーに追加します。
AVAssetReaderTrackOutput* asset_reader_output = [[AVAssetReaderTrackOutput alloc] initWithTrack:video_track outputSettings:dictionary]; [asset_reader addOutput:asset_reader_output];
アセット リーダーを開始します。
[asset_reader startReading];
サンプルを読み取る:
CMSampleBufferRef バッファ; while ( [asset_reader ステータス]==AVAssetReaderStatusReading ) buffer = [asset_reader_output copyNextSampleBuffer];
ダミアンの答えは、ビデオと1つのマイナーな変更でうまくいきました:ステップ3では、辞書を変更可能にする必要があると思います:
NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];