Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we add animated/simple image as a top layer to video and export it as a single video in Android?

I need to merge images to video as an overlay and export it. I have found ways to create video from images using javacv but didn't find any jar or library which do add images as an overlay to existing video, some of the links suggest to use FFMPEG and JNI to achieve this but sadly i don't have any knowledge of JNI. They use avfoundation framework in IOS to achieve the same.

enter image description here

The above image is replica of my requirements, if any one can guide me in right direction and provide me some useful stuff to start with would be appreciated.

What i have achieved so far is: 1) Compiled FFMPEG. 2) Generated .so files 3) Compiled and able to run Hello Jni project.

What i am searching for is: 1) Splitting video into frames. 2) Merging my overlay images with video frames 3) Recreating the video with audio.

and i know JNI is the only way to achieve this so searched a lot but didn't find any good JNI stuff to start with. I am not asking for the whole code but if some one can point me out with some good tutorial or blog would be great help.

Thanks!!

like image 631
Ravi K. Sharma Avatar asked May 13 '13 08:05

Ravi K. Sharma


1 Answers

The way to accomplish this is like you said - incorporate a video codec and use it to re-compose the video.

  1. Decode the original video
  2. Draw your overlay over the original video frames
  3. Encode the frames again.

Using FFMPEG with JNI is the obvious solution, but if you find any other codec library that can accomplish the same with pure Java, it will work too.

No knowledge of JNI? That's about time to learn it =)

References for learning:

  1. NDK docs on your file system: http://developer.android.com/tools/sdk/ndk/index.html#Docs

  2. JNI - http://192.9.162.55/docs/books/jni/html/jniTOC.html

  3. FFMPEG for Android - there are many tutorials out there and many source trees that contain a ready build environment. You can either follow them or just do it on your own - provided that you understand the NDK environment and can read makefiles. This is an example: http://vec.io/posts/how-to-build-ffmpeg-with-android-ndk

  4. Using FFMpeg to encode\decode frames - sadly, no good up-to-date tutorials here, there is the API documentation: http://ffmpeg.org/doxygen/trunk/index.html

  5. Blending bitmaps - use Android's Canvas infrastructure, or just manually copy pixels over each other and blend according to alpha values.

Warning - this is a complex library to build and you'd better experiment with easier NDK projects before attempting this one.

like image 196
SirKnigget Avatar answered Oct 26 '22 05:10

SirKnigget