Search:  
Gentoo Wiki

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


./make-thumbs.sh My\ Favorite\ Movie\[\]\{\}\"\".avi
./make-thumbs.sh "My favorite movie[]{}\"\".avi"

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

Resulting image without arguments. Size 346K
Resulting image without arguments. Size 346K

Resulting image is <movie file>.jpg with 3 lines, 3 columns, and 1024x768 resolution.

With arguments of 4 lines x 3 columns

Image 4 lines x 3 columns, 1024x768 resolution, offset +1. Size 457K
Image 4 lines x 3 columns, 1024x768 resolution, offset +1. Size 457K

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

Image with 4 lines, 3 columns, resolution of 1280x1024. Size 674K
Image with 4 lines, 3 columns, resolution of 1280x1024. Size 674K

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 !


--Wadlax 19:34, 21 июня 2007 (UTC)

Retrieved from "http://www.gentoo-wiki.info/MPlayer/Movie_thumbnail_preview"

Last modified: Thu, 28 Aug 2008 05:44:00 +0000 Hits: 1,065