java—裁剪具有不同纵横比的视频文件

3j86kqsm  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(318)

我试图让我的用户在上传到我的壁炉数据库之前,能够以不同的长宽比裁剪他们的视频。我正在使用android videocropview为我的用户显示视频编辑器布局,并使用simplevideoeditor裁剪视频,当我试图从videocropview获取信息,然后用simplevideoeditor裁剪文件时,我很难将两个库合并在一起这是我应该得到的结果,也是我得到的结果。所以我的问题是我做了什么坏事,我该怎么解决?
这是我的密码

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();

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题