Capturing SurfaceView into video file based on google/grafika examples - java

I would like to load video from file, make some transformation on it and render it back into file. Said transformation is mainly two videos overlapping and shifting one of them in time. Grafika has some examples relevant to this issue. RecordFBOActivity.java contains some code for rendering video file from surface. I'm having trouble changing two things:
instead of rendering primitives in motion I need to render previously decoded and transformed video
I would like to render surface to file as fast as posible, not along with playback
My only success so far was to load .mp4 file and add some basic seeking features to PlayMovieActivity.java. In my reasearch I came across these examples, which are also using generated video. I didn't found them quite useful, because I couldn't swap this generated video with decoded one from file.
Is it posible to modify code of RecordFBOActivity.java so it can display video from file instead of generated animation?

You can try INDE Media for Mobile, tutorials are here: https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials
Sample code showing how to enable editing or make transformation is on github: https://github.com/INDExOS/media-for-mobile
It has transcoding\remuxing functionality in MediaComposer class and a possibility to edit or transform frames. Since it uses MediaCodec API inside encoding is done on GPU so is very battery friendly and works as fast as possible.

Related

How to take high-res picture while sensing depth using project tango

How take picture using project tango ?
I read this answer: Using the onFrameAvailable() in Jacobi Google Tango API
which works for grabbing a frame but picture quality is not great. Is there any takePicture equivalent ?
Note that java API
public void onFrameAvailable(int cameraId) {
if (cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
mTangoCameraPreview.onFrameAvailable();
}
}
does not provide rgb data. If I use android camera to take picture, tango can not sense depth. There I will have to use TangoCameraPreview.
Thanks
You don't have to use TangoCameraPreview to get frames in Java. It is really just a convenience class provided to help with getting video on the screen. It appears to be implemented entirely in Java with calls to com.google.atap.tangoservice.Tango (i.e no calls to unpublished APIs). In fact, if you look inside the Tango SDK jar file, you can see that someone accidentally included a version of the source file - it has some diff annotations and may not be up to date but examining it is still instructive.
I prefer not to use TangoCameraPreview and instead call Tango.connectTextureId() and Tango.updateTexture() myself to load frame pixels into an OpenGL texture that I can then use however I want. That is exactly what TangoCameraPreview does under the hood.
The best way to capture a frame in pure Java is to draw the texture at its exact size (1280x720) to an offscreen buffer and read it back. This also has the side effect of converting the texture from whatever YUV format it has into RGB (which may or may not be desirable). In OpenGL ES you do this using a framebuffer and renderbuffer.
Adding the framebuffer/renderbuffer stuff to a program that can already render to the screen isn't a lot of code - about on par with the amount needed to save a file - but it is tricky to get right when you do it for the first time. I created an Android Studio sample capture app that saves a Tango texture as a PNG to the pictures folder (when you tap the screen) in case that is helpful for anyone.

Display animation in java?

I am very very new at java (as in, I took one beginner course) so please don't get super technical when answering me.
Earlier today I learned how you can load an image in java and display it in an applet.
I found a step-by-step youtube video that helped me do this.
Now I want to know how I can load an animation in java. Is that something that can be done? And can I get step-by-step instructions on how to do it? Basically, I already have a short .wmv file and I would like to display it when I run the program.
It also has audio that I would like to play along with it.
(i'm actually trying to make a video game with an animated character. java can be used to program games, so this should be doable, right? i don't care about making a game the "right" way or the way game developers usually do it, right now i just want to figure out the simple task of displaying an animation in java.)
thanks!
First of all, the wmv extension stands for video, and an animation is not a video. Its either a spritesheet, a gif image ect. In order to create a even simple animation, you must first learn some basic object oriented programming, become comfortable in creating and using classes, than you can advance to making your own class for taking care of sprites and cutting an image in a way that you can use it ect.
Example of a simple spriteshet:
This spritesheet is an simple image showing you one way to implement your 2d animation. You just have to cut the image parts from it using some rectangles. For 3d, you must use some other software and you must know that they use different kinds of extensions.
I wont dive into code, for the simple reason that I do not have time right now, but if you want further help, give my some contact like skype, facebook ect, I would love to help.
You could try the Java Media Framework javax.media.*. (caveat: rather old framework)
It appears you simply need to embed a media file such as video or audio into an applet. This can be achieved through a player embedded into an applet, similar to an individual frame or a .GIF file, that would be able to handle the .WMV extension.
Assuming awareness of the basic structure of a Java program, the main declaration to get an instance of a player is of the generic form, after:
player = Manager.createRealizedPlayer( mediaURL );
or
player = Manager.createPlayer( file.toURL() );
Good idea to go through the JMF documentation.

Modify Exif tags in Java for mp4 videos

Is there any API or library in Java available that will let me modify tags in the metadata for mp4 files? I need to modify the orientation (or rotation) tag in order to get videos to playback in the correction orientation. Something for Android would be preferrable.
Full disclosure: I'm the creator and maintainer of the mp4parser lib.
Use http://mp4parser.googlecode.com for opening the MP4 file. Navigate to the exif box (I have never seen that box) and modify it. Then write the file back to disk.
But are you really sure the exif box is changing the playback behavior? It rather seems to be an info box that tells you something about the recording situation.
I'd rather think you should modify the matrix in the Track Header Box (/moov/trak/tkhd) to retate the video. You might want to have a look a the Matrices part of the quicktime format specification (same as MP4 - at least for the matrices)
This answer here helps you with the matrix: https://stackoverflow.com/a/8177749/829133

Generating an mp3/wav/ogg Waveform using Java

Like soundcloud and zippyshare1, how can I generate an audio waveform image using java? are there any frameworks or open source libraries available for such case?
I wanted to generate an audio waveform as an image, and upon loading a track, the waveform image with will be loaded.
Start with this answer. The "further processing.." in this case might be to add each instantaneous value to a GeneralPath, then (scale that path to fit within the painting area and) draw it.
Here are two questions with answers on SO:
Java Program to create a PNG waveform for an audio file
How can I draw sound data from my wav file?
I like my answer to the second question the best because it explains how to do it in all cases, but it doesn't give code.
There are lots of other answers, too.

video-steganography in java

I need to create steganographic videos (videos with data hidden in them) for my project.
I need to carry this out by extracting all the frames from a video and then hiding data in the selected frames by replacing bits in the LSB of the pixel color value and then encoding all the frames to create a new video(note here that lossless formats are required otherwise I might end up losing hidden data).
My research motivated me to use xuggler for manipulating videos, 'png' format to save the extracted images as it is a lossless format(handling them as BufferedImage objects), and using 'avi' video files.
As of now I am able to extract all frames from a video and encode my hidden data in the lsb's.
But I am having problems in creating the new avi video file using xuggler. When I extract the frames from the new video they lose the hidden data. I don't understand how to get this right and keep the data intact. This could be due to some lossy compression technique being used to create the new video.The size of the new video does not matter to me. I also can't find the correct codec_id to create the new video. I am extensively using xuggler tutorial available on wiki.
decode and capture frames http://build.xuggle.com/view/Stable/job/xuggler_jdk5_stable/ws/workingcopy/src/com/xuggle/mediatool/demos/DecodeAndCaptureFrames.java
I can post my code as required...
The problem is in the algorithm you are using , as mpeg or other famous video compression techniques are lossy compression techniques you will be losing data when you convert the frames back to video stream . So in lossy video codecs you cannot use LSB techniques for steganography .
Instead what you can do is change the motion vectors of the videos in someway to hide steganographic data . The problem in this is that xuggler being a higher level api might not give you a way to find/alter the motion vectors of the p/b frame . ffmpeg which xuggler uses does have a option for you to visualize the motion vectors so your best bet for motion vectors algo is alter the source code of ffmpeg as its a open-source project . Do reply back if you find a better way to find motion vectors .
Well , there is a simpler video steganography method
You can refer to Real steganography with truecrypt
But if you really want to go with mpeg video compression you can refer to the wonderful
paper : Steganography in Compressed Video Stream but the problem still remains extracting and manipulating the motion vectors

Categories