On Thu, Oct 25, 2012 at 2:02 PM, Michael Bradshaw <<a href="mailto:mbradshaw@sorensonmedia.com">mbradshaw@sorensonmedia.com</a>> wrote:<br>> I've also included<br><br>Sorry, I meant to say that should you be interested, the source video file can be found at: <a href="https://docs.google.com/uc?export=download&id=0BxWx_dIBnyRoSnMyTFNGOHR1c2c">https://docs.google.com/uc?export=download&id=0BxWx_dIBnyRoSnMyTFNGOHR1c2c</a><br>
<br>The source I'm using, should you also be interested, is (remove the 'extern "C"' part to compile as C):<br><br>#include <stdio.h><br><br>extern "C"<br>{<br>#include <libavcodec/avcodec.h><br>
#include <libavformat/avformat.h><br>#include <libswresample/swresample.h><br>}<br><br>int main(int argc, char** argv)<br>{<br> AVFrame* frame;<br> AVFormatContext* formatContext;<br> AVStream* videoStream;<br>
AVCodecContext* codecContext;<br> AVPacket packet;<br> int frameFinished;<br> int result;<br><br> av_register_all();<br><br> frame = avcodec_alloc_frame();<br> if (!frame)<br> {<br> printf("Error allocating the frame\n");<br>
return 1;<br> }<br><br> formatContext = NULL;<br> if (avformat_open_input(&formatContext, "C:/Users/mbradshaw/Desktop/b/c/SIMPSONS_D2-CallOfTheSimpsons.m4v", NULL, NULL) != 0)<br> {<br> av_free(frame);<br>
printf("Error opening the file\n");<br> return 1;<br> }<br><br> if (avformat_find_stream_info(formatContext, NULL) < 0)<br> {<br> av_free(frame);<br> avformat_close_input(&formatContext);<br>
printf("Error finding the stream info\n");<br> return 1;<br> }<br> <br> videoStream = NULL;<br> for (unsigned int i = 0; i < formatContext->nb_streams; ++i)<br> {<br> if (formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)<br>
{<br> videoStream = formatContext->streams[i];<br> break;<br> }<br> }<br><br> if (videoStream == NULL)<br> {<br> av_free(frame);<br> avformat_close_input(&formatContext);<br>
printf("Could not find any video stream in the file\n");<br> return 1;<br> }<br><br> codecContext = videoStream->codec;<br> codecContext->codec = avcodec_find_decoder(codecContext->codec_id);<br>
if (codecContext->codec == NULL)<br> {<br> av_free(frame);<br> avformat_close_input(&formatContext);<br> printf("Couldn't find a proper decoder\n");<br> return 1;<br>
}<br> else if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0)<br> {<br> av_free(frame);<br> avformat_close_input(&formatContext);<br> printf("Couldn't open the context with the decoder\n");<br>
return 1;<br> }<br><br> av_init_packet(&packet);<br> while (av_read_frame(formatContext, &packet) == 0)<br> {<br> if (packet.stream_index == videoStream->index)<br> {<br> printf("packet.dts = %d\n", packet.dts);<br>
<br> frameFinished = 0;<br> result = avcodec_decode_video2(codecContext, frame, &frameFinished, &packet);<br><br> if (result >= 0 && frameFinished)<br> {<br>
break;<br> av_free_packet(&packet);<br> }<br> }<br><br> av_free_packet(&packet);<br> }<br> <br> avcodec_flush_buffers(codecContext);<br> printf("seek result: %d\n",<br>
av_seek_frame(formatContext, 1, -2000000000, AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY));<br><br> while (av_read_frame(formatContext, &packet) == 0)<br> {<br> if (packet.stream_index == videoStream->index)<br>
{<br> printf("packet.dts = %d\n", packet.dts);<br> <br> frameFinished = 0;<br> result = avcodec_decode_video2(codecContext, frame, &frameFinished, &packet);<br>
<br> if (result >= 0 && frameFinished)<br> {<br> break;<br> av_free_packet(&packet);<br> }<br> }<br><br> av_free_packet(&packet);<br>
}<br><br> av_free(frame);<br> avcodec_close(codecContext);<br> avformat_close_input(&formatContext);<br> return 0;<br>}