<?xml version="1.0" encoding="utf-8"?>
<!-- 
    Copyright 2006 Sönke Rohde
    http://soenkerohde.com
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="init();" viewSourceURL="srcview/index.html">

    <mx:Script>
        <![CDATA[
            // MovieSize
            [Bindable]
            public var ms:Array = [
                {label:"wxh (160x128)", data:"wxh"},
                {label:"sqcif (128x96)", data:"sqcif"},
                {label:"qcif (176x144)", data:"qcif"},
                {label:"240x160", data:"240x160"},
                {label:"cif (352x288", data:"cif"},
                "320x240","400x300","512x384", "640x480",
                {label:"4cif (704x576)", data:"4cif"},
                "800x600"];
            
            // Framerate
            [Bindable]
            public var fr:Array = ["12","15","25"];
            
            // Video-Bitrate
            [Bindable]
            public var vbr:Array = ["360","768","1000", "1600"];
            
            // Audio-Bitrate
            [Bindable]
            public var abr:Array = ["32", "48", "56", "64", "80", "112", "128"];
            
            // Audio Samplingrate
            [Bindable]
            public var sr:Array = ["11025", "22050", "44100"];
            
            private function init():void{
                if(Application.application.parameters.ffmpeg  != undefined){
                    this.ffmpeg.text = Application.application.parameters.ffmpeg;
                }
                if(Application.application.parameters.input  != undefined){
                    this.input.text = Application.application.parameters.input;
                }
                if(Application.application.parameters.output  != undefined){
                    this.output.text = Application.application.parameters.output;
                }
                this.onChange(null);
            }
            
            private function onChange(e:Event):void{
                this.command.text = this.getCommand(true);
            }
            
            private function getCommand(showLinebreaks:Boolean):String{
                var cmd:String = "\"" + this.ffmpeg.text + "\" ";
                if(showLinebreaks){
                    cmd += "\n";    
                }
                if(this.startoffset.text != "0"){
                    cmd += "-ss " + this.startoffset.text + " ";
                }
                
                cmd += "-i \"" + this.input.text + "\" ";
                if(showLinebreaks){
                    cmd += "\n";    
                }
                
                if(this.duration.text != ""){
                    cmd += "-t " + this.duration.text + " ";
                }
                
                cmd += "-s " + this.moviesize.value + " ";
                cmd += "-r " + this.framerate.value + " ";
                cmd += "-b " + this.videobitrate.value + " ";
                if(this.deinterlace.selected){
                    cmd += "-deinterlace ";
                }
                
                if(showLinebreaks){
                    cmd += "\n";    
                }
                if(this.audioenabled.selected){
                    cmd += "-ab " + this.audiobitrate.value + " ";
                    cmd += "-ar " + this.audiosamplingrate.value + " ";
                    if(this.stereo.selected){
                        cmd += "-ac 2 ";
                    }else{
                        cmd += "-ac 1 ";
                    }
                    this.audiobox.filters = [];
                }else{
                    cmd += "-an ";
                    var bf:BlurFilter = new BlurFilter();
                    bf.blurX = 2;
                    bf.blurY = 2;
                    bf.quality = 5;
                    this.audiobox.filters = [bf];
                }
                
                if(showLinebreaks){
                    cmd += "\n";    
                }
                if(this.cropbottom.text != "0"){
                    cmd += "cropbottom " + this.cropbottom.text + " ";    
                }
                if(this.cropleft.text != "0"){
                    cmd += "-cropleft " + this.cropbottom.text + " ";    
                }
                if(this.cropright.text != "0"){
                    cmd += "-cropright " + this.cropbottom.text + " ";    
                }
                if(this.croptop.text != "0"){
                    cmd += "-croptop " + this.cropbottom.text + " ";    
                }
                
                if(showLinebreaks && this.hasPadding()){
                    cmd += "\n";    
                }
                if(this.padbottom.text != "0"){
                    cmd += "-padbottom " + this.padbottom.text + " ";    
                }
                if(this.padleft.text != "0"){
                    cmd += "-padleft " + this.padbottom.text + " ";    
                }
                if(this.padright.text != "0"){
                    cmd += "-padright " + this.padbottom.text + " ";    
                }
                if(this.padtop.text != "0"){
                    cmd += "-padtop " + this.padbottom.text + " ";    
                }
                if(this.hasPadding()){
                    cmd += "-padcolor " + this.padcolor.selectedColor.toString(16) + " ";
                }
                
                if(showLinebreaks){
                    cmd += "\n";    
                }
                cmd += "\"" + this.output.text + "\"";
                return cmd;    
            }
            
            private function hasPadding():Boolean{
                return this.padbottom.text != "0" || this.padleft.text != "0" || this.padright.text != "0" || this.padtop.text != "0";    
            }
            
            private function copyToClipboard(e:Event):void{
                System.setClipboard(this.getCommand(false));
            }
            
        ]]>
    </mx:Script>

    <!-- Video -->
    <mx:Panel width="200" layout="vertical" title="Video" cornerRadius="10" y="0"
        left="5" top="5" bottom="5" horizontalAlign="center">
        <mx:Label text="Movie Size"/>
        <mx:ComboBox id="moviesize" dataProvider="{ms}" change="onChange(event)" selectedIndex="8"></mx:ComboBox>
        <mx:Label text="Framerate"/>
        <mx:ComboBox id="framerate" dataProvider="{fr}" change="onChange(event)" selectedIndex="2"></mx:ComboBox>
        <mx:Label text="Bitrate"/>
        <mx:ComboBox id="videobitrate" dataProvider="{vbr}" change="onChange(event)" selectedIndex="1"></mx:ComboBox>
        <mx:HRule width="160"/>
        <mx:CheckBox id="deinterlace" label="Deinterlace" click="onChange(event)" selected="true"/>
        <mx:HRule width="160"/>
        <mx:Label text="Start Offset"/>
        <mx:TextInput id="startoffset" change="onChange(event)" text="0"/>
        <mx:Label text="Duration"/>
        <mx:TextInput id="duration" change="onChange(event)"/>
    </mx:Panel>

    <!-- Audio -->
    <mx:Panel layout="vertical" title="Audio" alpha="1.0" cornerRadius="10" width="200" height="250"
        right="5" top="5" horizontalAlign="center">
        <mx:CheckBox id="audioenabled" label="Enable Audio" click="onChange(event)" selected="true"/>
        <mx:VBox id="audiobox">
            <mx:Label text="Bitrate"/>
            <mx:ComboBox id="audiobitrate" dataProvider="{abr}" change="onChange(event)" selectedIndex="3"></mx:ComboBox>
            <mx:Label text="Sampling Rate"/>
            <mx:ComboBox id="audiosamplingrate" dataProvider="{sr}" change="onChange(event)" selectedIndex="1"></mx:ComboBox>
            <mx:Label text="Channels"/>
            <mx:RadioButton id="stereo" label="Stereo" data="2" groupName="audiochannels" selected="false" click="onChange(event)"/>
            <mx:RadioButton id="mono" label="Mono" data="1" groupName="audiochannels" selected="true" click="onChange(event)"/>
        </mx:VBox>
    </mx:Panel>
    
    <!-- IO -->
    <mx:Panel height="200" layout="vertical" title="IO" cornerRadius="10"
        top="5" left="220" right="220" horizontalAlign="center">
        <mx:Label text="FFMPEG"/>
        <mx:TextInput id="ffmpeg" text="c:\tools\ffmpeg\ffmpeg.exe" width="90%" change="onChange(event)"/>
        <mx:Label text="Input"/>
        <mx:TextInput id="input" text="c:\videos\test.avi" change="onChange(event)" width="90%"/>
        <mx:Label text="Output"/>
        <mx:TextInput id="output" text="c:\videos\test.flv" change="onChange(event)" width="90%"/>
    </mx:Panel>
    
    <!-- Command -->
    <mx:Panel layout="absolute" title="Command" cornerRadius="10"
        right="220" left="220" top="220" bottom="5" horizontalAlign="center">
        <mx:TextArea id="command" top="10" bottom="70" right="30" left="10">
        </mx:TextArea>
        <mx:Button label="Copy to Clipboard" click="copyToClipboard(event)"
            bottom="40" right="30" left="10">
        </mx:Button>
    </mx:Panel>
    <mx:Panel width="200" layout="vertical" title="Padding / Crop" 
        bottom="5" right="5" top="270" horizontalAlign="center">
        <mx:Canvas width="160" height="120" backgroundColor="0xEEEEEE">
            <mx:Label text="Padding" x="0" y="0"/>
            <mx:TextInput x="25" y="50" width="50" text="0" id="padleft" change="onChange(event)"/>
            <mx:TextInput x="53" y="20" width="50" text="0" id="padtop" change="onChange(event)"/>
            <mx:TextInput x="82" y="50" width="50" text="0" id="padright" change="onChange(event)"/>
            <mx:TextInput x="53" y="80" width="50" text="0" id="padbottom" change="onChange(event)"/>
            <mx:ColorPicker x="138" y="98" id="padcolor" change="onChange(event)"/>
        </mx:Canvas>
        
        <mx:Canvas width="160" height="120" backgroundColor="0xEEEEEE">
            <mx:Label text="Crop" x="0" y="0"/>
            <mx:TextInput x="25" y="50" width="50" text="0" id="cropleft" change="onChange(event)"/>
            <mx:TextInput x="53" y="20" width="50" text="0" id="croptop" change="onChange(event)"/>
            <mx:TextInput x="82" y="50" width="50" text="0" id="cropright" change="onChange(event)"/>
            <mx:TextInput x="53" y="80" width="50" text="0" id="cropbottom" change="onChange(event)"/>
        </mx:Canvas>
    </mx:Panel>
    
</mx:Application>