Giter Site home page Giter Site logo

zhangbi18 / ffmpegcommand Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anjoiner/ffmpegcommand

0.0 0.0 0.0 61.78 MB

FFmpegCommand适用于Android的FFmpeg命令库,实现了对音视频相关的处理,能够快速的处理音视频,大概功能包括:音视频剪切,音视频转码,音视频解码原始数据,音视频编码,视频转图片或gif,视频添加水印,多画面拼接,音频混音,视频亮度和对比度,音频淡入和淡出效果等

Home Page: https://readdown.com

License: Apache License 2.0

Java 100.00%

ffmpegcommand's Introduction

FFmpegCommand

前景提要

在我们的开发中,经常会用到音视频相关内容,一般我们都会选择FFmpeg,但是其交叉编译对于我们来说是一件很麻烦的事情.所以这里方便日后使用,集成了关于FFmpeg相关库(mp3lame+libx264+fdk-aac),话不多说,请往下看~~

功能

Download License FFmpeg X264 mp3lame fdk-aac

  • 使用ffmpeg命令行进行音/视频转码
  • 使用ffmpeg命令行进行音/视频剪切
  • 使用ffmpeg命令行进行音/视频拼接
  • 使用ffmpeg命令行进行抽取音/视频
  • 使用ffmpeg命令行进行音视频合成
  • 使用ffmpeg命令行进行视频截图
  • 使用ffmpeg命令行进行视频转系列图片
  • 使用ffmpeg命令行给视频添加水印
  • 使用ffmpeg命令行进行视频转成Gif动图
  • 使用ffmpeg命令行进行图片合成视频
  • 使用ffmpeg命令行进行音频编码
  • 使用ffmpeg命令行进行多画面拼接视频
  • 使用ffmpeg命令行进行视频反序倒播
  • 使用ffmpeg命令行进行视频降噪
  • 使用ffmpeg命令行进行视频抽帧转成图片
  • 使用ffmpeg命令行进行视频叠加成画中画
  • 使用ffmpeg命令行进行音频编/解码PCM
  • 使用ffmpeg命令行进行倍速播放
  • 使用ffmpeg命令行进行视频解码YUV
  • 使用ffmpeg命令行进行视频编码H264
  • 使用ffmpeg命令行进行音频音量控制
  • 使用ffmpeg命令行进行音频混音
  • 使用ffmpeg命令行进行音频淡入、淡出效果
  • 使用ffmpeg命令行进行视频亮度控制
  • 使用ffmpeg命令行进行视频对比度控制
  • 使用ffmpeg命令行进行视频旋转
  • 使用ffmpeg命令进行视频固定宽高缩放

引入

根据最新版本替换下面的1.x.x, 比如: 1.0.8

implementation 'com.coder.command:ffmpeg:1.x.x'

使用

  1. 一般我们使用APP_ABI时只需要armeabi-v7aarm64-v8a就行了,所以只需要在app的bulid.gradle下加入如下代码:
android {
    ...
    defaultConfig {
        ...
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
            moduleName "app"
        }
    }
}
  1. 直接调用FFmpegCommand.runAsync(String[] cmd, ICallBack callback)方法,其中第一个参数由FFmpegUtils工具类提供.
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() {
         Log.d("FFmpegTest", "run: 耗时:" + (System.currentTimeMillis() - startTime));
     }
});

这里只是演示了音频剪切,很多如上述功能请自行查阅FFmpegUtils 如果其中不满足需求,可添加自己的FFmpeg命令.例如:

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() {
         Log.d("FFmpegTest", "run: 耗时:" + (System.currentTimeMillis() - startTime));
     }
})

功能详解

这里会用到对FFmpeg的命令使用, 如果不熟悉的话可以参考FFmpeg入门基础, 包含对FFmpeg参数说明, 以及部分基础功能的实现.

方法 作用 方法 作用
transformAudio 音频转码 transformVideo 视频转码
cutAudio 音频剪切 cutVideo 视频剪切
concatAudio 音频拼接 concatVideo 视频拼接
extractAudio 音频抽取 extractVideo 视频抽取
mixAudioVideo 音视频合成 screenShot 截取视频第一帧
video2Image 视频转图片 video2Gif 视频转gif
decodeAudio 音频解码PCM decode2YUV 视频解码YUV
image2Video 图片转视频 addWaterMark 添加视频水印
encodeAudio 音频编码 yuv2H264 视频编码H264
multiVideo 多画面拼接 reverseVideo 反向播放
videoDoubleDown 视频缩小一倍 videoDouble 视频放大一倍
videoSpeed2 倍速播放 denoiseVideo 视频降噪
audioFadeIn 音频淡入 audioFadeOut 音频淡出
videoBright 修改视频亮度 videoContrast 修改视频对比度
picInPicVideo 画中画 videoScale 视频固定缩放

常见问题

  1. 问: 可不可以不使用arm64-v8a?
    答: 可以,arm64-v8a只是加快了64位ARMv8(AArch64)的速度, 仅仅使用armeabi-v7a在64位上会稍稍慢一点, 不会有很大影响.

  2. 问: 如何编译ffmpeg.so系列文件的?
    答: 可以参考这篇FFmpeg编译4.1.4并移植到Android文章

  3. 问: 为什么在Android10上使用FFmpegCommand会报错?
    答: 检查是否是因为访问了外部文件, 因为Android10变更了申请文件权限处理, 在访问外部文件需特殊处理,如果简单处理的话可以在AndroidManifestapplication标签下加入

    android:requestLegacyExternalStorage="true"
  4. 问: Demo中生成的文件在哪里?
    答: 在/storage/emulated/0/Android/data/com.coder.ffmpegtest/cache/目录下

交流

QQ交流群

License

Copyright 2019 AnJoiner

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

ffmpegcommand's People

Contributors

anjoiner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.