News:

--

Main Menu

HELP - Batch Script to Rotate Videos

Started by flexdiggity1524, December 12, 2024, 12:20:54 PM

Previous topic - Next topic

flexdiggity1524

Hope this post finds everyone well. Though I have completed one successful batch script with the help of @eumagga0x2a in the past, I still consider myself a bit of a NOOB. Hence this request for help.

Desired Outcome: process a folder containing a bunch of "mp4" videos where the only change needed is to rotate the video by 90 degrees from landscape to portrait mode.

Please note that I'm on a Windows 11 machine and I run the latest Avidemux nightly build, and I can accomplish the aforementioned outcome manually using the following settings within the Avidemux app and saving:

* Video Output > Copy
* Audio Output (1 tracks) > Copy
* Output Format > MP4 Muxer > Configure > Rotate video > 90°
I don't touch any other settings.

The newly saved video then opens in my video player with the correct orientation and windows explorer also displays the correct orientation on the video's thumbnail. However, I can't seem to get the same outcome with the following script:

#PY  <- Needed to identify #

adm = Avidemux()
gui = Gui()
ext = "mp4"
sep = "\\"

# -------- set video rotation angle --------
ang = "90"

# -------- set input directory --------
inputFolder = "C:\\video\\" + ang

# -------- set output directory --------
outputFolder = "C:\\video"
   
def processVideo(vidin, outdir):
    if not adm.loadVideo(vidin):
        return 0
    adm.audioClearTracks()
    if adm.audioTotalTracksCount() <= 0:
        return 0
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy")
    adm.videoCodec("Copy")
    adm.setContainer("MP4", "muxerType=0", "optimize=0", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=" + ang, "clockfreq=0")
    return adm.save(outdir + sep + ang + " - " + basename(vidin) + "." + ext)


# -------- read content --------
vidlist = get_folder_content(inputFolder, ext)
if vidlist is None:
    gui.displayError("Error", "No " + ext + " files found in \"" + inputFolder + "\"")
    return 0

success = 0

for video in vidlist:
    success += processVideo(video, outputFolder)

if not success:
    gui.displayInfo("Warning", "No video files processed")
elif success == 1:
    gui.displayInfo("Finished", "One video out of " + str(len(vidlist)) + " processed")
else:
    gui.displayInfo("Finished", str(success) + " videos out of " + str(len(vidlist)) + " processed")

return success

The videos that the above script outputs seem to be identical to the original. I'm sure I'm missing something obvious, but I can't for the life of me see what that might be. Any guidance with the above would be much appreciated. Thanks in advance for your valuable time.

Regards,
Alex



eumagga0x2a

Quote from: flexdiggity1524 on December 12, 2024, 12:20:54 PM# -------- set video rotation angle --------
ang = "90"

You meant

ang = "1"
(the integer matching the enum value MP4_MUXER_ROTATE_90).

flexdiggity1524

Quote from: eumagga0x2a on December 13, 2024, 12:29:21 PMYou meant

ang = "1"
(the integer matching the enum value MP4_MUXER_ROTATE_90).

Like I said... NOOB  ;D

Thanks again for another assist!