The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

FFmpeg::Thumbnail - Create a thumbnail from a video

VERSION

Version 0.01

DESCRIPTION

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.

SYNOPSIS

    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');

ATTRIBUTES

video

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

FFmpeg::Command object with handles to all of the FFmepg::Command methods. Automatically set when the 'video' attribute is set. (Readonly)

duration

The length of the video, stored in seconds. It is automatically calculated and set from the 'ffmpeg' attribue. (Readonly)

filename

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"

default_offset

The time in the video (in seconds) at which to grab the thumbnail

file_format

Ffmpeg output file format, used by the '-f' argument. Defaults to 'image2' (png). 'mjpeg' (jpeg) is also known to work.

output_width

Width of the output thumnbail. Default output image size is 320x240.

output_width

Height of the output thumbnail. Default output image size is 320x240.

hide_log_output

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

METHODS

create_thumbnail

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();

_build_ffmpeg

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.

_build_duration

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*,/

_reset

Clear the 'ffmpeg' and 'duration' attributes.

_validate_offset

Checks $offset to make sure that it is numeric and <= $self->duration.

SEE ALSO

Video::Framegrab

A frame-grabber / thumbnail-creator built around mplayer.

AUTHOR

Brian Sauls, <bbqsauls at cpan.org>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc FFmpeg::Thumbnail

You can also look for information at:

LICENSE AND COPYRIGHT

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.