资源简介
实现从视频中保存了几幅图片。
一、参考的资料
http://blog.sina.com.cn/s/blog_4178f4bf01018wqh.html
http://www.guanggua.com/question/24057248-FFmpeg-undefined-references-to-av_frame_alloc.html
二、所有的环境
1.win10
2.vs2015
4.ffmpeg-3.4.1-win64
代码片段和文件信息
/*#define inline _inline
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif*/
#ifdef __cplusplus
extern “C“ {
#endif
#include
#include
#include
#includeame.h>
//#include
#ifdef __cplusplus
}
#endif
#include
#pragma comment(lib “avcodec.lib“)
#pragma comment(lib “avformat.lib“)
#pragma comment(lib “swscale.lib“)
#pragma comment(lib “avutil.lib“)
#include
const char* filename = “d:\\1.flv“;
static void Saveframe(AVframe *pframe int width int height int iframe);
int main(int argc char* argv[])
{
AVFormatContext *pFormatCtx(NULL);
int i = 0;
int videoStream = -1;
AVCodecContext *pCodecCtx(NULL);
AVCodec *pCodec(NULL);
AVframe *pframe(NULL);
AVframe *pframeRGB(NULL);
int numBytes = -1;
uint8_t *buffer(NULL);
AVPacket packet;
int frameFinished = -1;
// Register all formats and codecs
av_register_all();
// Open video file
if(avformat_open_input(&pFormatCtx filename NULL NULL)!=0)
return -1; // Couldn‘t open file
// Retrieve stream information
if (avformat_find_stream_info(pFormatCtxNULL)<0)
return -1; // Couldn‘t find stream information
// Dump information about file onto standard error
av_dump_format(pFormatCtx 0 filename false);
for (i = 0; i < pFormatCtx->nb_streams; i++)
{
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStream = i;
break;
}
}
if (videoStream == -1)
return -1; // 没有找到视频流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)
return -1; // Codec not found
// Open codec
if (avcodec_open2(pCodecCtx pCodecNULL)<0)
return -1; // Could not open codec
// Hack to correct wrong frame rates that seem to be generated by some codecs
if (pCodecCtx->time_base.num>1000 && pCodecCtx->time_base.den == 1)
pCodecCtx->time_base.den = 1000;
// Allocate video frame
pframe = av_frame_alloc();
// Allocate an AVframe structure
pframeRGB = av_frame_alloc();
if (pframeRGB == NULL)
return -1;
// Determine required buffer size and allocate buffer
numBytes = avpicture_get_size(AV_PIX_FMT_RGB24 pCodecCtx->widthpCodecCtx->height);
//buffer=malloc(numBytes);
buffer = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t));
// Assign appropriate parts of buffer to image planes in pframeRGB
avpicture_fill((AVPicture *)pframeRGB buffer AV_PIX_FMT_RGB24
pCodecCtx->width pCodecCtx->height);
// Read frames and save first five frames to disk
i = 0;
while (av_read_frame(pFormatCtx &packet) >= 0)
{
// Is this a packet from th
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-02-05 18:25 ffmpeg64\
目录 0 2018-02-05 18:25 ffmpeg64\include\
目录 0 2018-02-05 18:25 ffmpeg64\include\libavcodec\
文件 217771 2017-12-13 02:10 ffmpeg64\include\libavcodec\avcodec.h
文件 2570 2017-12-13 02:10 ffmpeg64\include\libavcodec\avdct.h
文件 3111 2017-12-13 02:10 ffmpeg64\include\libavcodec\avfft.h
文件 2853 2017-12-13 02:10 ffmpeg64\include\libavcodec\d3d11va.h
文件 4044 2017-12-13 02:10 ffmpeg64\include\libavcodec\dirac.h
文件 3715 2017-12-13 02:10 ffmpeg64\include\libavcodec\dv_profile.h
文件 2361 2017-12-13 02:10 ffmpeg64\include\libavcodec\dxva2.h
文件 1650 2017-12-13 02:10 ffmpeg64\include\libavcodec\jni.h
文件 2825 2017-12-13 02:10 ffmpeg64\include\libavcodec\mediacodec.h
文件 3763 2017-12-13 02:10 ffmpeg64\include\libavcodec\qsv.h
文件 4550 2017-12-13 02:10 ffmpeg64\include\libavcodec\vaapi.h
文件 5928 2017-12-13 02:10 ffmpeg64\include\libavcodec\vda.h
文件 7865 2017-12-13 02:10 ffmpeg64\include\libavcodec\vdpau.h
文件 8269 2017-12-13 02:10 ffmpeg64\include\libavcodec\version.h
文件 4029 2017-12-13 02:10 ffmpeg64\include\libavcodec\videotoolbox.h
文件 2285 2017-12-13 02:10 ffmpeg64\include\libavcodec\vorbis_parser.h
文件 6062 2017-12-13 02:10 ffmpeg64\include\libavcodec\xvmc.h
目录 0 2018-02-05 18:25 ffmpeg64\include\libavdevice\
文件 17918 2017-12-13 02:10 ffmpeg64\include\libavdevice\avdevice.h
文件 1861 2017-12-13 02:10 ffmpeg64\include\libavdevice\version.h
目录 0 2018-02-05 18:25 ffmpeg64\include\libavfilter\
文件 43095 2017-12-13 02:10 ffmpeg64\include\libavfilter\avfilter.h
文件 975 2017-12-13 02:10 ffmpeg64\include\libavfilter\avfiltergraph.h
文件 6316 2017-12-13 02:10 ffmpeg64\include\libavfilter\buffersink.h
文件 6608 2017-12-13 02:10 ffmpeg64\include\libavfilter\buffersrc.h
文件 2696 2017-12-13 02:10 ffmpeg64\include\libavfilter\version.h
目录 0 2018-02-05 18:25 ffmpeg64\include\libavformat\
文件 115772 2017-12-13 02:10 ffmpeg64\include\libavformat\avformat.h
............此处省略137个文件信息
评论
共有 条评论