Video and audio editor
preface
Sometimes we want to process audio and video, such as video editing, adding subtitles, clipping and other functions. Although there are some good open source projects on Github, if we want to carry out secondary development on this project, for example, I want to get the dynamic library of this project to encode YUV based on OpenH264, At this point, it is possible that the dynamic library does not integrate with the Open enh64 library, so for extensibility, I made a set of universal library, basically contains all the common audio and video processing library, you do not need to compile.
The compiled header files and dynamic libraries are available in the project’s core/ CPP directory (” fully open source “).
❝
Ps: here again recommend my another audio and video processing library AVEditor —-> function is improving, you can first pay attention to 😜.
AVEditor is a short video editing SDK that mimics DouYin audio and video processing. Features include beauty, filter, stickers, special effects, recording, segment recording, rate recording, sound change, soundtrack, RTMP live push stream, picture to video, clip, MP4 / FLV format encapsulation and other functions.
❞
introduce
V4.4 -dev + libx264 + Freetype + fontconfig + fribidi + Openh264 + liBFDK-aac + gnutls + speex + Libwebp + lame +opus + opencore-amr + HTTPS is a fast processing framework for audio and video editing, video editing, multiple video file merging, subtitle, watermarking, and reverse playback. You can also pass in the “FFmpeg” command for processing.
“Let’s take a look at the built-in features:“
“Video clip:“
“Video merge:“
“Video editing:“
How to use
1. Add dependencies
Implementation 'com. Devyk. Ffmpeglib: AVFFmpegCore: 1.0.1'Copy the code
2. Function API introduction
“The callback processing“
public interface ExecuteCallback {
/ * ** Start processing* /
void onStart(Long executionId);
/ * ** If the external passes in the duration of the current operation video, percentage progress is returned, whereas the subtle duration of the operation video is returned * * @param v * / void onProgress(float v); / * ** Processing succeeded* / void onSuccess(long executionId); / * ** Processing failure* / void onFailure(long executionId, String error); / * ** Cancel processing* / void onCancel(long executionId); / * ** ffmpeg execution log* / void onFFmpegExecutionMessage(LogMessage logMessage); } Copy the code
“AVEditor“
-
clip
AVVideo: //start: indicates the start time in seconds //duration: how many seconds to clip fun clip(start: Float, duration: Float) AVEditor: fun exec( epVideo: AVVideo. outputOption: OutputOption. executeCallback: ExecuteCallback) Copy the code
-
rotating
AVVideo: // Rotation: Rotation Angle (90,180,270 degrees only) //isFlip: mirrors or not fun rotation(rotation: Int, isFlip: Boolean) AVEditor: fun exec( epVideo: AVVideo. outputOption: OutputOption. executeCallback: ExecuteCallback) Copy the code
-
tailoring
AVVideo: //width: the width of the crop //height: cut the height //x: start at point x //y: start at y fun crop( width: Float. height: Float. x: Float, y: Float) AVEditor: fun exec( epVideo: AVVideo. outputOption: OutputOption. executeCallback: ExecuteCallback) Copy the code
-
Add text watermark
AVVideo: fun addText(avText: AVText) AVEditor: fun exec( epVideo: AVVideo. outputOption: OutputOption. executeCallback: ExecuteCallback) Copy the code
-
Add image Watermark
AVVideo: fun addDraw(epDraw: AVDraw) AVEditor: fun exec( epVideo: AVVideo. outputOption: OutputOption. executeCallback: ExecuteCallback) Copy the code
-
Video merge
AVEditor: fun merge( epVideos: List<AVVideo>, outputOption: OutputOption. executeCallback: ExecuteCallback) Copy the code
-
Add background music
AVEditor: music( videoin: String, audioin: String, output: String, videoVolume: Float. audioVolume: Float. executeCallback: ExecuteCallback ) Copy the code
-
Audio video separation
AVEditor: fun demuxer( inSource: String, outSource: String. format: Format. executeCallback: ExecuteCallback) Copy the code
-
Video upside down
AVEditor: fun reverse( videoin: String.out: String. vr: Boolean.// Whether the video is played backwards ar: Boolean.// Whether the audio is played backwards executeCallback: ExecuteCallback) Copy the code
-
Video to picture
AVEditor: fun video2pic( videoin: String.// Video input file out: String.// Image output path - directory w: Int, h: Int.// Output the width and height of the image rate: Float.// Number of images generated per second executeCallback: ExecuteCallback) Copy the code
-
Turn video Gif
AVEditor: fun video2Gif( videoin: String. gifOut: String. startDuration: Int. stopDuration: Int. executeCallback: ExecuteCallback ) Copy the code
-
Custom commands
AVEditor: // CMD: FFmpeg //duration: Duration for processing videos, which can be obtained by videouitls.getduration (videoPath) fun execCmd(cmd: String, duration: Long, executeCallback: ExecuteCallback) Copy the code
FFmpeg compilation tips
Sometimes we find some good projects on Github based on FFmpeg development, such as iJkPlayer, RxFFmpeg, etc. We want to do secondary development based on it, because we don’t know how to compile, and we don’t know which nodes need to be enabled to compile FFmpeg. At this point I would like to take the compilation script of some projects, based on which to do a secondary compilation. Generally speaking, some projects do not open source compile scripts for FFmpeg. At this time we can get the open source project static or dynamic library, here I take RxFFmpeg as an example, can see how I get it compiled script.
Clone RxFFmpeg first
git clone https://github.com/microshow/RxFFmpeg.git
Copy the code
2. Associate librxffmPEG-core. so
From the so we know that it should be FFmpeg compiled dynamic library, now we use cmake to associate with the SO
Cmake_minimum_required (VERSION 3.4.1) #JNI path set(FFMpeg_include_PATH ${CMAKE_SOURCE_DIR}) include_directories(${FFMpeg_include_PATH}/include/) add_library(RxFFmpeg SHARED IMPORTED) set_target_properties(RxFFmpeg PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/.. /.. /.. /libs/${CMAKE_ANDROID_ARCH_ABI}/librxffmpeg-core.so) find_library( log-lib log) FILE(GLOB JNI_ALL_C ${JNI_PATH}/*.cpp) add_library( ffmpeg-tools SHARED ${JNI_ALL_C} ) target_link_libraries( ffmpeg-tools RxFFmpeg ${log-lib} )Copy the code
3. Write JNI functions and get compilation scripts
//
// Created by DevYK on 2020-10-02.
//
#include <android/log.h>
extern "C"
{ #include "libavutil/avutil.h" } #include <jni.h> #define AV_TAG "AVLOG" #define LOGE(format, ...) __android_log_print(ANDROID_LOG_ERROR, AV_TAG, format, ##__VA_ARGS__) int JNI_OnLoad(JavaVM *javaVM, void *pVoid) { const char *config = avutil_configuration(); LOGE("FFMPEG VERSION%s \n", av_version_info()); LOGE("FFMPEG configuration %s \n", avutil_configuration()); return JNI_VERSION_1_6; } Copy the code
Run the following command to view information in the memory that the config pointer points to:
Well, we get the compilation information, and then we can improve the compilation of our project based on it. We can compile more functions than it. Just like the introduction at the beginning, I added some C++ libraries commonly used in the market, and basically reached the omni-purpose.
conclusion
Project address: AVFFmpegLib
I will not introduce how to compile here, but if you are interested, you can look at the Mobile-FFMPEG project, which is also based on the secondary packaging development here.
reference
- EpMedia
- FFmpeg Common command
- mobile-ffmpeg
- Android audio and video editing experience summary and open source project sharing