Author Topic: Getting length of video?  (Read 6045 times)

gbell12

  • Newbie
  • *
  • Posts: 2
Getting length of video?
« 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

FeRD_NYC

  • Newbie
  • *
  • Posts: 30
Getting length of video?
« Reply #1 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:

Code: [Select]
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!
« Last Edit: October 10, 2011, 10:09:58 AM by FeRD_NYC »

gbell12

  • Newbie
  • *
  • Posts: 2
Getting length of video?
« Reply #2 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

Pulson229

  • Newbie
  • *
  • Posts: 1
Getting length of video?
« Reply #3 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.

Agent_007

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3163
Getting length of video?
« Reply #4 on: March 30, 2010, 02:45:59 PM »
Pulson229: you are a spammer?
I am away between 15th of May - 15th of June. (yes, I am playing D3)

FeRD_NYC

  • Newbie
  • *
  • Posts: 30
Getting length of video?
« Reply #5 on: March 30, 2010, 04:07:01 PM »
Quote from: Agent_007
Pulson229: 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.
« Last Edit: October 10, 2011, 10:10:36 AM by FeRD_NYC »

bazu

  • Newbie
  • *
  • Posts: 1
Getting length of video?
« Reply #6 on: June 29, 2010, 07:24:23 AM »
Really useful, thanks Fred!

ykmgt

  • Newbie
  • *
  • Posts: 2
Re: Getting length of video?
« Reply #7 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());