On device extracting images from videos - creating video from images.

Overview

AndroidVideoTranscoder Build Status Download Hits-of-Code Javadoc API Gradle Version Kotlin GitHub license androidx

Surprisingly fast on device video transcoding.

Features

  • extracting images from video either ffmpeg or mediacodec
  • creating video from image either ffmpeg or mediacodec

Screenshot

How to use FFMpeg Part

Extracting frames

FFMpegTranscoder.extractFramesFromVideo(
		context = application, 
		frameTimes = times, 
		inputVideo = inputVideo, 
		id = "12345", 
		outputDir = frameFolder
	)
	.subscribeOn(Schedulers.io())
	.observeOn(AndroidSchedulers.mainThread())
	.subscribe(
	{ logv { "extract frames ${it.progress} ${it.message} ${(it.duration / 1000f).roundToInt()} s" } },
	{ logv { "extracting frames failed ${it.message}" }}, 
	{ logv { "extracting frames successfully completed" } }
)
.addTo(subscription)

Merging frames to create video

FFMpegTranscoder.createVideoFromFrames(
	context = application,
	frameFolder = frameFolder,
	outputUri = outputVideo,
	config = EncodingConfig(
	sourceFrameRate = 30 // every source image is a frame
	)
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
	{ logv { "merging frames ${it.progress} ${it.message} ${(it.duration / 1000f).roundToInt()} s" } },
	{ logv { "merging frames to create a video failed ${it.message}" }}, 
	{ logv { "video creation successfully completed" } }
)
.addTo(subscription)

How to use MediaCodec Part

Extracting frames

 MediaCodecTranscoder.extractFramesFromVideo(
	context = this,
	frameTimes = times,
	inputVideo = inputVideo,
	id = "loremipsum",
	outputDir = frameFolder,
	photoQuality = 100
    )
	.subscribeOn(Schedulers.io())
	.observeOn(AndroidSchedulers.mainThread())
	.subscribe(
	    { logv { "extractFramesFromVideo progress $it" }},
	    { logv { "extracting frames failed ${it.message}" }}, 
	    { logv { "extracting frames successfully completed" }}
	).addTo(subscription)

Merging frames to create video

MediaCodecTranscoder.createVideoFromFrames(
	frameFolder = frameFolder,
	outputUri = outputVideo,
	deleteFramesOnComplete = true
    )
	.subscribeOn(Schedulers.io())
	.observeOn(AndroidSchedulers.mainThread())
	.subscribe(
	    {logv { "createVideoFromFrames progress $it" }},
		{ logv { "merging frames to create a video failed ${it.message}" }}, 
		{ logv { "video creation successfully completed" } }
	).addTo(subscription)

How to install

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://dl.bintray.com/exozetag/maven' }
	}
}

Step 2. Add the dependency

dependencies {
	implementation 'com.exozet:transcoder:{version}'

	//Need to add ffmpeg dependencies if want to use FFMpegTranscoder(tested version 4.3.1.LTS)
	implementation 'com.arthenica:mobile-ffmpeg-full-gpl:{version}'
}

License

Copyright 2019 Exozet GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors

Jan Rabe

Ömür Kumru

You might also like...
Android Video Crop
Android Video Crop

🔺 Before using this library, read information below 🔺 This library is not more supported. If you want to add new feature or fix a bug, grab source

VideoView that plays video only when :eyes: are open and :boy: is detected with various other features
VideoView that plays video only when :eyes: are open and :boy: is detected with various other features

LookAtMe VideoView that plays video only when 👀 are open and 👦 is detected with various other features GIF AndroidPub (Medium) Post You can read the

mpv-android is a video player for Android based on libmpv.

mpv-android is a video player for Android based on libmpv.

NOVA is an open source video player for Android

NOVA: opeN sOurce Video plAyer Overview NOVA is an open source video player for Android. It consists in a fork of the original Archos Video Player Com

Simple and lightweight, yet polished and powerful Android video player based on ExoPlayer
Simple and lightweight, yet polished and powerful Android video player based on ExoPlayer

Just (Video) Player Android video player based on ExoPlayer It uses ExoPlayer's extension-ffmpeg with all its audio formats enabled (it can handle eve

Fermata Media Player is a free, open source audio and video player with a simple and intuitive interface.

Fermata Media Player About Fermata Media Player is a free, open source audio and video player with a simple and intuitive interface. It is focused on

A simple app showing how to make a YouTube Shorts/TikTok style video pager

It's pretty straightforward to get started using ExoPlayer by following the library's Hello world! documentation. Once you throw Android's lifecycles

An easy to use Instagram Video Downloader library for android apps.

Instagram-Video-Downloader-Library An easy to use library for directly download videos from ig reels, igtv. Implementation Step 1. Add the JitPack rep

Google's ML-Kit-Vision demo (android) for pre encoded video.
Google's ML-Kit-Vision demo (android) for pre encoded video.

Google's ML-Kit-Vision demo (android) for pre encoded video. Demos for camera preview and still image are also included. This project is actually extension of Google's own sample.

Comments
  • Support Android Q, by using new FFMpeg lib

    Support Android Q, by using new FFMpeg lib

    Ticket: #134586 Android Q seems that it does not permit to run FFMpeg from the files directories anymore. The current used ffmpeg lib still doesn't have a fix for this issue yet. so i used a new FFMpeg library which supports Android Q. This modification shouldn't break the implementation of anyone who uses TransCoder lib, except that we don't need to pass context parameter to FFMpeg methods anymore. As i mentioned the new lib dependency in README as well. Kindly check.

    opened by SembaMax 0
  • FATAL ERROR: The exception could not be delivered because it has already canceled/disposed

    FATAL ERROR: The exception could not be delivered because it has already canceled/disposed

    The exception could not be delivered to the customer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with.

    ` class MainActivity : AppCompatActivity() { var subscription: CompositeDisposable = CompositeDisposable()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        subscription = CompositeDisposable()
        setContentView(R.layout.activity_main)
    
        Logger.addLogger(LogcatLogger())
    
         val frameFolder = "saved_images/".parseExternalStorageFile()
        val outputVideo = "output_${System.currentTimeMillis()}.mp4".parseExternalStorageFile()
    
    
        MediaCodecTranscoder.createVideoFromFrames(
            frameFolder = frameFolder,
            outputUri = outputVideo,
            deleteFramesOnComplete = true)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                {
                    logv { "createVideoFromFrames onNext " }
    
                },
                {
                    logv { "createVideoFromFrames onError " }
                },
                { logv { "createVideoFromFrames onComplete " } }
            ).addTo(subscription)
    

    }

    private fun String.parseExternalStorageFile(): Uri = Uri.parse("${Environment.getExternalStorageDirectory()}/$this")
    

    }`

    and the error:

    E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1 Process: krt.studio.kotlinimg2vid, PID: 24540 io.reactivex.exceptions.UndeliverableException: **The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling** | java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:69) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method at com.exozet.transcoder.mcvideoeditor.MediaCodecCreateVideo.startEncoding(MediaCodecCreateVideo.java:150) at com.exozet.transcoder.mcvideoeditor.MediaCodecTranscoder$createVideoFromFrames$1.subscribe(MediaCodecTranscoder.kt:59) at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40) at io.reactivex.Observable.subscribe(Observable.java:12246) at io.reactivex.internal.operators.observable.ObservableDoOnLifecycle.subscribeActual(ObservableDoOnLifecycle.java:33) at io.reactivex.Observable.subscribe(Observable.java:12246) at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96) at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578) at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)  at java.util.concurrent.FutureTask.run(FutureTask.java:266)  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:764)  Caused by: java.lang.ClassCastException: Bootstrap method returned null at com.exozet.transcoder.mcvideoeditor.MediaCodecCreateVideo.startEncoding(MediaCodecCreateVideo.java:150)  at com.exozet.transcoder.mcvideoeditor.MediaCodecTranscoder$createVideoFromFrames$1.subscribe(MediaCodecTranscoder.kt:59)  at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)  at io.reactivex.Observable.subscribe(Observable.java:12246)  at io.reactivex.internal.operators.observable.ObservableDoOnLifecycle.subscribeActual(ObservableDoOnLifecycle.java:33)  at io.reactivex.Observable.subscribe(Observable.java:12246)  at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)  at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)  at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)  at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)  at java.util.concurrent.FutureTask.run(FutureTask.java:266)  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:764)  I/Process: Sending signal. PID: 24540 SIG: 9

    opened by ghost 0
Owner
null
Free p2p cdn android github sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀

Android p2p cdn sdk to distribute load and reduce costs(https://peervadoo.com) Vadootv is a p2p sdk integration to reduce your video streaming costs b

Vadootv 40 Oct 5, 2022
Yet Another Video Player (or YAVP) is a Video Player for Android that is based on Googles ExoPlayer.

Yet Another Video Player Yet Another Video Player (or YAVP) is a Video Player for Android that is based on Googles ExoPlayer. Who Is YAVP For? First o

null 62 Dec 29, 2022
Video Transcoder is an application which uses the open source program FFmpeg to transcode video files from one format to another.

Video Transcoder Do you want to encode videos on your phone into different formats, trim videos, or extract audio? Are you looking for a free solution

Branden Archer 358 Dec 30, 2022
Compose-video-player - Video player for Android Compose powered by ExoPlayer

Compose Video Player Video player for Android Compose powered by ExoPlayer. Addi

Juan Pablo Herrera 22 Dec 13, 2022
The Madman library (Media Ads Manager) enables you to advertise video contents with video ads.

Madman (Media ads manager) is a high performance alternative to Google's standard IMA android SDK. If you have your own VAST server and want to render video ads and have full control over the UI, then this library is for you.

Flipkart Incubator 65 Nov 10, 2022
Silky - Android application to convert videos from applications such as YouTube, Facebook, Twitter into audio (.mp3)

Silky Español (actualmente la app se encuentra en desarrollo ) Descripcion Aplic

null 2 Aug 24, 2022
LNSocial is a social media app dedicated to short-form videos created for and consumed by users.

LNSocial is a social media app dedicated to short-form videos created for and consumed by users. The length of videos is between 15-30 second

null 10 Jan 5, 2023
SocyMusic is an open-source Android music player written in Java with the aim of creating an easy-to-use app for exchanging and listening to top-quality music. Help us create it!

SocyMusic SocyMusic is an open-source Android music player written entirely in Java. It's objectives are to provide top-quality music to everyone for

Benji 23 Dec 26, 2022
Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support.

ijkplayer Platform Build Status Android iOS Video player based on ffplay Download Android: Gradle # required allprojects { repositories {

bilibili 31k Jan 3, 2023
Custom Android view with video player, loader and placeholder image

VideoPlayerView Custom Android view with video player, loader and placeholder image. To stay up-to-date with news about the library Usage Here is an e

Marcin Moskała 89 Nov 18, 2022