Home

Code

Writings

Presentations

Terms of Use

FAQ

Contact

Español

iRaccoonShow

Embedding Movies with SWFtools

Embedding Movies with SWFTools

Introduction

[This explanation assumes some knowledge of the SWFTools. If you don’t have any, reading this will not be a good starting point to learn how to use them. And I wonder whether it makes sense to read this if SWFTools cannot be useful to you. Caveat lector.]

I add video to some presentations I do. Because it is not straightforward (at least to me ;-)), I will describe here how to do it, so it might help others and myself, because I tend to forget.

Before the method itself, you should consider the following issues:

Streaming video is a better solution when you want to show something longer than a video snippet. Embedding is a better method when you need the presentation in only one file.

For those concerned with copyright issues, quoting used to be considered fair use. When things went digital, some copyright maximalists and lawmakers influenced by them seemed to understand that fair use was a bug, but it is actually a free speech feature.

Preparing the Movie

AFAIK, swfc can only embed SWF files. You have to convert the movie snippets into Flash format to be able to embed them.

There are many tools that can do the job. I use ffmpeg.

The most basic command reads:

ffmpeg -i input.avi output.swf

And if you want to convert only a snippet, setting the frame rate and maintaining the same quality, here is the command:

ffmpeg -i input.avi -ss 152 -t 10 -r 50 -sameq video-snippet.swf

-r sets the frame rate to the number you want. --ss sets the starting time in seconds (format hh:mm:ss.xxx is also allowed) and -t the duration of the snippet in the source video; in previous example, snippet will take from second 152 to second 162 from the original video. -sameq preserves the same video quality as the source.

If you have different source videos with different frame rates, you have to set both the video snippets and the master SWF file to the highest frame rate. So all videos will be set and played at the same frame rate.

Embedding the Video

To embed the snippet you need the following swfc code:

.flash filename="video-slide.swf" bbox=841x545 version=7
.swf movie "video-snippet.swf"
.frame 1
     .put movie
     .stop
     .action:
         movie._x = (Stage.width - movie._width) / 2;
         movie._y = (Stage.height - movie._height) / 2;
     .end
.frame 2
     .del movie
.end

The ActionScript code included above doesn’t work with Flash versions prior to 7.

It is important to create a Flash file that has the same width and height than the SWF that we want to insert the video snippet. Otherwise, video will be resized when inserted in the presentation, although centering will work.

Background color, frame rate and Flash version are properties that are to be set in the final Flash file. You can set them in the video slide and in the presentation, but if you use a viewer, you will have to set there again. This doesn’t mean that the video snippet doesn’t require the right frame rate (as explained above).

Inserting into a Presentation

Having a video slide is good to show only the video slide, but it isn’t very useful. Inserting it in a presentation makes sense as a video quote.

The way to insert the video slide into a presentation is to replace one of the slides of the presentation with the video slide, using the following command:

swfcombine presentation.swf -f "#2"=video-slide.swf -m -o video-presentation.swf

-f "#framenumber"=video-slide.swf can be used as many times as required to add as many videos as desired. -m is mandatory to avoid video being played in previous slides if you return to them. -o sets the file name of the output file.

This cannot be the final presentation, because it would be hardly watchable, since the Flash file must have set the frame rate to 25 fps (or the highest rate of any of the videos). You need a browsing method.

There are complete presentations (such as this), but this may be too complicated or may not suit your needs. A basic method is to add a viewer, as in the following command:

swfcombine -o final-presentation.swf /usr/share/swftools/swfs/keyboard_viewer.swf -r 50 -F 7 viewport=video-presentation.swf

-r fps should be set to the frame rate set for the video snippet and -F version should be set to 7 or above (otherwise centering won’t work). Resizing the viewer works with -X width and -Y height (values can be obtained from swfbbox video-presentation.swf).

And you have the final presentation with the embedded video snippet.

Acknowledgments

I would like to thank to Matthias Kramm for the original script and his outstanding work with SWFTools.

Both Chris Pugh and Ricardo Pedroso are to be thanked for their patience correcting my buggy version of the script and explaining the errors.

Questions?

If you have questions about this method, the best way to solve them is to subscribe to the SWFTools mailing list and ask your question there.

I’m subscribed to the list and I will try to solve the issues related to the matter explained here. I’m afraid I lack both time an expertise, so don’t expect much from me.

Last updated: 10/02/2011, 19:36

© 2008–2010 Pablo Rodríguez. Some rights reserved