Creating video skim of YUV video in matab - matlab

I am having Y,U,V components of some frames and now I want to create a video from these components. To be more specific I want to create video summary of a video. Till now I have obtained which frames needs to be there (after some processing) in final video skim and I want to generate a video skim from these frames.
Thanks.
Edit:
I have created video skim but I doubt that might not be the most efficient method. What I am doing is first I am storing the required frame's Y,U,V component in a cell then I am using frwrite function of matlab.

Related

Invisible Video Watermark

I am doing a project in invisible Video Watermarking in Matlab. But I don't know where to start and how to do it. All I can find is visible watermark on the video. Can anyone help?
If you search for the term 'steganographic' in this context it may help - steganography is basically hiding one message in another and some of the academic and basic building block material may favour this term. Some of the video techniques will be strongly related to single image techniques also as the hidden image or watermark, or part of the watermark more commonly, is hidden in individual frames within the video.
Some examples in the MathLab domain:
https://www.mathworks.com/matlabcentral/fileexchange/41326-steganography-using-lsb-substitution?requestedDomain=true
https://sites.google.com/site/cs534steganographyproject/home/matlab-code-and-examples

Correct Video for lens distortion in Matlab?

I have a video that was taken with a GoPro and I would like to get rid of the fisheye distortion. I know I can get rid of the fisheye with the gopro software, but I want to do this using Matlab instead.
I know there's this http://www.mathworks.com/help/vision/ref/undistortimage.html that applies for images, however, how would I apply it for a full video? The number of frames in the video 207 (it's like 5 - 6 second short video).
Thank you very much!
Can't you just sample your video stream at 24fp (using e.g. ffmpeg, see here ), apply your Matlab routine one frame at a time, then rebuild the video stream in Matlab itself?
You can apply undistortImage to each frame of the video. If the video is saved to a file, you can use vision.VideoFileReader to read it one frame at a time, and then you call undistortImage. Then you can write the undistorted frame to a different file using vision.VideoFileWriter, or you can display it using vision.VideoPlayer.
Of course, this is all assuming that you have calibrated your camera beforehand using the Camera Calibrator App.

Replace the first frame of a video with another frame using MATLAB

I am using MATLAB for a video processing task.
When I tried to create an object for the grayscale video (the video has a .FLV extension) using the mmreader function of MATLAB, it showed an warning saying that it cannot determine the number of frames.
Then when I tried to read the video using read(mmreader), it showed an error saying not enough memory for 3246 frames.
Therefore I just read the first frame of the video, edited it and now trying to place the frame in the position of the first frame of the video.
Things that I have done:
Read and extracted the first frame of a grayscale video (the file has a .FLV extension) using mmreader function of MATLAB.
I embedded some text in the frame.
Things that I want to do and need your help:
Replace the first frame of the source video with the edited frame (i.e. the frame with the embedded text in it)
Save and Play the video.

approach for recording grayscale video on iphone?

I am building an iphone app that needs to record grayscale video and save it to the camera roll. I'm stumped at how best to approach this.
I am thinking along the following lines:
Use a shader and opengl to transform the video to grayscale
Use AVFoundation (AVAssetWriter with an AVAssetWriterInputPixelBufferAdaptor) to write the video to the file.
My questions are:
Is this the right approach (simplest, best performance)?
If so, what would be the best way to go from opengl output to a CVPixelBufferRef input for the AVAssetWriterInputPixelBufferAdaptor?
If not, what would be a better approach?
Any nudge in the right direction is much appreciated!
In general, I'd agree with this approach. Doing your processing in an OpenGL ES 2.0 shader should be the most performant way of doing video frame alteration like this, but it won't be very simple. Fortunately, you can start from a pre-existing template that already does this.
You can use the sample application I wrote here (and explained here) as a base. I use custom shaders in this example to track colors in an image, but you could easily alter this to convert the video frames to grayscale (I even saw someone do this once). The code for feeding camera video into a texture and processing it could be used verbatim from that sample.
In one of the display options within that application, I render the processed image first to a framebuffer object, then use glReadPixels() to pull the resulting image back into bytes that I can work with on the CPU. You could use this to get the raw image data back after the GPU has processed a frame, then feed those bytes into CVPixelBufferCreateWithBytes() to generate your CVPixelBufferRef for writing to disk.
(Edit: 2/29/2012) As an update to this, I just implemented this kind of video recording in my open source GPUImage framework, so I can comment on the specific performance for the encoding part of this. It turns out that you can capture video from the camera, perform live filtering on it, grab it from OpenGL ES using glReadPixels(), and write that out as live H.264 video in 640x480 frames on an iPhone 4 at 30 FPS (the maximum camera framerate).
There were a few things that I needed to do in order to get this recording speed. You need to make sure that you set your AVAssetWriterInputPixelBufferAdaptor to use kCVPixelFormatType_32BGRA as its color format for input pixel buffers. Then, you'll need to re-render your RGBA scene using a color-swizzling shader to provide BGRA output when using glReadPixels(). Without this color setting, your video recording framerates will drop to 5-8 FPS on an iPhone 4, where with it they are easily hitting 30 FPS. You can look at the GPUImageMovieWriter class source code to see more about how I did this.
Using the GPUImage framework, your above filtering and encoding task can be handled by simply creating a GPUImageVideoCamera, attaching a target of a GPUImageSaturationFilter with the saturation set to 0, and then attaching a GPUImageMovieWriter as a target of that. The framework will handle the OpenGL ES interactions for you. I've done this, and it works well on all iOS devices I've tested.

MPEG-4 file behavior

In iphone i have a mpeg-4 video file, which when played & when i click in the middle or any portion of the video, its goes back & starts from beginning rather continuing from the place where i clicked.
Whereas the same file plays when the same behavior is extorted(ie. play, click in the middle of the video) works fine in quicktime player/safari.
Do someone have any thoughts on this?
The video proabably only has one keyframe at the beginning of the clip.
That means to recreate the image in the middle of the video, the player needs to go back to the first frame and apply the rules from every spanning frame. A good video player on powerful hardware would be able to calculate what the 20,000th frame on the fly essentially by playing the entire video to that point. However, that is quite a lot of calculation, so a less powerful video player (like one on a phone), would not be able to make all of the necessary calculations in a timely manner much faster than real time, so it might simply go back to the beginning.
One solution would be to put key-frames more frequently. That way you have a higher seek precision. Every 1-2 seconds is pretty standard and used by DirectTV (That is why it can sometimes take a second to change the station. Th box can't render the image until it receives a keyframe.)
A little explanation of keyframes...
If you don't know what a keyframe is, you need to understand a little about video compression. An uncompressed video would store the complete image for each frame. So, 30 frames would be the equivalent of jpgs (or other image format).
One of the larges gains in compression comes when, instead of storing the complete image in each frame, you only store the information that was different. For example, if you have a static scene and a ball flies through it, you only have to describe the path of the ball.
There are many rules for this calculation. Some of the rules are philosophically similar to the manner in which traditional animators layered cels above a static background. Other rules more resemble the way William Kentridge modifies the previous frame in his charcoal animation by panning, erasing, or drawing over.
Here is a good explanation of the mpeg-4 standard