HyperNext Studio > Files

Run external program with parameters


Now, I'm doing a program that will convert the video file using FFmpeg.
But I want to know, What script I have to write to run FFmpeg with parameters because FFmpeg is a program that requires parameters to work properly.
And I also want to know, How can I make a file dialog to pop-up then get a path of the file that has been selected and then set the value of the input field to that path.


Unfortunately the HN command to launch a program/file cannot send parameters to the target.

However, a work-around is to create a simple batch file with HN and then use this to launch the target with necessary parameters.

Attached is a very basic project that converts a video using FFmpeg on Windows X64 - the download link is at the bottom of this post.

The project just has one button and one field.
The location of FFmpeg is hardcoded in the script, and the final video is called Video1.mkv
The video to be converted is selected via a dialog box.

Note, the video source path has " (quotation marks) appended around it,  in case the full path contains spaces.
I didn't do this for the converted file path as it is just saved to the project directory.

Most of the code just displays information into field 1 as to aid debugging.

Also, FolderItemLaunch(fvar,1) executes the FFmpeg in the foreground to aid debugging.
Just use - FolderItemLaunch(fvar,0) to launch it in the background.

--- Code: ---Local fname,fvar,fdetails,ftypes,fpaths,fnames,fextens
Local fhandle
Local sourcePath

Clear field 1

@ --- Get file ---
Put '--- Get file ---' after field 1
Put fname after field 1
Put line 9 of fdetails into sourcePath
Put sourcePath after field 1

@ --- Create batch file ---
Local batchname
Put ' ' after field 1
Put '--- Create batch file ---' after field 1

Put MyDirectoryFN into batchname
Append FolderSeparatorFN onto batchname
Append 'mybatch.bat' onto batchname
Put batchname after field 1

@ --- Build batch file ---
Local commandLine
Put ' ' after field 1
Put '--- Build batch file ---' after field 1
WriteTLine(fvar, 'ECHO OFF')
Put 'C:\ffmpeg-win64\bin\ffmpeg.exe -i ' into commandLine
Append '"' onto commandLine
Append sourcePath onto commandLine
Append '"' onto commandLine
Append ' -c copy ' onto commandLine
Append 'Video1.mkv ' onto commandLine
Put commandLine after field 1
WriteTLine(fvar, 'PAUSE')

@ --- Run batch file ---
Put ' ' after field 1
Put '--- Run batch file ---' after field 1
Put 'DONE' after field 1

--- End code ---



[0] Message Index

Go to full version