ffmpeg在visual studio中怎么用?

IT老炮-大钊 2015-03-18 07:21:10
我从官网下载ffmpeg windows build,在vs2012中编译不了。总提示链接问题
#include <stdio.h>

#include "stdafx.h"

#pragma comment(lib , "avcodec.lib")



#ifdef __cplusplus

extern "C"

{

#endif



//这里#include 各种ffmpeg的头文件 我偷懒直接写某个函数的定义了

const char *avcodec_license(void);



#ifdef __cplusplus

}

#endif



int main()

{

const char* p = avcodec_license();



if (p)

{

printf("%s\n", p);

}



return 0;

}


错误 1 error LNK2019: 无法解析的外部符号 _avcodec_license,该符号在函数 _main 中被引用 D:\ffmpeg\ffmpeg\test.obj ffmpeg

我是哪里配置的有问题呢?
...全文
328 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
IT老炮-大钊 2015-03-23
  • 打赏
  • 举报
回复
库应该加全了
IT老炮-大钊 2015-03-20
  • 打赏
  • 举报
回复
我下载的是编译过的,应该不需要在编译了
a198997 2015-03-20
  • 打赏
  • 举报
回复
好像有三种的,有一种直接可以用的。链接错误是不是库没加全?看看设置。。。 如果下的是源代码需要先用mingw在windows下编译成库,然后再在vs中调用库。。。
ztenv 版主 2015-03-18
  • 打赏
  • 举报
回复
先用mingw在windows下编译成dll,然后再在vs中使用;
IT老炮-大钊 2015-03-18
  • 打赏
  • 举报
回复
http://blog.sina.com.cn/s/blog_4178f4bf01018wqh.html 完全按照这个文章配置的
IT老炮-大钊 2015-03-18
  • 打赏
  • 举报
回复
#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 <libavformat/avformat.h> #include <libavcodec/avcodec.h> #include <libswscale/swscale.h> #include <libavutil/imgutils.h> #include <libavutil/opt.h> #include <libavutil/channel_layout.h> #include <libavutil/samplefmt.h> #include <libswresample/swresample.h> #ifdef __cplusplus } #endif static void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame); int main(int argc, const char * argv[]) { AVFormatContext *pFormatCtx; int i, videoStream; AVCodecContext *pCodecCtx; AVCodec *pCodec; AVFrame *pFrame; AVFrame *pFrameRGB; AVPacket packet; int frameFinished; int numBytes; uint8_t *buffer; // Register all formats and codecs av_register_all(); // Open video file if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) != 0) //if (avformat_open_input(NULL, argv[1], NULL, NULL) != 0) return -1; // Couldn't open file // AVDictionary* pOptions = NULL; pFormatCtx->probesize = 100 * 1024; // pFormatCtx->max_analyze_duration = 5 * AV_TIME_BASE; // Retrieve stream information if (avformat_find_stream_info(pFormatCtx, &pOptions) < 0) { return -1;// Couldn't find stream information } // Dump information about file onto standard error av_dump_format(pFormatCtx, 0, argv[1], false); // Find the first video stream videoStream = -1; 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; // 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) return -1; // Codec not found // Open codec #ifdef __FFMPEG_0_6__ if (avcodec_open(ffmpeg_video.codec_ctx, ffmpeg_video.codec) < 0) #else if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) #endif 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(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->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, 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 the video stream? if (packet.stream_index == videoStream) { // Decode video frame avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); // Did we get a video frame? if (frameFinished) { static struct SwsContext *img_convert_ctx; #if 0 // Older removed code // Convert the image from its native format to RGB swscale img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height); // function template, for reference int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]); #endif // Convert the image into YUV format that SDL uses if (img_convert_ctx == NULL) { int w = pCodecCtx->width; int h = pCodecCtx->height; img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt, w, h, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if (img_convert_ctx == NULL) { fprintf(stderr, "Cannot initialize the conversion context!\n"); exit(1); } } int ret = sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); #if 0 // this use to be true, as of 1/2009, but apparently it is no longer true in 3/2009 if (ret) { fprintf(stderr, "SWS_Scale failed [%d]!\n", ret); exit(-1); } #endif // Save the frame to disk if (i++ <= 5) SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i); } } // Free the packet that was allocated by av_read_frame av_free_packet(&packet); } // Free the RGB image //free(buffer); av_free(buffer); av_free(pFrameRGB); // Free the YUV frame av_free(pFrame); // Close the codec avcodec_close(pCodecCtx); // Close the video file #ifdef _FFMPEG_0_6__ av_close_input_file(pFormatCtx.pFormatCtx); #else avformat_close_input(&pFormatCtx); #endif return 0; } static void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) { FILE *pFile; char szFilename[32]; int y; // Open file sprintf(szFilename, "frame%d.ppm", iFrame); pFile = fopen(szFilename, "wb"); if (pFile == NULL) return; // Write header fprintf(pFile, "P6\n%d %d\n255\n", width, height); // Write pixel data for (y = 0; y < height; y++) fwrite(pFrame->data[0] + y*pFrame->linesize[0], 1, width * 3, pFile); // Close file fclose(pFile); } 错误 2 error LNK2019: 无法解析的外部符号 _av_malloc,该符号在函数 _main 中被引用 D:\ffmpeg\ffmpeg\ffmpeg.obj ffmpeg

64,644

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧