项目作者: wlanjie

项目描述 :
android video record editor muxer sdk
高级语言: C
项目地址: git://github.com/wlanjie/trinity.git
创建时间: 2019-02-26T09:17:11Z
项目社区:https://github.com/wlanjie/trinity

开源协议:Apache License 2.0

下载


trinity

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

  1. 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

  1. 125218305

Contact me

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


































































































































































Video shooting

Function Description Whether to support
Multi-session recording
Custom duration
Custom camera configuration
Camera switch
flash
Focus adjustment
Manual focus
Mute
Beauty x
Microdermabrasion
Custom resolution and bit rate
Record background sound
Recording speed
Hard and soft coding
Video editing

Multi-segment editing
Replace fragment
Set clip time
Background music
Hard decode
Special effects

Filter
Flash white
Two split screen
Three-point screen
Quarter screen
Six split screen
Nine points screen
Blur split screen
Gaussian blur
Soul out
shake
glitch
70s
Face recognition

Rose eye markup
Princess
Sticker makeup
Falling pig
Cat head

Face effect

玫瑰眼妆

Special effects debugging

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

  1. brew install glfw

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

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

Automated test

  • Use uiautomator2 for automatic testing
    Use as follows:
    1. cd trinity
    2. python trinity.py
    Then use
    1. adb devices
    Just enter the device name in the terminal

Performance

性能

Use

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.

Add jcenter dependency

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

Load Libraries in Application class

  1. companion object {
  2. init {
  3. System.loadLibrary("trinity")
  4. System.loadLibrary("c++_shared")
  5. System.loadLibrary("marsxlog")
  6. }
  7. }

Permission requirements

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

Recording

Configuration parameter

  • Create a recording preview view

    1. val preview = findViewById<TrinityPreviewView>(R.id.preview)
  • Create a recording interface instance

    1. mRecord = TrinityRecord(preview)
  • Destroy the recording interface instance

    1. mRecord.release()

Callback settings

  • Set video rendering callback

    1. mRecord.setOnRenderListener(this)
  • Set recording progress callback

    1. mRecord.setOnRecordingListener(this)
  • Set camera callback

    1. mRecord.setCameraCallback(this)

Open preview

  • Start preview

    1. mRecord.startPreview()
  • End preview

    1. mRecord.stopPreview()
  • Set preview type

    1. // Set the display type
    2. // Include crop display, the original proportion is displayed in black
    3. mRecord.setFrame(mFrame)

Recording control / management

  • Switch camera

    1. mRecord.switchCamera()
  • Get the current camera

    1. // return the current camera id
    2. val facing = mRecord.getCameraFacing()
  • Switch flash

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

Start recording

  • Start recording a video

    1. /**
    2. * Start recording a video
    3. * @param path Recorded video save address
    4. * @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.
    5. * @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.
    6. * @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.
    7. * @param frameRate frame rate of video output
    8. * @param useHardWareEncode whether to use hard coding, if set to true, and hard coding is not supported, it will automatically switch to soft coding
    9. * @param audioSampleRate audio sample rate
    10. * @param audioChannel number of audio channels
    11. * @param audioBitRate audio bit rate
    12. * @param duration
    13. * @return Int ErrorCode.SUCCESS is success, others are failures
    14. * @throws InitRecorderFailException
    15. */
    16. mRecord.startRecording("/sdcard/a.mp4",
    17. 720,
    18. 1280,
    19. 2000, // 2M bit rate
    20. 30,
    21. false,
    22. 44100,
    23. 1, // Mono
    24. 128, // 128K Rate
    25. Int.MAX_VALUE)
  • End recording

    1. mRecord.stopRecording()

Video editing

Initialization

  • Create editor instance

    1. mVideoEditor = TrinityCore.createEditor(this)
  • Set preview screen

    1. val surfaceView = findViewById<SurfaceView>(R.id.surface_view)
    2. mVideoEditor.setSurfaceView(surfaceView)

Import video

  • Add a snippet
    1. val clip = MediaClip(file.absolutePath)
    2. mVideoEditor.insertClip(clip)
  • Add fragments based on subscripts
    1. val clip = MediaClip(file.absolutePath)
    2. mVideoEditor.insertClip(0, clip)
  • Delete a clip
    1. /**
    2. * Delete a segment in accordance with the subscript
    3. */
    4. mVideoEditor.removeClip(index)
  • Get the number of fragments
    1. val count = mVideoEditor.getClipsCount()
  • Get a clip based on the subscript
    1. /**
    2. * If the fragment does not exist, returns a null
    3. */
    4. val clip = mVideoEditor.getClip(index)
  • Replace a snippet based on a subscript
    1. mVideoEditor.replaceClip(index, clip)
  • Get all clips
    1. /**
    2. * Returns a collection of all clips
    3. */
    4. val clips = mVideoEditor.getVideoClips()
  • Total time to get all clips
    1. val duration = mVideoEditor.getVideoDuration()
  • Get the progress of the currently playing clip
    1. val current = mVideoEditor.getCurrentPosition()
  • Get start and end time of specified clip
    1. val timeRange = mVideoEditor.getClipTimeRange(index)
  • Find subscripts of clips based on time
    1. val index = mVideoEditor.getClipIndex(time)

    Background music

  • Add background music

    1. /**
    2. * @param config background music json content
    3. * The specific json content is as follows:
    4. * {
    5. * "path": "/sdcard/trinity.mp3",
    6. * "startTime": 0,
    7. * "endTime": 2000
    8. * }
    9. * json parameter explanation:
    10. * path: the local address of the music
    11. * startTime: the start time of this music
    12. * endTime: the end time of this music 2000 means this music only plays for 2 seconds
    13. */
    14. val actionId = mVideoEditor.addMusic(config)
  • Updated background music

    1. /**
    2. * @param config background music json content
    3. * The specific json content is as follows:
    4. * {
    5. * "path": "/sdcard/trinity.mp3",
    6. * "startTime": 2000,
    7. * "endTime": 4000
    8. *}
    9. * json parameter explanation:
    10. * path: the local address of the music
    11. * startTime: the start time of this music
    12. * endTime: the end time of this music 4000 means this music is played for 2 seconds from the start time to the end time
    13. */
    14. val actionId = mVideoEditor.addMusic(config)
  • Remove background music
    1. /**
    2. * Remove background music
    3. * @param actionId must be the actionId returned when adding background music
    4. */
    5. mVideoEditor.deleteMusic(actionId)

Add special effects

  • Add ordinary filters
    1. /**
    2. * Add filters
    3. * For example: the absolute path of content.json is /sdcard/Android/com.trinity.sample/cache/filters/config.json
    4. * The path only needs /sdcard/Android/com.trinity.sample/cache/filters
    5. * If the current path does not contain config.json, the addition fails
    6. * The specific json content is as follows:
    7. * {
    8. * "type": 0,
    9. * "intensity": 1.0,
    10. * "lut": "lut_124 / lut_124.png"
    11. * }
    12. *
    13. * json parameter explanation:
    14. * type: reserved field, currently has no effect
    15. * intensity: filter transparency, no difference between 0.0 and camera acquisition
    16. * lut: the address of the filter color table, must be a local address, and it is a relative path
    17. * Path splicing will be performed inside sdk
    18. * @param configPath filter parent directory of config.json
    19. * @return returns the unique id of the current filter
    20. */
    21. val actionId = mVideoEditor.addFilter(config)
  • Update filters

    1. /**
    2. * Update filters
    3. * @param configPath config.json path, currently addFilter description
    4. * @param startTime filter start time
    5. * @param endTime filter end time
    6. * @param actionId Which filter needs to be updated, must be the actionId returned by addFilter
    7. */
    8. mVideoEditor.updateFilter(config, 0, 2000, actionId)
  • Delete filter

    1. /**
    2. * Delete filter
    3. * @param actionId Which filter needs to be deleted, it must be the actionId returned when addFilter
    4. */
    5. mVideoEditor.deleteFilter (actionId)
  • Add vibrato effect

    1. /**
    2. * Add special effects
    3. * For example: the absolute path of content.json is /sdcard/Android/com.trinity.sample/cache/effects/config.json
    4. * The path only needs /sdcard/Android/com.trinity.sample/cache/effects
    5. * If the current path does not contain config.json, the addition fails
    6. * @param configPath filter parent directory of config.json
    7. * @return returns the unique id of the current effect
    8. */
    9. val actionId = mVideoEditor.addAction(configPath)
  • Updated vibrato effect

    1. /**
    2. * Update specific effects
    3. * @param startTime The start time of the effect
    4. * @param endTime End time of the effect
    5. * @param actionId Which effect needs to be updated, must be the actionId returned by addAction
    6. */
    7. mVideoEditor.updateAction(0, 2000, actionId)
  • Remove vibrato effect

    1. /**
    2. * Delete a special effect
    3. * @param actionId Which effect needs to be deleted, must be the actionId returned by addAction
    4. */
    5. mVideoEditor.deleteAction(actionId)

Start preview

  • Prepare

    1. mVideoEditor.prepare()
  • Play

    1. /**
    2. * @param repeat whether to repeat playback
    3. */
    4. mVideoEditor.play(repeat)
  • time out
    1. mVideoEditor.pause()
  • Resume playback
    1. mVideoEditor.resume()
  • Stop play
    1. mVideoEditor.stop()

Release resources

  1. mVideoEditor.destroy()

Export video

  • Create export instance
    1. val export = TrinityCore.createExport(this)
  • Start export
    1. /**
    2. * Start export
    3. * @param info export object
    4. * @param l export callback, success failed and progress
    5. * @return Int ErrorCode.SUCCESS is sucess, other failed
    6. */
    7. // Create export object, must be insert video out path
    8. val exportVideoInfo = VideoExportInfo("/sdcard/export.mp4")
    9. // use hardware decode
    10. exportVideoInfo.mediaCodecDecode = true
    11. // use hardware encode
    12. exportVideoInfo.mediaCodecEncode = true
    13. // video width
    14. exportVideoInfo.width = 544
    15. // video height
    16. exportVideoInfo.height = 960
    17. // frame rate
    18. exportVideoInfo.frameRate = 25
    19. // video bitrate 2M
    20. exportVideoInfo.videoBitRate = 2000
    21. // sample rate
    22. exportVideoInfo.sampleRate = 44100
    23. // channel
    24. exportVideoInfo.channelCount = 1
    25. // audio bitrate 128K
    26. exportVideoInfo.audioBitRate = 128
    27. export.export(exportVideoInfo, this)
  • Cancel
    1. export.cancel()
  • Freed
    1. export.release()
  1. Copyright 2019 Trinity, Inc.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.