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


1.11
date	2009.06.15.15.51.27;	author gfinch;	state Exp;
branches;
next	1.10;

1.10
date	2009.06.14.08.33.14;	author gfinch;	state Exp;
branches;
next	1.9;

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

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

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

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

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

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

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

1.2
date	2005.07.23.17.08.48;	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.11
log
@updates
@
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 ffmpeg plugin v2.1
# v 2.1 - add experimental 3gp support
# v 2.2 - format changed in ffmpeg from image to image2, update
# v 2.3 add youtube and flv formats

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

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


if ($command eq "version") {
    print "ffmpeg encoder plugin v2.3\n";
    exit 0;
}


if ($command eq "init") {

    # perform any initialisation needed
    # On error, print error message and exit 1
    # otherwise exit 0
    
    if (&location("ffmpeg") eq "") {
        print "The ffmpeg binary was not found, please install it and try again !";
	exit 1;
    }

    ##############################
    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 "1\n";
    exit 0;
}


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

   # audio types are: 0 - cannot encode audio, 1 - can encode using
   #  mp3, 2 - can encode using pcm, 3 - can encode using pcm and mp3
   # 4 - mp2, 8 - vorbis, 16 - AC3, 32 - AAC, 64 - AMR-NB

   # restrictions: 'fps=xx.yy' which
   # means "can only encode at xx.yy frames per second", size=x X y, arate=audio rate 
    # - otherwise set it to 'none'


    print "divx|divx (25 fps)|5|fps=25.00|avi|\n";
    print "asf|asf|5|none|asf|\n";
    print "3gp_h263|3gp (h263)|96|size=176x144,arate=8000|3gp|\n";
    print "3gp_mp4|3gp (mp4)|96|size=176x144,arate=8000|3gp|\n";
    print "flv|flv|9|arate=44100;22050;11025|flv|\n";
    print "flv-youtube|flv (425x318, optimised for youtube)|33|arate=44100;22050;11025,size=425x318|flv|\n";
    print "flv-youtubex|flv (other sizes, optimised for youtube)|33|arate=44100;22050;11025,aspect=1.3333:1|flv|\n";
    #print "theora|ogg-theora (experimental, requires ffmpeg2theora)|5|none|ogv\n";
    exit 0;
}




if ($command eq "get_rfx") {
    # nice example of how to give the user a choice of options

    if ($otype eq "flv"||$otype eq "flv-youtube"||$otype eq "flv-youtubex") {
	$aq=&rc_get("encoder_acodec");
	if ($aq==0) {
	    # mandatory section
	    print "<define>\n";
	    print "|1.7\n";
	    print "</define>\n";
	    
	    # mandatory section
	    print "<language_code>\n";
	    print "0xF0\n";
	    print "</language_code>\n";
	    
	    # optional section
	    print "<params>\n";
	    print "mp3|Use _mp3 audio codec|bool|1|1\n";
	    print "mp3lame|Use mp3_lame audio codec|bool|0|1\n";
	    print "</params>\n";

	}
    }
}







if ($command eq "encode") {
    # encode
    $encoder_command="ffmpeg";

    $ffver=`ffmpeg 2>&1|grep libavformat`;

    $ffver=(split(/\./,$ffver))[0];

    $ffver=(split(" ",$ffver))[-1];

    $usemp3=$ARGV[13];
    $usemp3lame=$ARGV[14];

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

    # default seems to be divx
    $vcodec="";
    if ($otype eq "asf") {
	$vcodec="-f asf";
    }
    elsif ($otype eq "3gp_h263") {
	$vcodec="-f h263";
    }
    elsif ($otype eq "3gp_mp4") {
	$vcodec="-f mp4";
    }
    elsif ($otype eq "flv"||$otype eq "flv-youtube"||$otype eq "flv-youtubex") {
	$vcodec="-f flv";
    }

    if ($otype eq "flv-youtube"||$otype eq "flv-youtubex") {
	$vcodec.=" -b 1024k -bt 256k -maxrate 1024k -minrate 1024k -bufsize 8192k";
    }

    # video stream
    $audio_com="";
    unless ($audiofile eq "") {
	$aq=&rc_get("encoder_acodec");
	$audio_com="-i $audiofile";
	if ($aq==1) {
	    #pcm
	    $audio_com.=" -acodec copy";
	}
	elsif ($aq==5) {
	    $audio_com.=" -acodec aac";
	}
	elsif ($aq==6) {
	    $audio_com.=" -acodec amr_nb";
	}
	elsif ($aq==0) {
	    if ($usemp3lame) {
		$audio_com.=" -acodec libmp3lame";
	    }
	    else {
		$audio_com.=" -acodec mp3";
	    }
	}
	elsif ($aq==3) {
	    $audio_com.=" -acodec vorbis";
	}
	else {
	    $audio_com.=" -acodec mp2";
	}

	if ($otype eq "flv-youtube"||$otype eq "flv-youtubex") {
	    $audio_com.=" -ab 128k -ar $arate";
	}
	elsif ($otype eq "flv") {
	    $audio_com.=" -ab 192k -ar $arate";
	}
	elsif ($otype eq "3gp_h263" || $otype eq "3gp_mp4") {
	    $audio_com.=" -ac 1 -ab 12 -ar 8000";
	}

    }
    
    $vid_length=($end-$start+1)/$fps;

    $err=">/dev/null 2>&1";
    if (defined($DEBUG_ENCODERS)) {
	$err="1>&2";
    }

    # unfortunately this does not work yet...
    if ($otype eq "theora") {
	$syscom="ffmpeg2theora -o \"$nfile\" -f image2 -i %8d$img_ext $audio_com -d off $err";
    }
    elsif ($otype eq "3gp") {
	$passfile="passfile";
	for $pass (1,2) {
	    $syscom="$encoder_command -strict 1 -pass $pass -passfile $passfile -y -r $fps -f image2 -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
	    if ($pass==1) {
		if (defined($DEBUG_ENCODERS)) {
		    print STDERR "ffmpeg_encoder command is: $syscom\n";
		}
		
		system ($syscom);
	    }
	}
    }
    else {
	if ($ffver>=52) {
	    $syscom="$encoder_command -metadata comment=\"$comment\" -metadata author=\"$author\" -metadata title=\"$title\" -y -r $fps -f image2 -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
	}
	else {
	    $syscom="$encoder_command -comment \"$comment\" -author \"$author\" -title \"$title\" -y -r $fps -f image2 -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
	}
    }

    if (defined($DEBUG_ENCODERS)) {
	print STDERR "ffmpeg_encoder command is: $syscom\n";
    }

    system ($syscom);

    &sig_complete;
    exit 0;
}



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



if ($command eq "finalise") {
    # do any finalising code
    
    # end finalising code
    print "finalised\n";
    exit 0;
}

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, frames start at selection
}


@


1.10
log
@updates
@
text
@d81 2
a82 2
    print "flv-youtube|flv (425x318, optimised for youtube)|3|arate=44100;22050;11025,size=425x318|flv|\n";
    print "flv-youtubex|flv (other sizes, optimised for youtube)|3|arate=44100;22050;11025,aspect=1.3333:1|flv|\n";
@


1.9
log
@updates
@
text
@d126 6
d176 1
a176 1
		$audio_com.=" -acodec mp3lame";
d226 6
a231 1
	$syscom="$encoder_command -comment \"$comment\" -author \"$author\" -title \"$title\" -y -r $fps -f image2 -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
@


1.8
log
@YUV unclamped yeah
@
text
@d58 1
a58 1
    print "0\n";
d89 33
d126 3
d169 6
a174 1
	    $audio_com.=" -acodec mp3";
d186 3
@


1.7
log
@updates
@
text
@d81 2
a82 2
    print "flv-youtube|flv (320x240, optimised for youtube)|3|arate=22050;11025,size=320x240|flv|\n";
    print "flv-youtubex|flv (other sizes, optimised for youtube)|3|arate=22050;11025,aspect=1.3333:1|flv|\n";
d114 1
a114 1
	$vcodec.=" -b 1024k -bt 256k -maxrate 1024k -minrate 1024k -bufsize 16384k";
d143 1
a143 1
	    $audio_com.=" -ar 22050 -ab 64k";
d165 1
a165 1
	    $syscom="$encoder_command -strict 1 -pass $pass -passfile $passfile -y -f image2 -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
d176 1
a176 1
	$syscom="$encoder_command -comment \"$comment\" -author \"$author\" -title \"$title\" -y -f image2 -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
@


1.6
log
@updates
@
text
@d13 1
d28 1
a28 1
    print "ffmpeg encoder plugin v2.1\n";
d69 1
d71 2
a72 2
   # restrictions: currently the only one implemented is 'fps=xx.yy' which
   # means "can only encode at xx.yy frames per second" 
d80 3
d109 8
d122 2
a123 1
	if ($aq==0) {
d127 7
a133 1
	    $audio_com=" -acodec aac -ac 1 -ab 12 -ar 8000";
d135 2
a136 2
	elsif ($aq==5) {
	    $audio_com=" -acodec amr_nb -ac 1 -ab 12 -ar 8000";
d141 8
@


1.5
log
@advanced encoders pt 1
@
text
@d12 1
a12 1

d132 1
a132 1
	$syscom="ffmpeg2theora -o \"$nfile\" -f image -i %8d$img_ext $audio_com -d off $err";
d137 1
a137 1
	    $syscom="$encoder_command -strict 1 -pass $pass -passfile $passfile -y -f image -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
d148 1
a148 1
	$syscom="$encoder_command -comment \"$comment\" -author \"$author\" -title \"$title\" -y -f image -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
@


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


1.3
log
@updates, add 3gp encoding to ffmeg_encoder
@
text
@d5 1
a5 1
# relesed under the GNU GPL 2
@


1.2
log
@make sure all files have license/copyright
@
text
@d10 2
a11 1
# LiVES ffmpeg plugin v2.0
d27 1
a27 1
    print "ffmpeg encoder plugin v2.0\n";
d74 2
d96 6
d110 6
d132 13
d146 1
a146 1
	$syscom="$encoder_command -comment \"$comment\" -author \"$author\" -title \"$title\" -y -f image -r $fps -i %8d$img_ext $audio_com -r $fps -t $vid_length $vcodec \"$nfile\" $err";
d164 1
a164 1

@


1.1
log
@Initial revision
@
text
@d3 6
a10 1
# salsaman@@xs4all.nl
@


1.1.1.1
log
@initial
@
text
@@
