How do I compress a bitmap to a video file with android. Like, adding the bitmap file to the video. I have a .png file which I decoded into a bitmap. Now, I want to add that bitmap to a video file so that when the video plays it also show the bitmap I added
If you just want to display the bitmap on top of the video when it is playing on your Android device, then the easiest thing is to display it in a separate view on top of the video, using a relative layout in your layout file, for example. This avoid CPU and battery consuming video manipulation.
If you actually want to add the image to the video so it is saved then one way to do this on Android is to use ffmpeg. There are several ways to use ffmpeg but one of the easier ones is to use a well supported ffmopeg wrapper, e.g.:
https://github.com/WritingMinds/ffmpeg-android-java
This allows you use the standard command line syntax for the ffmpeg instructions themselves, which you will find is well documented and supported on the web. For example, the following covers adding an image into a video:
https://ffmpeg.org/ffmpeg.html (look for ' overlay an image' near the bottom)
Note that adding the image is processing intensive, so you may quite likely find your device is not able to do this in real time - i.e. not able to add it while you are watching. If you have the luxury of being able to add the image first to the video and then watch it, then this may be more practical - you could even consider doing it on the server side after uploading the video, where you should have much more processing power.
If you must see the image and the video in real time then you may find a combination of the above approaches works for you - simply display the image over the video in realtime, and then add the image to the video afterwards before storing it.
Related
In one of my application i need to record video of my own screen.
I need to make a video in that user can take video of their app how it possible?
first question is it possible so? if yes then how? any useful links or some help
Thanks
Pragna Bhatt
Yes, it is possible, but with certain limitations. I have done it in one of my projects.
Android 4.4 adds support for screen recording. See here
If you are targeting lower versions, you can achieve it, but it will be slow. There is no direct or easy way to do it. What you will do is, create drawable from your view/layout. Convert that drawable to YUV format and send it to camera (see some library where you can give custom yuv image to camera), camera will play it like a movies, you can save that movies to storage. Use threads to increase frame-rate (new multi-core device will have high frame-rate).
Only create drawable (from view) when there is any change in view or its children, for that you can use Global Layout Listener. Otherwise send same YUV image to camera.
Limitation:
You can not create video of more than one activities (at a time), or their transactions, because you are creating image from view. (Work on it yourself, may be you'll find a way)
You can not increase frame rate from a certain point, because it depends on hardware of your device.
I am new to Android and I having troubles setting a dynamic background just like Tumblr login UI,
The link below is where I got some help.
Set Animated .GIF As Background Android
But it only works when I load small-size animation, or I have to drop lots of frames of a GIF animation which leads to incoherence.
If I load all the frames which will cause OutOfMemoryError, I don't think it's the right way.
Is tumblr uses GIF animation or it's actually a short video?
I know that Twitter converts all GIFs to MP4. Video compression is far better than GIFs leading to smoother playback and reduced bandwidth and happy users :) Is using MP4s an option?
More on the subject here.
Not sure how long your animation is, or how high res its frames are, but you probably need to look at loading the image frames in scaled down form into memory. The Android docs give a very coherent explanation of how to do this here (basically, you first find the res of the bitmap, then load a scaled down version of it appropriate to the device's screen resolution). It may also be that the animation is too long, and you need to look at forcing bitmaps to recycle (using bitmap.recycle()) once displayed.
I want to crop image of large size and tried using Bitmap.createBitmap but it gives OOM error. Also, tried multiple technique around createBitmap but none of them were successful.
Now I thinking of saving image to file system and crop it without loading image into memory that might solve the problem. But don't know how to do it.
User flow: User will take multiple pictures from in-app camera after each snap user can crop it manually or app will silently crop it on some predefine login and later it will send these images to server.
Can anybody guide me how I can achieve this?
There is a class called BitmapRegionDecoder which might help you, but it's available from API 10 and above.
If you can't use it :
Many image formats are compressed and therefore require some sort of loading into memory.
You will need to read about the best image format that fits your needs, and then read it by yourself, using only the memory that you need.
a little easier task would be to do it all in JNI, so that even though you will use a lot of memory, at least your app won't get into OOM so soon since it won't be constrained to the max heap size that is imposed on normal apps.
Of course, since android is open source, you can try to use the BitmapRegionDecoder and use it for any device.
I very much doubt you can solve this problem with the existing Android API.
What you need to do is obtain one of the available image access libraries (libpng is probably your best bet) and link it to your application via jni (see if there's a Java binding already available).
Use the low-level I/O operations to read the image a single scanline at a time. Discard any scanlines before or after the vertical cropped region. For those scanlines inside the vertical cropped region, take only those pixels inside the horizontal cropped region and write them out to the cropped image.
I have a very wide video that I am trying to crop a part of in the display and I was trying to find a method of perhaps taking a bitmap of the native resolution of that video and then doing what I like with that (i.e. move the video from side to side). I want to be able to watch the resized images placed on the screen as if the video is cropped. I imagine this would be done with something like getDrawingCache but I'm not getting the full resolution I'm looking for. Does anyone know a way around this?
Edit: I have found the latest source file for the videoview so I am going to see how well editing that will work
You can simply render the video on a surface larger than the actual display, and then manipulate the position and cropping of this view.
Having a video file, there is any way to access single pixel values?
I have two cases where I would like to access the pixels:
From the video camera
From a video file What I need is geting a pixel information for a certain place with something like getPixel(posX, posY) and returning the RGB information
I have an algorithm that detects blobs (homogeneous parts) of an image and I would like to implement it in real time using the android video camera and offline processing analyzing a video file.
Yes, but you'll need to do some work.
Extract a video frame from the source file with a tool such as FFmpeg. The result will be a JPEG or other such image file
Use an image processing tool, like Imagemagick, to extract the information for a pixel.
Presto!