I am using external camera with my application. The camera takes 9 pictures every second (9fps). The pictures are bitmaps 384x288. I need to create from this pictures a video file.
What I have tried:
Using Jcodec
The problem: jcodec is relatively slow, and for it to work properly i add the bitmaps to ArrayList and when the record stopped i convert the array to video. I takes to much time. For 30 sec video there is about 1 min rendering time.
Using native mediaCodec
The problem: I could only generate AVI files (video/avc) that not readable in the original android player. I can not use what is written here: http://bigflake.com/mediacodec/ because I developing for API 16. I have tried using (video/mp4v-es) but the video is corrupted and not playable in any player.
Using FFmpeg
The problem: Very complicated to implement in android, and I am not sure it will give me the result I needed after spending time to implement this. The result I need is to record video streaming as I get the bitmap without any delay.
What can you suggest me?
Related
My android app plays videos in Exoplayer 2, and now I'd like to play a video backwards.
I searched around a lot and found only the idea to convert it to a gif and this from WeiChungChang.
Is there any more straight-forward solution? Another player or a library that implements this for me is probably too much to ask, but converting it to a reverse gif gave me a lot of memory problems and I don't know what to do with the WeiChungChang idea. Playing only mp4 in reverse would be enough tho.
Videos are frequently encoded such that the encoding for a given frame is dependent on one or more frames before it, and also sometimes dependent on one or more frames after it also.
In other words to create the frame correctly you may need to refer to one or more previous and one or more subsequent frames.
This allows a video encoder reduce file or transmission size by encoding fully the information for every reference frame, sometimes called I frames, but for the frames before and/or after the reference frames only storing the delta to the reference frames.
Playing a video backwards is not a common player function and the player would typically have to decode the video as usual (i.e. forwards) to get the frames and then play them in the reverse order.
You could extend ExoPlayer to do this yourself but it may be easier to manipulate the video on the server side if possible first - there exist tools which will reverse a video and then your players will be able to play it as normal, for example https://www.videoreverser.com, https://www.kapwing.com/tools/reverse-video etc
If you need to reverse it on the device for your use case, then you could use ffmpeg on the device to achieve this - see an example ffmpeg command to do this here:
https://video.stackexchange.com/a/17739
If you are using ffmpeg it is generally easiest to use via a wrapper on Android such as this one, which will also allow you test the command before you add it to your app:
https://github.com/WritingMinds/ffmpeg-android-java
Note that video manipulation is time and processor hungry so this may be slow and consume more battery than you want on your mobile device if the video is long.
Is there a way to record square (640x640) videos and concat them in Android? I looked up in the Internet and found some solutions. The solution seems to be "ffmpeg". However, to use ffmpeg I need to dive into NDK and build ffmpeg from its sources. Is there a solution by only using the Android SDK?
My basic needs are:
Record multiple videos (square format)
Resize captured videos (i.e. 480x480 to 640x640)
Concat captured videos
Rotate final video (clockwise 90)
Final output will be in mp4 or mpg format
Is there a solution by only using the Android SDK?
Not really.
Your primary video recording option is MediaRecorder, and it supports exactly nothing of what you list. For example, there is no requirement for any Android device to support taking square videos.
You are also welcome to use the camera preview stuff to assemble your own videos from individual frames. Vine does this, AFAIK. There, you could perhaps use existing Bitmap facilities to handle the cropping, resizing, and rotating. However, this will be slow, and doing this work in a way that can keep up with a reasonable frame rate will be difficult. Also, I do not know if there is a library that can stitch those frames together into a video, or blend in any sort of audio (camera previews are pure images).
Is it possible to create video of series of Images present on SdCard using MediaCodec? if yes, can anyone share me the link?
I want to import images from sdCard and create video from those images, any suggestions???
I want to do this programmatically. I've tried using jcodec library but the process is very slow and I want to fasten up a little bit more.
Is there any chances that MediaCodec can do that in my ADT and in much faster way.
Importing images from SdCard --> making a good quality .mp4 video (faster than jcodec way).
You can try INDE Media Pack - https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials
It has transcoding\remuxing functionality as MediaComposer class and several sample effects like JpegSubstituteEffect - it shows how substitute video frame by a picture from jpg file. You can take black video as a refefence and put images on it with a possibility to set duration, add audio track with help of audio effect etc.
I know how to use ffmpeg to covert image sequence to a video.
What I want to do is start converting images to video, before I have all the images ready, i.e. as soon as I start to output images, ffmpeg starts conversion, and stops when the images stop coming. Is there any way to achieve this?
Edit : I'm trying this in Android.
If you want to store video on sdcard, you should start with FFMpegFrameRecorder class from OpenCV for Android. You can google it easily. It will allow you to add single frames and create a video bit-by-bit.
If you need to keep your video in memory, you will have to write your own frame recorder, which is not that trivial, but doable and I can help you a bit.
I'm making an app that takes a video and does some computation on the video. I need to carry out this computation on individual frames of the video. So, I have two questions:
Are videos in Android stored as a sequence of pictures? (I've seen a lot of Android devices that advertise having 25-30 fps cameras) If yes, can I, as a developer, get access to these frames that make up a video and how so?
If not, is there any way for me to generate at least 15-20 distinct frames per second from a video taken on an android device? (and of course, do the computation on those frames generated)
Videos are stored as videos. To manipulate frames one can use FFMPEG library. There are FFMPEG ports to Android such as in Dolphin opensource player. This would require C/C++ programming with NDK though.