Translate

Sunday, 5 November 2017

Creating a photo slideshow from the Linux command line

This is a quick and fairly straightforward way to create photo slideshows from the Linux command line using a script called dvd-slideshow and a related script called dir2slideshow.

The examples below generate a 720p  slideshow and are based on Ubuntu.

First, install  dvd-slideshow:

apt-get install dvd-slideshow

This will also install dir2slideshow.

The dvd-slideshow script is quite old (it was last updated in 2011) but it still works and is very useful. The script needs to be edited in order to generate an acceptable bit rate for higher definition videos because dvd-slideshow was designed for DVD resolution. 

On Ubuntu, the  dvd-slideshow script is in /usr/bin. To check its location on other distributions you can enter:

which dvd-slideshow

Since we are going to be using  the Flash video format (which works well for these purposes) we need to change the default bit rate for the flv format.

As superuser, open the script in an editor.

sudo gedit /usr/bin/dvd-slideshow

We need to navigate to the following section of code. At the beginning of this section, the script is checking whether the user has requested high quality (in which case the bit rate will be 2000000 bytes per second, or 2 megabits per second) or low quality (in which case the bit rate will be 5000000 bytes per second, or 500 kilobits per second). If neither, the bit rate will default to 1000000, or 1Mbps. All of these are too low for our purposes so we need to add an extra zero to the default bit rate. It should now read: video_bitrate=10000000 which is 10 Mbps (actually higher than Google's recommended bitrate for 720p).          

if [ "$output_format" == 'flv' ] ; then  # FLV
# need to change this to be dynamic (proportinal to size)
# video_bitrate=$(( 6000 * $dvd_width / 480 ))
if [ $high_quality -eq 1 ] ; then
video_bitrate=2000000  # this works ok for 320x240. 
qscale='-qscale 1'
framerate=30;
frames_per_ms=30000;
ppmtoy4m_frc='30:1'  # 30 fps
elif [ $low_quality -eq 1 ] ; then
video_bitrate=500000  # this works ok for 320x240. 
qscale='-qscale 7'
else
video_bitrate=1000000  # this works ok for 320x240. 
qscale='-qscale 5'
framerate='15'  # is this needed for .flv?
frames_per_ms=15000  # in ms
ppmtoy4m_frc='15:1'  # 15 fps
fi


Since we have hard-coded the bitrate for Flash video we need to remember not to request high or low quality when running dvd-slideshow otherwise that will override the default bit rate. 

We can now proceed to create a slideshow. Ensure all the images  for your slideshow are in a single directory, or a directory plus its sub-directories. I am not sure if all images have to be in JPEG format, but mine always are.  The dir2slideshow script allows to you set certain parameters for your slideshow which it will then output to a text file (which acts as an input to dvd-slideshow). There is documentation on Sourceforge about this script or you can  man dir2slideshow. The obvious parameters to set are the location of input and output directories as well as the duration of images and the type/duration of transitions. Here is an example:

dir2slideshow -n TEXT_FILE -c 1 -notitle IMAGE_DIRECTORY

In this example, the script builds TEXT_FILE from the image filenames in IMAGE_DIRECTORY and specifies a crossfade between each image of 1 second. The default image duration is 5 seconds but  a different duration can be specified with the -t switch. I usually avoid a title slide being generated because I design the title slide in Gimp and put it in the image directory. 

Once the TEXT_FILE has been generated it acts as an input to dvd-slideshow.There is documentation on this script on Sourceforge  or, once again, you can  man dvd-slideshow.    
Here is an example of the use of dvd-slideshow:

dvd-slideshow -s 1280x720 -n SLIDESHOW_NAME -f TEXT_FILE -a AUDIO_FILE -V 2 -w -o OUTPUT_DIRECTORY -flv

This means:
Switch and value Meaning
-s 1280x720 Size of the video in pixels (720p)
-n SLIDESHOW_NAME Name of the video file that will be generated
-f TEXT_FILE Text file that was output by the dir2slideshow script
-a AUDIO_FILE Audio file which will provide the soundtrack
-V 2 Verbose output, useful for checking that the script is behaving as expected
-w Widescreen format
-o OUTPUT_DIRECTORY Output directory of the video file
-flv Flash video format

For finer-grained control of the audio format and bit rate the audio file can be muliplexed with the video file using ffmpeg (the subject of a future blog post).


      

No comments:

Post a Comment