Wednesday, 27 February 2013

After Effects to Avidemux - Datamosh Round Trip

This tutorial for shows you how to export video prepared for datamoshing from After Effects, join clips and remove I-frames in Avidemux (freeware) to create the datamosh, then export the result as an image sequence for further processing in After Effects.

Thanks to datamosher on YouTube for his video tutorial on the process.

The datamosh effect makes use of GOP (group of pictures) structured video coding. The GOPs are made up of I-frames, P-frames and B-frames. The I-frames contain the full image and do not require any additional information to reconstruct them but the P and B-frames contain only difference information which need to reference the previous frame to be decoded correctly. The datamosh effect is produced when an I-frame is removed and the subsiquent P and B-frames are decoded incorrectly.

For this tutorial, I made two clips in After Effects, one some random colour blocks and another some basic text animation. In the mosh, the motion of the text animation will be applied to the final frame of the colour blocks. You can download the clips to follow along here.

First, we need to export the video clips. They should be of matching resolution.
Use the work area handles to select your first clip and select Composition, Add to Render Queue.

Now, in the Output Module Settings, select Format, H.264.

Next, under H.264 Options, go to Advanced Settings and set the keyframe distance to 300 frames. Then click OK, set your output destination and Render.

Do the same for your second clip.

Now open Avidemux 2.5.6. Don't use a later version as it doesn't allow exporting of image sequences which is required for the return trip to AE.
Now, in Avidemux, Open your first clip.  Two dialogue boxes will pop up, click no in each case.

With the first clip open, click Append. The same dialogue boxes will pop up, click no again.

Now we need to navigate to the I-frames in the middle of the clip. Do not delete the first I-frame of the sequence.  To navigate to the I-frames, use the double arrow navigation buttons at the bottom of the screen. You will see the Frame Type readout display 'Frame Type: I' when the playhead is at the I-frame. Next use the A and B buttons to set an in and out point around the I-frame. Now go to Edit and Delete.
Search for any more I-frames and delete them so that only the first I-frame remains.

You may use the Edit; Cut, Copy, Paste and Delete options to move frames around and create more advanced edits if you wish.

Now go to File and Save Video. Choose a location and name your file with the extension '.avi'.

Now you may reopen that file in Avidemux and upon playing, you should find that the datamosh has been applied. Next go to Save and Save Selection as JPEG Images. Now create a folder for your image sequence and click save.

Now that the image sequence has been saved you may reimport your image sequence to After Effects for further processing.  Go to Import, and select the first image of the sequence, ticking the JPEG Sequence box before opening.

And here is the final result with sound courtesy of Stefan Blomeier.