如何在android中的约束布局中保存png框架中的视频

问题描述

我正在开发一个需要将视频或图像插入具有一个或多个视频的PNG图像框架中的应用程序,该程序的图像部分运行良好,因为我可以将View转换为位图并保存它遇到的问题是,当我必须保存其中带有视频的图像帧时,我能够拾取视频并将其设置在“视频”视图中,但是当尝试保存它时,我就束手无策了。由于无法将视图转换为视频。

我的布局:

<androidx.constraintlayout.widget.ConstraintLayout
        android:id = "@+id/multiView"
        android:layout_width = "match_parent"
        android:layout_height = "0dp"
        android:layout_weight = "1" >
        
        <RelativeLayout
            android:id = "@+id/relativeLayout"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent" />
        
        <ImageView
            android:id = "@+id/frame"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent"
            android:scaleType = "fitXY"
            android:src = "@drawable/flowerpower"
            app:layout_constraintEnd_toEndOf = "parent"
            app:layout_constraintStart_toStartOf = "parent"
            app:layout_constraintTop_toTopOf = "parent" />
        
        
        <FrameLayout
            android:id = "@+id/stickerAdd"
            android:layout_width = "match_parent"
            android:layout_height = "match_parent" />
    
    </androidx.constraintlayout.widget.ConstraintLayout >

constraintlayout是父视图,具有其他视图,例如PNG图像视图和贴纸视图,用户选择的图像/视频被动态添加到帧的空白空间内的位置

这是我如何将图像与框架一起保存:

            View view = multiView;
            view.setDrawingCacheEnabled ( true );
            Bitmap bitmap = Bitmap.createBitmap ( view.getDrawingCache ( ) );
            view.setDrawingCacheEnabled ( false );

            File localFile = new File ( path,filename );
            FileOutputStream outputStream = new FileOutputStream ( localFile );
            bitmap.compress ( Bitmap.CompressFormat.JPEG,100,outputStream );
            outputStream.flush ( );
            outputStream.close ( );

            MediaScannerConnection.scanFile ( this,new String[] { localFile.getAbsolutePath ( ) },null,( path1,uri ) -> {
                    } );
            Toasty.custom ( MainActivity.this,"Image Saved",getColor ( R.color.colorPrimary ),getColor ( R.color.colorAccent ),Toast.LENGTH_SHORT,false,true ).show ( );

除了视频以外,有人可以帮助我如何保存它

解决方法

名为FFMPEG的名称是在一个或多个视频以及多个图像上创建,更新或执行某些操作的最佳方式。

您可以通过使用FFMPEG组合图像来从多个图像中创建视频,也可以使用此图像对视频进行更高级别的修改。

这是android中的击球员库,可以开始使用FFMPEG。该库在android 10或更高版本中也能正常工作。

https://github.com/tanersener/mobile-ffmpeg

这是实现

implementation 'com.arthenica:mobile-ffmpeg-full:4.4'

FFMPEG的官方文档:-

FFMPEG official documentation