Skip to main content
Participating Frequently
June 14, 2022
Answered

I want to determine with a script whether it is a layer created from a video file.

  • June 14, 2022
  • 2 replies
  • 377 views

I tried to determine from the script (jsx) if the target layer is .hasVideo is true,
With .hasVideo alone, you can also get adjustment layers and layers created from images.
Please tell me how to determine if it is a layer created from a video.

 

var layers=app.project.activeItem.layers;
for(var i=1; i <= layers.length; i++){
	if(layers[i].hasVideo){
		alert("The target layer is a layer created from the video.");
	}
}

 

If anyone knows how to tell if it's a layer created from a video, please let me know.

This topic has been closed for replies.
Correct answer Dan Ebberts

This test may be overkill, but I think it will do what you want:

if ((myLayer instanceof AVLayer) && myLayer.hasVideo && myLayer.source != null && (myLayer.source instanceof FootageItem) && myLayer.source.mainSource.file != null && ! myLayer.source.mainSource.isStill){

2 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
June 14, 2022

This test may be overkill, but I think it will do what you want:

if ((myLayer instanceof AVLayer) && myLayer.hasVideo && myLayer.source != null && (myLayer.source instanceof FootageItem) && myLayer.source.mainSource.file != null && ! myLayer.source.mainSource.isStill){
Mathias Moehl
Community Expert
Community Expert
June 14, 2022

and if you want to be prepared for all cases, I would  change the

"(myLayer instanceof AVLayer)"
to

"(typeof AVLayer != "undefined") &&  (myLayer instanceof AVLayer)"

Not 100% sure if this is also the case for AVLayers, but for TextLayer I noticed that it is actually undefined if there does not exist a single text layer (and there never existed one since Ae started). In that case a test like
"myLayer instanceof TextLayer" creates an error, but
"(typeof TextLayer != "undefined") &&  (myLayer instanceof TextLayer)"
returns false, which is the correct answer, since if no text layer exists at all, myLayer also definitely cannot be a text layer.

 

One of those strange bugs that occur rarely...

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Mylenium
Legend
June 14, 2022

You need to fetch the layer source item, not the layer itself, and determine its type.

 

Mylenium

Participating Frequently
June 16, 2022

The mainSource of the target layer is FileSource.
Furthermore, by judging by combining isStill and hasVideo of mainSource,
I was able to identify whether the target layer was a layer created from the video.

Thank you for your coopration.