HardwareVideoCodec is an efficient Android audio and video coding library that supports both soft and hard coding. You can easily encode video at any resolution, regardless of camera preview size. It’s all so simple. At present, we have iterated several stable versions, welcome to study and use, if there are bugs or suggestions, welcome to Issue.

A list,

HardwareVideoCodec is a high-performance, easy-to-use Android audio and video coding open source library that supports multiple filters, RTMP live streaming, and soft and hard editing. The performance of hard knitting is good, and there is no problem in measuring 1080p and 30FPS on the middle end machine of Qualcomm 630. Soft editing performance is poor, the same machine, soft editing can only reach 720P, 24FPS. Hard knitting has better performance and soft knitting has better compatibility. You need to select this option based on your service requirements. HardwareVideoCodec has now been iterated to version 1.6.3 with a new beauty filter, better beauty, and a library of 40+ filters. Support RTMP push stream, measured 1080p, 30FPS LAN push stream without performance pressure. Here are the main features:

  1. supportA high performanceRTMP live push stream.
  2. Support without restarting the Camera,Eager to changePicture resolution.
  3. Support includingBeauty filterInside more than 20 filters.
  4. Support videoSoft plaitandHard make.
  5. supportThe recordingThe video is saved on MP4.
  6. useOpenGLImage rendering, less CPU and memory footprint, qualcomm 630 mid-range machineHard makeAnd openRTMPPush current measured only12%CPU usage.

Features to be added

  1. Supports filtering of existing videos

Three, use,

  1. Add the following code to the Project build.gradle.
buildscript {
    ext.kotlin_version = '1.2.30'//Latest kotlin version
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}
Copy the code
  1. Import dependencies and add the following code to build.gradle in the Module.
dependencies {
    implementation 'com. Lmy. Codec: hardwarevideocodec: 1.6.3'
    implementation 'com. Lmy. Codec: RTMP: 1.6.3'// If you want to use RTMP push stream function}Copy the code
  1. Use HardwareVideoCodec in your Activity.
class MainActivity : AppCompatActivity() {
    private lateinit var mRecorder: VideoRecorderImpl
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val mTextureView = TextureView(this)
        setContentView(mTextureView)
        mRecorder = VideoRecorderImpl(this).apply {
            reset()
            setOutputUri("${Environment.getExternalStorageDirectory().absolutePath}/test.mp4") / /setOutputUri("RTMP: / / 192.168.16.125:1935 / live/livestream"// If you want to use RTMP push stream, change the path to RTMP push stream addresssetOutputSize(720, 1280)//Default 720x1280
            setFilter(NormalFilter::class.java)//Default NormalFilter
            setPreviewDisplay(mTextureView)
        }
        mRecorder.prepare()
        //For recording control
        mTextureView.setOnTouchListener { v, event ->
            when (event.action) {
                MotionEvent.ACTION_DOWN -> {
                    if (mRecorder.prepared())
                        mRecorder.start()
                }
                MotionEvent.ACTION_UP -> {
                    if (mRecorder.started())
                        mRecorder.pause()
                }
            }
            true
        }
    }
    override fun onDestroy() {
        super.onDestroy()
        mRecorder.release()
    }
}
Copy the code

Run it, grant the necessary permissions, and if nothing goes wrong, you’ll be able to see the camera. If you have any questions, please leave a comment or ISSUE in the comments section and I will answer them in time.

Open source agreement

2.0 HardwareVideoCodec is the GPL.