Meskalin <[email protected]> added the comment:
You can see new code at top or just look at below...
extern "C"
{
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
#include "libswscale/swscale.h"
}
int main(int argc, char *argv[]) {
AVFormatContext *pFormatCtx;
int i, videoStream;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVPacket packet;
char* fileName = "YourFile"; // Enter valid
file
// Register all formats and codecs
av_register_all();
// Open video file
if(av_open_input_file(&pFormatCtx, fileName,
NULL, 0, NULL)!=0)
return -1; // Couldn't open file
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream
information
// Dump information about file onto standard
error
dump_format(pFormatCtx, 0, fileName, 0);
// Find the first video stream
videoStream=-1;
for(i=0; i<pFormatCtx->nb_streams; i++) {
if(pFormatCtx->streams[i]->codec-
>codec_type==CODEC_TYPE_VIDEO)
{
videoStream=i;
break;
}
}
if(videoStream==-1)
return -1; // Didn't find a video stream
// Get a pointer to the codec context
for the video stream
pCodecCtx=pFormatCtx->streams[videoStream]-
>codec;
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx-
>codec_id);
if(pCodec==NULL) {
fprintf(stderr, "Unsupported
codec!\n");
return -1; // Codec not found
}
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
return -1; // Could not open
codec
int packetNumber=1;
printf("\n See the memory usage");
while(av_read_frame(pFormatCtx, &packet)>=0)
{
printf("\n Got Packet :%
d",packetNumber);
//********************************************
*****************
// Free the packet that was
allocated by av_read_frame
av_free_packet(&packet);
//********************************************
******************
packetNumber++;
}
// Close the codec
avcodec_close(pCodecCtx);
// Close the video file
av_close_input_file(pFormatCtx);
return 0;
}
________________________________________________
FFmpeg issue tracker <[email protected]>
<https://roundup.ffmpeg.org/issue2396>
________________________________________________