Skip to content

ijkplayer 直播模式优化,http-flv的格式,优化首帧,延时等

License

GPL-2.0 and 2 other licenses found

Licenses found

GPL-2.0
COPYING.GPLv2
GPL-3.0
COPYING.GPLv3
LGPL-3.0
COPYING.LGPLv3
Notifications You must be signed in to change notification settings

thebestzdp/ijkplayer-live-http-flv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ijkplayer

初步优化的方法(效果较弱)在live_mode分支
精简优化方法(有效)在live_mode_simple分支

##直播优化

针对HTTP-FLV方式的直播流优化

1 首帧优化

预设值解析格式为flv,预设值解码器相关参数,使用新的简化读流函数替换avformat_find_stream_info

方法:设置iformat为flv,使用live_find_stream_info代替avformat_find_stream_info 来快速设置metadata

播放首帧中,首帧读取前关闭缓冲,不进行读取prepare等待,首帧不进行音画同步等待,最大程度加快首帧显示。

方法:设置start_on_prepared,同时在视频渲染线程ffplay_video_thread中强制显示刷新首帧

添加DNS地址预解析方法。(没有实现)

2 流畅率

首帧前不设置缓冲,首帧后开启,设置最大缓冲时长为1s。 抖动缓冲(取消了)

3 延时

为保障直播实时性,添加的丢帧方法,该方法在读取线程(read_thread)中作丢帧检测和控制。

1)从packets队列中丢帧。

2)只丢音频帧以保证丢帧不会导致花屏。

3)每个单位时间内丢少量的帧,以保证播放不会出现卡顿。

4)丢帧控制的循环是一个GOP周期(视频的关键帧间隔时间),用GOP值而不用精准定时器,减少运算开销。

5)仅仅在播放中进行丢帧,缓冲或暂停中是不进行丢帧的。

动态丢帧界限控制:丢帧检测时长界限是动态变化的,使用单位时间内pts差变动作为丢帧时限变动的依据。通过计算比较时间间隔和进入帧队列中的音频数据的pts间隔来判定丢帧检测时长界限。

4 断流重启

直播流流时长(duration)参数一直为0,因此当出现读帧出错或是断网等断流情况,直播流会直接终止播放,需要断流重启方法。

断流重启方法会重新读取流数据的metadata,并重启设置解码器参数,然后开始重启播放流程。

5 重新发现音视频流

直播中出现音频流信息缺失的情况,或是断流重启中需要重新启动音视频流。需要进行重新发现音视频流过程。

Platform Build Status
Android Build Status
iOS Build Status

Video player based on ffplay

Download

  • Android:
  • Gradle
# required
allprojects {
    repositories {
        jcenter()
    }
}

dependencies {
    # required, enough for most devices.
    compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
    compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'

    # Other ABIs: optional
    compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8'
    compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
    compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8'
    compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'

    # ExoPlayer as IMediaPlayer: optional, experimental
    compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8'
}
  • iOS
  • in coming...

My Build Environment

Latest Changes

Features

  • Common
  • remove rarely used ffmpeg components to reduce binary size config/module-lite.sh
  • workaround for some buggy online video.
  • Android
  • platform: API 9~23
  • cpu: ARMv7a, ARM64v8a, x86 (ARMv5 is not tested on real devices)
  • api: MediaPlayer-like
  • video-output: NativeWindow, OpenGL ES 2.0
  • audio-output: AudioTrack, OpenSL ES
  • hw-decoder: MediaCodec (API 16+, Android 4.1+)
  • alternative-backend: android.media.MediaPlayer, ExoPlayer
  • iOS
  • platform: iOS 7.0~10.2.x
  • cpu: armv7, arm64, i386, x86_64, (armv7s is obselete)
  • api: MediaPlayer.framework-like
  • video-output: OpenGL ES 2.0
  • audio-output: AudioQueue, AudioUnit
  • hw-decoder: VideoToolbox (iOS 8+)
  • alternative-backend: AVFoundation.Framework.AVPlayer, MediaPlayer.Framework.MPMoviePlayerControlelr (obselete since iOS 8)

NOT-ON-PLAN

  • obsolete platforms (Android: API-8 and below; iOS: pre-6.0)
  • obsolete cpu: ARMv5, ARMv6, MIPS (I don't even have these types of devices…)
  • native subtitle render
  • avfilter support

Before Build

# install homebrew, git, yasm
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew install yasm

# add these lines to your ~/.bash_profile or ~/.profile
# export ANDROID_SDK=<your sdk path>
# export ANDROID_NDK=<your ndk path>

# on Cygwin (unmaintained)
# install git, make, yasm
  • If you prefer more codec/format
cd config
rm module.sh
ln -s module-default.sh module.sh
cd android/contrib
# cd ios
sh compile-ffmpeg.sh clean
  • If you prefer less codec/format for smaller binary size (include hevc function)
cd config
rm module.sh
ln -s module-lite-hevc.sh module.sh
cd android/contrib
# cd ios
sh compile-ffmpeg.sh clean
  • If you prefer less codec/format for smaller binary size (by default)
cd config
rm module.sh
ln -s module-lite.sh module.sh
cd android/contrib
# cd ios
sh compile-ffmpeg.sh clean
  • For Ubuntu/Debian users.
# choose [No] to use bash
sudo dpkg-reconfigure dash
  • If you'd like to share your config, pull request is welcome.

Build Android

git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.8.8

./init-android.sh

cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all

cd ..
./compile-ijk.sh all

# Android Studio:
#     Open an existing Android Studio project
#     Select android/ijkplayer/ and import
#
#     define ext block in your root build.gradle
#     ext {
#       compileSdkVersion = 23       // depending on your sdk version
#       buildToolsVersion = "23.0.0" // depending on your build tools version
#
#       targetSdkVersion = 23        // depending on your sdk version
#     }
#
# If you want to enable debugging ijkplayer(native modules) on Android Studio 2.2+: (experimental)
#     sh android/patch-debugging-with-lldb.sh armv7a
#     Install Android Studio 2.2(+)
#     Preference -> Android SDK -> SDK Tools
#     Select (LLDB, NDK, Android SDK Build-tools,Cmake) and install
#     Open an existing Android Studio project
#     Select android/ijkplayer
#     Sync Project with Gradle Files
#     Run -> Edit Configurations -> Debugger -> Symbol Directories
#     Add "ijkplayer-armv7a/.externalNativeBuild/ndkBuild/release/obj/local/armeabi-v7a" to Symbol Directories
#     Run -> Debug 'ijkplayer-example'
#     if you want to reverse patches:
#     sh patch-debugging-with-lldb.sh reverse armv7a
#
# Eclipse: (obselete)
#     File -> New -> Project -> Android Project from Existing Code
#     Select android/ and import all project
#     Import appcompat-v7
#     Import preference-v7
#
# Gradle
#     cd ijkplayer
#     gradle

Build iOS

git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios
cd ijkplayer-ios
git checkout -B latest k0.8.8

./init-ios.sh

cd ios
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all

# Demo
#     open ios/IJKMediaDemo/IJKMediaDemo.xcodeproj with Xcode
# 
# Import into Your own Application
#     Select your project in Xcode.
#     File -> Add Files to ... -> Select ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj
#     Select your Application's target.
#     Build Phases -> Target Dependencies -> Select IJKMediaFramework
#     Build Phases -> Link Binary with Libraries -> Add:
#         IJKMediaFramework.framework
#
#         AudioToolbox.framework
#         AVFoundation.framework
#         CoreGraphics.framework
#         CoreMedia.framework
#         CoreVideo.framework
#         libbz2.tbd
#         libz.tbd
#         MediaPlayer.framework
#         MobileCoreServices.framework
#         OpenGLES.framework
#         QuartzCore.framework
#         UIKit.framework
#         VideoToolbox.framework
#
#         ... (Maybe something else, if you get any link error)
# 

Support (支持)

  • Please do not send e-mail to me. Public technical discussion on github is preferred.
  • 请尽量在 github 上公开讨论技术问题,不要以邮件方式私下询问,恕不一一回复。

License

Copyright (c) 2017 Bilibili
Licensed under LGPLv2.1 or later

ijkplayer required features are based on or derives from projects below:

android/ijkplayer-exo is based on or derives from projects below:

android/example is based on or derives from projects below:

ios/IJKMediaDemo is based on or derives from projects below:

ijkplayer's build scripts are based on or derives from projects below:

Commercial Use

ijkplayer is licensed under LGPLv2.1 or later, so itself is free for commercial use under LGPLv2.1 or later

But ijkplayer is also based on other different projects under various licenses, which I have no idea whether they are compatible to each other or to your product.

IANAL, you should always ask your lawyer for these stuffs before use it in your product.

About

ijkplayer 直播模式优化,http-flv的格式,优化首帧,延时等

Resources

License

GPL-2.0 and 2 other licenses found

Licenses found

GPL-2.0
COPYING.GPLv2
GPL-3.0
COPYING.GPLv3
LGPL-3.0
COPYING.LGPLv3

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 58.0%
  • Objective-C 18.1%
  • Java 17.0%
  • Shell 5.8%
  • Makefile 0.9%
  • C++ 0.2%