Showing posts with label video effect. Show all posts
Showing posts with label video effect. Show all posts

Saturday, March 14, 2009

motion stabilization tutorial

After reading Jacob's post today:
http://jakedth.tumblr.com/post/85794790/cinelerra-cv-motion-tracking-tutorial

I realized I never mastered a repeatable method to stabilize shakey video using Cinelerra's motion tracking tool. The Motion effect is very powerful, but also difficult to understand. At least for me. In addition, the manual isn't much help because it is couched in confusing terminology.

The motion tracker can do a lot of different things. However in this post, I am going to keep it simple and only describe how to stabilize shakey video. I made it easy for myself and chose a sample piece of video that bounces around pretty badly:


This movement left and right and up and down is called Translation. Or to a programmer, movement on the Cartesian Coordination System. Before we get into further discussion, familiarize yourself with what the manual says about the motion tracker:
http://heroinewarrior.com/cinelerra/cinelerra.html#MOTION

What You Need to Make It Work
Since the manual's description of motion tracking is cryptic, I'm going to try to clarify the muddy waters. In order to stabilize a section of video, you're going to need a few things:
1) a easily identifiable object in your video that will be used to track motion
2) a box that encircles that object. The following is important: this box needs to be wide and tall enough to encompass the range of motion of the shakey video.
3) a video track (master layer) with the range of motion that needs to be stabilized
4) a video track (target layer) that will be stabilized

I would suggest starting small. Just try stabilization with a clip of video that is short (<10seconds) and needs stabilization throughout.

Step 1: Apply the motion effect to the video track you want to stabilize
Like so:


Step 2: Open the Motion tracker effect dialog.
In order to simplify the configuration process for the motion tracker, I've divided the configuration box into the only three sections you'll need to worry about:


Step 3: Enable Draw Vectors (in Section 2 of the graphic above)
You may leave Track Single Frame selected. Also, Frame Number set to 0 means that the motion tracking of your video will start at the beginning of the timeline.

Step 4: Use Translation Block and Search Radius and Block X/Y to fit a box around an easily identifiable object in your video that will be used to track motion (in Section 1 of the graphic above)

In the above picture, you'll notice there are two boxes around the Budweiser sign. The center box around the Budweiser sign is the Translation Block. You'll make the Translation Block fit neatly around the object you're tracking. The outer box is the Translation Search Radius. For the purpose of this tutorial, we'll make the Translation Block always fit within the Translation Search Radius. Below is a graphic depicting these components:


The Translation Search Radius needs to be as large as the range of motion of the video. In other words, the Search Radius needs to be large enough to accommodate all the shaking of your video. If the shaking extends beyond that box, strange things happen, like the motion tracker will start tracking another object in your video. Remember that.

Finally, Block X and Block Y represent the X/Y coordinate location of where you will move your Translation Search Radius.

In sum, you will configure those objects just discussed in the Motion Tracker effect dialog. To review:
1) Encircle the object you want to track with the Translation Block
2) Encompass the entire range of motion of your shakey video inside the Translation Search Radius
3) Use the Block X and Block Y coordinates to move the Translation Search Radius (including the Translation Block) around the screen

It is cumbersome to move the boxes around and X/Y coordinate plane using a round dial. The Translation Block and Search Radius should be drag and drop. The motion tracker interface can definitely be improved upon in this respect.

Step 5: In Section 3 of the Motion config screen, set Action to Track Pixel and set Calculation to Save Coordinates to /tmp
The reason why we do this is that we are going to Track the motion of the video around our selected object (the Translation Block). The coordinates of the movement will be saved in temporary files, which we will later apply to a second track.

You may now either playback the video or render out a test video to see the results of the motion tracking. As the motion effect is very CPU intensive, I would recommend just doing a few seconds of playback or rendering, just to make sure the motion tracker is working properly. I also recommend rendering to a file, as it will be at the same speed as a playback, but will also give you some output that you can replay at will.

Reviewing Vector Paths and Translation Block object
Once you've rendered out a test file, review the vector path to make sure the Motion tracker is always centered on the Translation Block, the object you want to track. I have found that the Motion tracker is easily confused if the object you've chosen to track is a similar color to the background. You'll know it loses track when the arrow on one end of the vector path no longer points to the original object in your translation block.

Also, the Motion tracker will lose track if the Translation Search Radius is not wide enough to capture the entire range of motion of the camera movement. In my Budweiser example, I found that I needed to widen Search Radius to more than half the width of the video so that the Motion tracker would stay on track.

Step 6: In the Motion effect on the original track, deselect Draw Vectors, set Action to Stabilize Pixel and set Calculation to Load Coordinates from /tmp


Step 7: Make a duplicate of your original track
Once you have good motion tracking, you will then be able to apply your saved coordinates to another track or Target Layer. In my Budweiser example, I simply made a duplicate of the track that I generated the coordinates from. One way to make a duplicate of the original track is to:
* in the patch bay of the original track, set both the playback and record to on
* select the entire track (key "a")
* press "c" for copy
* create a new video track (Shift-T)
* in the patch bay of the new track, make sure playback and record are both set to on
* press "v" for paste

This procedure *should* copy the motion effect as well, with the settings from Step 6. If the settings from Step 6 are not in the Motion effect dialog, manually set them.


Step 8: Set the original track to not playback.
The Target Layer (duplicated track) should already be set to playback from the last step.


Step 9: Playback or Render the Video
Again, I suggest to render out the video to a file, as playing back or rendering will take the same amount of time.

Step 10: Analyze your results
You'll find that with motion stabilization, your video will tend to bounce around and you'll see black borders appear along with the motion removal. The easiest way to remove them is to experiment with different zoom levels (Z axis levels) using the Projector (NOT the Camera). For my Budweiser video, I found I needed to zoom in 1.6x. Of course, the side effect is that it may ruin whatever cinematic effect you were trying to achieve. So be advised!

Here were my results from earlier today:
1) The original video:


2) Motion vectors being generated to /tmp:


3) Motion stabilized


4) Video zoomed in to crop after stabilization. Note this crops out most of the interesting content of the video:


Advanced Use
I had a second video that bounced around quite a bit:


This time, I followed my own directions from above, but the resulting video came out jittery and jumpy:


Therefore, I increased the sensitivity of the Motion tracker by increasing Translation Search Steps from 256 to 1024:


This still was not sufficient, as I saw a couple jitters and jumps. I increased Translation Search Steps from 1024 to 8196. Be advised that this took about four times as long to render as having Translation Search Steps set to 1024. But it did remove the jitters and jumps!


The final outcome..sweet!


Enjoy!
The Mule

Thursday, November 06, 2008

converting 1080p video, part III

Here is another experiment in order to justify my planned expenditure of $4000 on the Canon EOS 5D Mark II. Down the road of doom I plod, unabated in my quest.

If I am to get the new Canon, I will be integrating some of its video along with video from my current 720p cam, the JVC HD10U. Therefore as a test, I threw some test 1080p video from the Canon and output from my JVC together on the timeline in Cinelerra.

Upconvert 720p or Downconvert 1080p?
For the time being, I don't want to upconvert the 720p video. Instead, I reduced the 1080p's resolution (downrezzed) in Cinelerra. This makes more sense from a practical point of view, as rendering 1080p video in its pure, unadulterated state will surely:
1) increase my storage needs
2) increase the time to render final output

In the future, after I have a few bucks lying around to spend on a next generation dual, quad core with terabytes of disk and a bluray writer, I will then start rendering final videos to 1080p format.

Integrating the two videos
Back to the task at hand, I put the mjpeg conversion of the 1080p video from my last 1080p blog entry on the timeline, along with another video I recently finished:


I set my project format to 720P:


This reduced the size of the 1080P track in the Compositor:


I could see that I only had part of the 1080p video displayed, I used a calculator to find the ratio between 1280 and 1920 pixels:
1280/1920 = .6667

In the Compositor window, I entered this percentage into the Z-Axis of the Projector's "Show Tool Info" screen:


This effectively "zoomed out" on the 1080p video track so that the entire frame is now shown:


Now, both tracks of the video are for all intents and purposes, 720P. If interested, I've put the downrezzed video (3.2MB) here for you to check out.

Please forgive the lousy quality of the 720p track, but the JVC is really horrible in low light..another reason why I want to get the Canon.

Update 11/9/2008
One thing I neglected to mention is that the frame rate of the 1080p track from the Canon is 30fps, whereas the 720p video track from my JVC is 29.97. In order to accurately merge these two tracks into my 720p project, I will need to apply the Decimate video effect in Cinelerra. Decimate drops frames from a video track. It takes an input frame rate of a higher fps and uses the project's lower frame rate as output. In this case, I want to lower the frame rate of the Canon's track from 30 down to 29.97fps. So the input rate would be 30fps and the output is the frame rate of the project, 29.97 fps.

As noted in the Cinelerra documentation, always place computationally intensive effects AFTER the Decimate effect, as those effects will be rendered at the lower frame rate, thus using less CPU cycles.

Using Decimate, I can now be assured that I will have no synchronization problems when merging 1080p and 720p video.
end update

Tally ho!
the mule

Tuesday, October 28, 2008

converting 1080p video, part II

A couple nights back, I spent a few hours finding a usable intermediate format for 1080P video editing. Of course, my goal was to prove that I can still use my preferred NLE Cinelerra in order to edit the gorgeous, high definition output from the Canon EOS 5D Mark II. An alternative way of putting it is that this is my justification for purchasing what will amount to a $4000 camera!

Import: which format works well?
Since Cinelerra is rather picky about the types of video it accepts (see my original Quicktime compatability document), it was a challenge to find a Cinelerra-editable intermediate format for that test 1080p video I told you about in the first part of this two-part blog entry. The video is a five-second city scene of a bicycler launching from a stop. That video is 23MB.

Keep in mind that various versions of media encoders (like ffmpeg and mplayer) do not always implement codecs and container formats consistently. Also, program dependencies for the encoders across different Linux distros complicate matters. So what I state as working below may not work for you. (Your mileage may vary). Note that I am currently using Fedora 7, 64-bit.

Caveats aside, transcoding the biker video to the following formats did NOT work:
- I420 from ffmpeg
- rawvideo (RAW YV12) from ffmpeg

Here are a couple formats that did work:
1) MJPEG output from ffmpeg
2) RAW YV12 output from mplayer

MJPEG from FFmpeg
Playback Performance
This format seems to be a likely candidate, as I got about 15fps on my dual, quad core Dell SC1430 in Cinelerra.

File Size
The resulting file size is small..about 35MB for five seconds of 1080P.

Image Quality Compared to Original
The image quality is very good. However, the colors seem bit oversaturated and dark in contrast to the original. With a bit of tweaking to the conversion command, I might be able to get more realistic colors out of the conversion. Here's a comparison shot:


Editing Notes
No problems surfaced with a couple initial edits and renderings. As this is a compressed format, there will be some loss of quality over successive encodings.

Here is the command I used to convert the video:
ffmpeg -i Video1.MOV -b 3000k -vcodec mjpeg -ab 256k -ar 44100 -acodec mpeg4aac -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me hex -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 testmjpeg.mov

This is the same conversion command that I ran in part I of this blog entry.

Information about the file looks like this in mplayer:
Playing testmjpeg.mov. ISO: File Type Major Brand: Original QuickTime Quicktime/MOV file format detected. [mov] Video stream found, -vid 0 VIDEO: [jpeg] 1920x1080 24bpp 30.000 fps 0.0 kbps ( 0.0 kbyte/s) ========================================================================== Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family Selected video codec: [ffmjpeg] vfm: ffmpeg (FFmpeg MJPEG decoder) ==========================================================================


RAWYV12 from mplayer
Playback Performance
Playback is slow, 7fps, roughly 1/2 the speed of MJPEG. Not a show stopper.

File Size
Huge. About 450MB for about five seconds of video. Woah!

Image Quality Compared to Original
Image quality is very good as well. Less saturated then the mjpeg version. That's what almost 100MB/sec pays for.


Editing Notes
This is an uncompressed format, corresponding to the YUV 4:2:0 spec:
http://en.wikipedia.org/wiki/YUV#Y.27UV420p_.28and_Y.27V12.29

Also, here is an excellent article on understanding color sampling:
http://www.dvxuser.com/articles/colorspace/

Cinelerra loads the raw YV12 file, but the timeline does not show thumbnails. Not a show stopper, but a bit of a bummer. The one benefit of yuv4mpeg stream from mplayer is that you can feed that stream directly into mjpegtools for further processing.

Update 2008/11/22
It seems that 1080p in raw yuv format is actually unusable in my Fedora 9 Cinelerra install. When I load a project with a large raw yuv file, Cinelerra hangs for ten minutes as it loads the file. Once loaded, the GUI tends to freeze for another ten minutes. Thus, it seems that MJPEG may be my only choice for rendering 1080p.

I will continue to experiment.
end update

Here is the command I used to convert the video:
mplayer Video1.MOV -vo yuv4mpeg

I received this message while trying to convert the video
************************************************
**** Your system is too SLOW to play this! ****
************************************************
Possible reasons, problems, workarounds:
- Most common: broken/buggy _audio_ driver
- Try -ao sdl or use the OSS emulation of ALSA.
- Experiment with different values for -autosync, 30 is a good start.

So, I amended my command to add the autosync feature, which gradually adjusts the audio/video synchronization based on audio delay:
mplayer Video1.MOV -autosync 30 -vo yuv4mpeg

That seemed to alleviate the messages. Without redirecting to a specified filename, Mplayer outputs a file called "stream.yuv".

Information about the file looks like this in mplayer:
Playing stream.yuv. YUV4MPEG2 file format detected. YUV4MPEG2 Video stream 0 size: display: 1920x1080, codec: 1920x1080 VIDEO: [YV12] 1920x1080 12bpp 30.000 fps 0.0 kbps ( 0.0 kbyte/s) ========================================================================== Opening video decoder: [raw] RAW Uncompressed Video VDec: vo config request - 1920 x 1080 (preferred colorspace: Planar YV12) VDec: using Planar YV12 as output csp (no 0) Movie-Aspect is 1.78:1 - prescaling to correct movie aspect. VO: [xv] 1920x1080 => 1920x1080 Planar YV12 [ASPECT] Warning: No suitable new res found! [ASPECT] Warning: No suitable new res found! Selected video codec: [rawyv12] vfm: raw (RAW YV12) ==========================================================================

Quality
There seem to be quite a difference in the colors rendered by each format. The MJPEG-formatted file seems to much closer to the original than the raw YV12.

Applying Effects

For fun, I applied an oil painting effect to this five seconds of video. I then rendered the output to MJPEG format. I was disappointed to find out that five seconds of video with the oil paint effect applied takes a full three minutes and twenty seconds to render at 1080p in my dual, quad core Dell SC1430. Holy cow! I guess I won't be doing Star Wars green screens in 1080p!


In the interest of full disclosure, the oil paint effect is a notorious CPU hog and is not indicative of the type of work the average editor will perform. Another note: while rendering the output, all eight CPUs were maxed out at 95% utilization. Kowabunga!

To give people hope, applying a simple title to the image doesn't do too much damage to load on the CPU. The video with a title rendered to MJPEG format took twenty seconds.

Thoughts
My goal is to get some really fantastic looking video rendered from Cinelerra. In combination with the new Canon and some wise encoding choices, I believe I should be able to do this. This article shows that I'm getting closer, but I'm not there yet. I'm hoping to get closer with another round of experimentation.

One final thing..be ready to spend money on RAM. I noticed my paltry 2GB was immediately sucked up by Cinelerra when I was doing these various test videos. I'm going to get another 4GB and will let you know if that helps.

more to come.
The Mule

Friday, March 16, 2007

grungy, grainy video effect

I wanted to degrade a video to black and white and give it a grainy effect. Here's what I started with:


I then used the following settings to extract the color from the image:


The image then looked like this:


I then applied a histogram effect, tweaking the red/blue/green channels only allowing the higher frequencies:



To give the image a grainy look:


However, the grains looked too sharp, so I applied a blur using a pixel width of 8:


To this result:


Here's a test video (4.7MB):
test video

The next experiment will tweak the audio for additional weirdness.

Sunday, March 04, 2007

perspective effect used for titles

To begin a recent video, I wanted to simulate the Star Wars introductory title trick, where the titles start close and then fade off into the distance. To do this, I used the Perspective effect. I began with a very simple scrolling title. Note that a Motion Type of "Bottom to Top" is selected, as well as a speed to provide the motion:



I began the experiment with a very plain title:


I then applied the Perspective effect to the title:



And clicked on the magnifying glass to start playing around with the parameters of the effect:


The grid shown represents a flat, two-dimensional space, but grabbing and moving each of the four corners of the grid will create the illusion of three-dimensional space:


Note in the above image that the lower grid corners have been pulled and stretched wider than the dialog box in order for the titles to be really stretched. This enhances the perception of depth, as shown below:


It is extremely effective to apply the perspective effect in combination with some motion. Here is the final result:
perspective_test.mpg
23MB

Wednesday, January 31, 2007

using the histogram function to turn on the light

Wow. I used the histogram function to lighten up a dark video. It really did wonders. I simply changed the Value parameter as in the graphic below:


Here are the results. Before applying histogram:

After applying histogram:


Test videos:
Before
(3Mb)
After
(4Mb)

Reference
Here are two articles on histograms and their purpose. The second taught me a great deal:
http://en.wikipedia.org/wiki/Image_histogram
http://www.illustratedphotography.com/photography-tips/basic/contrast

Wednesday, November 29, 2006

very simple interpolate effect experiment

I wanted to use the interpolate effect to mimic motion, or at least generate a smooth flow between static images. I thought I might be able to use this effect for video overlays and such.

For the experiment, I used four png images, each with a green dot near the center of each image. For each image, I moved the dot a bit so that the arrangement of the four images on the Cinelerra timeline would show a circle of green dots when played back. First, I imported each still frame into a Cinelerra project formatted to 30fps and 320x180. Then, I stretched each png to the length of 30 frames using the "align cursor on frames" option and then re-added the first png image to the end of the timeline in order to complete the circle of dots. Finally, I added the interpolate effect with an "input frames per second" value of 1.

Here is the resultant video with no interpolate effect (17Kb).

Here is the video with the interpolate effect applied (38Kb).

It does mimic movement, but is not very interesting just yet. I will try to add motion blurs to enhance this.

Monday, October 30, 2006

motion experiment, part III

Update 2009/03/17
I finally put together a motion stabilization tutorial. Hopefully, it helps folks who are as confused as I using the thing.
*** end update ***

The motion stabilizer is one of the most difficult effects to use in Cinelerra, as it has so many knobs and switches to figure out. It is very frustrating.

I had more luck this time with the motion effect, but it was still very hard to get working correctly. I kept playing around with different settings, but ended up using these:
- translation block around 1/6 of entire screen
- translation block more wide than high (400x150)
- track single frame
- stabilize subpixel
- zoom set to auto in compositor

Once I did get it working, I thought I did have a better feel for how the different parts interact. But the motion effect seems to be is something you have to spend a LOT of time with to get working correctly. It is still frustrating, though.

Here is the fruit of my labor:
http://content.serveftp.net/video/cinlover.mpg
Here was the original:
http://content.serveftp.net/video/cinlover2.mpg
both about 3MB

I definetly think the motion is better stabilized.

I will try to post a more detailed description of the steps I went through. Perhaps even a video, as motion stabilization is a real art. I wish it could be simplified in the software.

the mule

Thursday, October 19, 2006

motion experiment, part II

Update 2009/03/17
I finally put together a motion stabilization tutorial. Hopefully, it helps folks who are as confused as I using the thing.
*** end update ***

I was able to get a better result from the video I made a while back. I realized I did not use the "Previous Frame Same Block" option originally. This made a huge difference. As I didn't have much time to fuss with it, I lowered the translation search steps to 128 as you suggest.

Here are my results with comparison of before, after and zoom. The video is very compressed, but you can see that the zoom doesn't degrade too badly, as my source is HDV, which is something you'd be interested in seeing:
http://content.serveftp.net/video/motionexercise.m2v
7MB

Here's the next in the series:
/2006/10/motion-experiment-part-iii.html

Thursday, September 21, 2006

first split screen..

I used the projector and camera automation to do my first split screen today:
split.mpg
670K

Tuesday, August 29, 2006

smooth scrolling credits for Cinelerra

An easy way to simulate scrolling credits is to use a very long jpeg or png image and use camera automation in order to scroll from the top part of the image all the way to the bottom of it. The one issue that has been called out on the Cinelerra boards is that the default camera automation is done using bezier curves. So, what'd you'd see by taking the defaults is that the scrolling would quicken at the beginning and the end of the automation, but be somewhat linear in the middle. The steps below show how to straighten out the curves in order to make the scrolling linear from beginning to end; in other words, a constant rate of scrolling all the way through the automation. Thanks to Nicolas from Paris for the directions!

- turn on the X and Y camera position indicators in the View menu
- click on the "Generate keyframes while tweaking" small key icon in the Timeline or Compositor
- for the scroll beginning, modify the Y position of the camera, in the compositor window. You can also click the "?" icon to enter the value directly
- at the end of the scroll, click and then I go back 1 frame to edit the Y camera position again
- go back to the main window and select "Camera Y" in the view menu.
- type "Alt-F" to modify the "Camera Y" green line height to see it entirely on the video track
- click on the start keyframe while typing "CTRL" to modify the keyframe curve slope
- do the same for the end keyframe in order to get a straight line between the start and end keyframes

After tweaking the settings, the scroll speed becomes nice and linear.

Saturday, August 26, 2006

blurred title

Boy, does that blur effect take forever in Cinelerra. And my box isn't a slouch: P4, 3.2Ghz, 2GB of 400DDR. For this short, four second video, it took 4.5 minutes to apply the blur effect on the title at DVD resolution using YUV4MPEG & FFMPEG. Ridiculous. Here it is though:
blurred title

Baby steps, I tell myself.

Tuesday, May 09, 2006

chroma key test

Seems my camera does a better job with blue colors than green colors for chroma blue/green screen fun. Here's an example of using a blue pillow case for a chroma key background. Kinda came out well, minus the blue border around my hair!
http://content.serveftp.net/video/chromaTest2.mpg
3.3MB

Saturday, March 25, 2006

motion stabilization effect experiment

Update 2009/03/17
I finally put together a motion stabilization tutorial. Hopefully, it helps folks who are as confused as I using the thing.
*** end update ***

Tonight, I used Cinelerra's motion tracker to stabilize a section of shakey video. The source was some sunset footage taken in high wind. The wind was so blustery that the camera and tripod were shaking. Cinelerra's motion stabilization saved the day, though.

Here is the video before motion stabilization
Here is the video after motion stabilization applied
(both vids ~7MB)

Pretty good, no?

Update:
Here's the next in the series:
/2006/10/motion-experiment-part-ii.html