fahimfarhan / SimpleVideoEditor

A very simple free and open-source android video editor made with Mp4Composer that allows you to crop, trim and apply filters :)
MIT License
48 stars 14 forks source link

Crop Video with a special view #4

Open anonym2 opened 3 years ago

anonym2 commented 3 years ago

Hi first of all , thank you for your library . Im using your library to let my users crop their video in variables aspect ratio , im using this This CropVideoView as a replacement for your Simplecropview , the crop is not working corretly as it should , what im doing wrong ? Here s my code ` Uri fileUri = Uri.fromFile(new File(FinalSingleNewPath)); String destPath = getVideoFilePath();

                                        Log.e(TAG, "translateX = "+  mVideoCropView.getRealPositionX() + " translateY = "+  mVideoCropView.getRealPositionY() );
                                        Log.e(TAG, "resolution.width = "+mVideoCropView.getWidth()+" resolution.getHeight = "+mVideoCropView.getHeight());

                                        FillModeCustomItem fillModeCustomItem = new FillModeCustomItem(
                                                mVideoCropView.getScaleX(),
                                                mVideoCropView.getRotate(),
                                                (int) mVideoCropView.getRealPositionX(),
                                                (int) mVideoCropView.getRealPositionY(),
                                                mVideoCropView.getVideoWidth() ,
                                                mVideoCropView.getVideoHeight()
                                        );

                                        aftercorp.final_flash.EditPostFile.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, SinglePicture.this, mylogger);
                                        mp4Composer
                                             .size(mVideoCropView.getWidth(), mVideoCropView.getHeight()) // Dont fake it anymore
                                                .fillMode(FillMode.CUSTOM)
                                                .customFillMode(fillModeCustomItem);

                                        if(composerGlFilter != null){
                                            mp4Composer.filter(composerGlFilter);
                                        }else{
                                            mp4Composer.filter(glFilterGroup);
                                        }

                                        mp4Composer.trim(0,  mVideoCropView.getDuration())
                                                .listener(new Mp4Composer.Listener() {
                                                    @Override
                                                    public void onProgress(double progress) {
                                                        Log.d(TAG, "onProgress = " + progress);
                                                        new Thread()
                                                        {
                                                            public void run()
                                                            {
                                                                CropVIdeo.this.runOnUiThread(new Runnable()
                                                                {
                                                                    public void run()
                                                                    {
                                                                        //Do your UI operations like dialog opening or Toast here
                                                                        Toast.makeText( CropVIdeo.this, "onProgress = " + progress, Toast.LENGTH_SHORT).show();
                                                                    }
                                                                });
                                                            }
                                                        }.start();
                                                    }

                                                    @Override
                                                    public void onCompleted() {
                                                        Log.d(TAG, "onCompleted()");

                                                        new Thread()
                                                        {
                                                            public void run()
                                                            {
                                                                CropVIdeo.this.runOnUiThread(new Runnable()
                                                                {
                                                                    public void run()
                                                                    {
                                                                        //Do your UI operations like dialog opening or Toast here
                                                                        Toast.makeText( CropVIdeo.this, "codec complete path = " + destPath, Toast.LENGTH_SHORT).show();
                                                                    }
                                                                });
                                                            }
                                                        }.start();
                                                    }

                                                    @Override
                                                    public void onCanceled() {
                                                        Log.d(TAG, "onCanceled");

                                                        new Thread()
                                                        {
                                                            public void run()
                                                            {
                                                                CropVIdeo.this.runOnUiThread(new Runnable()
                                                                {
                                                                    public void run()
                                                                    {
                                                                        //Do your UI operations like dialog opening or Toast here
                                                                        Toast.makeText( CropVIdeo.this, "videoProcessing onCanceled", Toast.LENGTH_SHORT).show();
                                                                    }
                                                                });
                                                            }
                                                        }.start();
                                                    }

                                                    @Override
                                                    public void onFailed(Exception exception) {
                                                        Log.e(TAG, "onFailed()", exception);

                                                        new Thread()
                                                        {
                                                            public void run()
                                                            {
                                                                CropVIdeo.this.runOnUiThread(new Runnable()
                                                                {
                                                                    public void run()
                                                                    {
                                                                        //Do your UI operations like dialog opening or Toast here
                                                                        Toast.makeText( CropVIdeo.this, exception.getMessage(), Toast.LENGTH_SHORT).show();

                                                                    }
                                                                });
                                                            }
                                                        }.start();

                                                    }
                                                });

                                        mp4Composer.start();

`

ooyellow58 commented 2 years ago

Any solution? I am interested in your update.