• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to render a mp4 animation from jsx script?

Community Beginner ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

I have some complex automation in Photoshop based on a jsx script that calls some actions to create both a static image and an animation automatically.

The logic and sequence in the script is working perfectly fine and the only thing that I still need to figure out in my script is how I can have the jsx script to execute the same export as I would get by clicking on File > Export > Render Video

I want my script to set all the options and perform the export automatically without user interaction.

 

Here is a snippet of the code just to show where I would place the render if I can discover how to do it.

 

var minhapasta = File($.fileName).parent.fsName;

var basenome = prompt("Escreva a base do nome de arquivos para usar! (evite acentos e caracteres especiais", "my_test_files"); 

var doc = app.activeDocument;

var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 12;
jpgOptions.embedColorProfile = true;
jpgOptions.formatOptions = FormatOptions.PROGRESSIVE;
if(jpgOptions.formatOptions == FormatOptions.PROGRESSIVE){
jpgOptions.scans = 5};
jpgOptions.matte = MatteType.NONE;

doAction("pedaco1","Marcus Tavares - auto");
//first save as static image (working fine)
doc.saveAs (new File(decodeURI(minhapasta) +'/' + basenome + '01' + '.jpg'), jpgOptions, true);
//then just after saving a copy as static image, I should have the block that renders the animation that is already created by the action and name it using this: decodeURI(minhapasta) +'/' + basenome + '01' + '.mp4'

 

Could you please help with this? I searched everywhere and could not find a reference so I could base in it.

 

Thanks!

TOPICS
Actions and scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Feb 21, 2021 Feb 21, 2021

Do you have Adobe Scriptlistener plug-in installed. If you do use file>Export>Render Video... fill in the dialog for the way you want to encode and save the video.  The create a Javascript render function for your script using the action manager code recorded by Adobe plug-in. After your script run the action  and save a jpeg file add a step that uses the function you created to render a video. .

Votes

Translate

Translate
Community Beginner , Feb 23, 2021 Feb 23, 2021

Thanks!

That was exactly what I was looking for. I used script listener and this cleaner script to translate the captured code into a more readable javascript code.

For others who may arrive in this thread in the future, this is the function for exporting the timeline as MP4.

function export2(directory, name2, ameFormatName, amePresetName, useDocumentSize, frameRate, manage, selectedFrames, quality, Z3DPrefHighQualityErrorThreshold) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 21, 2021 Feb 21, 2021

Copy link to clipboard

Copied

Do you have Adobe Scriptlistener plug-in installed. If you do use file>Export>Render Video... fill in the dialog for the way you want to encode and save the video.  The create a Javascript render function for your script using the action manager code recorded by Adobe plug-in. After your script run the action  and save a jpeg file add a step that uses the function you created to render a video. .

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

Thanks!

That was exactly what I was looking for. I used script listener and this cleaner script to translate the captured code into a more readable javascript code.

For others who may arrive in this thread in the future, this is the function for exporting the timeline as MP4.

function export2(directory, name2, ameFormatName, amePresetName, useDocumentSize, frameRate, manage, selectedFrames, quality, Z3DPrefHighQualityErrorThreshold) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor2.putPath( s2t( "directory" ), directory );
	descriptor2.putString( s2t( "name" ), name2 );
	descriptor2.putString( s2t( "ameFormatName" ), ameFormatName );
	descriptor2.putString( s2t( "amePresetName" ), amePresetName );
	descriptor2.putBoolean( s2t( "useDocumentSize" ), useDocumentSize );
	descriptor2.putDouble( s2t( "frameRate" ), frameRate );
	descriptor2.putEnumerated( s2t( "pixelAspectRatio" ), s2t( "pixelAspectRatio" ), s2t( "document" ));
	descriptor2.putEnumerated( s2t( "fieldOrder" ), s2t( "videoField" ), s2t( "preset" ));
	descriptor2.putBoolean( s2t( "manage" ), manage );
	descriptor2.putBoolean( s2t( "selectedFrames" ), selectedFrames );
	descriptor2.putEnumerated( s2t( "renderAlpha" ), s2t( "alphaRendering" ), s2t( "none" ));
	descriptor2.putInteger( s2t( "quality" ), quality );
	descriptor2.putInteger( s2t( "Z3DPrefHighQualityErrorThreshold" ), Z3DPrefHighQualityErrorThreshold );
	descriptor.putObject( s2t( "using" ), s2t( "videoExport" ), descriptor2 );
	executeAction( s2t( "export" ), descriptor, DialogModes.NO );
}

//call it like this
var minhapasta = File($.fileName).parent.fsName;
export2(new File( minhapasta ), 'myvideo.mp4', "H.264", "1_High Quality.epr", true, 23.976, true, true, 1, 5);

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

Thanks for this, I'm trying to run this as a batch on a folder of images to export multiple videos, how do i retain the original names to export the videos date stamped or number sequenced? As an action using the render to video function it exports with the same filename, so keeps over writing the original, also with your script it only saves as myvideo.mp4, hope you can help thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 07, 2023 Jul 07, 2023

Copy link to clipboard

Copied

Script is not working in PS 24.1.0

 

This functionality may not be available in this version of photoshop.

Could not complete the command because of a problem with media encoder.

Line 23 -

executeAction( s2t( "export" ), descriptor, DialogModes.NO );

Is the error message i am getting. Render works fine without the script.

What can i change to make the script work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

LATEST

works fine in PS 25.3.1

 

if you don't need the whole Video you can replace

descriptor2.putBoolean( s2t( "selectedFrames" ), selectedFrames );

width

descriptor2.putInteger( s2t( "inFrame" ), startFrame );
descriptor2.putInteger( s2t( "outFrame" ), endFrame );

and update the export2 function call.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 06, 2022 Sep 06, 2022

Copy link to clipboard

Copied

Thanks for this, I'm trying to run this as a batch on a folder of images to export multiple videos, how do i retain the original names to export the videos date stamped or number sequenced? As an action using the render to video function it exports with the same filename, so keeps over writing the original, also with your script it only saves as myvideo.mp4, hope you can help thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines