Android中的视频压缩包含图片压缩工具
原文地址:https://blog.csdn.net/weixin_36495794/article/details/93190679
FFmpeg?壓縮效率低,時間長,使用繁瑣,增大apk體積? ? ? ? ?silicompressor完勝。輕巧占用小壓縮速度快前提看你設(shè)置的壓縮幀率。并且可以壓縮圖片等等。項目地址https://github.com/TangfeiJi/SiliCompressor-master
Gradle引入方法不建議使用會出現(xiàn)apk文件名重名裝不上
1.Gradle
implementation'com.iceteck.silicompressorr:silicompressor:2.2.1'
2.添加相關(guān)權(quán)限(手機得動態(tài)申請權(quán)限)
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
3.使用
使用很簡單,直接調(diào)用相關(guān)方法傳入文件路徑就能獲得壓縮之后新文件的路徑
<1> 視頻壓縮(需要在子線程中使用)
壓縮視頻文件并返回新視頻的文件路徑(參數(shù)傳入原視頻videoPath和壓縮后destinationDirectory存放的文件夾,返回壓縮后圖片絕對路徑)。橫屏視頻的outWidth寬度? ?outHeight高度? ?bitrate比特率(碼率)越高數(shù)據(jù)大? 體積越大一般450000
StringfilePath=SiliCompressor.with(Context).compressVideo(videoPath, destinationDirectory,outWidth,outHeight,bitrate);
StringfilePath=SiliCompressor.with(Context).compressVideo(videoPath, destinationDirectory);默認(rèn)720? 480 450000
<2> 圖片壓縮(需要在子線程中使用)給大家分享幾個壓縮圖片地址吧
https://tinypng.com/??? ?單次壓縮20張? 多的話要會員
http://zhitu.isux.us/? ? ? ?單次壓縮20張? 多的話要會員
https://zh.recompressor.com/?? ? 免費的我認(rèn)為最好用的推薦
壓縮圖像并返回新圖像的文件路徑
StringfilePath=SiliCompressor.with(Context).compress(imagePath, destinationDirectory);
壓縮圖像并在刪除源圖像時返回新圖像的文件路徑
StringfilePath=SiliCompressor.with(Context).compress(imagePath, destinationDirectory,true);
壓縮圖像可繪制并返回新圖像的文件路徑
StringfilePath=SiliCompressor.with(Context).compress(R.drawable.icon);
壓縮圖像并返回新圖像的位圖數(shù)據(jù)
BitmapimageBitmap=SiliCompressor.with(Context).getCompressBitmap(imagePath);
壓縮圖像并在刪除源圖像的同時返回新圖像的位圖數(shù)據(jù)
BitmapimageBitmap=SiliCompressor.with(Context).getCompressBitmap(imagePath,true);
如果有的項目和你這樣引用一致(會出現(xiàn)apk文件名稱相同? 打包后安裝失敗? 也就是provider命名重名了,改名字得module導(dǎo)入修改)以下是module里的AndroidManifest.xml
Module的導(dǎo)入(apk文件名稱相同其實導(dǎo)入后就會取你項目的applicationId 無須設(shè)置能關(guān)聯(lián)你項目)
module地址? ??https://github.com/TangfeiJi/SiliCompressor-master
1.把下載好的項目module通過Import module導(dǎo)入到項目中(注意module的sdk版本小于等于主項目版本)
在項目Gradle中加入implementation project(':silicompressor')2.在工程Gradle中加入
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
3.增加相關(guān)的權(quán)限(手機得動態(tài)申請權(quán)限)
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
4.用法和上述的一樣記住在子線程中使用
https://github.com/TangfeiJi/SiliCompressor-master
https://github.com/Tourenathan-G5organisation/SiliCompressor
?
格式?分辨率?行頻?規(guī)格?
480i?720×480?15.25kHz?數(shù)字標(biāo)清(SDTV)?
480p?720×480?31.5kHz?數(shù)字標(biāo)清(SDTV)?
1080i?1920×1080?33.75kHz?數(shù)字高清(HDTV)?
720p?1280×720?45kHz?數(shù)字高清(HDTV)?
1080p?1920×1080?67.5kHz?全高清(Full?HDTV)?
總結(jié)
以上是生活随笔為你收集整理的Android中的视频压缩包含图片压缩工具的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里技术团队的组件与团队管理的核心技能
- 下一篇: Google Android Senso