Difference between revisions of "API:EPrints/Plugin/Convert/Thumbnails"
(2 intermediate revisions by one other user not shown) | |||
Line 10: | Line 10: | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
− | + | The Thumbnail How-to may also be useful: [[How to customise thumbnails]] | |
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
<!-- Pod2Wiki=head_synopsis --> | <!-- Pod2Wiki=head_synopsis --> | ||
==SYNOPSIS== | ==SYNOPSIS== | ||
− | < | + | <source lang="perl">use EPrints; |
− | + | # enable audio previews | |
− | + | $c->{plugins}->{'Convert::Thumbnails'}->{params}->{audio} = 1; | |
− | + | # disable video previews | |
− | + | $c->{plugins}->{'Convert::Thumbnails'}->{params}->{video} = 0; | |
− | + | # enable audio_*/video_* previews | |
− | + | $c->{thumbnail_types} = sub { | |
− | + | my( $list, $repo, $doc ) = @_; | |
− | + | push @$list, qw( audio_mp4 audio_ogg video_mp4 video_ogg ); | |
− | + | }; | |
− | + | ... | |
− | + | my $plugin = $session->plugin( "Convert" ); | |
− | + | my %available = $plugin->can_convert( $doc ); | |
− | + | $plugin = $available{"thumbnail_video"}->{plugin}; | |
− | + | $new_doc = $plugin->convert( $doc, "thumbnail_video" ); | |
− | + | </source> | |
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 45: | Line 45: | ||
Conversion of images, videos and audio into preview/thumbnail versions. | Conversion of images, videos and audio into preview/thumbnail versions. | ||
− | This plugin wraps the ImageMagick | + | This plugin wraps the ImageMagick ''convert'' and ''ffmpeg'' tools. |
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 51: | Line 51: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=head_testing_audio_and_video_conversion --> |
− | == | + | ===Testing Audio and Video Conversion=== |
− | + | When files are uploaded to EPrints a file format identification process occurs. This is based on the <code>EP_TRIGGER_MEDIA_INFO</code> callbacks. A set of callbacks are provided by ''lib/cfg.d/media_info.pl''. To customise these copy the file to your repository's ''cfg.d/'' directory. | |
− | |||
− | |||
+ | This plugin relies on the <code>media</code> info added by the file format identification. To check this is working export the EPrint as XML and check for a <media> entry in your document: | ||
− | < | + | <pre> ./bin/export [archiveid] eprint XML [eprintid]</pre> |
− | < | ||
− | |||
− | + | At any time you can re-run the file format identification by using <code>redo_mime_type</code> in epadmin: | |
− | < | + | <pre> ./bin/epadmin redo_mime_type [archiveid] eprint [eprintid] --verbose</pre> |
+ | If ''ffprobe'' is configured correctly you should see it being called for each document. | ||
− | + | Finally, to regenerate thumbnails do: | |
− | |||
− | |||
− | + | <pre> ./bin/epadmin redo_thumbnails [archiveid] [eprintid] --verbose</pre> | |
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 77: | Line 73: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=head_parameters --> |
− | === | + | ==PARAMETERS== |
− | + | These parameters can be set through the '''plugins.pl''' configuration file. You must also configure the '''executables''' locations for <em>convert</em> and <em>ffmpeg</em> in [[API:EPrints/SystemSettings|EPrints::SystemSettings]]. | |
− | |||
− | |||
− | |||
− | |||
− | < | ||
− | |||
− | |||
− | < | ||
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | * convert_formats = { ext => mime_type } | ||
+ | : Define the formats supported for input by the call_convert() method. | ||
− | + | * ffmpeg_formats = { ext => mime_type } | |
− | + | : Define the formats supported for input by the call_ffmpeg() method. | |
− | |||
− | + | * sizes = { size => [$w, $h] } | |
+ | : Define the size of thumbnails that can be generated e.g. "small => [66,50]". The image dimensions generated may be smaller than those specified if the aspect ratio of the source document is different. | ||
− | + | : Images are output in 8-bit paletted PNG. | |
+ | * video = 1 | ||
+ | : Enable video previews. | ||
− | + | * audio = 1 | |
− | + | : Enable audio previews. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | * video_height = "480" | |
+ | : Video preview vertical lines. | ||
− | + | * audio_sampling = "44100" | |
+ | : Audio frequency sampling rate in Hz. | ||
+ | * audio_bitrate = "96k" | ||
+ | : Audio bit rate in kb/s | ||
− | < | + | * audio_codec = "libfaac" |
− | < | + | : <em>ffmpeg</em> compiled-in AAC codec name. |
− | |||
− | Video frame rate in fps. | + | * frame_rate = "10.00" |
+ | : Video frame rate in fps. | ||
− | < | + | * video_codec = "h264" |
+ | : <em>ffmpeg</em> compiled-in H.264 codec name (may be libx264 on some platforms). | ||
+ | * video_rate = "1500k" | ||
+ | : Video bit rate in kilobits. | ||
− | + | * call_convert = sub( $plugin, $dst, $doc, $src, $geom, $size ) | |
− | + | : See [[API:EPrints/Plugin/Convert/Thumbnails#call_convert|call_convert]]. | |
− | |||
− | + | * call_ffmpeg = sub( $plugin, $dst, $doc, $src, $geom, $size, $offset ) | |
− | + | : See [[API:EPrints/Plugin/Convert/Thumbnails#call_ffmpeg|call_ffmpeg]]. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | See [[API:EPrints/Plugin/Convert/Thumbnails#call_ffmpeg|call_ffmpeg]]. | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 189: | Line 127: | ||
<!-- Pod2Wiki=head_methods --> | <!-- Pod2Wiki=head_methods --> | ||
==METHODS== | ==METHODS== | ||
− | + | <!-- Pod2Wiki=head_can_convert --> | |
− | |||
− | |||
− | <!-- Pod2Wiki= | ||
− | |||
===can_convert=== | ===can_convert=== | ||
Line 207: | Line 141: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=head_convert --> |
===convert=== | ===convert=== | ||
Line 219: | Line 153: | ||
<!-- Pod2Wiki= --> | <!-- Pod2Wiki= --> | ||
− | <!-- Pod2Wiki= | + | <!-- Pod2Wiki=head_export --> |
===export=== | ===export=== | ||
Line 233: | Line 167: | ||
<!-- Pod2Wiki=head_utility_methods --> | <!-- Pod2Wiki=head_utility_methods --> | ||
===Utility Methods=== | ===Utility Methods=== | ||
− | + | $ver = $plugin->convert_version() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Returns the MAJOR.MINOR version of ImageMagick. | Returns the MAJOR.MINOR version of ImageMagick. | ||
Returns 0.0 if the version can not be determined. | Returns 0.0 if the version can not be determined. | ||
− | + | $ok = $plugin->is_video( $doc ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Returns true if $doc is a video. | Returns true if $doc is a video. | ||
− | + | $doc = $plugin->intermediate( $doc, $src, $geom, $src ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Attempt to find an intermediate document that we can use to convert from (e.g. make a thumbnail from a preview version). | Attempt to find an intermediate document that we can use to convert from (e.g. make a thumbnail from a preview version). | ||
Returns the original $doc if not intermediate is found. | Returns the original $doc if not intermediate is found. | ||
− | + | $plugin->call_convert( $dst, $doc, $src, $geom, $size ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Calls the ImageMagick <em>convert</em> tool to convert $doc into a thumbnail image. Writes the image to $dst. $src is the full path to the main file from $doc. The resulting image should not exceed $geom dimensions ([w,h] array ref). | Calls the ImageMagick <em>convert</em> tool to convert $doc into a thumbnail image. Writes the image to $dst. $src is the full path to the main file from $doc. The resulting image should not exceed $geom dimensions ([w,h] array ref). | ||
Line 289: | Line 187: | ||
This method can be overridden with the '''call_convert''' parameter. | This method can be overridden with the '''call_convert''' parameter. | ||
− | + | $plugin->call_ffmpeg( $dst, $doc, $src, $geom, $size, $offset ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Uses the <em>ffmpeg</em> tool to do the image conversion of $doc. $dst is the filename to write to, $src is the filename to read from and $geom is the image dimensions to write. | Uses the <em>ffmpeg</em> tool to do the image conversion of $doc. $dst is the filename to write to, $src is the filename to read from and $geom is the image dimensions to write. | ||
Line 305: | Line 194: | ||
$offset is the time offset to extract (for '''audio'''/'''video'''). It is an array ref of [HOUR, MINUTE, SECOND, FRAME]. | $offset is the time offset to extract (for '''audio'''/'''video'''). It is an array ref of [HOUR, MINUTE, SECOND, FRAME]. | ||
− | + | $plugin->export_mp3( $dst, $doc, $src, $rate ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Export $src to $dst in MP3 format at sampling rate $rate. | Export $src to $dst in MP3 format at sampling rate $rate. | ||
− | + | $plugin->export_audio( $dst, $doc, $src, $container ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Export audio-only $src to $dst in $container format. | Export audio-only $src to $dst in $container format. | ||
Audio is encoded as <em>audio_codec</em>. | Audio is encoded as <em>audio_codec</em>. | ||
− | + | $plugin->export_video( $dst, $doc, $src, $container ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Export audio and video $src to $dst in $container format with vertical lines $lines maintaining aspect ratio. | Export audio and video $src to $dst in $container format with vertical lines $lines maintaining aspect ratio. | ||
Line 347: | Line 209: | ||
Audio is encoded as <em>audio_codec</em>. | Audio is encoded as <em>audio_codec</em>. | ||
− | + | $plugin->export_cell( $dir, $doc, $src, $geom, $size, $offset ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Export $src to $dst in JPG format in dimensions $geom from offset $offset. | Export $src to $dst in JPG format in dimensions $geom from offset $offset. | ||
− | + | $secs = $plugin->calculate_offset( $duration, $offset ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Translates a seconds or percentage offset into seconds from the start time. If the resulting time is greater than $duration returns $duration. | Translates a seconds or percentage offset into seconds from the start time. If the resulting time is greater than $duration returns $duration. | ||
Latest revision as of 09:56, 22 January 2013
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki
Contents
NAME
EPrints::Plugin::Convert::Thumbnails - thumbnail-sized versions of audio/video/images
The Thumbnail How-to may also be useful: How to customise thumbnails
SYNOPSIS
use EPrints;
# enable audio previews
$c->{plugins}->{'Convert::Thumbnails'}->{params}->{audio} = 1;
# disable video previews
$c->{plugins}->{'Convert::Thumbnails'}->{params}->{video} = 0;
# enable audio_*/video_* previews
$c->{thumbnail_types} = sub {
my( $list, $repo, $doc ) = @_;
push @$list, qw( audio_mp4 audio_ogg video_mp4 video_ogg );
};
...
my $plugin = $session->plugin( "Convert" );
my %available = $plugin->can_convert( $doc );
$plugin = $available{"thumbnail_video"}->{plugin};
$new_doc = $plugin->convert( $doc, "thumbnail_video" );
DESCRIPTION
Conversion of images, videos and audio into preview/thumbnail versions.
This plugin wraps the ImageMagick convert and ffmpeg tools.
Testing Audio and Video Conversion
When files are uploaded to EPrints a file format identification process occurs. This is based on the EP_TRIGGER_MEDIA_INFO
callbacks. A set of callbacks are provided by lib/cfg.d/media_info.pl. To customise these copy the file to your repository's cfg.d/ directory.
This plugin relies on the media
info added by the file format identification. To check this is working export the EPrint as XML and check for a <media> entry in your document:
./bin/export [archiveid] eprint XML [eprintid]
At any time you can re-run the file format identification by using redo_mime_type
in epadmin:
./bin/epadmin redo_mime_type [archiveid] eprint [eprintid] --verbose
If ffprobe is configured correctly you should see it being called for each document.
Finally, to regenerate thumbnails do:
./bin/epadmin redo_thumbnails [archiveid] [eprintid] --verbose
PARAMETERS
These parameters can be set through the plugins.pl configuration file. You must also configure the executables locations for convert and ffmpeg in EPrints::SystemSettings.
- convert_formats = { ext => mime_type }
- Define the formats supported for input by the call_convert() method.
- ffmpeg_formats = { ext => mime_type }
- Define the formats supported for input by the call_ffmpeg() method.
- sizes = { size => [$w, $h] }
- Define the size of thumbnails that can be generated e.g. "small => [66,50]". The image dimensions generated may be smaller than those specified if the aspect ratio of the source document is different.
- Images are output in 8-bit paletted PNG.
- video = 1
- Enable video previews.
- audio = 1
- Enable audio previews.
- video_height = "480"
- Video preview vertical lines.
- audio_sampling = "44100"
- Audio frequency sampling rate in Hz.
- audio_bitrate = "96k"
- Audio bit rate in kb/s
- audio_codec = "libfaac"
- ffmpeg compiled-in AAC codec name.
- frame_rate = "10.00"
- Video frame rate in fps.
- video_codec = "h264"
- ffmpeg compiled-in H.264 codec name (may be libx264 on some platforms).
- video_rate = "1500k"
- Video bit rate in kilobits.
- call_convert = sub( $plugin, $dst, $doc, $src, $geom, $size )
- See call_convert.
- call_ffmpeg = sub( $plugin, $dst, $doc, $src, $geom, $size, $offset )
- See call_ffmpeg.
METHODS
can_convert
%types = $plugin->can_convert( $doc )
Returns a hash map of types this plugin can convert $doc to.
This may be relatively expensive to do if the plugin has to call an external tool to determine if it can export something.
convert
$new_doc = $plugin->convert( $eprint, $doc, $type )
Request the plugin converts $doc to $type, as returned by can_convert.
export
@filelist = $plugin->export( $dir, $doc, $type )
Request the plugin converts $doc to $type, as returned by can_convert. Outputs the resulting files to $dir and returns their paths (excluding the leading $dir part).
Utility Methods
$ver = $plugin->convert_version()
Returns the MAJOR.MINOR version of ImageMagick.
Returns 0.0 if the version can not be determined.
$ok = $plugin->is_video( $doc )
Returns true if $doc is a video.
$doc = $plugin->intermediate( $doc, $src, $geom, $src )
Attempt to find an intermediate document that we can use to convert from (e.g. make a thumbnail from a preview version).
Returns the original $doc if not intermediate is found.
$plugin->call_convert( $dst, $doc, $src, $geom, $size )
Calls the ImageMagick convert tool to convert $doc into a thumbnail image. Writes the image to $dst. $src is the full path to the main file from $doc. The resulting image should not exceed $geom dimensions ([w,h] array ref).
$size is the thumbnail-defined size (as-in the keys to the sizes parameter).
This method can be overridden with the call_convert parameter.
$plugin->call_ffmpeg( $dst, $doc, $src, $geom, $size, $offset )
Uses the ffmpeg tool to do the image conversion of $doc. $dst is the filename to write to, $src is the filename to read from and $geom is the image dimensions to write.
$size is the thumbnail-defined size (as-in the keys to the sizes parameter or audio or video).
$offset is the time offset to extract (for audio/video). It is an array ref of [HOUR, MINUTE, SECOND, FRAME].
$plugin->export_mp3( $dst, $doc, $src, $rate )
Export $src to $dst in MP3 format at sampling rate $rate.
$plugin->export_audio( $dst, $doc, $src, $container )
Export audio-only $src to $dst in $container format.
Audio is encoded as audio_codec.
$plugin->export_video( $dst, $doc, $src, $container )
Export audio and video $src to $dst in $container format with vertical lines $lines maintaining aspect ratio.
Video is encoded as video_codec.
Audio is encoded as audio_codec.
$plugin->export_cell( $dir, $doc, $src, $geom, $size, $offset )
Export $src to $dst in JPG format in dimensions $geom from offset $offset.
$secs = $plugin->calculate_offset( $duration, $offset )
Translates a seconds or percentage offset into seconds from the start time. If the resulting time is greater than $duration returns $duration.
To specify seconds either use just a number (1234) or append 's' (1234s).
To specify a percentage of $duration append '%' (52%).
SEE ALSO
EPrints::Plugin, EPrints::Plugin::Convert.
AUTHOR
Copyright 2009 Tim Brody <tdb2@ecs.soton.ac.uk>, University of Southampton, UK.
This module is released under the GPLv3 license.
COPYRIGHT
Copyright 2000-2011 University of Southampton.
This file is part of EPrints http://www.eprints.org/.
EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see http://www.gnu.org/licenses/.