SkillAgentSearch skills...

Trinity

android video record editor muxer sdk

Install / Use

/learn @wlanjie/Trinity

README

trinity

If the trinity project is helpful to you, you can use paypal to support the author

https://www.paypal.me/wlanjie

中文文档

icon~

Android Arsenal Download platform License

trinity is an open source shooting and short video processing tool, written in kotlin and c++, which implements most of the popular features of short video editing software.

Apk download

  • Please check actions options ci build result

QQ exchange group

125218305

Contact me

  • email: wlanjie888@gmail.com

git commit specification

Code Specification

System version

Support Android 4.3 And above

Development environment

  • Android Studio 3.5
  • NDK r20
  • kotlin 1.3.41

Open source library used

  • fdk-aac
  • ffmpeg 3.4
  • libx264
  • xlogger
  • mnnkit

Features

<table> <tr> <td rowspan="16">Video shooting<br/> </tr> <tr> <td>Function Description</td> <td>Whether to support</td> </tr> <tr> <td>Multi-session recording</td> <td align="center">√</td> </tr> <tr> <td>Custom duration</td> <td align="center">√</td> </tr> <tr> <td>Custom camera configuration</td> <td align="center">√</td> </tr> <tr> <td>Camera switch</td> <td align="center">√</td> </tr> <tr> <td>flash</td> <td align="center">√</td> </tr> <tr> <td>Focus adjustment</td> <td align="center">√</td> </tr> <tr> <td>Manual focus</td> <td align="center">√</td> </tr> <tr> <td>Mute</td> <td align="center">√</td> </tr> <tr> <td>Beauty</td> <td align="center">x</td> </tr> <tr> <td>Microdermabrasion</td> <td align="center">√</td> </tr> <tr> <td>Custom resolution and bit rate</td> <td align="center">√</td> </tr> <tr> <td>Record background sound</td> <td align="center">√</td> </tr> <tr> <td>Recording speed</td> <td align="center">√</td> </tr> <tr> <td>Hard and soft coding</td> <td align="center">√</td> </tr> <tr> <td rowspan="6">Video editing<br/> </tr> <tr> <td>Multi-segment editing</td> <td align="center">√</td> </tr> <tr> <td>Replace fragment</td> <td align="center">√</td> </tr> <tr> <td>Set clip time</td> <td align="center">√</td> </tr> <tr> <td>Background music</td> <td align="center">√</td> </tr> <tr> <td>Hard decode</td> <td align="center">√</td> </tr> <tr> <td rowspan="14">Special effects<br/> </tr> <tr> <td>Filter</td> <td align="center">√</td> </tr> <tr> <td>Flash white</td> <td align="center">√</td> </tr> <tr> <td>Two split screen</td> <td align="center">√</td> </tr> <tr> <td>Three-point screen</td> <td align="center">√</td> </tr> <tr> <td>Quarter screen</td> <td align="center">√</td> </tr> <tr> <td>Six split screen</td> <td align="center">√</td> </tr> <tr> <td>Nine points screen</td> <td align="center">√</td> </tr> <tr> <td>Blur split screen</td> <td align="center">√</td> </tr> <tr> <td>Gaussian blur</td> <td align="center">√</td> </tr> <tr> <td>Soul out</td> <td align="center">√</td> </tr> <tr> <td>shake</td> <td align="center">√</td> </tr> <tr> <td>glitch</td> <td align="center">√</td> </tr> <tr> <td>70s</td> <td align="center">√</td> </tr> <tr> <td rowspan="6">Face recognition<br/> </tr> <tr> <td>Rose eye markup</td> <td align="center">√</td> </tr> <tr> <td>Princess</td> <td align="center">√</td> </tr> <tr> <td>Sticker makeup</td> <td align="center">√</td> </tr> <tr> <td>Falling pig</td> <td align="center">√</td> </tr> <tr> <td>Cat head</td> <td align="center">√</td> </tr> </table>

Face effect

<img src="roseEye.png" width = "318" height = "665" alt="玫瑰眼妆" align=center />

Special effects debugging

Use xcode to debug special effects in the project, you need to install glfw before use

brew install glfw

Then use xcode to openlibrary/src/main/cpp/opengl.xcodeprojJust
Switch effect call code

image_process.OnAction("param/blurScreen", 0);

Automated test

cd trinity
python trinity.py

Then use

adb devices

Just enter the device name in the terminal

Performance

<img src="memory.png" width = "402" height = "283" alt="性能" align=center />

Use

<font color=red>Note: The permission judgment is not made in the SDK. The caller needs to apply for permission when using it. The time involved in the SDK is milliseconds.</font>

Add jcenter dependency

dependencies {
    implementation 'com.github.wlanjie:trinity:0.2.9.1'
}

Load Libraries in Application class

companion object {
    init {
      System.loadLibrary("trinity")
      System.loadLibrary("c++_shared")
      System.loadLibrary("marsxlog")
    }
  }

Permission requirements

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Recording

Configuration parameter

  • Create a recording preview view
val preview = findViewById<TrinityPreviewView>(R.id.preview)
  • Create a recording interface instance
mRecord = TrinityRecord(preview)
  • Destroy the recording interface instance
mRecord.release()

Callback settings

  • Set video rendering callback
mRecord.setOnRenderListener(this)
  • Set recording progress callback
mRecord.setOnRecordingListener(this)
  • Set camera callback
mRecord.setCameraCallback(this)

Open preview

  • Start preview
mRecord.startPreview()
  • End preview
mRecord.stopPreview()
  • Set preview type
// Set the display type
// Include crop display, the original proportion is displayed in black
mRecord.setFrame(mFrame)

Recording control / management

  • Switch camera
mRecord.switchCamera()
  • Get the current camera
// return the current camera id
val facing = mRecord.getCameraFacing()
  • Switch flash
mRecord.flash(mFlash)
  • Setting up zoom
// Set the focal length zoom, 0-100 100 is the maximum zoom
mRecord.setZoom(0)
  • Set exposure
// Set the camera exposure, 100 is the maximum exposure
mRecord.setExposureCompensation(0)
  • Manual focus
// Set manual focus, parameters are x and y
mRecord.focus(mPointF)
  • Set the angle of the recorded video
/**
 * @param rotation Rotation angle includes 0 90 180 270
 */
mRecord.setRecordRotation(0)
  • Set up silent recording
mRecord.setMute(false)
  • Double speed recording
/**
 * @param speed contains 0.25 0.5 1.0 2.0 4.0 times the speed
 */
mRecord.setSpeed(mSpeed)

Start recording

  • Start recording a video
/**
 * Start recording a video
 * @param path Recorded video save address
 * @param width The width of the recorded video. The SDK will do a 16-times integer operation. The width of the final output video may be inconsistent with the setting.
 * @param height The height of the recorded video. The SDK will do a 16-times integer operation. The width of the final output video may be inconsistent with the setting.
 * @param videoBitRate The bit rate of the video output. If it is set to 2000, it is 2M. The final output and the set may be different.
 * @param frameRate frame rate of video output
 * @param useHardWareEncode whether to use hard coding, if set to true, and hard coding is not supported, it will automatically switch to soft coding
 * @param audioSampleRate audio sample rate
 * @param audioChannel number of audio channels
 * @param audioBitRate audio bit rate
 * @param duration
 * @return Int ErrorCode.SUCCESS is success, others are failures
 * @throws InitRecorderFailException
 */
mRecord.startRecording("/sdcard/a.mp4",
                      720,
                      1280,
                      2000, // 2M bit rate
                      30,
                      false,
                      44100,
                      1, // Mono
                      128, // 128K Rate
                      Int.MAX_VALUE)
  • End recording
mRecord.stopRecording()

Video editing

Initialization

  • Create editor instance
mVideoEditor = TrinityCore.createEditor(this)
  • Set preview screen
val surfaceView = findViewById<SurfaceView>(R.id.surface_view)
mVideoEditor.setSurfaceView(surfaceView)

Import video

  • Add a snippet
val clip = MediaClip(file.absolutePath)
mVideoEditor.insertClip(clip)
  • Add fragments based on subscripts
val clip = Media
View on GitHub
GitHub Stars916
CategoryContent
Updated1d ago
Forks281

Languages

C

Security Score

100/100

Audited on Mar 30, 2026

No findings