live555+ffmpeg实时视频推流

实时视频流通常是由安防设备负责推流,服务器端进行解析和转发,手机app播放视频流。

在开发服务器端和手机app时,为了方便调试码流和解决相关bug,我们在windows平台下利用

ffmpeg获取采集实时视频流,并对视频流进行H264编码后推流到视频流服务器。

分析详细的代码之前,先看运行效果:

下面先看main的代码:

 
int _tmain(int argc, char* argv[])
{
    init_ffmpeg();
 
    CCameraVideo* cVideo = new CCameraVideo(true);
 
    //rtmp://192.168.3.94:1935/live/home    
    int frame_index = 0;
    int64_t start_time = 0;
 
    //SDL----------------------------
    SDL_Window *screen = NULL;
    SDL_Renderer* sdlRenderer=NULL;
    SDL_Texture* sdlTexture = NULL;
    SDL_Thread *video_tid = NULL;
    SDL_Event event;
    unsigned int sdlFlag = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
    if (SDL_Init(sdlFlag)) 
    {
        printf("Could not initialize SDL - %s\n", SDL_GetError());
        return -1;
    }
 
    int screen_w = 1280;
    int screen_h = 780;
    //SDL 2.0 Support for multiple windows
    AVCodecContext* pCodecCtx = cVideo->getInputCodecContext();
    if (pCodecCtx)
    {
        screen_w = pCodecCtx->width / VIDEO_SCALE;
        screen_h = pCodecCtx->height / VIDEO_SCALE;
    }
 
    screen = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, 
        SDL_WINDOWPOS_UNDEFINED, screen_w, screen_h, SDL_WINDOW_OPENGL);
 
    if (screen != NULL) 
    {
        sdlRenderer = SDL_CreateRenderer(screen, -1, 0);
        //IYUV: Y + U + V  (3 planes)
        //YV12: Y + V + U  (3 planes)
        sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,
            screen_w, screen_h);
 
        SDL_SetWindowSize(screen, 1280, 1280.0*(float)screen_h / (float)screen_w);
        SDL_SetWindowPosition(screen, 300, 100);
    }    
 
    SDL_Rect sdlRectS1;
    SDL_Rect rect;
    rect.x = 0;
    rect.y = 0;
    rect.w = screen_w;
    rect.h = screen_h;
    SDL_Rect sdlRectS2;
    SDL_Rect sdlRectD1;
    SDL_Rect sdlRectD2;
    SDL_Texture *myTexture;
 
    thread_exit = 0;
    thread_pause = 0;
    unsigned int threadID = 0;
    HANDLE aT
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值