In our development, we often use audio and video related content, we usually choose FFmpeg, but its cross-compilation is a troublesome thing for us. FFmpegCommand (mp3lame+libx264+ fdK-aac)FFmpegCommand (mp3LAME +libx264+ fdK-aAC)FFmpegCommand

function

Internal encapsulation part of FFmpeg simple command line functions, can be eaten directly ~

  • Use ffmpeg command line for voice/video transcoding
  • Use the FFmpeg command line for sound/video clipping
  • Use ffmpeg command line for voice/video splicing
  • Extract sound/video using ffmpeg command line
  • Use ffmpeg command line for audio and video composition
  • Use the FFmpeg command line to capture video shots
  • Use ffmpeg command line for video to series pictures
  • Use the FFmpeg command line to add a watermark to the video
  • Use ffmpeg command line to convert video to Gif
  • Use the FFmpeg command line for picture composition video
  • Audio encoding using ffMpeg command line
  • Use ffMPEG command line for multi-screen splicing video
  • Use ffmpeg command line to play video in reverse order
  • Video noise reduction using ffMPEG command line
  • Use the FFmpeg command line to extract video frames into pictures
  • Use ffmpeg command line for video overlay into picture-in-picture
  • Audio codec/decode PCM using ffMPEG command line
  • Double speed playback using ffmpeg command line
  • Use ffMPEG command line for video decoding YUV
  • Use ffMPEG command line for video encoding H264
  • Use ffmpeg command line for audio volume control
  • Use ffmpeg command line for audio mixing
  • Use ffmpeg command line for audio fade-in and fade-out
  • Use ffMPEG command line for video brightness control
  • Use ffMPEG command line for video contrast control
  • Use the FFmpeg command line for video rotation
  • Use the ffmpeg command for fixed width and height zooming



————–Demo APK download address —————

The introduction of

implementation 'com.coder.com mand: ffmpeg: 1.0.7'
Copy the code

use

  1. In general we useAPP_ABIWhen you just need toarmeabi-v7aandarm64-v8aSo just add the following code to your app under Bulid. gradle:
android {
    ...
    defaultConfig {
        ...
        ndk {
            abiFilters 'armeabi-v7a'.'arm64-v8a'
            moduleName "app"}}}Copy the code
  1. Direct callFFmpegCommand.runAsync(String[] cmd, ICallBack callback)Method, where the first argument is given byFFmpegUtilsUtility classes are provided.
final long startTime = System.currentTimeMillis();
String input =Environment.getExternalStorageDirectory().getPath() + File.separator +
                        "DCIM" + File.separator + "test.mp3";
String output =Environment.getExternalStorageDirectory().getPath() + File.separator +
                        "DCIM" + File.separator + "output.mp3";

FFmpegCommand.runAsync(FFmpegUtils.cutAudio(input, "00:00:30"."00:00:40",
     output), new CommonCallBack() {
     @Override
     public void onComplete(a) {
         Log.d("FFmpegTest"."Run: time:"+ (System.currentTimeMillis() - startTime)); }});Copy the code

This is just a demo of audio clipping, check out FFmpegUtils and add your own FFmpeg command if it doesn’t meet your needs. Such as:

String cmd = "ffmpeg -y -i %s -vn -acodec copy -ss %s -t %s %s";
String result = String.format(cmd, input, "00:00:30"."00:00:40", output);
FFmpegCommand.runAsync(result.split(""), new CommonCallBack() {
     @Override
     public void onComplete(a) {
         Log.d("FFmpegTest"."Run: time:"+ (System.currentTimeMillis() - startTime)); }})Copy the code

Function details – implementation methods

Here will use the command to use FFmpeg, if not familiar with the FFmpeg can refer to the basic basic, including the FFmpeg parameter description, as well as part of the basic function of the implementation.

methods role methods role
transformAudio Audio transcoding transformVideo Video transcoding
cutAudio Audio clip cutVideo Video clip
concatAudio Audio joining together concatVideo Video stitching
extractAudio Audio extract extractVideo Video sampling
mixAudioVideo Audio video synthesis screenShot Capture the first frame of the video
video2Image Video to picture video2Gif Turn video GIF
decodeAudio Audio decoding PCM decode2YUV Video decoding YUV
image2Video Picture to video addWaterMark Adding a Video Watermark
encodeAudio Audio coding yuv2H264 Video encoding H264
multiVideo Multiscreen splicing reverseVideo Reverse playback
videoDoubleDown The video is doubled in size videoDouble Double the size of the video
videoSpeed2 Times the speed of playback denoiseVideo Video noise reduction
audioFadeIn Audio fade in audioFadeOut Audio out
videoBright Modify video brightness videoContrast Modify video Contrast
picInPicVideo Picture in picture videoScale Video fixed zoom

Q&A

  1. Q: Is it possible not to use ARM64-V8A? A: Yes, arm64-V8A just speeds up the 64-bit ARMv8(AArch64), just using Armeabi-V7A will be slightly slower in 64-bit and won’t have a big impact.

  2. Q: how to compile ffmpeg.so series files? A: Check out this article on FFmpeg compiling 4.1.4 and porting it to Android

  3. Q: Why do I get an error using FFmpegCommand on Android10? A: Check whether it is because of access to external files, because Android10 has changed the application file permission processing, the access to external files needs special processing, if simple processing can be added under the Application tag of AndroidManifest

    android:requestLegacyExternalStorage="true"
    Copy the code
  4. Q: Where are the files generated in the Demo? A: in/storage/emulated / 0 / Android/data/com. The coder. Ffmpegtest/cache directory