Git Product home page Git Product logo

androidvideotranscoder's Introduction

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

androidvideotranscoder's People

Contributors

kibotu avatar omurkmr avatar sembamax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidvideotranscoder's Issues

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

Dependecy

Is this still working ?
Can you please help me how to install it?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.