FFmpeg::Thumbnail - Create a thumbnail from a video
Version 0.01
A wrapper for FFmpeg::Command specifically for creating video thumbnails. Grabs a frame at a specific point in the video and stores it as an image using ffmpeg ( http://ffmpeg.org ).
Provides the ability to set specific output paramaters, such as file-type and file size, and use them across multiple video files.
use FFmpeg::Thumbnail; # Create a thumbnail 20 seconds into the video. my $foo = FFmpeg::Thumbnail->new( { video => '/my/video/file.flv' } ); my $offset = 20; my $output_filname = "/my/output/image.png"; $foo->create_thumbnail( $offset, $output_filename ); # Create five evenly-spaced jpeg's my $bar = FFmpeg::Thumbnail->new( { video => '/my/video/file.flv' } ); $bar->file_format( 'mjpeg'); my $filename( '/my/default/filename_' ); my $num_thumbs = 5; for ( my $i=0; $i <= $bar->duration; $i+=$bar->duration / $num_thumbs ){ $bar->create_thumbnail( $i, $filename.$i."_.jpeg" ); } # Create 640x480 thumbnails at 21 seconds for two separate videos my $baz = FFmpeg::Thumbnail->new( { video => '/my/video/file.flv' } ); $baz->output_width( 640 ); $baz->output_height( 480 ); $baz->offset( 21 ); $baz->create_thumbnail( undef, '/my/first/thumbnail.png'); $baz->video( '/my/video/second_file.flv' ); $baz->create_thumbnail( undef, '/my/second/thumbnail.png');
Complete path and filename for the source video. It can be changed after instantiantion if you wish to use the same output settings for different videos.
FFmpeg::Command object with handles to all of the FFmepg::Command methods. Automatically set when the 'video' attribute is set. (Readonly)
The length of the video, stored in seconds. It is automatically calculated and set from the 'ffmpeg' attribue. (Readonly)
Output filename. The filename extension, here, has no bearing on the actual output format. That is set by the 'file_format' attribute, so it is possible to create a thumbnail named "thumbnail.jpg" that actually has an 'image/png' MIME type. Defaults to "/tmp/thumbnail.png"
The time in the video (in seconds) at which to grab the thumbnail
Ffmpeg output file format, used by the '-f' argument. Defaults to 'image2' (png). 'mjpeg' (jpeg) is also known to work.
Width of the output thumnbail. Default output image size is 320x240.
Height of the output thumbnail. Default output image size is 320x240.
Turns off ffmpeg's log output. You can still access this through the stdout() and stderr() handles. Log output is suppressed by default ( ->hide_log_output == 1 ).
Creats a thumbnail image using a specified offset and specified filename, or, if not specified, defaults. Will overwrite if a file already exists with that filename.
Usage:
# Create a thumbnail from $offset and store it at $output_filename: $foo->create_thumbnail( $offset, $output_filename ); # Create a thumbnail from $offset and store it at the default location: $foo->create_thumbnail( $offset ); # Create a thumbnail from the video's beginning and store it at $filename: $foo->create_thumbnail( undef, $output_filename); # Create a thumbnail from the video's beginning and store it at the default location: $foo->create_thumbnail();
Creats a new FFmpeg::Command object, sets $self->video as the input_options, and executes to populate $self->ffmpeg->stderr with the input video's meta data.
Builder for the "duration" attribute. Reads the length of the video from $self->ffmpeg->stderr and converts it seconds.
/Duration:\s+(\d+):(\d+):(\d+)(?:\.\d+)?\s*,/
Clear the 'ffmpeg' and 'duration' attributes.
Checks $offset to make sure that it is numeric and <= $self->duration.
A frame-grabber / thumbnail-creator built around mplayer.
Brian Sauls, <bbqsauls at cpan.org>
<bbqsauls at cpan.org>
Please report any bugs or feature requests to bug-video-thumbnail at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Video-Thumbnail. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-video-thumbnail at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc FFmpeg::Thumbnail
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Video-Thumbnail
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Video-Thumbnail
CPAN Ratings
http://cpanratings.perl.org/d/Video-Thumbnail
Search CPAN
http://search.cpan.org/dist/Video-Thumbnail/
Copyright 2011 Brian Sauls, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install FFmpeg::Thumbnail, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FFmpeg::Thumbnail
CPAN shell
perl -MCPAN -e shell install FFmpeg::Thumbnail
For more information on module installation, please visit the detailed CPAN module installation guide.