MPlayer/Movie_thumbnail_preview
Contents |
Description
If you want to create "movie preview" - put together few frames from the movie in one image, you can use following script.
Requirements
The script uses mplayer and convert from packages media-video/mplayer and media-gfx/imagemagick.
Addendum
- The script correcly handling filenames with spaces, i.e.:
./make-thumbs.sh My\ Favorite\ Movie\[\]\{\}\"\".avi
./make-thumbs.sh "My favorite movie[]{}\"\".avi"
- Temporary files resides in /tmp
- The tesulting file is in jpg compression, with quality of a 100.
- Without arguments, the script will show help and then exit.
Usage
<script-path>/make-thumbs.sh <name of the video-file> [amount of lines] [amount of columnts] [final resolution] [offset] [suffix]
What is offset?
The script pick frames from a movie in certain positions.
With offset you can change the positions, to pick better movieframes for the resulting picture.
What is suffix for the resulting file?
With suffix you can name resulting file as <name of video-file>_<suffix>.jpg i.e.
movie_1.jpg, movie_2.jpg - that's useful to find a good offset.
Usage examples
Without arguments
- /home/<loginname>/make-thumbs.sh <your_movie_file>
- ./make-thumbs.sh Elephants_Dream_1024.avi
Resulting image is <movie file>.jpg with 3 lines, 3 columns, and 1024x768 resolution.
With arguments of 4 lines x 3 columns
- /home/<loginname>/make-thumbs.sh <movie filename> 4 3 0 1 1
- ./make-thumbs.sh Elephants_Dream_1024.avi 4 3 0 1 1
Resulting image is <movie-file name>_1.jpg with 4 lines, 3 columns, resolution of 1024x768, and frame offset of +1
With arguments of 4 lines, 3 columns and resolution of 1280x1024
- /home/<>/make-thumbs.sh <movie filename> 4 3 1280x1024
- ./make-thumbs.sh Elephants_Dream_1024.avi 4 3 1280x1024
Resulting image <movie filename>.jpg with 4 lines, 3 columns, and resolution of 1280x1024.
Script
| File: make-thumbs.sh |
FILE="$1"; # File name
Image_Rows="$2"; # Number of lines
Image_Columns="$3"; # Number of columns
Image_Resolution="$4"; # Resolution of the final image
# Frame offset
Time_Shift="$5"; # Time shift
File_Suffix="$6"; # File suffix, i.e aaa.avi -> aaa_1.jpg aaa_2.jpg
#+++ In case of no arguments
if [ "$FILE" = "" ]
then
echo 'What video file do you want to use?';
echo 'Use <video-file> [Number of lines] [Number of columns] [Resolution of the final image] [Offset] [Suffix of the resulting image]';
echo 'Suffix is a usual number. Resulting file <video-file>_<Number-suffix>.jpg';
echo 'Resulting quality of the jpg-file - 100';
exit 1;
fi
if [ "$Image_Rows" = "" ]
then
Image_Rows="3"
fi
if [ "$Image_Columns" = "" ]
then
Image_Columns="3"
fi
if [ "$Image_Resolution" = "" ]
then
Image_Resolution="1024x768"
fi
if [ "$Image_Resolution" = "0" ]
then
Image_Resolution="1024x768"
fi
if [ "$Time_Shift" = "" ]
then
Time_Shift="0"
fi
if [ "$File_Suffix" != "" ]
then
File_Suffix="_$File_Suffix";
fi
#--- In case of no arguments
FILENAME=${FILE%.*};
# Temporary value of INFO contain data about the video file
INFO=`mplayer -msglevel all=0 -identify -nosound -vc dummy -vo null "$1"`;
# Height of original video frame
HEIGHT=`expr "$INFO" : '.*HEIGHT=\([0-9]*\)'`;
# Width of the original video frame
WIDTH=`expr "$INFO" : '.*WIDTH=\([0-9]*\)'`;
# Number of frames
NUM=$(($Image_Rows*$Image_Columns));
# Time offset
LEN=$((`expr "$INFO" : '.*LENGTH=\([0-9]*\)'`/( $NUM +2)));
#+++ Picking up frames
for kadr in `seq 1 $NUM`
do
echo "Processing frame $kadr ?? $NUM";
mplayer -msglevel all=0 -nosound -vo jpeg:outdir=/tmp:quality=100 -frames 2 -ss `echo $Time_Shift+$kadr*$LEN|bc` "$1" > /dev/null;
rm /tmp/00000001.jpg;
mv /tmp/00000002.jpg /tmp/"$kadr.jpg";
done
#--- Picking up frames
#+++ Inserting frames
echo Inserting frames...;
Command="convert ";
for i in `seq 1 $Image_Rows`
do
for j in `seq 1 $Image_Columns`
do
kadr=`echo "($i-1)*$Image_Columns+$j"|bc`;
x_pos=$(( ($HEIGHT+10)*($i-1) ));
y_pos=$(( ($WIDTH+10)*($j-1) ));
Command="$Command -page +$y_pos+$x_pos /tmp/$kadr.jpg";
done
done
Command="$Command -background white -mosaic -bordercolor white -border 10x10 -quality 100 /tmp/tmp0.jpg";
$Command;
#--- Inserting frames
# Changing size
convert /tmp/tmp0.jpg -auto-orient -thumbnail $Image_Resolution -quality 100 /tmp/tmp.jpg
#+++ Removing temporary files
for kadr in `seq 1 $NUM`
do
rm /tmp/"$kadr.jpg";
done
rm /tmp/tmp0.jpg;
#--- Removing temporary files
mv /tmp/tmp.jpg "$FILENAME$File_Suffix.jpg"
echo All done! - The file is "$FILENAME$File_Suffix.jpg"
|
References
! Authors agreed to publish the script !
- Russian discussion of the script in the thread of gentoo.ru forum
- Frames from the Elephants Dream movie
--Wadlax 19:34, 21 ???? 2007 (UTC)
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and list their apartments, townhouses and units.
