├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── videocompress │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── videocompress │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── videocompress │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── silicompressor ├── .gitignore ├── build.gradle ├── libs ├── aspectjrt-1.7.3.jar └── isoparser-1.0.6.jar ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── iceteck │ └── silicompressorr │ └── ApplicationTest.java ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── iceteck │ │ └── silicompressorr │ │ ├── FileUtils.java │ │ ├── SiliCompressor.java │ │ ├── Util.java │ │ ├── VideoCompress.java │ │ └── videocompression │ │ ├── Config.java │ │ ├── InputSurface.java │ │ ├── MP4Builder.java │ │ ├── MediaController.java │ │ ├── Mp4Movie.java │ │ ├── OutputSurface.java │ │ ├── Sample.java │ │ ├── TextureRenderer.java │ │ ├── Track.java │ │ └── VideoController.java └── res │ └── values │ └── strings.xml └── test └── java └── com └── iceteck └── silicompressorr └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VideoCompress 2 | Android视频压缩 3 | 4 | 博客地址:http://blog.csdn.net/qq_36421691/article/details/79113392 5 | 6 | 首先: 视频压缩是硬解的压缩,我最开始接触压缩是FFMpeg压缩,使用的是 https://github.com/chenzhihui28/VideoRecorderAndCompressor ,想尝试的人也可以去看下,但是当我压缩的时候发现,压缩时间很慢,比如压缩1分46秒(253M,ViVO x7 plus)的视频花了2分多钟,具体时间自己可以去测,因为项目需要上传本地视频,本地视频一般很大。。假如是5分钟的视频那么用FFMpeg压缩时间就大于5分钟。。。,而且FFMpeg的命令我真的来不及去玩。。。里面涉及到东西有点多。。 7 | 8 | 然后: 项目又要很快要把这个压缩功能做完。。。我又没做过这个。。简直是一窍不通。。。 然后实在没法只有github上来找。。。。 之后了解到了硬解,十分感谢这篇文章,大家都可以去看下 https://github.com/Tourenathan-G5organisation/SiliCompressor 这篇文章看了之后,经测试 1分46秒的视频压缩只要1分10几秒左右,如果手机好点,还可以更快。。。。 但是这个文章没有progress,这让我很不方便查看,然后我就去浏览Issuses发现了有个人对这个progress进行了修改 https://github.com/fishwjy/VideoCompressor 我就把两篇文章合在一起使用了。。。。。 9 | 10 | 最后: 选择本地视频通过 https://github.com/LuckSiege/PictureSelector 来选择的,大家都可以去看下。。。。。 11 | 12 | 结语: github上的这个Wiki没怎么玩过不知道咋写。。。。。连传图和传gif都不知道咋玩。。。所以效果只有自己去测了, 而且这个项目只是做压缩的一个记录。。。。。如果有其他建议麻烦大家指正。 13 | 14 | # 错误 15 | Error:(56, 1) A problem occurred evaluating project ':silicompressor'. 16 | > Could not read script 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'. 17 |   > Connection timed out: connect 18 | # 解决方法 19 | 在silicompressor/build.gradle删除以下两句话,然后rebulid(原因是没有梯子) 20 | // Place it at the end of the file 21 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 22 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' 23 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.videocompress" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | compile 'com.github.LuckSiege.PictureSelector:picture_library:v2.1.7' 29 | implementation project(':silicompressor') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/videocompress/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.videocompress; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.videocompress", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/videocompress/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.videocompress; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.content.res.Configuration; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import android.os.Bundle; 10 | import android.os.Environment; 11 | import android.util.Log; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.iceteck.silicompressorr.VideoCompress; 18 | import com.luck.picture.lib.PictureSelector; 19 | import com.luck.picture.lib.config.PictureConfig; 20 | import com.luck.picture.lib.config.PictureMimeType; 21 | import com.luck.picture.lib.entity.LocalMedia; 22 | 23 | import java.io.File; 24 | import java.text.SimpleDateFormat; 25 | import java.util.Date; 26 | import java.util.List; 27 | import java.util.Locale; 28 | 29 | public class MainActivity extends Activity implements View.OnClickListener { 30 | private static final String TAG = "MainActivity"; 31 | private Button localButton; 32 | private Button compressButton; 33 | private long startTime, endTime; 34 | private String outputDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath(); 35 | private String inputDir=""; 36 | private TextView inputText; 37 | private TextView outPutText; 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_main); 42 | initView(); 43 | } 44 | 45 | private void initView(){ 46 | localButton=findViewById(R.id.localButton); 47 | compressButton=findViewById(R.id.compressButton); 48 | localButton.setOnClickListener(this); 49 | compressButton.setOnClickListener(this); 50 | inputText=findViewById(R.id.inputText); 51 | outPutText=findViewById(R.id.outPutText); 52 | } 53 | 54 | @Override 55 | public void onClick(View view) { 56 | switch (view.getId()){ 57 | case R.id.localButton: 58 | setPicture(); 59 | break; 60 | case R.id.compressButton: 61 | final String destPath = outputDir + File.separator + "VID_" + new SimpleDateFormat("yyyyMMdd_HHmmss", getLocale()).format(new Date()) + ".mp4"; 62 | outPutText.setText(destPath); 63 | VideoCompress.compressVideoLow(inputDir, destPath, new VideoCompress.CompressListener() { 64 | @Override 65 | public void onStart() { 66 | startTime = System.currentTimeMillis(); 67 | setTime(startTime,"开始时间"); 68 | 69 | } 70 | 71 | @Override 72 | public void onSuccess() { 73 | endTime = System.currentTimeMillis(); 74 | setTime(endTime,"结束时间"); 75 | Log.i(TAG,"压缩后大小 = "+getFileSize(destPath)); 76 | openFile(new File(destPath)); 77 | } 78 | 79 | @Override 80 | public void onFail() { 81 | endTime = System.currentTimeMillis(); 82 | setTime(endTime,"失败时间"); 83 | } 84 | 85 | @Override 86 | public void onProgress(float percent) { 87 | Log.i(TAG,String.valueOf(percent) + "%"); 88 | } 89 | }); 90 | break; 91 | } 92 | } 93 | 94 | private void setPicture(){ 95 | // 进入相册 以下是例子:用不到的api可以不写 96 | PictureSelector.create(MainActivity.this) 97 | .openGallery(PictureMimeType.ofVideo())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio() 98 | .imageSpanCount(4)// 每行显示个数 int 99 | .selectionMode(PictureConfig.SINGLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE 100 | .previewVideo(true)// 是否可预览视频 true or false 101 | .enablePreviewAudio(true) // 是否可播放音频 true or false 102 | .isCamera(false)// 是否显示拍照按钮 true or false 103 | .openClickSound(false)// 是否开启点击声音 true or false 104 | .videoQuality(1)// 视频录制质量 0 or 1 int 105 | .videoMaxSecond(60)// 显示多少秒以内的视频or音频也可适用 int 106 | .videoMinSecond(10)// 显示多少秒以内的视频or音频也可适用 int 107 | .recordVideoSecond(60)//视频秒数录制 默认60s int 108 | .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code 109 | } 110 | 111 | 112 | @Override 113 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 114 | super.onActivityResult(requestCode, resultCode, data); 115 | if (resultCode==RESULT_OK){ 116 | switch (requestCode){ 117 | case PictureConfig.CHOOSE_REQUEST: 118 | List selectList = PictureSelector.obtainMultipleResult(data); 119 | for (int i = 0; i 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 |