这是一个由 kotlin 、C++ 编写的 RTMP 推流项目

Overview

AVRtmpPushSDK

欢迎关注 AVRtmpPushSDK 直播开源项目,这是一个由 kotlin 、C++ 编写的项目。整个项目完成了采集、 视音频处理、编码、数据发送前处理、数据发送的功能。整个项目支持 flv 封包,rtmp 上传,当然也向外面提供了封包和上传的相关接口。 整个项目均由个人编写完成,可能某些地方会有一些不足之处,欢迎您提出宝贵的意见和建议。

下载 APK 体验

支持功能

  • 音视频硬件编码
  • 动态码率调整
  • 摄像头参数设置
  • 音频编码参数设置
  • 视频编码参数设置
  • 支持添加图片、文字水印
  • 支持摄像头切换
  • 支持 flv 封包
  • 支持自动对焦
  • 支持 Live 模式下横竖屏动态切换

###要求

Android SDK 版本 18+

如何使用

1、添加远程依赖

implementation 'com.devyk.av.rtmp.library:AVRtmpPushSDK:1.0.0'

2、添加权限

">

  

  

  


  

  

  


  

  


  

  

ps: 在Android 6.0以后很多权限需要动态申请. 如果你想快速使用,可以将项目的targetSdkVersion设置在23一下。

3、预览窗口

">
    <com.devyk.av.rtmp.library.widget.AVLiveView
            android:id="@+id/live"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            live:back="true"
            live:fps="25"
            live:sampleRate="44100"
            live:preview_height="1280"
            live:preview_width="720"
            live:videoMaxRate="300"
            live:videoMinRate="200"
    />

4、参数配置

4.1、XML 配置

是否后置摄像头优先 -> live:back

预览编码的帧率 -> live:fps

音频采样率 -> live:sampleRate

预览宽高 -> live:preview_height/live:preview_width

视频最大码率 -> live:videoMaxRate

视频最低码率 -> live:videoMinRate

4.2、代码配置

4.2.1 、音频采集编码参数设置

//初始化音频参数
var audioConfiguration = AudioConfiguration.createDefault()
live.setAudioConfigure(audioConfiguration)

4.2.2、视频编码参数设置

        var videoConfiguration = VideoConfiguration.Builder()
            .setBps(400, 800)
            .setFps(25)
            .setCodeType(VideoConfiguration.ICODEC.ENCODE)
            .setSize(320, 240)
            .setIfi(5)
            .setMediaCodec(true)
            .build()
        live.setVideoConfigure(videoConfiguration)

4.2.3、camera 预览参数设置

        //初始化 camera 参数
        var cameraConfiguration = CameraConfiguration.Builder()
            .setFacing(CameraConfiguration.Facing.FRONT)
            .setFps(25)
            .setPreview(320, 240)
            .build()
        live.setCameraConfigure(cameraConfiguration)

####5、设置打包器

var mPacker = RtmpPacker()
live.setPacker(mPacker)

6、设置发送器

private var mDataSource = "rtmp://[ip]:[port]/devykLive/live1"

 mSender = RtmpSender()
 mSender.setDataSource(mDataSource)
 live.setSender(mSender)

7、添加水印

    /**
     * OpenGL 物体坐标,对应 Android 屏幕坐标
     *
     * -1.0,1.0                             1.0,1.0
     *  -------------------------------------
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                                   |
     *  |                   这里就是水印坐标   |
     *  |                          |-----    |
     *  |                          |    |    |
     *  |                          ——-—-|    |
     *  --------------------------------------
     * -1.0,1.0                             1.0,-1.0
     * 默认水印坐标地址,对应在屏幕右下角,用户可以自定义坐标
     */
    private var mVertexData = floatArrayOf( 
        0.55f, -0.9f, //第一个点 左下角
        0.9f, -0.9f, //第二个点 右下角
        0.55f, -0.7f, //第三个点 左上角
        0.9f, -0.7f //第四个点  右上角
    )

//设置 Bitmap 水印 第二个参数如果传 null 那么默认在右下角
live.setWatermark(Watermark(BitmapFactory.decodeResource(resources,R.mipmap.live_logo), mVertexData))

//设置文字水印 textSize 设置 20 那么会根据设置的坐标进行拉伸,传入 null 内部自动处理
live.setWatermark(Watermark("随播",Color.WHITE,20,null))

8、开始预览

live.startPreview()

9、连接 rtmp 服务器

mSender?.setOnConnectListener(lis: OnConnectListener)
mSender?.connect()
 
 //rtmp 直播服务器连接回调
 public interface OnConnectListener {
    /**
     * 开始链接
     */
    fun onConnecting()

    /**
     * 连接成功
     */
    fun onConnected()

    /**
     * 推送失败
     */
    fun onFail(message:String)

    /**
     * 关闭
     */
    fun onClose()
}

10、开始直播

//开始进行打包
mPacker.start()
//开始进行直播推流
live.startLive()

11、动态设置码率

 live.setVideoBps(bps:Int)

12、停止直播

//停止音视频采集编解码
live.stopLive()
//关闭 rtmp 服务
mSender?.close()
//关闭打包器
mPacker.stop()

13、横竖屏适配

//1、Activity 页面添加如下配置
   android:configChanges="orientation|keyboardHidden|screenSize"

//2. 实现横竖屏切换监听
    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        live.previewAngle(this)
    }
You might also like...
Youtube Android Clone 🚀an Android Youtube Clone made out of XML and Kotlin
Youtube Android Clone 🚀an Android Youtube Clone made out of XML and Kotlin

Youtube Android Clone 🚀 This app consumes The Youtube Api to fetch and display a list of popular videos, The app uses MVVM design pattern to allow se

Sample HLS Video player in Kotlin with mvvm

HLSVideoPlayer Sample HLS Video player in Kotlin with mvvm Note: mvvm is partially implemented due to time constraint, so here is a scope for improvem

A white noise app developed with Kotlin. It helps to mediate, sleep better, focus, relax and be calm.
A white noise app developed with Kotlin. It helps to mediate, sleep better, focus, relax and be calm.

A white noise app developed with Kotlin. It helps to mediate, sleep better, focus, relax and be calm.

script(s) to build ffmpeg for android, including support for RTMP (and OpenSSL)

android-ffmpeg-with-rtmp This repository contains script(s) to build ffmpeg for android with RTMP (and OpenSSL) support. Instructions Install the Andr

Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Kotlin_practice_problems Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs

Zipline This library streamlines using Kotlin/JS libraries from Kotlin/JVM and Kotlin/Native programs. It makes it possible to do continuous deploymen

Kotlin-oop - Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura.

Projeto React OOP Repositório criado para ser utilizado pelo projeto de Kotlin OOP desenvolvido em Kotlin nas aulas feitas através da plataforma Alura

Kotlin-koans - Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax

kotlin-koans-edu Kotlin Koans are a series of exercises to get you familiar with

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in Kotlin with Jetpack Compose and a backed in Kotlin hosted on AppEngine.

Conferences4Hall Real life Kotlin Multiplatform project with an iOS application developed in Swift with SwiftUI, an Android application developed in K

🚀Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )
🚀Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )

JsonToKotlinClass Hi, Welcome! This is a plugin to generate Kotlin data class from JSON string, in another word, a plugin that converts JSON string to

Android + Kotlin + Github Actions + ktlint + Detekt + Gradle Kotlin DSL + buildSrc = ❤️

kotlin-android-template 🤖 A simple Github template that lets you create an Android/Kotlin project and be up and running in a few seconds. This templa

LifecycleMvp 1.2 0.0 Kotlin  is MVP architecture implementation with Android Architecture Components and Kotlin language features
LifecycleMvp 1.2 0.0 Kotlin is MVP architecture implementation with Android Architecture Components and Kotlin language features

MinSDK 14+ Download Gradle Add to project level build.gradle allprojects { repositories { ... maven { url 'https://jitpack.io' }

Kotlin TodoMVC – full-stack Kotlin application demo

Kotlin full stack TodoMVC This project is an example implementation of the TodoMVC app written in Kotlin. More specifically, it's the Kotlin port of t

Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock
Integration Testing Kotlin Multiplatform Kata for Kotlin Developers. The main goal is to practice integration testing using Ktor and Ktor Client Mock

This kata is a Kotlin multiplatform version of the kata KataTODOApiClientKotlin of Karumi. We are here to practice integration testing using HTTP stub

Small kotlin library for persisting _single instances_ of kotlin data classes
Small kotlin library for persisting _single instances_ of kotlin data classes

PerSista Small library for persisting single instances of kotlin data classes. NB: PerSista uses typeOf() internally which is marked as @ExperimentalS

Annotation processor that generates a kotlin wrapper class for a java file, enabling named parameters for kotlin callers.

Annotation processor that generates a kotlin wrapper class for a java file, enabling named parameters for kotlin callers.

Opinionated Redux-like implementation backed by Kotlin Coroutines and Kotlin Multiplatform Mobile

CoRed CoRed is Redux-like implementation that maintains the benefits of Redux's core idea without the boilerplate. No more action types, action creato

Comments
  • 想要默认打开后置摄像头,设置   live:back=

    想要默认打开后置摄像头,设置 live:back="true"无效,应该怎么改呢?

    用的红米手机

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:live="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ActivityB">

    <com.devyk.av.rtmp.library.widget.AVLiveView
        android:id="@+id/live"
        live:back="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <androidx.appcompat.widget.AppCompatButton
        android:text="開始推流"
        live:layout_constraintTop_toTopOf="parent"
        android:id="@+id/btn_start"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    

    </androidx.constraintlayout.widget.ConstraintLayout>

    opened by roybill 0
  • 想要让后置摄像头向左旋转90度,设置CameraConfiguration参数无效,该怎么解决呢?

    想要让后置摄像头向左旋转90度,设置CameraConfiguration参数无效,该怎么解决呢?

        //初始化 camera 参数
        var cameraConfiguration = CameraConfiguration.Builder()
            .setRotation(45)      //无效
            .setOrientation(CameraConfiguration.Orientation.LANDSCAPE)  //无效
            .setFacing(CameraConfiguration.Facing.BACK) //默认打开后置摄像头
            .setFps(25)
            .setPreview(320, 240)
            .build()
    
        mLive.setCameraConfigure(cameraConfiguration)
    
    opened by roybill 0
Owner
DevYK
1. 要记住人生的道路永远没有捷径,天下也没有白吃的午餐。 2. 时刻保持一颗学习的心。 3. 机会都是留给有准备的人。 4. 自信。 5. 向音视频资深工程师奋斗。
DevYK
A Custom Video Player with Controls in Kotlin

UNT-Video-Player A Custom Video Player with Controls in Kotlin Hello folks, Here is the custom video player built in Kotlin; with SeekBar, fast forwar

ultroNeous Technologies 0 Nov 8, 2021
Music Player - This is a basic music player built with Android Studio and Kotlin

Music Player Made by Jenny Cárdenas This is a basic music player built with Android Studio and Kotlin, it shows two views in the UI, the user can play

Jenny C 3 Oct 28, 2021
Toedoe - A To-do app that made using Kotlin

Toedoe Android Study Jam It is a To-do app that I made using Kotlin in this app

Abhishek Kumar Yadav 0 Jan 7, 2022
Autodownload MP3 API With Kotlin

Autodownload MP3 API Overview This project leverages Spring Boot, Google's YouTube API, and youtube-dl to provide an API to download videos and conver

Julien 1 Jul 1, 2022
Chess Kotlin Tornadofx - 2 player Chess using Forsyth edwards notation (Fen)

Chess_Kotlin_Tornadofx 2 player Chess using Forsyth edwards notation (Fen) , Sta

null 1 Jan 30, 2022
Echo is a lightweight and minimal music player for Android, built with Android Studio and written in Kotlin

Echo - Echo, A light-weight, minimal music player for Android, with shuffle, favorites and audio visualization

Divins Mathew 0 Feb 7, 2022
SpotiFlyer - Kotlin Multiplatform Music Downloader ,supports Spotify, Youtube, Gaana, Jio-Saavn and SoundCloud

SpotiFlyer Kotlin Multiplatform Music Downloader ,supports Spotify, Youtube, Gaa

Gas Com IT 1 Feb 8, 2022
Youtube-dl UI - Youtube-dl ui built with kotlin and jetpack compose

youtube-dl_UI youtube-dl ui built with kotlin and jetpack compose.

null 0 Feb 11, 2022
iOS(iPhone & iPad) and Android Radio/Podcast Streaming Apps built in Kotlin Multiplatform Mobile (KMM) with SwiftUI & Jetpack Compose

iOS(iPhone & iPad) and Android Radio/Podcast Streaming Apps built in Kotlin Multiplatform Mobile (KMM) with SwiftUI & Jetpack Compose

MwaiBanda 1 May 31, 2022
A modern front-end for YouTube built using Kotlin compose

A modern front-end for YouTube built using Kotlin compose, with Material You theming and many more features.

Nick 379 Jan 5, 2023