====== Scripting ====== From the 2.1 branch on, Avidemux uses the SpiderMonkey ECMAScript language to handle scripting. Project files are based on ECMAScript. You can use ECMAScript to do your custom scripts. This documentation will present Avidemux commands. ===== Creating a script file ===== The first thing to take care of is that an Avidemux ECMAScript project must start with "//AD". For example, like this: //AD //--automatically built-- //--Project: /tmp/l.js var app = new Avidemux(); You will probably want to create an instance of the Avidemux class, that will give you access to Avidemux internal functions. This is done by the new Avidemux() command, you will note that in all examples, the instance is refered to as "app". **Warning:** most non integer parameters must be sent double quoted. It is generally a good idea to save a project file and use it as a starting point for your custom scripts. ===== Using functions ===== After you have the standard head of your script, as explained in the previous section, you then call all of the functions with a '.' after the variable name you declared. For example, with the line **var(nbsp)app(nbsp)=(nbsp)new(nbsp)Avidemux();**, you would use **app.function** where //function// is the name of the function you want. For list of available functions, see other sections of this article. Some example function calls: * app.load("/home/user/Movie.mpg.idx"); * app.clearSegments(); * app.addSegment(0,0,20084); * app.markerA=4898; * app.markerB=4902; * app.video.addFilter("crop","left=10","right=0","top=4","bottom=4"); * app.video.addFilter("resize","w=704","h=468","algo=0"); * app.video.addFilter("fluxsmooth","temporal_threshold=7","spatial_threshold=7"); ===== Additional functions ===== Here is the set of commands which are not part of the Avidemux class. They can be accessed directly. ^Command ^Parameter ^Parameter ^Return ^Description ^ |displayError |string | | |Display an error popup with the message | |displayInfo |string | | |Display an info popup with the message | |fileReadSelect | | |filename |Open the file selector (read) | |fileWriteSelect | | |filename |Open the file selector (write) | |allFilesFrom |directory | |Number of files from that directory |Initiate the directory parsing | |nextFile | | |filename |Returns the next filename | ===== Avidemux functions ===== ^Command ^Parameter ^Parameter ^Return ^Description ^ |load |"filename" | | |Load the video (erasing all) | |append |"filename" | | |Append the video to the existing video(s) | |save |"filename" | | |Save output to the given filename | |saveDVD |"filename" | | |Set output format to MPEG PS and save | |saveOGM |"filename" | | |Set output format to OGM and save | |clearSegments | | | |Remove all segments, after that command you have 0 frames available! | |addSegment |reference |start,len | |Add a new segment from the source reference, starting at frame start with len frames | |goToTime |hh |mm,ss | |Go to frame at hh hour, mm minutes and ss seconds | |forceUnpack | | | |Set autounpack, you must call it before loading a file, and it will be unpacked | |setContainer |"container" | | |Set the output container (must be between "") - available choices are PS, ES, TS, OGM, AVI, AVI_DUAL, AVI_UNP | There are also a couple of variables you may want to change: * markerA: set the A marker (e.g.: app.markerA=100; set markerA to the 100th frame) * markerB: set the B marker ===== Avidemux video functions ===== ^Command ^Parameter ^Parameter ^Return ^Description ^ |addFilter |"filter name" |"filter param" | |Add the filter | |clearFilters | | | |Removes all video filters | |Codec |"codec name" |"codec conf"[,"codec extra"] | |Select the encoder, using the conf, which can be "CBR=bitrate", "CQ=qz", "2PASS=size" or "SAME=0" | |saveJpeg |"filename" | | |Save the current frame as a JPEG file | |getWidth | | |integer |Returns video width | |getHeight | | |integer |Returns video height | |getFps1000 | | |integer |Returns the video framerate * 1000 | |setFps1000 |integer | | |set the video framerate * 1000 | |getFCC | | |string |returns video FourCC as a string | |isVopPacked | | |integer |Returns if video has packed bitstream or not | |hasQpel | | |integer |Returns if video has Qpel or not | |hasGmc | | |integer |Returns if video has GMC or not | |setPostProc |type |threshold,strength | |Set postprocessing | ===== Avidemux audio functions ===== ^Command ^Parameter ^Parameter ^Return ^Description ^ |scanVbr | | | |Build the time map needed for MP3 VBR | |save |"filename" | | |Save the audio track as filename | |load |"type" |"filename" | |Load audio as an external track, type is the file type - AC3, MP3, WAV, filename is the name of the file to load | |getNbTracks | | |integer |Returns the number of audio tracks at frame frame | |setTrack |track | | |Select track "track" | There are also a couple of variables you may want to change as above, if your instance has been created by app=new(nbsp)Avidemux(). You will access them using app.audio.xxx=yyy: * normalize: 1 (normalize activated), 0 (not activated) * downsample: same for downsample (48(nbsp)kHz to 44.1(nbsp)kHz) * resample: set the new frequency * delay: set the delay in ms * film2pal: 1 (film2pal activated), 0 (not activated) * mono2stereo: ditto stereo2mono: ditto ===== See also ===== [[tutorial:Scripting tutorial]]