简体   繁体   中英

how to save video which is in side a png frame in constraint layout in android

I am developing an app which requires a video or an image to be inserted inside a PNG image frame with one or multiple videos, the image part of the program is working well since I can just convert the View into a bitmap and save it, the issue I face comes when I have to save the image frame with a video inside it, I am able to pick up a video and set it inside the Video-view as well but when trying to save it, I am left helpless. Since there is no way to convert a view into a video.

My layout:

<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 >

The constraintlayout is the parent view which has the other view like the PNG imageview and the stickerview, the images/video selected by the users are added dynamically to the position inside the blank space of a frame

Here is how I am saving the images with the frame :

            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" , null ,
                    getColor ( R.color.colorPrimary ) , getColor ( R.color.colorAccent ) , Toast.LENGTH_SHORT ,
                    false , true ).show ( );

Can anyone help me in how to save this but as a video

The name called FFMPEG is the best way to create, update or do some operations over video or videos and over multiple images also.

you can create video from multiple images by combining images using FFMPEG or you can do higher level modification on the video using this.

this is the batter library in android for getting started and play around with FFMPEG. this library is working fine in android 10 or higher too.

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

This is the implementation

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

The official documentation for FFMPEG:-

FFMPEG official documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM