ffmpeg获取RTSP视频流信息

飞来科技  发布时间:2019-08-08 09:02:04

本文关键词:ffmpeg 发送rtsp

ffmpeg 发送rtsp_ffmpeg 推送rtsp流_ffmpeg rtsp hls

【示例简介】

【示例截图】

【体系源码】

#include"FFPlayVeido.h"

FFPlayVedio::FFPlayVedio(HWNDhwd)

charsdl_var[64];

sprintf(sdl_var,"SDL_WINDOWID=%d",hwd);//主窗口句柄

putenv(sdl_var);

//初始化

av_register_all();

avformat_network_init();

if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)){

printf("CouldnotinitializeSDL-%s\n",SDL_GetError());

return;

FFPlayVedio::~FFPlayVedio()

voidFFPlayVedio::OnInit(HWNDhwd)

voidFFPlayVedio::GetVedioPlay(char*name)

AVFormatContext *pFormatCtx;

inti,videoindex;

AVCodecContext *pCodecCtx;

AVCodec *pCodec;

charfilepath[]="rtsp://admin:123456@192.168.1.252:554/mpeg4cif";

pFormatCtx=avformat_alloc_context();

ffmpeg 推送rtsp流_ffmpeg 发送rtsp_ffmpeg rtsp hls

if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=){

printf("Couldn'topeninputstream.(无法打开输入流)\n");

return;

if(av_find_stream_info(pFormatCtx)<)

printf("Couldn'tfindstreaminformation.(无法获取流信息)\n");

return;

videoindex=-1;

for(i=;i<pFormatCtx->nb_streams;i )

if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)

videoindex=i;

break;

if(videoindex==-1)

printf("Didn'tfindavideostream.(没有找到视频流)\n");

return;

pCodecCtx=pFormatCtx->streams[videoindex]->codec;

pCodec=avcodec_find_decoder(pCodecCtx->codec_id);

if(pCodec==NULL)

printf("Codecnotfound.(没有找到解码器)\n");

return;

if(avcodec_open2(pCodecCtx,pCodec,NULL)<)

printf("Couldnotopencodec.(无法打开)\n");

return;

AVFrame *pFrame,*pFrameYUV;

ffmpeg 发送rtsp_ffmpeg 推送rtsp流_ffmpeg rtsp hls

pFrame=avcodec_alloc_frame();

pFrameYUV=avcodec_alloc_frame();

uint8_t*out_buffer=(uint8_t*)av_malloc(avpicture_get_size(PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height));

avpicture_fill((AVPicture*)pFrameYUV,out_buffer,PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height);

//SDL---------------------------

intscreen_w=,screen_h=;

//SDL2.0Supportformultiplewindows

SDL_Window*screen;

screen_w=pCodecCtx->width;

screen_h=pCodecCtx->height;

screen=SDL_CreateWindow("Simplestffmpegplayer'sWindow",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,

screen_w,screen_h,

SDL_WINDOW_OPENGL);

if(!screen){

printf("SDL:couldnotcreatewindow-exiting:%s\n",SDL_GetError());

return;

SDL_Renderer*sdlRenderer=SDL_CreateRenderer(screen,-1,);

//IYUV:Y U V(3planes)

//YV12:Y V U(3planes)

SDL_Texture*sdlTexture=SDL_CreateTexture(sdlRenderer,SDL_PIXELFORMAT_IYUV,SDL_TEXTUREACCESS_STREAMING,pCodecCtx->width,pCodecCtx->height);

SDL_RectsdlRect;

sdlRect.x=;

sdlRect.y=;

ffmpeg 推送rtsp流_ffmpeg rtsp hls_ffmpeg 发送rtsp

sdlRect.w=screen_w;

sdlRect.h=screen_h;

//SDLEnd----------------------

intret,got_picture;

AVPacket*packet=(AVPacket*)av_malloc(sizeof(AVPacket));

//OutputInfo-----------------------------

printf("FileInformation(文档资料)---------------------\n");

av_dump_format(pFormatCtx,,filepath,);

printf("-------------------------------------------------\n");

#ifOUTPUT_YUV420P

FILE*fp_yuv=fopen("output.yuv","wb ");

#endif

structSwsContext*img_convert_ctx;

img_convert_ctx=sws_getContext(pCodecCtx->width,pCodecCtx->height,pCodecCtx->pix_fmtffmpeg 发送rtsp,pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P,SWS_BICUBIC,NULL,NULL,NULL);

//------------------------------

while(av_read_frame(pFormatCtx,packet)>=)

if(packet->stream_index==videoindex)

ret=avcodec_decode_video2(pCodecCtx,pFrame,&got_picture,packet);

if(ret<)

printf("DecodeError.(解码错误)\n");

return;

if(got_picture)

sws_scale(img_convert_ctx,(constuint8_t*const*)pFrame->data,pFrame->linesize,,pCodecCtx->height,pFrameYUV->data,pFrameYUV->linesize);

ffmpeg 推送rtsp流_ffmpeg rtsp hls_ffmpeg 发送rtsp

#ifOUTPUT_YUV420P

inty_size=pCodecCtx->width*pCodecCtx->height;

fwrite(pFrameYUV->data[],1ffmpeg 发送rtsp,y_size,fp_yuv);//Y

fwrite(pFrameYUV->data[1],1,y_size/4,fp_yuv);//U

fwrite(pFrameYUV->data[2],1,y_size/4,fp_yuv);//V

#endif

//SDL---------------------------

SDL_UpdateTexture(sdlTexture,&sdlRect,pFrameYUV->data[],pFrameYUV->linesize[]);

SDL_RenderClear(sdlRenderer);

SDL_RenderCopy(sdlRenderer,sdlTexture,&sdlRect,&sdlRect);

SDL_RenderPresent(sdlRenderer);

//SDLEnd-----------------------

//Delay40ms

SDL_Delay(40);

av_free_packet(packet);

sws_freeContext(img_convert_ctx);

#ifOUTPUT_YUV420P

fclose(fp_yuv);

#endif

SDL_Quit();

av_free(out_buffer);

av_free(pFrameYUV);

avcodec_close(pCodecCtx);

avformat_close_input(&pFormatCtx);

return;

voidFFPlayVedio::StopVedio()

本文来自互联网,由机器人自动采编,文章内容不代表本站观点,请读者自行辨别信息真伪,如有发现不适内容,请及时联系站长处理。

    相关阅读
    时时彩平台