如何解决裁剪具有不同纵横比的视频文件
我试图让我的用户可以在将视频上传到我的壁炉数据库之前以不同的宽高比裁剪他们的视频。我正在使用 Android-VideoCropView 为我的用户显示视频编辑器布局,并使用 SimpleVideoEditor 来裁剪视频。但是,当我尝试将两个库合并在一起时,我很难从 VideoCropView 获取信息,然后使用 SimpleVideoEditor 裁剪文件,这是 the result I should have,这是 the result I got。所以我的问题是我做错了什么,我该如何解决?
这是我的代码
Uri fileUri = Uri.fromFile(new File(stringvideofile));
String destPath = getVideoFilePath();
//1.
float baseWidthPx = mVideoCropView.getVideoWidth(); // should be +// todo: match every views one side,then set that side. need an if-else
float baseHeightPx = mVideoCropView.getVideoHeight() ;
// 2. get the center of crop quad
float cropQuadCenterX,cropQuadCenterY;
cropQuadCenterX = mVideoCropView.getRealPositionX() + baseWidthPx/2;
cropQuadCenterY = mVideoCropView.getRealPositionY() + baseHeightPx/2;
// 3. get video frame quad center
float videoQuadCenterX,videoQuadCenterY;
videoQuadCenterX = mVideoCropView.getWidth()/2;
videoQuadCenterY = mVideoCropView.getHeight()/2;
float dx = videoQuadCenterX - cropQuadCenterX;
float dy = videoQuadCenterY - cropQuadCenterY;
dx = 2*dx/baseWidthPx; // idk why multiply with 2 :/ divide with baseSizePx to get ratio,that makes sense but why 2???
dy = 2*dy/baseHeightPx;
float translateX = dx,translateY = dy;
FillModeCustomItem fillModeCustomItem = new FillModeCustomItem(
mVideoCropView.getScaleX(),mVideoCropView.getRotate(),translateX,translateY,mVideoCropView.getVideoWidth(),mVideoCropView.getVideoHeight()
);
GlFilterGroup glFilterGroup;
if(composerGlFilter == null) {
composerGlFilter = new GlFilter();
}
glFilterGroup = new GlFilterGroup(new GlFilter()); // the default filter
Log.e(TAG,"currentGlFilter is null");
final Logger mylogger = new Logger() {
@Override
public void debug(String tag,String message) {
Log.d(tag,message);
}
@Override
public void error(String tag,String message,Throwable error) {
Log.e(tag,"Message: "+message + ". Error: "+error.getLocalizedMessage());
}
@Override
public void warning(String tag,String message) {
Log.w(tag,message);
}
};
mp4Composer = null;
mp4Composer = new Mp4Composer(fileUri,destPath,CropVideoActivity.this,mylogger);
mp4Composer
.size(mVideoCropView.getWidth(),mVideoCropView.getHeight()) // fake it till you make it
.fillMode(FillMode.CUSTOM)
.customFillMode(fillModeCustomItem);
if(composerGlFilter != null){
mp4Composer.filter(composerGlFilter);
}else{
mp4Composer.filter(glFilterGroup);
}
mp4Composer.trim(mStartTimeMs,mVideoCropView.getDuration())
.listener(new Mp4Composer.Listener() {
@Override
public void onProgress(double progress) {
Log.d(TAG,"onProgress = " + progress);
new Thread()
{
public void run()
{
CropVideoActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
//Do your UI operations like dialog opening or Toast here
Toast.makeText( CropVideoActivity.this,"onProgress = " + progress,Toast.LENGTH_SHORT).show();
}
});
}
}.start();
}
@Override
public void onCompleted() {
Log.d(TAG,"onCompleted()");
new Thread()
{
public void run()
{
CropVideoActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
//Do your UI operations like dialog opening or Toast here
Toast.makeText( CropVideoActivity.this,"codec complete path = " + destPath,Toast.LENGTH_SHORT).show();
}
});
}
}.start();
}
@Override
public void onCanceled() {
Log.d(TAG,"onCanceled");
new Thread()
{
public void run()
{
CropVideoActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
//Do your UI operations like dialog opening or Toast here
Toast.makeText( CropVideoActivity.this,"videoProcessing onCanceled",Toast.LENGTH_SHORT).show();
}
});
}
}.start();
}
@Override
public void onFailed(Exception exception) {
Log.e(TAG,"onFailed()",exception);
new Thread()
{
public void run()
{
CropVideoActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
//Do your UI operations like dialog opening or Toast here
Toast.makeText( CropVideoActivity.this,"exception.getMessage() : "+exception.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
}.start();
}
});
mp4Composer.start();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。