Autorotate with scripting - how to pass variables (AviDemux 2.6.7 r8980).

Started by albybara, December 21, 2013, 06:39:25 PM

Previous topic - Next topic

albybara

Hi,

I am trying to automate rotation, resizing and recompression of videos taken from a Galaxy S3. I use exiftool to read the metadata of the mp4 and then call AviDemux with the correct filters. Although I guess I could do everything in Python since I am not familir with the language I have chosen the batch+python approach.

-the batch file:
@SET PATH=%PATH%;C:\Program Files\Avidemux 2.6 - 64bits;C:\Program Files (x86)\K-Lite Codec Pack\Tools
FOR %%f IN (*.mp4) DO @FOR /F %%i IN ('exiftool.exe -T -Rotation %%f') DO avidemux.exe --var rotation=%%i --force-alt-h264 --load "%%f" --run resizeall.py --save "%%~nf.avi" --quit >NUL:


this is rendered for instance as --var rotation=90

the python script:
if rotation==0:
   adm.addVideoFilter("swscale", "width=960", "height=540", "algo=2", "sourceAR=0", "targetAR=0")
elif rotation==90:
   adm.addVideoFilter("rotate", "angle=270")
   adm.addVideoFilter("swscale", "width=540", "height=960", "algo=2", "sourceAR=0", "targetAR=0")


I assumed that the variable rotation (set with --var rotation) could be called from within the script by just its name but it seems like this isn't the case. Could someone please advice?

The error is:
Exception: (_tp_dict_get) KeyError: rotation
[...snip...] line 8

Line 8 of course is where the "if" is...

mean

The simpler would be to create 2 scripts and call one or the other depending on the rotation needed

albybara

Well MSDOS is a pretty different thing from UNIX!  ;)

If I want to test for 4 different conditions (I pasted two angles only for simplicity but of course there are 4) besides the 4 scripts I have to nest 3 IF (because ELSEIF does not exist) if I choose the string substitution with native commands I have to set the value to an environment variable and use substitution but again I have to work with delayed expansions which is not the default in all windows environments. If tomorrow I decide to automate some other task I have to multiply the number of scripts required and complicate even more the batch file.

From my point of view this approach is not elegant neither easily manageable. I work similarly while scripting SQL queries to be run through scripts where I also pass variables but there is a well documented way of reading those variables from within the SQL which I did not find here.

My preferred solution would still be to maintain the approach I used so far and I am just a single step from it, all I need to do is understand how variables are passed to Python and how to reference them from within it. I have searched quite a lot but did not find a single example or note about it. Of course I do not necessarily need to use Python if JS can do the same... but again I would need some guidance.

I do also believe that this would interest others and could represent an addition (in the examples) to the scripting section because the rotation of videos taken with mobiles phones is a pain in the back for lots of people... (and the reason why I resorted to AviDemux now more than a year ago) :)

mean

No simple solution right now
Passing variable is not supported with tinypy and the js part is lagging/incomplete

albybara

Ok, so I gave up and I resorted to duplicating the script. However just for the sake of not dropping it completely:

...any chance of reading environment variables from tinypy? Can the os module be imported? Maybe with a few steps (that do not require recompiling possibly)...

mean


I12learn



mean