VideoHelp Forum




+ Reply to Thread
Results 1 to 5 of 5
  1. Member
    Join Date
    Jan 2009
    Location
    United States
    Search Comp PM
    I've been interested in this for some time now, and recently have figured out some neat (to me at least) things I can create for my own home movie dvds. I thought I'd create a thread where I can share this with the forum and also see what ideas others might have on the same topic. I'll start off with more basic options in this first post (banners/titles/credits), and will follow up with more advanced ideas like creating your own transitions from scratch, screen in screen, and others.

    Note: My camera takes videos that are 640x480 in frame size, and the dvds I make are in NTSC format 720x480. All examples I provide assume these specifications, but it shouldn't be too hard to translate this to your specific situation.

    Banners/Titles: I like to include a short title segment before each of my home movies. Of course, there are a number of editing suites in Linux which will do this for you, but this is about making your own. The easiest way I know to do this is to use dvd-slideshow. I create an all black png image and type the title information in large white font on the image using gimp (I store the original in xcf format as well just in case I want to make edits). Then I use dvd-slideshow to turn the png image into dvd video. To make things work best, you should make sure the format of your dvd encoded movie file and the title segment you are creating will match up (same frame rate, size, audio codec, audio bitrate, etc). You can either change how you encode your movies, or the settings in dvd-slideshow, or both to make these match. In my case, I ended up editing the dvd-slideshow bash file and changing the applicable switch on the ffmpeg line from “-ac 6” to “-ac 2” so it would create stereo ac3 audio instead of 6 channel ac3. There is no one right way to do this, so long as both dvd ready files will match up so you can append them in avidemux later. Here is an example of a dvd-slideshow input file to create a title segment:
    Code:
    background:0::black 
    fadein:0.5 
    title.png:2 
    fadeout:0.5
    This will start with a black frame, fade the credits in, and then fade back to pure black. Since the background of the credits page is also black, only the credits themselves will fade in and out. The only problem now is that if you append this in front of your home movie file you will have a rather abrupt transition from a black screen to the first frame of your video. There are many ways to handle this (more below), but one quick and easy way is to use the fade in filter in avidemux to have the first 15 or so frames fade from black when you encode your home movie to dvd format. Once you have both your title segment and your movie segment coded, you can then join them together with avidemux. First open the title segment, and then select File/Append and have avidemux append the dvd-movie file. From here all you have to do is make sure the video & audio settings are set to “ copy”, and set the format to “mpeg-ps” and save the combined video using a new name.

    Two quick notes on opening dvd-slideshow generated files with avidemux:
    if you create a dvd encoded file that is less than 35 frames, avidemux will give you an error when you try to open it. The segment created above is 2 seconds long so it won't present a problem. However, if you start working with very short transitions (right around 1 sec or less) you could run into this issue. Also, when avidemux first opens an mpeg file it creates an index for that file. If you create a new vob with with the same name as one you have already opened with avidemux, you need to delete the old .idx file before opening it with avidemux or the video will appear as if it was corrupt because it opened the file using the old .idx file. If you have problems opening a dvd-slideshow file with avidemux, first check for these two issues.

    The title segment above is pretty snappy, but after I started doing this of course I wanted more. Why not crossfade from the title.png to the first frame of the video? Avidemux will let you export any frame of a video as either a jpeg or bmp file, so I tried this out with a bmp of the first frame of a video which had already been encoded in dvd format. First I had to open the bmp file in gimp and then save it as a .png file so dvd-slideshow could handle it. Then I ran dvd-slideshow, crossfading from my title image to the first frame in the video:
    Code:
    background:0::black
    fadein:.5 
    title.png:2 
    crossfade:1
    firstframe.png:0.534   
    #(0.034 seconds creates a single frame at 29.97 fps.  See note on timing below.)
    Unfortunately, once I mated the two files up in avidemux I found out that dvd-slideshow changed the shape of the first frame so it didn't match up (try this to see what I mean). This gave a nice smooth fade, followed by an abrupt wobbly transition to the moving video. After playing with this for a while, it turns out there is a simple fix for this; stretch the firstframe.png file so it is 112% of its original height, leaving the width alone. After using gimp to stretch the png image to 720x538 pixels, it works perfectly! You can also use the other transition option in dvd-slideshow (wipe) the same way if you want, and have the movie push aside the title screen.

    Introductory & Final Credits: These are very much like the title segments, but I like to do something a little different here. One thing that looks nice is to create one image with just a title like “Credits” at the top, and another copy of the same image with the credits included below. Then you can crossfade from the bare “credits” page to the one with the credit information included. If you have multiple credits pages you can use this to fade the credits themselves in and out while having the title “credits” remain on the screen the entire time.

    Having text fly in from the distance (or fly out if you wish): Start with a 720x480 (or 720x538 if you wish) black image, and center “Created with Linux” on the page with large white font, naming the file “linux.png”. Next, resize the canvas to 10x the original size, (7200x4800) and create a new black layer background to fill in the new canvas space and name this “big_linux.png”. This will cause your original text to look tiny when you view the entire image. Then use the dvd-slideshow kenburns feature to make the phrase fly in:
    Code:
    background:0::black
    fadein:.5 
    big_linux.png:.534 
    big_linux.png:.5::kenburns:100%;middle;10%;middle 
    linux.png:4  
    #you could also use the big version with “::crop:10%;middle” to hold the zoom.
    fadeout:.5
    You can do the same fly in/out effect with a frame from a movie as well. Lets say this time you want to start with the first frame of your unprocessed video file named “firstframe.bmp”. Since my unprocessed movies are 640x480, I need to either stretch the image or add black bars to bring the width to 720. Then I need to stretch the height by 12% to account for the fact that dvd-slideshow resizes the height back down. You could do this with gimp, but here is how I do this with imagemagick (more on this great tool later). Run the following into the command lines in a folder where you placed the first frame of your unprocessed movie (titled firstframe.bmp):
    Code:
    convert -size 720x480 xc:black  black_im.png        # create an all black image 
    composite -gravity center firstframe.bmp black_im.png  firstframe.png  # Combine the first frame over the black image creating a new png file with bars.
    convert firstframe.png -resize 100%x112%  firstframe.png  #Stretch the image height to 12% taller.
    Now that we have the base image ready to go, we need to center it in a black background 10 times it's size:
    Code:
    convert -size 7200x5380 xc:black  big_black_im.png        # create a really big all black image 
    composite -gravity center firstframe.png big_black_im.png  big_firstframe.png   #center the frame in the big black image.
    Now you can use the following as the input file for dvd-slideshow to create a title segment using a zoom transition to the first frame of the video:
    Code:
    background:0::black 
    fadein:.5 
    title.png:3 
    fadeout:.5 
    background:0.409 
    crossfade:0.25 
    big_firstframe.png:.159 
    big_firstframe.png:1::kenburns:100%;middle;10%;middle
    Note on dvd-slideshow timing: Older versions of dvd-slideshow had a very straightforward way of parsing timing. All you had to do was enter the amount of time each line should generate in the slideshow. Starting with version 0.8, they changed this for reasons entirely unclear to me. Now the time for any transition line is subtracted equally from the time of the lines above and below it. This is pretty straightforward (but still unnecessarily complex) if you have a picture showing for 4 seconds with transition lines before and after it each lasting 1 second. What this means is the picture will only be shown for a total of 3 seconds, with .5 seconds devoted to each of the transition effects before and after it (for a total subtraction of 1 sec). In cases of an initial fade in or a final fadeout, the image line closest to the transition has the entire transition time deducted from it's playing time. So if you have an image at the end of the show with a 1 second crossfade before it and a 1 second fadeout after it, you would need to set the time for that image to 4.5 seconds to have it display for a total of 3 seconds.
    Quote Quote  
  2. Member
    Join Date
    Jan 2009
    Location
    United States
    Search Comp PM
    More advanced transitions and effects:All of the examples above relied on the transition or kenburns capability built into dvd-slideshow. But what if you want to make your own custom transitions or effects? This is very simple when you put the following three facts together:

    1)You can export every frame in a movie file to a series of images using either avidemux or ffmpeg.
    2)Imagemagick allows you to manipulate images in truly amazing ways from the command line.
    3)You can convert a series of image files into video using dvd-slideshow, avidemux, ffmpeg, or mencoder.

    Put another way; using a bash script, you can do anything with moving video that you can do to a single image file using imagemagick! For more information on imagemagick, check out this page on the command line options, as well as this page on use examples. This tool is really amazing, and what I'll show below will only scratch the surface!

    Creating a barn door wipe transition: I like the barn door wipe transition in Kino, but for reasons I won't go into now I would prefer to process my videos in avidemux. So I decided to “roll my own” barndoor wipe transition. We'll start with two images, title.png (black with white writing), and firstframe.png (the first frame of an unprocessed video). Both images are 640x480 in size (different than the examples above). To make the first frame of the video push in from the the sides over the title image, all you have to do is paste progressively skinnier crops of the title page centered over the first frame. The following script will generate the frames for this effect:
    Code:
    #!/bin/bash 
    tmpname=tmpcrop.png 
    ext=.png 
    startimage=title.png 
    endimage=firstframe.png 
    qual="100%" 
    
    echo "Creating the animation frames and the dvdslideshow text file." 
    percent=100 
    counter=0 
    while (( percent > 0 )) 
      do 
    	counter=$(($counter+1)) 
    	convert $startimage  -gravity center  -crop $percent%x100% -quality $qual  $tmpname 
    	composite -gravity center $tmpname $endimage -quality $qual frame$counter$ext 
    	percent=$(($percent-2)) 
      done
    The convert line crops the center portion of title.png and pastes them into a temporary file. Then the composite line combines the temporary file over the first frame of the video. As the width of the crop taken from the center of the title page shrinks, it generates the desired effect. This script is easy to read, but has the problem of adding an extra save of the cropped image to disk for every iteration of the loop. To speed this up, replace the convert and composite lines with the following line which does both steps without an extra write to disk:
    Code:
    convert -gravity center $endimage \( $startimage  -gravity center  -crop $percent%x100% +repage \) -composite -quality $qual frame$counter$ext
    The basic “barn door” formula above can be modified to create a number of other wipe transitions. If you switch “$percent%x100%” to “100%x$percent%”, the bars will come in from the top and bottom instead of the sides. If you change it to $percent on both, you will create a closing square. If you switch the positions of $startimage and $endimage and change the loop to count up from 0 to 100 instead of counting down, you will create a center bar transition. Change the center bar from vertical to horizontal by switching $percent and 100%. Or you can create an expanding plus sign by doing the center bar effect twice (once vertical, once horizontal) during each pass. Reverse the expanding plus sign and the closing square, and you get two more effects. Lastly, take the original barn door equation and change both instances of “center” to east, west, north, or south, and the new image will come in from the side, top, or bottom.

    After you run the script, you should have a series of images named frame1.png, frame2.png, etc. If you want to view them as a video, open the first frame in avidemux, and it will pull the rest in. From here you can add an audio track (even if it is just silence), and convert the video to whatever format you want (more on this later). One thing you will notice is the title page is only shown in full for one frame. To make this useful as a title frame you need to create additional video making the title page fade in and then hold for a few seconds before transitioning to the first frame of the video. Since dvd-slideshow can handle creating the initial fade in and display of the title frame, and also can convert the clip into dvd ready video and audio (silence), I use the following script to turn the whole thing into a title segment ready to be appended in front of the movie file. All you have to do is place this script in a folder containing the first frame of the video the title is for (named “ff.bmp”), the title.png image, and a text file named "slideshowstart.txt" (which contains the dvd-slideshow commands you want to fade in and display the title page) and run the script.
    Code:
    #!/bin/bash
    ext=.png
    startimage=title.png
    endimage=ff.bmp
    qual="100%"
    
    #check to see if title image and first frame exist.
         if [ ! -e $startimage ]; then
    	read -p "$startimage not found.  Exiting script."
    	exit 0
         fi #end if	[ ! -e $startimage ]
    
         if [ ! -e $endimage ]; then
    	read -p "$endimage not found.  Exiting script."
    	exit 0     
         fi #end if	[ ! -e $endimage ]
    
    #Make sure both input files are 720 x 538 pixels.  Add black bars on sides of the endimage if needed (in case image came from unprocessed avi file).
    convert $endimage -resize 100%x112% tmpimage1.png  #stretch the bmp to make it taller
    convert -size 720x538 xc:black tmp_black.png   #create an all black image
    composite -gravity center tmpimage1.png tmp_black.png  tmpimage2.png  #overlay the stretched image on the black image.  If it was less than 720, black bars will be appear.
    endimage=tmpimage2.png
    convert $startimage -resize 720x538! $startimage
    
    echo "Creating the animation frames and the dvdslideshow text file."
    vobname=title_barndoortrans
    percent=100
    counter=0
    while (( percent > 0 ))
      do
    	counter=$(($counter+1))
    	convert -gravity center $endimage \( $startimage  -gravity center  -crop $percent%x100% +repage \) -composite -quality $qual frame$counter$ext
    	echo "frame$counter$ext:0.034" >> tmp_dvdslideshow.txt
    	echo "Created frame$counter$ext"
    	percent=$(($percent-3))
      done
    
    
    #check to see if there are files with dvd-slideshow commands to be inserted first or last
         if [ -e slideshowstart.txt ]; then
    	echo "found dvd-slideshow commands for the front of the file"
    	cat slideshowstart.txt tmp_dvdslideshow.txt > tmp.txt
    	cat tmp.txt > tmp_dvdslideshow.txt
    	rm tmp.txt
         fi
         if [ -e slideshowend.txt ]; then
    	echo "found dvd-slideshow commands for the end of the file"
    	cat slideshowend.txt >> tmp_dvdslideshow.txt
         fi
    
    #Render the slideshow
    dvd-slideshow -n $vobname -f 'tmp_dvdslideshow.txt'
    
    # remove the old vob.idx file (if present), plus the dvd-slideshow log file, and the dvd-slideshow xml file and script temp files.
    echo "Cleaning up temporary files."
    rm $vobname.vob.idx
    rm $vobname.log
    rm $vobname.xml
    rm tmpimage1.png
    rm tmpimage2.png
    rm tmp_dvdslideshow.txt
    rm tmp_black.png
    
    #clean up the animation frames
    while (( counter > 0 ))
      do
    	rm frame$counter$ext
    	counter=$(($counter-1))
      done
    Creating a transition segment joining two videos: In the examples above all of the transitions have been coded to dvd-format to be attached to dvd-encoded files. I've found that this method doesn't work as well when joining two files for two reasons: 1) avidemux has problems opening very short dvd encoded files (< 35 frames). And 2) When you encode a video to dvd with avidemux the last frame in the dvd encoded file doesn't always match the last frame of the original file (I'm not sure why). In this example I'll show how to generate a transition without using dvd-slideshow. Start with two segments of unprocessed video named clip1 and clip2. You want to transition from the last frame of clip1 to the first frame of clip2. Extract the last frame of clip1 and the first frame of clip2, naming them “lfclip1.bmp” and “ffclip2.bmp”. Next, use one of the transition scripts outlined above to generate the frames that transition from lfclip1 to ffclip2. Once you have these frames, open frame1.png with avidemux, and it will bring the rest of the series in. Now add an audio track (I use a wav file of silence I generated in audacity), set the frame rate, and set the video codec to ffv1 and the audio codec to wav pcm and save the video as an avi. Now open clip1 and clip 2 (separately) and code each one as avis with the same video and audio codecs you just used for the transition file. Both of these codecs are (to my knowledge) lossless so this way all 3 clips end up in the same format without a lossy conversion. Now all you have to do is append all three together, and encode the whole thing to dvd format.

    Creating your own fade transition: If you aren't using dvd-slideshow, you may want to create your own crossfade script. Here is the key line to place within the script loop:
    Code:
    composite -blend $percent  -gravity center $endimage $startimage -matte -quality $Qual  frame$counter$ext
    Other effects: As I mentioned above, what I've shown here really just scratches the surface of what imagemagick allows you to do. For example, if you want to have a “picture in picture” movie, all you have to do is extract the frames from both movies and crop and resize (as needed) the frames you want to insert from movie A to movie B, and then use the compose command to place the result into each frame of movie B. You could probably also do a “green screen” or “blue screen” processing where you shoot your movie in front of a colored screen, and then convert that color into a transparency and then overlay the action over either a moving or stationary background. If you are interested in this, you might check out this page on the imagemagick use examples section. I'll close out this post with a command to make ffmpeg extract all of the frames of a video into png format.
    Code:
    ffmpeg -i movie.avi  images%05d.png
    I haven't yet learned how to use ffmpeg to turn the processed png frames into an avi video encoded as ffv1 and wav pcm yet, but once I do this I'll be able to further automate this process. If someone knows the proper ffmpeg command to do this conversion I would appreciate it if you would share it here!
    Quote Quote  
  3. Member
    Join Date
    Oct 2009
    Location
    United States
    Search Comp PM
    Mountain Man, you and I are doing much the same thing. I have found some ways to add some extra effects to my video titles by using Fred Weinhaus scripts. Here is a link to Fred's scripts http://www.fmwconcepts.com/imagemagick/index.php. I use Gimp and Fred's Glow script to make one of the title images. I will then use DVD-SLIDESHOW to convert it to a video. I will then use FFMPEG or AVIDEMUX to extract the images into folder. I will then use some more scripts to modify those images.
    Quote Quote  
  4. Member
    Join Date
    Jan 2009
    Location
    United States
    Search Comp PM
    Good link optrader, and also good to see I'm not the only one playing around with this! I suggest looking at those scripts even for those who plan on writing their own scripts (like me), because it gives a good idea of the breadth of what ImageMagick is capable of. I've been playing around with masks/transparency, and should have a script to do with moving video what he calls "Radial Gradient" on the Transitions page.
    Quote Quote  
  5. Member
    Join Date
    Jan 2009
    Location
    United States
    Search Comp PM
    In my posts above all of the transitions involved moving from one still frame to another, and a gui editor was needed for at least part of the processing. I've been working on this further, and this post will describe how to:
    • 1) Join two movie files together.
      2) With a transition involving moving video (not still images).
      3) All from the command line.
    This last part is important because if it can all be done via command line you can automate the whole process via bash script.

    We'll start assuming you have two video files you want to join together using one of the transitions described in my second post above. Ideally you have avoided any lossy conversions when editing these two files to this point. You should also be in a new directory since this process will create a number of files you will want to clean up later.

    Assuming you want to have the two files joined together with 1 second of transition, the first thing we need to do is break each file up into two parts; the main body of each file, and the 1 second clips which will be used for the transition. For file1 the body will be all of the file except the last second, and for file2 the body will be the entire file following the first second. Using ffmpeg, we can perform the cuts with the following commands:

    For file 1 (file1.avi):
    Code:
    #create a file with the last second of video.  
    # clip1starttime is expressed as hh:mm:ss.ss  and represents 1 second from the end of the file.
    #use ffmpeg -i file1.avi to see the duration of the file.  Then subtract 1 second.
    ffmpeg  -ss clip1starttime -i file1.avi  -vcodec ffv1 -acodec pcm_s16le -ar 44100 -ac 2  clip1.avi
    
    #create the body of the video (all but last second).
    ffmpeg -t clip1starttime -i file1.avi  -vcodec ffv1 -acodec pcm_s16le -ar 44100 -ac 2  body1.avi
    For file 2 (file2.avi):
    Code:
    #create a file with the first second of video
    ffmpeg -t 00:00:01.00 -i file2.avi  -vcodec ffv1 -acodec pcm_s16le -ar 44100 -ac 2  clip2.avi
    
    #create the body of the video (all but first second)
    ffmpeg  -ss 00:00:01.00 -i file2.avi  -vcodec ffv1 -acodec pcm_s16le -ar 44100 -ac 2  body2.avi
    Next use ffmpeg to extract the (roughly 30) images each from clip1 and clip2:
    Code:
    ffmpeg -i clip1.avi clip1_image%d.bmp
    ffmpeg -i clip2.avi clip2_image%d.bmp
    Now use one of the transition scripts referenced in my post above to create the desired transition effect (crossfade, barndoor wipe, etc). Since you will be working with two streams of images instead of two stills, you will need to modify the script slightly to handle this. Instead of having each iteration perform the operation using the same two files as inputs, you will want to walk through the two streams instead. So for the 10th iteration of the while loop, you will be operating on clip1_image10.bmp and clip2_image10.bmp. If this isn't clear, I will post some example scripts of moving video transitions in a future post which should help.
    Note: I'm using bitmap images here instead of png images because I've run into intermittent problems with ffmpeg not liking the png images imagemagick creates.

    Once you run your transition script, you will now have a stream of images representing the finished transition. We will use ffmpeg to convert this stream of images back into video shortly, but first we need to handle the audio track.

    First use ffmpeg to extract the audio tracks from clip1 and clip2 as wav files:
    Code:
    ffmpeg -i clip1.avi -acodec copy clip1.wav
    ffmpeg -i clip2.avi -acodec copy clip2.wav
    Now that we have both audio files, we want to create a single file which crossfades from one to the other. You can use SoX to do this from the command line with the following commands:
    Code:
    #Create a wave file with a straight line fade out of the audio from clip1.wav
    sox  clip1.wav  clip1fade.wav  fade  t   0 0 1
    #Create a wave file with a straight line fade in of the audio from clip2.wav
    sox  clip2.wav  clip2fade.wav  fade  t   1 0 0
    #Merge the two fade wave files into a single file named clipcomb.wav:
    sox -m clip1fade.wav clip2fade.wav clipcomb.wav
    Now you can use ffmpeg to convert the stream of images created earlier and clipcomb.wav into an avi file named transition.avi:
    Code:
    ffmpeg -r 29.97 -i frame%d.bmp -i clipcomb.wav -vcodec ffv1  -r 29.97 -s 720x480 -acodec copy   transition.avi
    All that is left to do is join body1.avi, transition.avi, and body2.avi together into a single avi file. You can do this with mencoder:
    Code:
    mencoder -oac copy -ovc copy body1.avi transition.avi body2.avi -o finalmovie.avi
    Thats all there is to it! You now have a completed avi file you can code to whatever format you want.



    Note on ffmpeg and file timing: You can pull the duration of a movie or wav file into a bash script using the following command:
    Code:
    duration=$(ffmpeg -i movie.avi 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,// )
    However, if there is a problem with the way ffmpeg perceives the length of the file it can report a different length than you would see if you opened the file in avidemux, etc. In most cases using ffmpeg to create a new avi file with -acodec and -vcodec set to copy will clear this up. In some cases the audio track can be a little bit longer than the video track, and ffmpeg will report the length of the audio track. This creates problems when trying to pull an exact clip from the end of a file to create a transition. The best way I've found to fix this problem is to have ffmpeg copy just the video track to one file using the -an switch, and then extract just the wav file to a separate file. Once the video is in a separate file, you can get the duration of that file, and use ffmpeg to put them back together only copying the amount of audio that equals the length of the video:
    Code:
    ffmpeg -t $videoonlyduration -i videoonly.avi -i audioonly.wav -vcodec copy -acodec copy newfile.avi
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!