資源簡(jiǎn)介
最新版本ffmpeg提取任意格式視頻幀并保存
代碼片段和文件信息
#include?“stdafx.h“
#include?
#include?
#include?
extern?“C“{
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
};
//libavformat?用來(lái)處理解析視頻文件并將包含在其中的流分離出來(lái),?而libavcodec?則處理原始音頻和視頻流的解碼
using?namespace?std;
#pragma??comment(lib“avcodec.lib“)
#pragma??comment(lib“avdevice.lib“)
#pragma??comment(lib“avfilter.lib“)
#pragma??comment(lib“avformat.lib“)
#pragma??comment(lib“avutil.lib“)
#pragma??comment(lib“postproc.lib“)
#pragma??comment(lib“swresample.lib“)
#pragma??comment(lib“swscale.lib“)
void?SaveBmp(AVCodecContext?*CodecContex?AVframe?*Picture?int?width?int?heightint?num);
int?main(){
char*?sourceFile?=?“F:\\愛(ài)在春天?TV版?47.flv“;
AVFormatContext?*pInputFormatContext?=?avformat_alloc_context();//NULL;?
AVCodecContext?*pInputCodecContext?=?NULL;?
AVCodec?*pInputCodec?=?NULL;
//注冊(cè)庫(kù)中含有的所有可用的文件格式和編碼器,這樣當(dāng)打開(kāi)一個(gè)文件時(shí),它們才能夠自動(dòng)選擇相應(yīng)的文件格式和編碼器。
av_register_all();
int?ret;
//?打開(kāi)視頻文件
if((ret=avformat_open_input(&pInputFormatContext?sourceFile?NULL?NULL))!=0){
cout<<“?can‘t?open?file?“< ????return?-1;
}
//?取出文件流信息
if(avformat_find_stream_info(pInputFormatContextNULL)<0){?
cout<<“?can‘t?find?suitable?codec?parameters“< return?-1;
}
//用于診斷?//產(chǎn)品中不可用
//dump_format(pInputFormatContext?0?sourceFile?false);
//僅僅處理視頻流
//只簡(jiǎn)單處理我們發(fā)現(xiàn)的第一個(gè)視頻流
//??尋找第一個(gè)視頻流
int?videoIndex?=?-1;
for(int?i=0;?inb_streams;?i++)?{
if(pInputFormatContext->streams[i]->codec->codec_type?==?AVMEDIA_TYPE_VIDEO){
videoIndex?=?i;
break;
}
}?
?if(-1?==?videoIndex){
?cout<<“?can‘t?find?video?stream?!“< ?return?-1;
?}
?//?得到視頻流編碼上下文的指針
?pInputCodecContext?=?pInputFormatContext->streams[videoIndex]->codec;?
?//??尋找視頻流的解碼器
?pInputCodec?=?avcodec_find_decoder(pInputCodecContext->codec_id);??
?if(NULL?==?pInputCodec){
?cout<<“can‘t?decode?“< ?return?-1;
?}
?//?通知解碼器我們能夠處理截?cái)嗟腷it流,bit流幀邊界可以在包中
?//視頻流中的數(shù)據(jù)是被分割放入包中的。因?yàn)槊總€(gè)視頻幀的數(shù)據(jù)的大小是可變的,
?//那么兩幀之間的邊界就不一定剛好是包的邊界。這里,我們告知解碼器我們可以處理bit流。
?if(pInputCodec->capabilities?&?CODEC_CAP_TRUNCATED){
?pInputCodecContext->flags|=CODEC_FLAG_TRUNCATED;
?}
?//打開(kāi)解碼器
?if(avcodec_open2(pInputCodecContext?pInputCodecNULL)?!=?0)?{
?cout<<“decode?error“< ?return?-1;
?}
?int?videoHeight;
?int?videoWidth;
?videoWidth?=?pInputCodecContext->width;
?videoHeight?=?pInputCodecContext->height;?
?AVPacket?InPack;
?int?len?=?0;
?AVframe?Outframe;
?int?nComplete=0;
?//??加入這句話來(lái)糾正某些編碼器產(chǎn)生的幀速錯(cuò)誤
/*?if(pInputCodecContext->frame_rate>1000?&&?pInputCodecContext->frame_rate_base==1)
?pInputCodecContext->frame_r
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-09-08?14:55??FfmpegTest1\
?????目錄???????????0??2013-09-08?14:55??FfmpegTest1\Debug\
?????目錄???????????0??2013-09-08?13:56??FfmpegTest1\FfmpegTest1\
?????目錄???????????0??2013-09-08?09:30??FfmpegTest1\FfmpegTest1\Debug\
?????文件????????2612??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\CL.read.1.tlog
?????文件?????????692??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\CL.write.1.tlog
?????文件??????????55??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\FfmpegTest1.lastbuildstate
?????文件????????1405??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\FfmpegTest1.log
?????文件?????1179648??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\FfmpegTest1.pch
?????文件???????????0??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\FfmpegTest1.unsuccessfulbuild
?????文件????????1486??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\cl.command.1.tlog
?????文件???????11679??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\stdafx.obj
?????文件???????52224??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\vc100.idb
?????文件??????126976??2013-09-08?08:55??FfmpegTest1\FfmpegTest1\Debug\vc100.pdb
?????文件????????7972??2013-09-08?10:15??FfmpegTest1\FfmpegTest1\FfmpegTest1.vcxproj
?????文件????????1334??2013-09-08?10:15??FfmpegTest1\FfmpegTest1\FfmpegTest1.vcxproj.filters
?????文件?????????143??2013-09-06?15:17??FfmpegTest1\FfmpegTest1\FfmpegTest1.vcxproj.user
?????文件????????1743??2013-09-06?15:18??FfmpegTest1\FfmpegTest1\ReadMe.txt
?????文件????17116160??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\avcodec-55.dll
?????文件?????1241600??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\avdevice-55.dll
?????文件?????1988608??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\avfilter-3.dll
?????文件?????5139968??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\avformat-55.dll
?????文件??????357888??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\avutil-52.dll
?????文件??????303104??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\ffmpeg.exe
?????文件????????5828??2013-09-08?14:46??FfmpegTest1\FfmpegTest1\ffmpegTest.cpp
?????文件??????527872??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\ffplay.exe
?????文件??????143360??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\ffprobe.exe
?????文件??????187392??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\postproc-52.dll
?????文件?????????298??2013-09-06?15:18??FfmpegTest1\FfmpegTest1\stdafx.cpp
?????文件?????????320??2013-09-06?15:18??FfmpegTest1\FfmpegTest1\stdafx.h
?????文件??????279040??2013-09-06?12:54??FfmpegTest1\FfmpegTest1\swresample-0.dll
............此處省略94個(gè)文件信息
評(píng)論
共有 條評(píng)論