13

AVAssetReader を介してサンプルを読み取るにはどうすればよいですか? AVAssetReader を使用して複製または混合する例を見つけましたが、これらのループは常に AVAssetWriter ループによって制御されます。AVAssetReader を作成し、それを読んで各サンプルを取得することは可能ですか?

ありがとう。

4

2 に答える 2

27

ビデオサンプルについて話しているのか、オーディオサンプルについて話しているのか、あなたの質問からは不明です。ビデオ サンプルを読むには、次の手順を実行する必要があります。

  1. AVAssetReader を構築します。

    asset_reader = [[AVAssetReader alloc] initWithAsset:asset error:&error]; (error checking goes here)

  2. アセットからビデオ トラックを取得します。

    NSArray* video_tracks = [asset tracksWithMediaType:AVMediaTypeVideo]; AVAssetTrack* video_track = [video_tracks objectAtIndex:0];

  3. 目的のビデオ フレーム形式を設定します。

    NSMutableDictionary* 辞書 = [[NSMutableDictionary alloc] init];
    [辞書 setObject:[NSNumber numberWithInt:<CVPixelBuffer.h からのフォーマット コード>] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey];

    特定のビデオ形式は機能しないことに注意してください。また、リアルタイムで何かを行っている場合、特定のビデオ形式は他のものよりもパフォーマンスが優れています (たとえば、BGRA は ARGB よりも高速です)。

  4. 実際のトラック出力を構築し、アセット リーダーに追加します。

    AVAssetReaderTrackOutput* asset_reader_output = [[AVAssetReaderTrackOutput alloc] initWithTrack:video_track outputSettings:dictionary];
    [asset_reader addOutput:asset_reader_output];
  5. アセット リーダーを開始します。

    [asset_reader startReading];

  6. サンプルを読み取る:

    CMSampleBufferRef バッファ;
    while ( [asset_reader ステータス]==AVAssetReaderStatusReading )
          buffer = [asset_reader_output copyNextSampleBuffer];
    
于 2010-11-18T15:03:16.110 に答える
2

ダミアンの答えは、ビデオと1つのマイナーな変更でうまくいきました:ステップ3では、辞書を変更可能にする必要があると思います:

NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
于 2011-05-18T11:10:45.483 に答える