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).


      

Sunday 29 January 2017

Getting mailto links to work with Google Chrome and DWM

The issue here is that mailto links in Web pages should run up client email software (where installed) when clicked in Google Chrome  under Linux. However this doesn't work unless a desktop environment (like Gnome) is installed.

This blog post provides a workaround for dwm users and was tested under Ubuntu Xenial (6.04.1 LTS). It might cause mailto links to fail under other desktop environments so take a backup of your work as recommended below.

When a mailto link such as nonesuchperson@nonesuchaddress.com is selected, Google Chrome calls a program called xdg-email located in /usr/bin.

xdg-email is a script which checks to see which desktop environment (DE) is being used and then, if possible, runs up a mail compose Window in email client software like Thunderbird. It is called by Google Chrome (but not apparently by Firefox) when a mailto link is clicked. However,  if you are not using a desktop environment, Chrome just runs up an empty browser window.  

The solution I identified was to force xdg-email to think I am using the LXDE environment in which case it correctly runs my email client software (Claws Mail).

First, check to see which email client is associated on your system with a mailto link by running:

xdg-mime query default "x-scheme-handler/mailto" 

By default (and I am not sure why) this command returns the following on my system: 

thunderbird.desktop 

By adding the line

x-scheme-handler/mailto=claws-mail.desktop; 
#or thunderbird.desktop etc

to the file

 ~/.local/share/applications/mimeapps.list 

the xdg-mime command shown above now returns

claws-mail.desktop;

Next, it is necessary to force the /usr/bin/xdg-email script to think we are using the LXDE DE (you have to do this as superuser and it is wise to make a backup copy of the script). The script will then check mimeapps.list to see which email client is being used.

Within the  detect_DE()  function (line 412 in my version) replace all of the following code with just DE=lxde;

    if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
      case "${XDG_CURRENT_DESKTOP}" in
         # only recently added to menu-spec, pre-spec X- still in use
         Cinnamon|X-Cinnamon)
           DE=cinnamon;
           ;;
         ENLIGHTENMENT)
           DE=enlightenment;
           ;;
         # GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
         GNOME*)
           DE=gnome;
           ;;
         KDE)
           DE=kde;
           ;;
         LXDE)
           DE=lxde;
           ;;
         MATE)
           DE=mate;
           ;;
         XFCE)
           DE=xfce
           ;;
         X-Generic)
           DE=generic
           ;;
      esac

    fi

Now run xdg-mail in a terminal window which should run up your email client software instead of an empty browser window. 

In my case the revised xdg-mail script also works under the desktop environments such as KDE and LXDE.  However, to note this is a workaround for dwm users so it might cause the script to fail in another DE.