• iOS使用ffmpeg播放rstp实时监控视频数据流


    一、编译针对iOS平台的ffmpeg库(kxmovie)
    最近有一个项目。须要播放各种格式的音频、视频以及网络摄像头实时监控的视频流数据,经过多种折腾之后,最后选择了kxmovie,kxmovie项目已经整合了ffmpeg和简单的播放器,详细能够參考kxmovie主页:https://github.com/kolyvan/kxmovie 
    编译kxmovie非常easy,已经支持iOS 6.1 和 armv7s,一次成功。编译过程没出现什么问题:
    git clone git://github.com/kolyvan/kxmovie.git
    cd kxmovie
    git submodule update --init 
    rake
    二、使用kxmovie
    1.kxmovie/output目录下文件加入到project
    2.加入框架:MediaPlayer, CoreAudio, AudioToolbox, Accelerate, QuartzCore, OpenGLES and libz.dylib,libiconv.dylib
    3.加入lib库:libkxmovie.a, libavcodec.a, libavformat.a, libavutil.a, libswscale.a, libswresample.a
    4.播放视频:
    ViewController *vc;
        vc = [KxMovieViewController movieViewControllerWithContentPath:path parameters:nil];
        [self presentViewController:vc animated:YES completion:nil]; 
    5.详细使用參考demoproject:KxMovieExample
    三、碰到的问题
    播放本地视频和网络视频正常。播放网络摄像头实时监控视频流(h264)的时候出现错误:

    [rtsp @ 0x906cc00] UDP timeout, retrying with TCP

    [rtsp @ 0x906cc00] Nonmatching transport in server reply

    [rtsp @ 0x906cc00] Could not find codec parameters for stream 0 (Video: h264): unspecified size

    Consider increasing the value for the 'analyzeduration' and 'probesize' options

    Couldn't find stream information

    跟踪代码,错误是在avformat_find_stream_info获取流信息失败的时候的时候触发

     

    if(avformat_find_stream_info(pFormatCtx,NULL) < 0) {

        av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information ");

        goto initError;

    }

    经过几天的摸索,终于确定是网络的问题(在模拟器播放一直出错。在3G网络下能播放iOS使用ffmpeg播放rstp实时监控视频数据流)。详细原因预计是rstp视频流。程序默认採用udp传输或者组播,导致在私有网络视频流不能正常传输。
    解决方法。把视频流的传输模式强制成tcp传输:

    ……

    // Open video file

    pFormatCtx = avformat_alloc_context();  

    //有三种传输方式:tcp udp_multicast udp,强制採用tcp传输

    AVDictionary* options = NULL;

    av_dict_set(&options, "rtsp_transport", "tcp", 0);

    if(avformat_open_input(&pFormatCtx, [moviePathcStringUsingEncoding:NSASCIIStringEncoding],                              NULL,&options) != 0) {

        av_log(NULL, AV_LOG_ERROR, "Couldn't open file ");

        goto initError;

    }

    // Retrieve stream information

    if(avformat_find_stream_info(pFormatCtx,NULL) < 0) {

        av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information ");

        goto initError;

        }
    ……
  • 相关阅读:
    Restful 的概念预览
    Bootstrap中alerts的用法
    Bootstrap HTML编码规范总结
    Bootstrap中img-circle glyphicon及js引入加载更快的存放位置
    PI数据库
    memcached
    Bootstrap中样式Jumbotron,row, table的实例应用
    js事件监听
    jquery显示隐藏操作
    HDU4521+线段树+dp
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5280745.html
Copyright © 2020-2023  润新知