Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i use the following to parse each frame from the mov file. </p> <pre><code>-(NSData *)nextFrame { AVPacket packet; NSData *frame = nil; while(!frame &amp;&amp; av_read_frame(pFormatCtx, &amp;packet)&gt;=0) { if(packet.stream_index == streamNo) { frame = [[[NSData alloc] initWithBytes:packet.data length:packet.size] autorelease]; } av_free_packet(&amp;packet); } return frame; } </code></pre> <p>although watch out since av_read_frame does not verify the frames, that is done in the decoding step. this means that the "frames" returned might contain extra information which are not part of the actual frame.</p> <p>to init the AVFormatContext *pFormatCtx and AVCodecContext *pCodecCtx I use this code (which I believe is derived from Martin Böhme's example code):</p> <pre><code> AVCodec *pCodec; // Register all formats and codecs av_register_all(); // Open video file if(avformat_open_input(&amp;pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL)!=0) goto initError; // Couldn't open file // Retrieve stream information if(avformat_find_stream_info(pFormatCtx,NULL)&lt;0) goto initError; // Couldn't find stream information // Find the video stream streamNo = -1; for(int i=0; i&lt;pFormatCtx-&gt;nb_streams; i++){ if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO) { streamNo = i; break; } } if(streamNo == -1) goto initError; // Didn't find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtx-&gt;streams[streamNo]-&gt;codec; // Find the decoder for the video stream pCodec=avcodec_find_decoder(pCodecCtx-&gt;codec_id); if(pCodec==NULL) goto initError; // Codec not found // Open codec if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0) goto initError; // Could not open codec return self; initError: NSLog(@"initError in VideoFrameExtractor"); [self release]; return nil; </code></pre> <p>hope this helps someone in the future.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload