Possible to use command line and specify project script and output file path?

Started by Who, January 08, 2023, 11:53:17 PM

Previous topic - Next topic

Who

What I would like to be able to do is from a MacOS command prompt or from within a shell script, call Avidemux with two options:

1) The path and filename of a previously created project script.

2) The desired path and filename to save the file under (since you can't specify that in the project script).

Then when I run it, I would want it to simply read the project script, and act as if I had clicked on the save button, using the path and filename given in the second option.  Then when it is finished I want it to exit the program.

(Actually what I really want to do is have it send me an alert when it is finished but since there is no way to do that from within Avidemux, I would need it to exit the program when it finishes the save).

Is any of this possible?

eumagga0x2a

Quote from: Who on January 08, 2023, 11:53:17 PM2) The desired path and filename to save the file under (since you can't specify that in the project script).

Of course you can:

adm = Avidemux()
# your script goes in here
adm.save("/Full/path/to/output/filename.extension")

Quote from: Who on January 08, 2023, 11:53:17 PMWhat I would like to be able to do is from a MacOS command prompt or from within a shell script, call Avidemux with two options:

1) The path and filename of a previously created project script.

2) The desired path and filename to save the file under

/Applications/Avidemux_<VERSION>.app/Contents/MacOS/Avidemux2.8 --run /Path/to/script.py --save /Path/to/output --quit

Who

Quote from: eumagga0x2a on January 09, 2023, 01:04:11 AM
Quote from: Who on January 08, 2023, 11:53:17 PM2) The desired path and filename to save the file under (since you can't specify that in the project script).

Of course you can:

adm = Avidemux()
# your script goes in here
adm.save("/Full/path/to/output/filename.extension")

Sorry, I should have been more clear.  There is no way from within the Avidemux GUI to save the output filename to the project script, at least not that I am aware of.  I was also not aware you could do it the way you mentioned, but it's a lot easier to get the filename from the GUI's file picker, or alternately to just specify it in the command line.

Quote from: eumagga0x2a on January 09, 2023, 01:04:11 AM
Quote from: Who on January 08, 2023, 11:53:17 PMWhat I would like to be able to do is from a MacOS command prompt or from within a shell script, call Avidemux with two options:

1) The path and filename of a previously created project script.

2) The desired path and filename to save the file under

/Applications/Avidemux_<VERSION>.app/Contents/MacOS/Avidemux2.8 --run /Path/to/script.py --save /Path/to/output --quit

Thanks, I did not know you could do that.  I tried running it from the command line but since I didn't have a project waiting to be done I just tried it with the --quit option, but of course that just caused it to close immediately after opening.  When you want to use Avidemux in the normal fashion (not running it from a script) is there no way to get it to close only when the encoding is finished?  Maybe instead of the checkbox that says "Keep dialog open when finished" (something I have never personally used), you could have three radio buttons and this dialog:

When finished
  - Keep dialog open
  - Close Avidemux
  - Do nothing (default)

Just a suggestion.

This also brings up another point, if I drag a video file into the Avidemux window it will open it, which is what I would expect.  But if I drag a project script file in, it tries to open it as a video file and fails.  You would think that if you were dragging in a file with a .py extension it would at least check to see if it's a project script.  I don't know if that action works correctly on other platforms, but it doesn't work in MacOS.

Anyway this information will be very helpful next time I have a batch of these to do, so thanks!

eumagga0x2a

Quote from: Who on January 09, 2023, 06:09:33 PMThere is no way from within the Avidemux GUI to save the output filename to the project script, at least not that I am aware of.

You are correct, this is not possible via GUI.

Quote from: Who on January 09, 2023, 06:09:33 PMit's a lot easier to get the filename from the GUI's file picker

This is actually what the "Queue" (Command + U) command in the "File" menu is for.

Quote from: Who on January 09, 2023, 06:09:33 PMI tried running it from the command line but since I didn't have a project waiting to be done I just tried it with the --quit option, but of course that just caused it to close immediately after opening.  When you want to use Avidemux in the normal fashion (not running it from a script) is there no way to get it to close only when the encoding is finished?

To ask Avidemux to "pull the plug" for itself after an encode, you have to proceed like in the example command line. On Windows, it is possible to shutdown the computer once an encoding is finished (so that Windows then kills Avidemux). But only on Windows.

Quote from: Who on January 09, 2023, 06:09:33 PMif I drag a video file into the Avidemux window it will open it, which is what I would expect.  But if I drag a project script file in, it tries to open it as a video file and fails.

This is sort of by design as filename extensions are in general meaningless for Avidemux (it looks into the file to determine its type). The only exception is the special case of VapourSynth script files (.vpy) which are Python scripts.

I fear that enabling drag-n-drop of project files might cause more harm than good – project scripts are very universal and powerful in Avidemux.



Who

Quote from: eumagga0x2a on January 10, 2023, 01:18:29 AMI fear that enabling drag-n-drop of project files might cause more harm than good – project scripts are very universal and powerful in Avidemux.
Seems like you don't give your users any credit for knowing what they're doing, but you could mitigate any risk.  When a project script is dragged and dropped into the Avidemux window, you could first of all check the first line or two of the script to make certain it really is an Avidemux project script and not some random Python script, and then you could pop up a box that says "It appears you want to run a project script" followed by whatever warnings or cautions you may want to give, and that has a "Continue" and a "Cancel" button.  That way, just dragging in the wrong file would not cause any issues unless the user clicked the "Continue" button.

Beyond that, I don't see that it's any more of a problem than the possibility of the user picking the wrong file when using the "Run project script" option. There is a point at which too much hand-holding gets in the way of productivity.  And I have to wonder, what would be the absolute worst thing that could happen if you allowed users to drag and drop project scripts?  I mean, once you realize you have tried to run the wrong script, couldn't you just close Avidemux and start over?

eumagga0x2a

Quote from: Who on January 10, 2023, 07:23:54 PMwhat would be the absolute worst thing that could happen if you allowed users to drag and drop project scripts?

Drag and drop of videos means in Avidemux append. Running a script can do almost everything, absolutely not related to append operation, breaking the model of interaction. The worst thing would be data loss from overwriting existing files, I think.

You are right that a human error can occur at any stage when using the current way to run project script files as well, but I still feel safer when dropping a script on Avidemux window by accident will only trigger an error message.