Here is the code that converts the video
Code:
sub validate_link_pre {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'validate_link'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my ($link) = @_;
$link = convert_video($link);
return $link;
}
sub convert_video {
# -------------------------------------------------------------------
my $link = shift;
my $linksdb = $DB->table('Links');
my $cfg = Links::Plugins::get_plugin_user_cfg('ConvertVideo');
my $vf_field = $cfg->{video_file_field};
my $ff_field = $cfg->{flash_file_field};
my $thumb = $cfg->{thumbnail_file_field};
# return if no video file uploaded
my $fh = $linksdb->file_info( $vf_field, $link->{ID} ) or return $link;
my $full_path = "$fh";
# get the mpeg filename
my $filename = $full_path;
$filename =~ s/(.+)\/\d+-([^\/]+)\.$/$2/g;
# get the info from the movie file
my ($swidth, $sheight, $bitrate) = get_mov_info($full_path);
my $size_cmd = generate_dimensions($swidth,$sheight);
# set the flash filename
my $flvfile = $CFG->{admin_root_path} . "/tmp/" . $link->{ID} . ".flv";
# convert mpeg file to flash file and put it to field "flv_file"
my $mpeg_cmd = "ffmpeg -y -i $full_path";
if ($size_cmd) {
$mpeg_cmd .= $size_cmd;
}
$mpeg_cmd .= " -ar 22050 -ab 64 -ac 2 -r 15";
if ($cfg->{flash_quality}) {
$mpeg_cmd .= " -b " . $cfg->{flash_quality};
}
if ($cfg->{watermark_file} and -f $cfg->{watermark_file} and -s $cfg->{watermark_file}) {
$mpeg_cmd .= " -vhook '/usr/lib/vhook/watermark.so -f $cfg->{watermark_file}'";
}
$mpeg_cmd .= " $flvfile";
my $res = system "$mpeg_cmd";
if ($res == 0) {
$link->{$ff_field} = GT::SQL::File->open($flvfile);
#unlink $flvfile;
}
# capture the thumbnail picture at the 10th second frame
if (!$link->{$thumb}) {
my $output_fpath = generate_thumbnail($full_path,"$link->{$vf_field}");
if (ref $output_fpath eq 'HASH') {
}
else {
# print "** output_fpath: $output_fpath\n";
$link->{$thumb} = GT::SQL::File->open($output_fpath);
}
}
=tag
my $thumbnail = $CFG->{admin_root_path} . "/tmp/thumbnail-" . $link->{ID} . ".png";
my $thumb_cmd = "ffmpeg -y -i $full_path -vframes 1 -ss ";
$thumb_cmd .= $cfg->{thumbnail_frame_second} =~ /^\d\d\:\d\d\:\d\d$/ ? $cfg->{thumbnail_frame_second} : "00:00:10";
$thumb_cmd .= " -an -vcodec png -f rawvideo -s ";
$thumb_cmd .= $cfg->{thumbnail_size} ? $cfg->{thumbnail_size} : "80x80";
$thumb_cmd .= " $thumbnail";
my $res2 = system "$thumb_cmd";
if ($res2 == 0) {
$link->{$thumb} = GT::SQL::File->open($thumbnail);
unlink $thumbnail;
}
=cut
return $link;
}
And here is the code in my plugin to call the convert_video function.
Code:
sub post_add_link {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'add_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'add_link' code to run, otherwise the code will continue as normal.
#
my ($link) = @_;
my $results = shift;
if($results->{Review_Validated} == "Yes")
{
$link = Plugins::ConvertVideo::convert_video($link);
}
return $link;
}
Quite honestly, I really don't know the defference between @this and $this or shift and @_.
Or even what it is.
But I'm always open to learn
Sacrifice is not about what you lose,
it is about what you gain in the process.