使用ijkPLayer播放rtsp协议地址

问题

  • 因为FFmpeg的config文件默认没有开启对rtsp协议的支持,因此致使rtsp的地址一直没法播放

解决方法

  • 来到ijkplayer/config目录下,找到module-lite.sh文件,该文件是编译FFmpeg的配置文件。ios

  • 打开该文件,找到
    export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=rtp"
    修改成如下,就能够打开rtsp协议了
    export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=rtp"web

  • 打开rtsp音视频分离器
    export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=rtsp"bash

  • 执行如下命令,链接配置文件,开始编译
    cd config
    rm module.sh
    ln -s module-lite.sh module.sh
    cd ios
    ./compile-ffmpeg.sh clean
    ./compile-ffmpeg.sh all
    ide

编译完成后,发现rtsp协议已经支持,但仍播放不了,并可看到错误信息
No codec could be found with id 8svg

从新打开module-lite.sh文件,添加如下两行
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-decoder=mjpeg"
export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=mjpeg"oop

从新编译,打包Framework,发现能够正常播放,可是实际播放效果不理想,卡顿严重!优化

优化ijkplayer

  • 添加相应的配置代码,使其达到最佳的播放效果
IJKFFOptions *options = [IJKFFOptions optionsByDefault];

    [options setPlayerOptionIntValue:30  forKey:@"max-fps"];
    [options setPlayerOptionIntValue:1  forKey:@"framedrop"];
    [options setPlayerOptionIntValue:0  forKey:@"start-on-prepared"];
    [options setPlayerOptionIntValue:0  forKey:@"http-detect-range-support"];
    [options setPlayerOptionIntValue:48  forKey:@"skip_loop_filter"];
    [options setPlayerOptionIntValue:0  forKey:@"packet-buffering"];
    [options setPlayerOptionIntValue:2000000 forKey:@"analyzeduration"];
    [options setPlayerOptionIntValue:25  forKey:@"min-frames"];
    [options setPlayerOptionIntValue:1  forKey:@"start-on-prepared"];

    [options setCodecOptionIntValue:8 forKey:@"skip_frame"];

    [options setFormatOptionValue:@"nobuffer" forKey:@"fflags"];
    [options setFormatOptionValue:@"8192" forKey:@"probsize"];
    [options setFormatOptionIntValue:0 forKey:@"auto_convert"];
    [options setFormatOptionIntValue:1 forKey:@"reconnect"];

    [options setPlayerOptionIntValue:1  forKey:@"videotoolbox"];

    // 帧速率(fps) (能够改,确认非标准桢率会致使音画不一样步,因此只能设定为15或者29.97)
    [options setPlayerOptionIntValue:29.97 forKey:@"r"];
    // -vol——设置音量大小,256为标准音量。(要设置成两倍音量时则输入512,依此类推
    [options setPlayerOptionIntValue:512 forKey:@"vol"];

    _player = [[IJKFFMoviePlayerController alloc] initWithContentURL:self.url withOptions:options];