Hey guys,<div><br></div><div>I'm walking through frames of a video to do some analysis on the pixel data. I'd like to save each frame as an image so I can verify the analysis algorithm is running on the expected data.</div>
<div><br></div><div>I don't want to use the ffmpeg command-line to save out the frames because for some reason the frame counts are not matching. Ffmpeg.exe saves more frame jpegs than avcodec_decode_video2 seems to find.</div>
<div><br></div><div>Here's my code:<br><div><br></div><div><font face="courier new, monospace"><br></font></div><div><div><font face="courier new, monospace">while (av_read_frame(pFormatCtx, &packet) >= 0) </font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">  </span>{</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">         </span>// Is this a packet from the video stream?</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">          </span>if (packet.stream_index == videoStreamIndex && </font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                             </span>(frameLocation++ % frameSkip == 0)</font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                  </span>)</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">           </span>{</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font face="courier new, monospace">                  </font></span></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                    </span></font></div>
<div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                  </span>// Decode video frame</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                       </span>avcodec_decode_video2(pCodecCtx, pFrameYUV, &isFrameFinished, &packet);</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                        </span>// Did we get a video frame?</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                        </span>if (isFrameFinished) {</font></div>
</div></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                        </span>             // I'D LIKE TO SAVE FRAME AS A JPEG HERE</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">                        </span>}</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">         </span>}</font></div><div><font face="courier new, monospace"><span class="Apple-tab-span" style="white-space:pre">   </span>}</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">This is with ffmpeg 0.11.1.</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">Thanks!</font></div>