3

I am trying to convert a .bat file to python, almost everything is working fine, only the compression part is not working, I point out the flags and the path to the "rar.exe", but it's not working at all in the python version. What I need to correct to have the same behavior of the ".bat" version?

Thank you

batVersion.bat

@echo off

setlocal EnableDelayedExpansion
set "FolderBaseName=myFolder"

set "DropBoxFolder=D:\Tests\3.asc\MyDropBox"
set "BaseOutputFolder=D:\Tests\3.asc\TEMP"

for %%I in (*.png) do (

    set "slaveName=%%~nI"
    set "slaveName=!slaveName:~6!
    set "OutputFolder=%BaseOutputFolder%_!slaveName!"

    echo !slaveName!   
    md "!OutputFolder!" 2>nul

    for %%J in (*.mp4*) do (      
        ffmpeg -i "%%~fJ" -i "%%~fI" -filter_complex overlay "!OutputFolder!\%%~nJ.mp4"
    )


    "C:\Program Files\WinRAR\rar.exe" a -cfg- -ep1 -inul -m5 "%DropBoxFolder%\%FolderBaseName%_!slaveName!" "!slaveName:~6!\*"
    rd /S /Q "!OutputFolder!"
)
pause

pythonVersion.py

def processVideos():

    FolderBaseName   = "myFolder"
    DropBoxFolder    = "D:\\Tests\\3.asc\\MyDropBox"
    BaseOutputFolder = "D:\\Tests\\3.asc\\TEMP"

    for img in os.listdir("D:\\Tests\\3.asc"):
        if img.endswith(".png"):

            slaveName = img.split('.')[0]

            OutputFolder = BaseOutputFolder+'_'+slaveName + '\\'

            #create tmp folder
            if not os.path.exists(OutputFolder): os.makedirs(OutputFolder)

            for video in os.listdir("D:\\Tests\\3.asc"):
                if video.endswith(".mp4"):

                    command = [ 'ffmpeg',
                                '-i', "D:\\Tests\\3.asc\\"+video,
                                '-i', "D:\\Tests\\3.asc\\"+img,
                                '-filter_complex', 'overlay',
                                OutputFolder+'\\'+str(video)]

                    pipe = subprocess.Popen(command, stdout = subprocess.PIPE) #, bufsize=10**8


            commandRar = [ 'C:\\Program Files\\WinRAR\\rar.exe',
                            'a',
                            '-cfg-',
                            '-ep1',
                            '-inul',
                            '-m5',
                            DropBoxFolder+'\\'+FolderBaseName+'_'+slaveName]

            # this doesnt work, and also I only want it to happen after the conversion above has finished
            pipeRar = subprocess.Popen(commandRar, stdout = subprocess.PIPE)    

processVideos()

3 Answers 3

3

You need to use the communicate method for the Popen objects you're creating.

blah = Popen(...)
blah.communicate()

This will also block until it is finished, after which you can start the 2nd command.

Sign up to request clarification or add additional context in comments.

2 Comments

That works, but I am not compressing the correct folder. i want to compress the "TEMP_FODLER" where the videos are beeing saved out.
Not that familiar with Winrar, but your popen there does not seem identical to the Python version, which is missing some stuff at the end.
0
import subprocess
blah = subprocess.Popen('aaa.bat', stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
blah.communicate()

1 Comment

This appears to be the same as the accepted answer from six years ago, just with a bit more context (such as some sample parameters for Popen().
-1
REN *.log *.txt
MKDIR LOG


FINDSTR "TYPE:1=20000" *.txt > TYPE-1-20000
FINDSTR "TYPE:2=50000" *.txt > TYPE-2-50000
FINDSTR "TYPE:3=100000" *.txt > TYPE-3-100000
FINDSTR "TYPE:4=500000" *.txt > TYPE-4-500000
FINDSTR "OFFLINE" *.txt > OFFLINE
FINDSTR "RTRCT " *.txt > RTRCT 
FINDSTR "RJCT" *.txt > RJCT
FINDSTR "DSPNS" *.txt > DSPNS
FINDSTR "WITHDRAWAL" *.txt > WITHDRAWAL
REN *.? *.txt
MOVE "TYPE-1-20000.TXT" LOG
MOVE "TYPE-2-50000.TXT" LOG
MOVE "TYPE-3-100000.TXT" LOG
MOVE "TYPE-4-500000.TXT" LOG
MOVE      "OFFLINE.TXT" LOG
MOVE "RTRCT.TXT" LOG
MOVE "RJCT.TXT" LOG
MOVE "DSPNS.TXT" LOG
MOVE "WITHDRAWAL.TXT" LOG

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.