head	1.9;
access;
symbols
	start:1.1.1.1 salsaman:1.1.1;
locks; strict;
comment	@# @;


1.9
date	2009.07.07.15.42.43;	author gfinch;	state Exp;
branches;
next	1.8;

1.8
date	2009.06.14.02.48.34;	author gfinch;	state Exp;
branches;
next	1.7;

1.7
date	2008.01.22.16.04.21;	author gfinch;	state Exp;
branches;
next	1.6;

1.6
date	2007.06.29.17.18.15;	author gfinch;	state Exp;
branches;
next	1.5;

1.5
date	2005.12.07.03.43.59;	author gfinch;	state Exp;
branches;
next	1.4;

1.4
date	2005.12.06.23.39.46;	author gfinch;	state Exp;
branches;
next	1.3;

1.3
date	2005.07.23.17.08.48;	author gfinch;	state Exp;
branches;
next	1.2;

1.2
date	2005.01.05.19.31.49;	author gfinch;	state Exp;
branches;
next	1.1;

1.1
date	2004.11.22.15.47.40;	author gfinch;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2004.11.22.15.47.40;	author gfinch;	state Exp;
branches;
next	;


desc
@@


1.9
log
@encoder update
@
text
@#!/usr/bin/perl

# (c) G. Finch (salsaman)

# released under the GNU GPL 3 or later
# see file COPYING or www.gnu.org for details

#######################################################################
# LiVES mencoder plugin v1.9

# 1.7 add kvcd back in
# 1.8 use mjpeg with -ovc copy (thanks to Rich Felker for the suggestion)
# 1.9 add ffv1 and png support (thanks to anonymous) 

#######################################################################

if (!defined($standalone)) {
    my $smogrify=`which smogrify`;
    chomp($smogrify);
    require $smogrify;
}
else {
    $command=$ARGV[0];
}


#######################################################################


if ($command eq "version") {
    print "mencoder encoder plugin v1.9\n";
    exit 0;
}


if ($command eq "init") {
    # perform any initialisation needed
    # On error, print error message and exit 1
    # otherwise exit 0

    if (&location("mencoder") eq "") {
	print "Mencoder was not found. Please install it and try again.";
	exit 1;
    }
    
    # end init code
    print "initialised\n";
    exit 0;
}



if ($command eq "get_capabilities") {
    # return capabilities - this is a bitmap field
    # bit 0 - takes extra parameters (using RFX request)
    # bit 1 - unused
    # bit 2 - can encode png
    # bit 3 - not pure perl
    print "4\n";
    exit 0;
}



if ($command eq "get_formats") {
   # for each format: -
   # return format_name|display_name|audio_types|restrictions|extension|

   # audio types are: 0 - cannot encode audio, 1 - can encode using
   #  mp3, 2 - can encode using pcm, 4 - can encode using mp2, 8 - vorbis

   print "mjpeg|MJPG|2|none|avi|\n";
   print "ffv1|FFV1 (lossless)|2|none|avi|\n";
   print "kvcd|kvcd (experimental))|4|arate=32000;44100;48000,fps=24;25;30,aspect=352:240,hblock=16,vblock=16|mpg|\n";
   
   exit 0;
}



if ($command eq "encode") {
    # encode 

    $encoder_command="mencoder";

    # remove ":"'s from comments, mencoder doesn't like them even in quotes
    $title=~ s/:/ /g;
    $author=~ s/:/ /g;
    $comment=~ s/:/ /g;

    # mencoder doesn't like empty strings either
    if ($title eq "") {
	$title=" ";
    }
    if ($author eq "") {
	$author=" ";
    }
    if ($comment eq "") {
	$comment=" ";
    }

    if ($otype eq "") {
	$otype="mjpeg";
	&rc_set("output_type",$otype);
    }

    # set the codec
    $vcodec="mjpeg";
    
    if ($otype eq "mpeg4" || $otype eq "mpeg2video" || $otype eq "ffv1") {
	$vcodec=$otype;
    }

    if ($otype eq "mpg1") {
	$vcodec="mpeg1video";
    }
    
    $mf_ver=&rc_get("mplayer_mf_version");
    
    $tmpvid="tmpvid";
    $err=">/dev/null 2>&1";
    if (defined($DEBUG_ENCODERS)) {
	$err="1>&2";
    }

    # TODO - recheck this
    $zeroframe=&mkname(0);
    `cp 00000001$img_ext $zeroframe$img_ext $err`;



    #prepare video stream

    if ($mf_ver==1) {
	if ($img_ext eq ".png") {
	    $syscom="$encoder_command  -mf on -mf type=png -vc mpng -o \"$tmpvid\" -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip -ofps $fps \\*$img_ext -frames " . ($end-$start+2) . " $err";
	}
	else {
	    $syscom="$encoder_command  -mf on -mf h=$vsize:w=$hsize:type=jpg -o \"$tmpvid\" -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip -ofps $fps \\*$img_ext -frames " . ($end-$start+2) . " $err";
	}
    }
    else {
	if ($img_ext eq ".png") {
	    $syscom=$encoder_command . " -mf fps=$fps:type=png -vc mpng -o \"" . $tmpvid . "\" -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip mf://*" . $img_ext . " -frames " . ($end-$start+2) . " $err";
	}
	else {
	    $syscom=$encoder_command . " -mf h=$vsize:w=$hsize:type=jpg -o \"" . $tmpvid . "\" -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip -ofps " . $fps . " mf://*" . $img_ext . " -frames " . ($end-$start+2) . " $err";
	}
    }
    if (defined($DEBUG_ENCODERS)) {
	print STDERR "Debug: mencoder command 1 is: $syscom\n";
    }
    system($syscom);

    $audio_com="";
    unless ($audiofile eq "") {
	$audio_com=" -oac copy -audiofile " . $audiofile;
    }

    if ($otype eq "mjpeg" || $otype eq "ffv1") {
	$syscom=$encoder_command . " -mc 0 -o \"$nfile\" $audio_com -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip -ofps $fps $tmpvid -info comment=\"$comment\":name=\"$title\":artist=\"$author\" $err";
    }
    elsif ($otype eq "kvcd") {
	$abitrate=112;
	$matrix="8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79";
	$inter_matrix="16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44";
	$scale="scale=352:240";

	$syscom="$encoder_command $tmpvid -mc 0 -of mpeg -ovc lavc -oac lavc -lavcopts acodec=mp2:abitrate=$abitrate:vcodec=mpeg1video:keyint=".int($fps).":mbd=1:vrc_minrate=64:vrc_maxrate=3000:vrc_buf_size=320:aspect=4/3:intra_matrix=$matrix:inter_matrix=$inter_matrix -vf $scale -o \"$nfile\"";

    }
    if (defined($DEBUG_ENCODERS)) {
	print STDERR "Debug: mencoder command 2 is: $syscom\n";
    }
    system($syscom);

    # required
    &sig_complete;
    exit 0;
}


if ($command eq "clear") {
    # this is called after "encode"
    # note that encoding could have been stopped at any time
    $tmpvid="tmpvid";
    if (-f $tmpvid) {
	unlink $tmpvid;
    }
    &sig_complete;
    exit 0;
}


if ($command eq "finalise") {
    # do any finalising code

    # ...

    # end finalising code
    print "finalised\n";
    exit 0;
}


###### subroutines #######




sub get_format_request {
    # return the code for how we would like audio and video delivered
    # this is a bitmap field composed of:
    # bit 0 - unset=raw pcm audio; set=pcm audio with wav header
    # bit 1 - unset=all audio; set=clipped audio
    # bit 2 - unset=all frames; set=frames for selection only

    return 7; # clipped pcm wav, clipped frames
}

@


1.8
log
@updates
@
text
@d143 1
a143 1
	if ($img_ext=".png") {
@


1.7
log
@advanced encoders pt 1
@
text
@d9 1
a9 1
# LiVES mencoder plugin v1.8
d13 1
d31 1
a31 1
    print "mencoder encoder plugin v1.8\n";
d59 1
a59 1
    print "0\n";
d73 1
d110 1
a110 1
    if ($otype eq "mpeg4" || $otype eq "mpeg2video") {
d133 1
d135 6
a140 1
	$syscom="$encoder_command  -mf on -mf h=$vsize:w=$hsize:type=jpg -o \"$tmpvid\" -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip -ofps $fps \\*$img_ext -frames " . ($end-$start+2) . " $err";
d143 6
a148 1
	$syscom=$encoder_command . " -mf h=$vsize:w=$hsize:type=jpg -o \"" . $tmpvid . "\" -ovc lavc -lavcopts vcodec=$vcodec:vhq -ovc copy -noskip -ofps " . $fps . " mf://*" . $img_ext . " -frames " . ($end-$start+2) . " $err";
d160 1
a160 1
    if ($otype eq "mjpeg") {
@


1.6
log
@update to gpl 3; other fixes
@
text
@d54 4
a57 2
    # 1 = can encode with frame changes (with an event.frames file)
    # 2 = can encode with fps changes (with an event.fps file)
@


1.5
log
@encoder plugin fixes
@
text
@d5 1
a5 1
# relesed under the GNU GPL 2
@


1.4
log
@add -fPIC to livido plugins, fix mencoder_encoder
@
text
@d9 1
a9 1
# LiVES mencoder plugin v1.7
d12 1
d30 1
a30 1
    print "mencoder encoder plugin v1.7\n";
@


1.3
log
@make sure all files have license/copyright
@
text
@a101 7
    # set intermediate codec
    $icodec="mjpeg";

    if (&version_hash((split(" ",`mencoder 2>/dev/null`))[1])>=1000000) {
	$icodec="ljpeg";
    }

d129 1
a129 1
	$syscom="$encoder_command  -mf on -mf h=$vsize:w=$hsize:type=jpg -o \"$tmpvid\" -ovc lavc -lavcopts vcodec=$icodec -noskip -ofps $fps \\*$img_ext -frames " . ($end-$start+2) . " $err";
d132 1
a132 1
	$syscom=$encoder_command . " -mf h=$vsize:w=$hsize:type=jpg -o \"" . $tmpvid . "\" -ovc lavc -lavcopts vcodec=$icodec -noskip -ofps " . $fps . " mf://*" . $img_ext . " -frames " . ($end-$start+2) . " $err";
d145 1
a145 1
	$syscom=$encoder_command . " -mc 0 -o \"$nfile\" $audio_com -ovc lavc -lavcopts vcodec=$vcodec:vhq -noskip -ofps $fps $tmpvid -info comment=\"$comment\":name=\"$title\":artist=\"$author\" $err";
@


1.2
log
@fix encoder check
@
text
@d3 5
@


1.1
log
@Initial revision
@
text
@d4 3
a6 1
# LiVES mencoder plugin v1.6
d24 1
a24 1
    print "mencoder encoder plugin v1.6\n";
d61 1
a61 3
   #  mp3, 2 - can encode using pcm, 3 - can encode using pcm and mp3

   print "mjpeg|MJPG|2|none|avi|";
d63 3
a65 4
   # use mjpeg-tools instead 
   #print "mpg1|mpeg1 (23.976 fps)|2|fps=23.976|";
   #print "mpeg2video|mpeg2video (23.976 fps)|2|fps=23.976|";
   #print "mpeg4|mpeg4|2|none|"; - doesn't seem to produce correct video 
d127 2
d146 12
a157 1
    $syscom=$encoder_command . " -mc 0 -o \"$nfile\" $audio_com -ovc lavc -lavcopts vcodec=$vcodec:vhq -noskip -ofps $fps $tmpvid -info comment=\"$comment\":name=\"$title\":artist=\"$author\" $err";
@


1.1.1.1
log
@initial
@
text
@@
