資源簡介
FFmpeg和SDL,讀內存中的視頻流,進行縮放和播放,VC2010下
代碼片段和文件信息
#include?“include\sdl2\SDL.h“
extern?“C“
{
#include?“include\libavformat\avformat.h“
#include?“include\libswscale\swscale.h“
};
FILE?*fp?=?NULL;
int?read_buffer(void?*opaqueuint8_t?*bufint?buf_size)
{
if(!feof(fp))
{
int?true_size?=?fread(buf1buf_sizefp);
return?true_size;
}
else
return?-1;
}
int?Resolutionchange(AVCodecContext?*pCodecCtxAVframe?*pframeAVframe?*pNewframeint?pNewWidthint?pNewHeight)
{
pNewframe->linesize[0]?=?pNewWidth;
pNewframe->linesize[1]?=?pNewWidth/2;
pNewframe->linesize[2]?=?pNewWidth/2;
struct?SwsContext?*pSwsCtx?=?NULL;
pSwsCtx?=?sws_getContext(pCodecCtx->widthpCodecCtx->heightPIX_FMT_YUV420PpNewWidthpNewHeightPIX_FMT_YUV420PSWS_SINCNULLNULLNULL);
if(pSwsCtx?==?NULL)
return?-1;
sws_scale(pSwsCtxpframe->datapframe->linesize0pCodecCtx->heightpNewframe->datapNewframe->linesize);
sws_freeContext(pSwsCtx);
return?0;
}
int?main(int?argcchar?**argv)
{
av_register_all();
avformat_network_init();
AVFormatContext?*pFormatCtx?=?NULL;
pFormatCtx?=?avformat_alloc_context();
char?filepath[]=“test.ts“;
fp?=?fopen(filepath“rb+“);
if(fp?==?NULL)
return?-1;
unsigned?char?*aviobuffer?=?(unsigned?char?*)av_malloc(32768);//32K
AVIOContext?*avio?=?avio_alloc_context(aviobuffer327680NULLread_bufferNULLNULL);
pFormatCtx->pb?=?avio;
if(avformat_open_input(&pFormatCtxNULLNULLNULL)!=?0)
return?-2;
if(avformat_find_stream_info(pFormatCtxNULL)?0)
return?-3;
int?videoindex?=?-1;
for(int?i=0;inb_streams;i++)
{
if(pFormatCtx->streams[i]->codec->codec_type?==?AVMEDIA_TYPE_VIDEO)
{
videoindex=i;
break;
}
}
if(videoindex?==?-1)
return?-4;
AVCodecContext?*pCodecCtx;
pCodecCtx?=?pFormatCtx->streams[videoindex]->codec;
AVCodec?*pCodec;
pCodec?=?avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
return?-5;
if(avcodec_open2(pCodecCtx?pCodecNULL)?0)
return?-6;
AVframe?*pframe*pNewframe;
pframe?=?av_frame_alloc();
pNewframe?=?av_frame_alloc();
int?PictureSize?=?avpicture_get_size(PIX_FMT_YUV420PpCodecCtx->widthpCodecCtx->height);
uint8_t?*buffer?=?(uint8_t?*)av_malloc(PictureSize*sizeof(uint8_t));
avpicture_fill((AVPicture?*)pNewframebufferPIX_FMT_YUV420PpCodecCtx->widthpCodecCtx->height);
if(SDL_Init(SDL_INIT_VIDEO?|?SDL_INIT_AUDIO?|?SDL_INIT_TIMER))
return?-7;
SDL_Window?*window?=?nullptr;
window?=?SDL_CreateWindow(“MyPlayer“SDL_WINDOWPOS_UNDEFINEDSDL_WINDOWPOS_UNDEFINEDpCodecCtx->widthpCodecCtx->heightSDL_WINDOW_OPENGL);
if(!window)
return?-7;
SDL_Renderer?*renderer?=?nullptr;
renderer?=?SDL_CreateRenderer(window-10);
if(renderer?==?nullptr)
return?-8;
SDL_Texture?*texture?=?nullptr;
texture?=?SDL_CreateTexture(rendererSDL_PIXELFORMAT_YV12SDL_TEXTUREACCESS_STREAMINGpCodecCtx->widthpCodecCtx->height);
????SDL_Rect?rect;
SDL_Event?event;
AVPacket?*packet=(AVPacket?*)malloc(sizeof(AVPacket));
av_new_pac
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-06-12?17:36??Debug\
?????文件???????33792??2015-06-12?17:53??Debug\FFmpeg_10.exe
?????文件??????415848??2015-06-12?17:53??Debug\FFmpeg_10.ilk
?????文件??????609280??2015-06-12?17:53??Debug\FFmpeg_10.pdb
?????目錄???????????0??2015-06-12?17:12??FFmpeg_10\
?????目錄???????????0??2015-06-12?17:53??FFmpeg_10\Debug\
?????文件???????13264??2015-06-12?17:53??FFmpeg_10\Debug\CL.read.1.tlog
?????文件?????????290??2015-06-12?17:53??FFmpeg_10\Debug\CL.write.1.tlog
?????文件?????????658??2015-06-12?17:12??FFmpeg_10\Debug\FFmpeg_10.exe.em
?????文件?????????724??2015-06-12?17:12??FFmpeg_10\Debug\FFmpeg_10.exe.em
?????文件?????????616??2015-06-12?17:53??FFmpeg_10\Debug\FFmpeg_10.exe.intermediate.manifest
?????文件??????????47??2015-06-12?17:53??FFmpeg_10\Debug\FFmpeg_10.lastbuildstate
?????文件????????2763??2015-06-12?17:53??FFmpeg_10\Debug\FFmpeg_10.log
?????文件???????29453??2015-06-12?17:53??FFmpeg_10\Debug\FFmpeg_10.obj
?????文件?????????208??2015-06-12?17:12??FFmpeg_10\Debug\FFmpeg_10_manifest.rc
?????文件?????????646??2015-06-12?17:53??FFmpeg_10\Debug\cl.command.1.tlog
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件???????????2??2015-06-12?17:53??FFmpeg_10\Debug\li
?????文件????????1978??2015-06-12?17:53??FFmpeg_10\Debug\li
............此處省略213個文件信息
- 上一篇:Win7開機動畫275890
- 下一篇:全國行政省、市、縣區、鄉村GE地標地名
評論
共有 條評論