Giter VIP home page Giter VIP logo

videoprocessor's Introduction

VideoProcessor

VideoProcessor使用Android原生的MediaCodec实现视频压缩、剪辑、混音、快慢放及倒流的功能(快慢放及倒流支持音频同步变化),在支持MediaCodec的手机上优于使用FFmpeg的方案

  • 体积小 :编译后的aar只有262K,ffmpeg一个so就7、8M,精简之后也差不多还有一半大小
  • 速度快 :在huaweiP9上压缩(1080P 20s 20000k -> 720p 2000k)
lib 耗时
VideoProcessor 13.3s
ffmpeg 172s
ffmpeg(ultrafast) 74s

Gradle

在根目录下的build.gradle里添加maven仓库

allprojects {
		repositories {
			...
			maven { url 'https://www.jitpack.io' }
		}
	}

添加依赖 要求minSdkVersion 21

	dependencies {
	        implementation 'com.github.yellowcath:VideoProcessor:2.4.2'
	}

Changelog

2.4.2

  • 解决arm64的机器上crash的问题
  • 解决某些情况下进度计算错误的问题

2.4.0

  • 兼容Android Q
  • 去掉对support lib的依赖

使用

基本用法如下

    VideoProcessor.processor(context)
            .input(inputVideoPath)
            .output(outputVideoPath)
            .outWidth(outWidth)
            .outHeight(outHeight)
            .process();

VideoProcessor支持多种参数同时处理,完整参数如下

VideoProcessor.processor(context)
       .input(inputVideoPath) // .input(inputVideoUri)
       .output(outputVideoPath)
       //以下参数全部为可选
       .outWidth(width)
       .outHeight(height)
       .startTimeMs(startTimeMs)//用于剪辑视频
       .endTimeMs(endTimeMs)    //用于剪辑视频
       .speed(speed)            //改变视频速率,用于快慢放
       .changeAudioSpeed(changeAudioSpeed) //改变视频速率时,音频是否同步变化
       .bitrate(bitrate)       //输出视频比特率
       .frameRate(frameRate)   //帧率
       .iFrameInterval(iFrameInterval)  //关键帧距,为0时可输出全关键帧视频(部分机器上需为-1)
       .progressListener(listener)      //可输出视频处理进度
       .process();

用户使用时可自行根据需要调用,例如

    //视频两倍速
    VideoProcessor.processor(context)
            .input(inputVideoPath)
            .output(outputVideoPath)
            .speed(2.0f)
            .process();

此外,其它功能

//视频逆序
VideoProcessor.reverseVideo(context, inputVideoPath, outputVideoPath,reverseAudio,listener);
//混音,支持渐入渐出
VideoProcessor.mixAudioTrack(context, inputVideoPath, aacAudioPath, outputVideoPath, startMs, endMs, videoVolume, audioVolume,fadeInSec, fadeOutSec);

Demo

enter image description here

videoprocessor's People

Contributors

pinguo-huangwei avatar po1xiao avatar yellowcath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

videoprocessor's Issues

项目用的都是Surface模式去编解码吗?

edit,如果用buffer模式会有什么坑吗,我这边遇到Buffer模式编解码,有些问题编码完,视频的YUV数据中UV数据好像有点问题,不知道你有没有遇到这样的问题。

java.lang.IllegalArgumentException

throwing exception when mixing audio file to video , audio file is stored in sdcard. exception is only thworing on some devices.

02-14 12:10:32.269 24952-24952/com.hw.photomovie W/System.err: java.lang.IllegalArgumentException
02-14 12:10:32.269 24952-24952/com.hw.photomovie W/System.err: at android.media.MediaExtractor.readSampleData(Native Method)
02-14 12:10:32.269 24952-24952/com.hw.photomovie W/System.err: at com.hw.videoprocessor.VideoProcessor.mixAudioTrack(VideoProcessor.java:864)
02-14 12:10:32.269 24952-24952/com.hw.photomovie W/System.err: at com.hw.photomovie.sample.DemoPresenter$5.onRecordFinish(DemoPresenter.java:465)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at record.GLMovieRecorder$1$1$1.run(GLMovieRecorder.java:92)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at android.os.Looper.loop(Looper.java:148)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5451)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at java.lang.reflect.Method.invoke(Native Method)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-14 12:10:32.270 24952-24952/com.hw.photomovie W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

[BUG]进度计算有错误

VideoProgressAve.java

public void setEncodeTimeStamp(long timeStampUs) {
        if (mListener == null) {
            return;
        }
        if(mSpeed!=null){
            timeStampUs = (long) (timeStampUs*mSpeed);
        }
        mEncodeProgress = (timeStampUs/1000f - mStartTimeMs)/(mEndTimeMs - mStartTimeMs);
        mEncodeProgress = mEncodeProgress <0?0:mEncodeProgress;
        mEncodeProgress = mEncodeProgress>1?1:mEncodeProgress;
        mListener.onProgress((mEncodeProgress + mAudioProgress) / 2);
        CL.i("mEncodeProgress:"+mEncodeProgress);
    }

timeStampUs是从0开始计算的
mStartTimeMs:377295 | mEndTimeMs:449886 | timeStampUs:43459255

代码修改建议如下

mEncodeProgress = (timeStampUs/1000f)/(mEndTimeMs - mStartTimeMs);

关于视频压缩质量问题

大佬,您好。我用红米手机试了下库里的压缩视频方法。源视频70.05M,压缩后70.07M,耗费时间87s。用FFMPEG压缩后只有18.6M。这个压缩质量有点差啊?

压缩结束回调事件?

请问哪个压缩结束回调事件?

我使用进度来进行判断回调,但是发现进度会多次触发1(即为100%),感觉这个进度有问题。

不同项目中压缩时间大小不一致问题

同一个手机,使用demo或者我新建一个项目后依赖videoprocessor,压缩同一个视频耗时15s左右,但是我使用在正式项目中压缩时长就增加,大概耗费40s,主要是设置参数一样,但是压缩完成后的视频大小差距好几倍,压缩代码都一样

int outWidth = originWidth / 2;
int outHeight = originHeight / 2;
int outbitrate = bitrate / 10;

VideoProcessor.compressVideo(getApplicationContext(), srcPath, destPath, outWidth, outHeight, outbitrate, new VideoProgressListener() {
@OverRide
public void onProgress(float progress) {
//压缩视频进度
LogUtils.e("Compress Video progress percent:" + ((int) (progress * 10000)) / 100.0 + "%");
}
});

Project processing video failed

I am currently getting the following error:
04-19 17:26:04.698 24523-24638/com.hw.videoprocessor E/WVMExtractor: Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
04-19 17:26:07.441 24523-24644/com.hw.videoprocessor I/OMXClient: MuxOMX ctor
04-19 17:26:07.466 24523-24644/com.hw.videoprocessor E/ACodec: [OMX.qcom.video.encoder.avc] storeMetaDataInBuffers (output) failed w/ err -1010
04-19 17:26:07.467 24523-24644/com.hw.videoprocessor W/ACodec: do not know color format 0x7fa30c04 = 2141391876
04-19 17:26:07.468 24523-24644/com.hw.videoprocessor W/ACodec: do not know color format 0x7f000789 = 2130708361
04-19 17:26:07.495 24523-24644/com.hw.videoprocessor I/ACodec: setupAVCEncoderParameters with [profile: Baseline] [level: Level51]
04-19 17:26:07.497 24523-24644/com.hw.videoprocessor E/ACodec: [OMX.qcom.video.encoder.avc] configureCodec returning error -1010
04-19 17:26:07.497 24523-24644/com.hw.videoprocessor E/ACodec: signalError(omxError 0x80001001, internalError -1010)
04-19 17:26:07.498 24523-24643/com.hw.videoprocessor E/MediaCodec: Codec reported err 0xfffffc0e, actionCode 0, while in state 3
04-19 17:26:07.498 24523-24641/com.hw.videoprocessor E/MediaCodec: configure failed with err 0xfffffc0e, resetting...
04-19 17:26:07.506 24523-24644/com.hw.videoprocessor I/OMXClient: MuxOMX ctor
04-19 17:26:07.533 24523-24641/com.hw.videoprocessor E/MediaCodec: android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1884)
at com.hw.videoprocessor.VideoEncodeThread.doEncode(VideoEncodeThread.java:95)
at com.hw.videoprocessor.VideoEncodeThread.run(VideoEncodeThread.java:67)

I am currently testing under the following environment:

OS name: Android
OS version: 7.1.2
Model: Nexus 6P

希望提供arm64-v8a 版本的SO包

你好!大佬,我看了一下你的的库,在armeabi-v7a文件下有提供声音处理库,但是没有提供arm64-v8a版本的so库,希望完善一下,谢谢

关于设置特殊前缀信息的一些疑点

您好,我在看您的项目时,发现关于设置特殊前缀信息这一块有些问题希望能和您探讨一下:

在VideoProcessor.mixAudioTrack方法中您对通过Extrator.getTrackFormat方法获得的MediaFormat对象设置了特殊前缀设置信息,但是在google的官方文档中有如下一句话:

These keys are always included in the track MediaFormat obtained from the MediaExtractor#getTrackFormat. Codec-specific data in the format is automatically submitted to the codec upon start(); you MUST NOT submit this data explicitly.

这说明如果通过Extrator.getTrackFormat方法获取的MediaFormat对象是不需设置前缀信息的,而且在mixAudioTrack方法中注释掉相关设置代码后运行依旧正常,关于这个问题您能说明一下吗,太感谢了 ^_^

如果可以的话您能讲解一下
audioMediaFormat.setByteBuffer("csd-0", csd);
中csd的值为什么这么生成吗,感谢感谢 ^_^

完全不能用啊

选择一个大一点的视频直接就压缩不了了 然后小一点的压了一点就压不了了

出现压缩进度到99%就卡住不动了,也不出现异常

2020-04-14 10:02:33.424 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9474491
2020-04-14 10:02:33.451 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.94883215
2020-04-14 10:02:33.482 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9515984
2020-04-14 10:02:33.512 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9529774
2020-04-14 10:02:33.543 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9557437
2020-04-14 10:02:33.574 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9571263
2020-04-14 10:02:33.606 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9598916
2020-04-14 10:02:33.635 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9612743
2020-04-14 10:02:33.665 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9640397
2020-04-14 10:02:33.696 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9654223
2020-04-14 10:02:33.726 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9681877
2020-04-14 10:02:33.757 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9695703
2020-04-14 10:02:33.789 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9727528
2020-04-14 10:02:33.818 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.974136
2020-04-14 10:02:33.849 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.97690225
2020-04-14 10:02:33.879 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9782853
2020-04-14 10:02:33.911 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.98105156
2020-04-14 10:02:33.940 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.98243475
2020-04-14 10:02:33.971 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.985201
2020-04-14 10:02:34.001 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.98727566
2020-04-14 10:02:34.032 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9889331
2020-04-14 10:02:34.063 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9903163
2020-04-14 10:02:34.093 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.9930825
2020-04-14 10:02:34.124 31838-1147/com.hc_android.hc_css I/wy_activity: VideoProcessor:onProgress0.99446565

Show progress percentage in Audio Mix

Hey,

mixing a 60s recording with 3-4 photos takes usually 35-40s on my mobile device. Is there a possibility to reduce this time? And more importantly, can we have a progress listener just like GLMovieRecorder.startRecord() has OnRecordListener which gives the progress percentage?
This would improve the experience of end user because waiting for long time (with no displayed progress) gives a feel that something has gone wrong.

android.media.MediaCodec$CodecException: start failed

同时压缩文件超过2个时会报错

2020-05-30 18:36:25.405 11258-11585/com.hw.videoprocessor W/System.err: android.media.MediaCodec$CodecException: start failed
2020-05-30 18:36:25.406 11258-11585/com.hw.videoprocessor W/System.err: at android.media.MediaCodec.native_start(Native Method)
2020-05-30 18:36:25.406 11258-11585/com.hw.videoprocessor W/System.err: at android.media.MediaCodec.start(MediaCodec.java:2075)
2020-05-30 18:36:25.406 11258-11585/com.hw.videoprocessor W/System.err: at com.hw.videoprocessor.VideoEncodeThread.doEncode(VideoEncodeThread.java:116)
2020-05-30 18:36:25.406 11258-11585/com.hw.videoprocessor W/System.err: at com.hw.videoprocessor.VideoEncodeThread.run(VideoEncodeThread.java:65)
2020-05-30 18:36:25.410 11258-11588/com.hw.videoprocessor W/System.err: android.media.MediaCodec$CodecException: start failed
2020-05-30 18:36:25.410 11258-11588/com.hw.videoprocessor W/System.err: at android.media.MediaCodec.native_start(Native Method)
2020-05-30 18:36:25.411 11258-11588/com.hw.videoprocessor W/System.err: at android.media.MediaCodec.start(MediaCodec.java:2075)
2020-05-30 18:36:25.411 11258-11588/com.hw.videoprocessor W/System.err: at com.hw.videoprocessor.VideoEncodeThread.doEncode(VideoEncodeThread.java:116)
2020-05-30 18:36:25.411 11258-11588/com.hw.videoprocessor W/System.err: at com.hw.videoprocessor.VideoEncodeThread.run(VideoEncodeThread.java:65)

AndroidQ压缩文件时报错

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.hc_android.hc_css-e2V6zxpyAL14GvCnDlqGxg==/base.apk"],nativeLibraryDirectories=[/data/app/com.hc_android.hc_css-e2V6zxpyAL14GvCnDlqGxg==/lib/x86, /data/app/com.hc_android.hc_css-e2V6zxpyAL14GvCnDlqGxg==/base.apk!/lib/x86, /system/lib, /system/product/lib]]] couldn't find "libsoundtouch.so"

IllegalArgumentException in mixAudio (passing url string)

Hey,

I am getting the following error on execution of code. It seems videoprocessor only supports local audio file path and doesn't support external audio url.

String audioPath = mMusicUri.toString();
VideoProcessor.mixAudioTrack(mRecordShareView.getActivity(), file.getAbsolutePath(), audioPath, mixFile.getAbsolutePath(), null, null, 0,
                                    100, 1f, 1f);
java.lang.IllegalArgumentException
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:71)
        at com.hw.videoprocessor.VideoProcessor.mixAudioTrack(VideoProcessor.java:674)
        at com.demo.photomovie.RecordSharePresenter$3.onRecordFinish(RecordSharePresenter.java:228)

请问是否有旋转视频的功能

请问是否有旋转视频的功能,也就是横向旋转为竖向视频,就是rotate video & re-encoding。
如果没有,我可以试试看,能不能实现这个功能。

压缩后变大了

在使用ffmpeg压缩后的视频,大约100M,使用该项目再进行压缩,保证全部输出关键帧的情况下,视频由100M变成了400M,我的理解再怎么压缩不应该变大才对啊

minSdk < 21的话就集成不了了

minSdk为19,gradle里面implementation失败了,日志如下:

uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [com.github.yellowcath:VideoProcessor:2.3.3] C:\Users\Fgb.gradle\caches\transforms-1\files-1.1\VideoProcessor-2.3.3.aar\31435ecdb022228d8ca0f9a0ca396e39\AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.hw.videoprocessor" to force usage (may lead to runtime failures)

看了下VideoProcessor的gradle发现minSdk是21,有办法兼容下吗

AVC编码规格问题

你好:

原本视频 Format profile : Baseline@L4
压缩后 Format profile : High@L4

最终造成压缩后视频比原本还大,我看在重新编码视频的代码里有配置

boolean supportProfileHigh = VideoUtil.trySetProfileAndLevel(mEncoder, mimeType, outputFormat, MediaCodecInfo.CodecProfileLevel.AVCProfileHigh, MediaCodecInfo.CodecProfileLevel.AVCLevel31 );

请问在手机上需要配置到高级别的规格吗?

关于视频解码并输送到编码器

您好,请问视频解码丢弃不需要的帧后,将保留的帧通过mEncoder.createInputSurface();创建的Surface输入到编码器可以吗?为什么还要增加OpenGL处理?我感觉使用OpenGL很慢,比如我需要裁剪3分钟的视频,需要很长时间,如果将OpenGL处理去掉会不会快很多?

++frameIndex;
                            this.mDecoder.releaseOutputBuffer(outputBufferIndex, doRender);
                            if (doRender) {
                                boolean errorWait = false;

                                try {
                                    this.mOutputSurface.awaitNewImage();
                                } catch (Exception var20) {
                                    errorWait = true;
                                    CL.e(var20.getMessage(), new Object[0]);
                                }

                                if (!errorWait) {
                                    if (videoStartTimeUs == -1L) {
                                        videoStartTimeUs = info.presentationTimeUs;
                                        CL.i("videoStartTime:" + videoStartTimeUs / 1000L, new Object[0]);
                                    }

                                    this.mOutputSurface.drawImage(false);
                                    long presentationTimeNs = (info.presentationTimeUs - videoStartTimeUs) * 1000L;
                                    if (this.mSpeed != null) {
                                        presentationTimeNs = (long)((float)presentationTimeNs / this.mSpeed);
                                    }

                                    CL.i("drawImage,setPresentationTimeMs:" + presentationTimeNs / 1000L / 1000L, new Object[0]);
                                    this.mInputSurface.setPresentationTime(presentationTimeNs);
                                    this.mInputSurface.swapBuffers();
                                    continue label151;
                                }
                            }

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.