今天代码有点看不动了,所以从网上找点学习资料,等学看完学习资料再继续研究
https://blog.csdn.net/qq819853294/article/details/8296622
https://www.jianshu.com/p/58a2777baf56
https://blog.csdn.net/yao_hou/article/details/80559161
通过网上学习,同步在自己电脑完成了ffmpeg的第一个demo。
步骤如下
1.给mac用HomeBrew安装 FFMpeg。
3.Code
代码如下
#import <Foundation/Foundation.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
//ffmpeg程序的第一句,注册库
av_register_all();
printf("avcodec_configuration:\n%s",avcodec_configuration());
AVFormatContext *afc = NULL;
int nRet =avformat_open_input(&afc, "/Users/wangfei/Documents/wangfei/ffmpeg学习/FFTest/FFTest/Q利游戏终季01中文字幕.mp4", 0, 0);
if (nRet < 0) {
printf("can not find video!\n");
} else {
printf("open video success");
int durTime = afc->duration / AV_TIME_BASE;
printf("durTime is \n%d",durTime);
unsigned streamCount = afc->nb_streams;
for (int i = 0 ; i < streamCount; i++) {
AVCodecContext *acc = afc->streams[i]->codec;
if (acc->codec_type == AVMEDIA_TYPE_VIDEO) {
AVCodec *codec = avcodec_find_decoder(acc->codec_id);
if (!codec) {
}
int ret = avcodec_open2(acc, codec, NULL);
if (ret != 0) {
char buf[1024] = {0};
av_strerror(ret, buf, sizeof(buf));
}
}
}
}
if (afc) {
avformat_close_input(&afc);
}
}
return 0;
}