Andrew Church wrote: >> nice -n 19 transcode -o $FIL.img/$FIL.img -y im -F png -x ffmpeg,null -i >> $FIL.avi --frame_interval 299.7 >> >> works as advertised and gives me an image almost exactly every ten >> seconds -- it's still off by a frame every ten minutes or so, possibly >> because the real fraction we need is 30000/1001. >> > > Glad to hear that. I actually hadn't realized that --frame_interval was > decimal-point compliant (: but I suspect the real solution is to use > time-based intervals, perhaps along the lines of your earlier suggestion: > -c 0:00:00-2:00:00/0:00:10 or the like. > > --Andrew Church > [EMAIL PROTECTED] > http://achurch.org/ > > Right, a way to specify an interval would be great -- compare the block of timecodes I'm having to use below!
So just for the record, here's the script I cobbled together -- it extracts an image every ten seconds exactly, converts the image to a thumbnail, and makes a montage. The thumbnails are renamed to provide the absolute time value (when the image was broadcast). Output is clean -- all the verbose stuff is turned off or throttled: Extract an image from every ten seconds of video on joe2 ("thumbnails help" for syntax and options). Starting to extract images from 5 files in /db11/2007/2007-01/2007-01-31 at 2007-02-03 14:30 ... Extracting images from 2007-01-31_0000_Training_B.avi ... Creating thumbnails for 2007-01-31_0000_Training_B.img ... Creating a montage of 2007-01-31_0000_Training_B.avi thumbnails ... Extracting images from 2007-01-31_0006_Training_C.avi ... Creating thumbnails for 2007-01-31_0006_Training_C.img ... Creating a montage of 2007-01-31_0006_Training_C.avi thumbnails ... Completed the task of extracting images and creating thumbnails and montages for 5 files /db11/2007/2007-01/2007-01-31 at 2007-02-04 03:43. Dave #!/bin/bash # # /usr/local/bin/thumbnails # # Extracts an image from every ten seconds in a video and converts it to a thumbnail, # also makes a montage of the thumbnails. # # Syntax: thumbnails [#] or [<directory>] # thumbnails /db1/2006/2006-12/2006-12-28 # thumbnails 1 # # In a cron job, the last will run the script in yesterday's directory every day. # # Changelog: # # ----------------------------------------------------------------------------------- # Add a help screen if [ "$1" = "-h" -o "$1" = "--help" -o "$1" = "help" ] then echo -e "\nthumbnails [#] or [<directory>]" echo -e "\n\tThe thumbnails script extracts an image from every ten seconds" echo -e "\tin a video and converts it to a thumbnail." echo -e "Syntax:" echo -e "\tthumbnails \t\t(process the files in the current directory)" echo -e "\tthumbnails 0 \t\t(process today's files -- useful cron job)" echo -e "\tthumbnails 5 \t\t(process the files from five days ago)" echo -e "\tthumbnails /db3/2007/2007-01/2007-01-15 \t(process a directory)\n" echo -e "\tNumbers work only within the current capture drive.\n" exit fi echo -e "Extract an image from every ten seconds of video on $(uname -n) (\"thumbnails help\" for syntax and options)." function stem() { local name=${1##*/} local name0="${name%.*}" echo "${name0:-$name}" } # Locate the current capture drive (the first db drive with more than 1% free) for i in $(df | cut -d'/' -f4 | grep db | sort); do if [ "$(df /$i | grep $i | cut -b 52-54)" -lt 99 ] ; then DRV=$i ; break ; fi done # Check for flags and assign variables if [ "$1" = "" ] ; then DIR=$(pwd) elif [ "$(echo $1 | grep [^0-9])" = "" ] # if the first parameter is an integer then DIR="/$DRV/$(date -d "-$1 day" +%Y)/$(date -d "-$1 day" +%Y-%m)/$(date -d "-$1 day" +%F)" else DIR="$1" fi # Check if the directory exists and move to it if it does if [ -d $DIR ] then cd $DIR else echo -e "\nSorry -- unable to locate a directory called '$DIR'.\n" exit fi # Check for *.avi files in the chosen directory if [ "$(ls *.avi)" = "" ] then echo -e "\nThere are no avi files to process in $DIR.\n" exit else echo -e "\nStarting to extract images from $(ls *.avi | grep -c .avi) files in $DIR at $(date '+%F %H:%M') ...\n" fi # Create an image directory for each video file for FIL in $(ls *.avi); do # Strip the extension FIL=$(stem $FIL) # Check if the images exist if [ -d "$FIL.img" ] then echo -e "$FIL.avi images have been extracted." else mkdir -p -m 775 $FIL.img echo -e "Extracting images from $FIL.avi ... " # This method of extraction is a shorter command, but is not completely time-accurate: #nice -n 19 transcode -q 0 -o $FIL.img/$FIL.img -y im -F png -x ffmpeg,null -i $FIL.avi --frame_interval 299.7003 2> /dev/null # Extract an image every ten seconds from each file nice -n 19 transcode -q 0 -o $FIL.img/$FIL.img -y im -F png -x ffmpeg,null -i $FIL.avi -c \ 0:00:00-0:00:00.1,0:00:10-0:00:10.1,0:00:20-0:00:20.1,0:00:30-0:00:30.1,0:00:40-0:00:40.1,0:00:50-0:00:50.1,\ 0:01:00-0:01:00.1,0:01:10-0:01:10.1,0:01:20-0:01:20.1,0:01:30-0:01:30.1,0:01:40-0:01:40.1,0:01:50-0:01:50.1,\ 0:02:00-0:02:00.1,0:02:10-0:02:10.1,0:02:20-0:02:20.1,0:02:30-0:02:30.1,0:02:40-0:02:40.1,0:02:50-0:02:50.1,\ 0:03:00-0:03:00.1,0:03:10-0:03:10.1,0:03:20-0:03:20.1,0:03:30-0:03:30.1,0:03:40-0:03:40.1,0:03:50-0:03:50.1,\ 0:04:00-0:04:00.1,0:04:10-0:04:10.1,0:04:20-0:04:20.1,0:04:30-0:04:30.1,0:04:40-0:04:40.1,0:04:50-0:04:50.1,\ 0:05:00-0:05:00.1,0:05:10-0:05:10.1,0:05:20-0:05:20.1,0:05:30-0:05:30.1,0:05:40-0:05:40.1,0:05:50-0:05:50.1,\ 0:06:00-0:06:00.1,0:06:10-0:06:10.1,0:06:20-0:06:20.1,0:06:30-0:06:30.1,0:06:40-0:06:40.1,0:06:50-0:06:50.1,\ 0:07:00-0:07:00.1,0:07:10-0:07:10.1,0:07:20-0:07:20.1,0:07:30-0:07:30.1,0:07:40-0:07:40.1,0:07:50-0:07:50.1,\ 0:08:00-0:08:00.1,0:08:10-0:08:10.1,0:08:20-0:08:20.1,0:08:30-0:08:30.1,0:08:40-0:08:40.1,0:08:50-0:08:50.1,\ 0:09:00-0:09:00.1,0:09:10-0:09:10.1,0:09:20-0:09:20.1,0:09:30-0:09:30.1,0:09:40-0:09:40.1,0:09:50-0:09:50.1,\ 0:10:00-0:10:00.1,0:10:10-0:10:10.1,0:10:20-0:10:20.1,0:10:30-0:10:30.1,0:10:40-0:10:40.1,0:10:50-0:10:50.1,\ 0:11:00-0:11:00.1,0:11:10-0:11:10.1,0:11:20-0:11:20.1,0:11:30-0:11:30.1,0:11:40-0:11:40.1,0:11:50-0:11:50.1,\ 0:12:00-0:12:00.1,0:12:10-0:12:10.1,0:12:20-0:12:20.1,0:12:30-0:12:30.1,0:12:40-0:12:40.1,0:12:50-0:12:50.1,\ 0:13:00-0:13:00.1,0:13:10-0:13:10.1,0:13:20-0:13:20.1,0:13:30-0:13:30.1,0:13:40-0:13:40.1,0:13:50-0:13:50.1,\ 0:14:00-0:14:00.1,0:14:10-0:14:10.1,0:14:20-0:14:20.1,0:14:30-0:14:30.1,0:14:40-0:14:40.1,0:14:50-0:14:50.1,\ 0:15:00-0:15:00.1,0:15:10-0:15:10.1,0:15:20-0:15:20.1,0:15:30-0:15:30.1,0:15:40-0:15:40.1,0:15:50-0:15:50.1,\ 0:16:00-0:16:00.1,0:16:10-0:16:10.1,0:16:20-0:16:20.1,0:16:30-0:16:30.1,0:16:40-0:16:40.1,0:16:50-0:16:50.1,\ 0:17:00-0:17:00.1,0:17:10-0:17:10.1,0:17:20-0:17:20.1,0:17:30-0:17:30.1,0:17:40-0:17:40.1,0:17:50-0:17:50.1,\ 0:18:00-0:18:00.1,0:18:10-0:18:10.1,0:18:20-0:18:20.1,0:18:30-0:18:30.1,0:18:40-0:18:40.1,0:18:50-0:18:50.1,\ 0:19:00-0:19:00.1,0:19:10-0:19:10.1,0:19:20-0:19:20.1,0:19:30-0:19:30.1,0:19:40-0:19:40.1,0:19:50-0:19:50.1,\ 0:20:00-0:20:00.1,0:20:10-0:20:10.1,0:20:20-0:20:20.1,0:20:30-0:20:30.1,0:20:40-0:20:40.1,0:20:50-0:20:50.1,\ 0:21:00-0:21:00.1,0:21:10-0:21:10.1,0:21:20-0:21:20.1,0:21:30-0:21:30.1,0:21:40-0:21:40.1,0:21:50-0:21:50.1,\ 0:22:00-0:22:00.1,0:22:10-0:22:10.1,0:22:20-0:22:20.1,0:22:30-0:22:30.1,0:22:40-0:22:40.1,0:22:50-0:22:50.1,\ 0:23:00-0:23:00.1,0:23:10-0:23:10.1,0:23:20-0:23:20.1,0:23:30-0:23:30.1,0:23:40-0:23:40.1,0:23:50-0:23:50.1,\ 0:24:00-0:24:00.1,0:24:10-0:24:10.1,0:24:20-0:24:20.1,0:24:30-0:24:30.1,0:24:40-0:24:40.1,0:24:50-0:24:50.1,\ 0:25:00-0:25:00.1,0:25:10-0:25:10.1,0:25:20-0:25:20.1,0:25:30-0:25:30.1,0:25:40-0:25:40.1,0:25:50-0:25:50.1,\ 0:26:00-0:26:00.1,0:26:10-0:26:10.1,0:26:20-0:26:20.1,0:26:30-0:26:30.1,0:26:40-0:26:40.1,0:26:50-0:26:50.1,\ 0:27:00-0:27:00.1,0:27:10-0:27:10.1,0:27:20-0:27:20.1,0:27:30-0:27:30.1,0:27:40-0:27:40.1,0:27:50-0:27:50.1,\ 0:28:00-0:28:00.1,0:28:10-0:28:10.1,0:28:20-0:28:20.1,0:28:30-0:28:30.1,0:28:40-0:28:40.1,0:28:50-0:28:50.1,\ 0:29:00-0:29:00.1,0:29:10-0:29:10.1,0:29:20-0:29:20.1,0:29:30-0:29:30.1,0:29:40-0:29:40.1,0:29:50-0:29:50.1,\ 0:30:00-0:30:00.1,0:30:10-0:30:10.1,0:30:20-0:30:20.1,0:30:30-0:30:30.1,0:30:40-0:30:40.1,0:30:50-0:30:50.1,\ 0:31:00-0:31:00.1,0:31:10-0:31:10.1,0:31:20-0:31:20.1,0:31:30-0:31:30.1,0:31:40-0:31:40.1,0:31:50-0:31:50.1,\ 0:32:00-0:32:00.1,0:32:10-0:32:10.1,0:32:20-0:32:20.1,0:32:30-0:32:30.1,0:32:40-0:32:40.1,0:32:50-0:32:50.1,\ 0:33:00-0:33:00.1,0:33:10-0:33:10.1,0:33:20-0:33:20.1,0:33:30-0:33:30.1,0:33:40-0:33:40.1,0:33:50-0:33:50.1,\ 0:34:00-0:34:00.1,0:34:10-0:34:10.1,0:34:20-0:34:20.1,0:34:30-0:34:30.1,0:34:40-0:34:40.1,0:34:50-0:34:50.1,\ 0:35:00-0:35:00.1,0:35:10-0:35:10.1,0:35:20-0:35:20.1,0:35:30-0:35:30.1,0:35:40-0:35:40.1,0:35:50-0:35:50.1,\ 0:36:00-0:36:00.1,0:36:10-0:36:10.1,0:36:20-0:36:20.1,0:36:30-0:36:30.1,0:36:40-0:36:40.1,0:36:50-0:36:50.1,\ 0:37:00-0:37:00.1,0:37:10-0:37:10.1,0:37:20-0:37:20.1,0:37:30-0:37:30.1,0:37:40-0:37:40.1,0:37:50-0:37:50.1,\ 0:38:00-0:38:00.1,0:38:10-0:38:10.1,0:38:20-0:38:20.1,0:38:30-0:38:30.1,0:38:40-0:38:40.1,0:38:50-0:38:50.1,\ 0:39:00-0:39:00.1,0:39:10-0:39:10.1,0:39:20-0:39:20.1,0:39:30-0:39:30.1,0:39:40-0:39:40.1,0:39:50-0:39:50.1,\ 0:40:00-0:40:00.1,0:40:10-0:40:10.1,0:40:20-0:40:20.1,0:40:30-0:40:30.1,0:40:40-0:40:40.1,0:40:50-0:40:50.1,\ 0:41:00-0:41:00.1,0:41:10-0:41:10.1,0:41:20-0:41:20.1,0:41:30-0:41:30.1,0:41:40-0:41:40.1,0:41:50-0:41:50.1,\ 0:42:00-0:42:00.1,0:42:10-0:42:10.1,0:42:20-0:42:20.1,0:42:30-0:42:30.1,0:42:40-0:42:40.1,0:42:50-0:42:50.1,\ 0:43:00-0:43:00.1,0:43:10-0:43:10.1,0:43:20-0:43:20.1,0:43:30-0:43:30.1,0:43:40-0:43:40.1,0:43:50-0:43:50.1,\ 0:44:00-0:44:00.1,0:44:10-0:44:10.1,0:44:20-0:44:20.1,0:44:30-0:44:30.1,0:44:40-0:44:40.1,0:44:50-0:44:50.1,\ 0:45:00-0:45:00.1,0:45:10-0:45:10.1,0:45:20-0:45:20.1,0:45:30-0:45:30.1,0:45:40-0:45:40.1,0:45:50-0:45:50.1,\ 0:46:00-0:46:00.1,0:46:10-0:46:10.1,0:46:20-0:46:20.1,0:46:30-0:46:30.1,0:46:40-0:46:40.1,0:46:50-0:46:50.1,\ 0:47:00-0:47:00.1,0:47:10-0:47:10.1,0:47:20-0:47:20.1,0:47:30-0:47:30.1,0:47:40-0:47:40.1,0:47:50-0:47:50.1,\ 0:48:00-0:48:00.1,0:48:10-0:48:10.1,0:48:20-0:48:20.1,0:48:30-0:48:30.1,0:48:40-0:48:40.1,0:48:50-0:48:50.1,\ 0:49:00-0:49:00.1,0:49:10-0:49:10.1,0:49:20-0:49:20.1,0:49:30-0:49:30.1,0:49:40-0:49:40.1,0:49:50-0:49:50.1,\ 0:50:00-0:50:00.1,0:50:10-0:50:10.1,0:50:20-0:50:20.1,0:50:30-0:50:30.1,0:50:40-0:50:40.1,0:50:50-0:50:50.1,\ 0:51:00-0:51:00.1,0:51:10-0:51:10.1,0:51:20-0:51:20.1,0:51:30-0:51:30.1,0:51:40-0:51:40.1,0:51:50-0:51:50.1,\ 0:52:00-0:52:00.1,0:52:10-0:52:10.1,0:52:20-0:52:20.1,0:52:30-0:52:30.1,0:52:40-0:52:40.1,0:52:50-0:52:50.1,\ 0:53:00-0:53:00.1,0:53:10-0:53:10.1,0:53:20-0:53:20.1,0:53:30-0:53:30.1,0:53:40-0:53:40.1,0:53:50-0:53:50.1,\ 0:54:00-0:54:00.1,0:54:10-0:54:10.1,0:54:20-0:54:20.1,0:54:30-0:54:30.1,0:54:40-0:54:40.1,0:54:50-0:54:50.1,\ 0:55:00-0:55:00.1,0:55:10-0:55:10.1,0:55:20-0:55:20.1,0:55:30-0:55:30.1,0:55:40-0:55:40.1,0:55:50-0:55:50.1,\ 0:56:00-0:56:00.1,0:56:10-0:56:10.1,0:56:20-0:56:20.1,0:56:30-0:56:30.1,0:56:40-0:56:40.1,0:56:50-0:56:50.1,\ 0:57:00-0:57:00.1,0:57:10-0:57:10.1,0:57:20-0:57:20.1,0:57:30-0:57:30.1,0:57:40-0:57:40.1,0:57:50-0:57:50.1,\ 0:58:00-0:58:00.1,0:58:10-0:58:10.1,0:58:20-0:58:20.1,0:58:30-0:58:30.1,0:58:40-0:58:40.1,0:58:50-0:58:50.1,\ 0:59:00-0:59:00.1,0:59:10-0:59:10.1,0:59:20-0:59:20.1,0:59:30-0:59:30.1,0:59:40-0:59:40.1,0:59:50-0:59:50.1,\ 1:00:00-1:00:00.1,1:00:10-1:00:10.1,1:00:20-1:00:20.1,1:00:30-1:00:30.1,1:00:40-1:00:40.1,1:00:50-1:00:50.1,\ 1:01:00-1:01:00.1,1:01:10-1:01:10.1,1:01:20-1:01:20.1,1:01:30-1:01:30.1,1:01:40-1:01:40.1,1:01:50-1:01:50.1,\ 1:02:00-1:02:00.1,1:02:10-1:02:10.1,1:02:20-1:02:20.1,1:02:30-1:02:30.1,1:02:40-1:02:40.1,1:02:50-1:02:50.1,\ 1:03:00-1:03:00.1,1:03:10-1:03:10.1,1:03:20-1:03:20.1,1:03:30-1:03:30.1,1:03:40-1:03:40.1,1:03:50-1:03:50.1,\ 1:04:00-1:04:00.1,1:04:10-1:04:10.1,1:04:20-1:04:20.1,1:04:30-1:04:30.1,1:04:40-1:04:40.1,1:04:50-1:04:50.1,\ 1:05:00-1:05:00.1,1:05:10-1:05:10.1,1:05:20-1:05:20.1,1:05:30-1:05:30.1,1:05:40-1:05:40.1,1:05:50-1:05:50.1,\ 1:06:00-1:06:00.1,1:06:10-1:06:10.1,1:06:20-1:06:20.1,1:06:30-1:06:30.1,1:06:40-1:06:40.1,1:06:50-1:06:50.1,\ 1:07:00-1:07:00.1,1:07:10-1:07:10.1,1:07:20-1:07:20.1,1:07:30-1:07:30.1,1:07:40-1:07:40.1,1:07:50-1:07:50.1,\ 1:08:00-1:08:00.1,1:08:10-1:08:10.1,1:08:20-1:08:20.1,1:08:30-1:08:30.1,1:08:40-1:08:40.1,1:08:50-1:08:50.1,\ 1:09:00-1:09:00.1,1:09:10-1:09:10.1,1:09:20-1:09:20.1,1:09:30-1:09:30.1,1:09:40-1:09:40.1,1:09:50-1:09:50.1 2> /dev/null fi # End the check for $FIL.img # Move into the image directory cd $FIL.img # Rename the images with absolute time stamps for IMG in $(ls *.png); do DATE="$( echo $IMG | cut -d'_' -f1 )" HOUR="$( echo $IMG | cut -d'_' -f2 )" STEM="$( echo $IMG | cut -d'.' -f1 )" LAPS="$( echo $IMG | cut -d'.' -f2 | cut -b 7-9 )"0 STMP=$(date -d "+$LAPS seconds"\ $DATE\ $HOUR +%F_%H:%M:%S) mv $IMG $STEM\_$STMP.png done # Define the subdirectory THUMBS="thumbnails" # Check if the thumbnails have already been created if [ "$(ls -A $THUMBS 2> /dev/null)" ] then echo -e "$FIL.img thumbnails have been created." else mkdir -p -m 775 $THUMBS echo -e "Creating thumbnails for $FIL.img ... " # Read each image in turn and run convert on it for IMG in $(ls *.png); do # Strip the extension IMG=$(stem $IMG) nice -n 19 convert -thumbnail 68x63 $IMG.png $THUMBS/$IMG.jpg done # Done making thumbnails fi # Return to the video directory cd .. # Write a montage of the thumbnails if [ -e "$FIL.jpg" ] then echo -e "$FIL.jpg montage is complete.\n" else echo -e "Creating a montage of $FIL.avi thumbnails ...\n" nice -n 19 montage -tile 15 -geometry +1,+1 $FIL.img/$THUMBS/*.jpg $FIL.jpg fi done # Done processing an avi file echo -e "\nCompleted task of extracting images and creating thumbnails and montages echo -e "for $(ls *.avi | grep -c .avi) files in $DIR at $(date '+%F %H:%M').\n" # EOF