Avidemux Forum

Avidemux => Stable branch (2.5) discussion => Topic started by: gbell12 on March 16, 2010, 03:24:16 AM

Title: Getting length of video?
Post by: gbell12 on March 16, 2010, 03:24:16 AM
Hi everyone,

The scripting documentation gives examples like this:

app.clearSegments();
app.addSegment(0,0,500);
app.addSegment(0,600,19468);

...to delete frames between 500 and 600.  Problem is the length of the video, 19468, is a magic number, specific to the video.  This makes automated editing difficult.  I don\'t see a get function to get the size (in frames) of the loaded video.  Am I missing something?

Thanks,
George
Title: Getting length of video?
Post by: FeRD_NYC on March 23, 2010, 04:30:57 AM
I was stuck on this problem for a while, also. My current scripting need is to trim the first N frames off of a directory full of different-length AVI files, which requires setting a segment {N,$END] and using copy mode. There didn't seem to be any way to get the length via the script functions provided.

Fortunately, I found a solution. Experimenting with the GUI, I noticed that immediately after loading a file, the display showed that markers A and B were set to the 0'th and last frames, respectively.

Sure enough, that's true when scripting as well, at least UNTIL you call app.clearSegments();

So, the solution I used in my script, to properly trim a fixed number of frames from the start of an arbitrarily-long file, ended up looking like so:

function processFile(filename, targetfile) {
        var len;
        // Load the file
        app.load(filename);
        //displayError("A=" + app.markerA + " B=" + app.markerB)
        len = app.markerB+1;

        //01 segments
        app.clearSegments();
        app.addSegment(0,0,len);
        app.markerA=425;
        app.markerB=len-1;


Hope this helps!
Title: Getting length of video?
Post by: gbell12 on March 24, 2010, 08:24:03 AM
Excellent, thanks Ferd!  There\'s some mention of using the markers in the docs, but I couldn\'t find how to access their values from a script.
Cheers,
gbell
Title: Getting length of video?
Post by: Pulson229 on March 30, 2010, 08:00:10 AM
Interesting post dude....discussion are always helpful in one way or the other. Thanks for giving out information. It’s really nice and mean full.
Title: Getting length of video?
Post by: Agent_007 on March 30, 2010, 02:45:59 PM
Pulson229: you are a spammer?
Title: Getting length of video?
Post by: FeRD_NYC on March 30, 2010, 04:07:01 PM
Quote from: Agent_007Pulson229: you are a spammer?

LOL. Just because his first ever post on the forum, which consists of nothing but "Generic Thread-Response Verbiage Selection D", was posted at 04:00:10? As if on some sort of automated schedule, or something? To jump right to the suggestion that he might be some sort of spambot... Why, Agent_007, that seems a bit mean... full! ;)

Anyway, back on topic... glad I could be of assistance, grbell12, hope you managed to get your script sorted out! If it's anything involved, please do share. There's far too few examples of "real-world task" script solutions available in the documentation, IMHO! I have a feeling looking at others' code is the best way to really get a feel for avidemux scripting.
Title: Getting length of video?
Post by: bazu on June 29, 2010, 07:24:23 AM
Really useful, thanks Fred!
Title: Re: Getting length of video?
Post by: ykmgt on February 29, 2012, 03:31:26 PM
If you want to know not selected area of markerA to markerB but whole length on Avidemux,

app.video.frameCount

is the answer. Check below in your scripts.

displayInfo(app.video.frameCount.toString());