在Android中整合FFmpeg
原文連結:ofollow,noindex">https://www.jianshu.com/p/a62b6520e0de
介紹
Android是沒法直接整合的,需要自己下載原始碼去編譯;在網上找了一下,沒找到可以直接用而且沒bug的庫,就自己折騰了一下
FFmpeg具體編譯過程:https://www.jianshu.com/p/81cb36b610f4
整合方法
Step 1. Add the JitPack repository to your build file
//Add it in your root build.gradle at the end of repositories: allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
Step 2. Add the dependency
//Add the dependency dependencies { implementation 'com.github.tyhjh:FFmpeg:-SNAPSHOT' }
使用方法:
//呼叫FFmpeg命令,command為FFmpeg命令,返回值為0,則操作成功 String command; int result = FFmpeg.getsInstance().run(command.split(" "));
圖片轉GIF示例
//本專案提供一個視訊轉GIF示例,其他功能可以通過呼叫FFmpeg命令自己實現 new Thread(new Runnable() { @Override public void run() { String pathFrom = "/mnt/sdcard/av.mp4"; String pathTo = "/mnt/sdcard/av.gif"; Setting setting = new Setting(true, 1080, 1920, 20, 0, 20); Mv2Gif.convert(pathFrom, pathTo, setting); } }).start();
相關文章:Android錄屏+視訊轉Gif實現