# How to get the total seconds of a video?

Hello guys,
I’m having trouble getting to put the total amount of seconds of a video on the trim end parameter automatically. To contextualize, I’m using the Dropdown Menu to select videos within the moviefilein. I would like to know if it is possible to insert this information in seconds in the trim end without making it impossible for me to touch the trim end later.
It would be cool if someone could help me, Thanks.

I am not clear what you are trying to achieve…

Why do you want to know the total amount of seconds of a movie?
and why do you want to put the total amount of seconds (=duration of the movie) in the trim end parameter?
Probably I misunderstood the question, but if you leave the end trim to fraction (%) and leave the value to 1, that will be the end of the video, but at that point there’s no trim… unless you want to trim the beginning of the movie and leave the end as it is?

1 Like

I will explain to make it more clear, I am developing software on Touchdesigner that is a video player, with 4 outputs of video and presets load and I need to make the trim easily to change and modify by the user but when the user opens the video the Trim parameter doesn’t load the total amount of seconds automatically, and I need to be in seconds not in fractions :(. So I found this trick when I change to fractions and put on the start trim 0 and 1 for the trim end, then change to seconds, which gives me the total amount of seconds on the trim end. But I need to do this automatically. So when I choose a video, keeps the total seconds of the last video… and I have to do this process manually, So I wish if there may be a resolution for this without putting a reference on the trim end then I can modify the value without break the code, tell me if you understand, English is not my first language kkkk but I think you can understand, Thank you

hey Gustavo @Rawlim ,

I would use `numSeconds` to get the lenght of a movie in seconds.
This is a little python line. Documentation here moviefileinTOP Class - Derivative

I have to rush out now, but I can provide an example if you need a hand or if you are not familiar with python.

The python line would be something like

``````op('moviefilein1').numSeconds
``````
1 Like

Hey @FaustoB, thanks for reply again.
So if i put in the trim end this expression when i will try to ajust the trim end by hand the expression will break right? So i am trying to get this kind of expression without breaking it.

Hey i found the solution…
Thanks for helping figure out, i will upload the result if you want to see what i did.
totalseconds.tox (566 Bytes)

Actually its not working good @FaustoB kkkkkkkkk
Because the pattern of customize components max range is 1 so when i tryied to move the fader to change the value, the total value became 1 again

The problem with asking for movie length is that when you ask for it, it may take a few frame for a correct value to appear in the Info CHOP since it may take a few frames to (close a prior file) and open a new file. Unless you have a Movie File In TOP for each movie that you will play (so you don’t have to re-use one Movie File In TOP) instead of using the Movie File In TOP, and if you’re using the Experimental especially, I recommend you use the moviePlayer component in the palette as it’s a wrapper around the Movie File In TOP that manages closing/opening files smoothly and asynchronously, and reports correctly the file properties and states. To get a non-UI version of it, click its Create Engine COMP pulse. You would use 4 movieEngines for a 4-channel mixer.

1 Like

Good point Greg, thanks for the heads up and for pointing us in the direction of how to properly resolve this!
However don’t underestimate the power of us creative punks used to make strange and probably inefficient things with your software!

I think I have put together a decent workaround that should be doing the job for @Rawlim.

File below. It might need some more testing but based on my quick testing, I think it’s doing the job.

MovieFile lenght in secs.toe (4.4 KB)

I have left some comments in the network, but basically:

#1 Use the slider to trim the movie file

#2 Change the movie file in “moviefilein1_Fraction”.
This node is used to calculate the movie length in seconds. I’ve found that using `numSeconds` (or grabbing the length from the Info CHOP) directly in this movie file it was creating all sorts of problems when trimming and/or changing the file.

#3 use the “moviefilein1_Seconds” to drive your installation. This is the movie file that gets trimmed. This node grabs the movie file from “moviefilein1_Fraction”.

I hope it helps and I hope that this isn’t unacceptably too punk!!!
As always, this is one way to approach this, but likely there are better, slimmer and more optimized ways to resolve this.

1 Like

Hey there,
I’m sorry for the delay @FaustoB , actually I’m already using the movieEngine @greg. But I’m also using the Dropdownmenu to select the videos. My problem was that when i selected a new video by the Dropdownmenu my Trim end parameter did not update the amount in seconds of the video automatically.
So to solve this problem i created an script (parameter execute DAT) to refresh the parameter page and returns me the total amount of seconds in the Trim end parameter with the expression " op(‘info1’)[‘true_length’]/op(‘info1’)[‘sample_rate’] ".
Still does not returns me the number of seconds automatically but it is working kkk.
I wanna thank you @FaustoB @greg for your attention and time. I am so sorry for the delay guys.