android 视频 渲染,在Android中,如何使用VidEffects的滤镜渲染视频

解决方案:

我发现了这个很棒且易于实现的框架:https : //github.com/MasayukiSuda/Mp4Composer-android

只需在build.gradle中添加其依赖项即可:

dependencies {

// jCenter

implementation 'com.daasuu:Mp4Composer-android:0.1.6'

}

并使用以下代码根据每种效果导出过滤的视频:

renderVideoIntoMp4(myVideoURL, new GlInvertFilter()); // add the Filter you want

void renderVideoIntoMp4(String filePath, GlFilter filter) {

tempVideoPath = getVideoFilePath();

//Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/temp_video.mp4";

new Mp4Composer(filePath, tempVideoPath)

// .rotation(Rotation.ROTATION_270)

//.size(720, 1280)

.fillMode(FillMode.PRESERVE_ASPECT_FIT)

.filter(filter)

.mute(false)

.flipHorizontal(false)

.flipVertical(false)

.listener(new Mp4Composer.Listener() {

@Override

public void onProgress(double progress) {

Log.i(Configurations.TAG, "SAVING PROGRESS: " + progress);

}

@Override

public void onCompleted() {

Log.i(Configurations.TAG, "onCompleted()");

exportMp4ToGallery(getApplicationContext(), tempVideoPath);

Log.i(Configurations.TAG, "SAVED VIDEO PATH: " + tempVideoPath);

File file = new File(tempVideoPath);

file.delete();

}

@Override

public void onCanceled() {

}

@Override

public void onFailed(Exception e) {

Log.i(Configurations.TAG, "onFailed(): " + e.getMessage());

}

})

.start();

}

public static void exportMp4ToGallery(Context context, String filePath) {

final ContentValues values = new ContentValues(2);

values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");

values.put(MediaStore.Video.Media.DATA, filePath);

context.getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,

values);

context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,

Uri.parse("file://" + filePath)));

}

public File getAndroidMoviesFolder() {

return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

}

public String getVideoFilePath() {

return getAndroidMoviesFolder().getAbsolutePath() + "/temp_video.mp4";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
利用Android MediaCodec API 来加工mp4视频, 可实现滤镜、旋转、缩放Sample VideoNo filterGlGlayScaleFilterapplyGlMonochromeFilterapplyGlWatermarkFilterapplyGradle    dependencies {        // jCenter         implementation 'com.daasuu:Mp4Composer-android:0.1.1'     }Usage    new Mp4Composer(srcMp4Path, destMp4Path)             .rotation(Rotation.ROTATION_90)             .size((width) 540, (height) 960)             .fillMode(FillMode.PRESERVE_ASPECT_FIT)             .filter(new GlSepiaFilter())             .listener(new Mp4Composer.Listener() {                 @Override                 public void onProgress(double progress) {                     Log.d(TAG, "onProgress = "   progress);                 }                 @Override                 public void onCompleted() {                     Log.d(TAG, "onCompleted()");                     runOnUiThread(() -> {                         Toast.makeText(context, "codec complete path ="   destPath, Toast.LENGTH_SHORT).show();                     });                 }                 @Override                 public void onCanceled() {                     Log.d(TAG, "onCanceled");                 }                 @Override                 public void onFailed(Exception exception) {                     Log.e(TAG, "onFailed()", exception);                 }             })             .start();Builder MethodmethoddescriptionrotationRotation of the movie, default Rotation.NORMALsizeResolution of the movie, default same resolution of src moviefillModeOptions for scaling the bounds of an movie. PRESERVE_ASPECT_FIT is fit center. PRESERVE_ASPECT_CROP is center crop , default PRESERVE_ASPECT_FITfilterThis filter is OpenGL Shaders to apply effects on video. Custom filters can be created by inheriting GlFilter.java. , default GlFilter(No filter)videoBitrateSet Video Bitrate, default video bitrate is 0.25 * 30 * outputWidth * outputHeight
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值