News:

--

Main Menu

Batch Conversion Issue

Started by T-Bauss, January 02, 2020, 05:30:46 PM

Previous topic - Next topic

T-Bauss

Hello,

I am having an issue with my batch conversions.  the batch its self works and the produces a videos, the issue I am having is that they are all still MP4 and display no information in the properties of the converted video, I am trying to have them converted to MKV.  Any help is appreciated.

Thanks

#
# Load all the files in c:\tmp with .mp4 extension.
# That's it.
#
gui=Gui()
adm=Avidemux()
ext="mp4"
sep="\\"
#
def convert(filein):   
    filename=basename(filein)
    dir=dirname(filein)
    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    adm.setPostProc(3, 3, 0)
    adm.videoCodec("Copy")
    adm.audioClearTracks()
    adm.setSourceTrackLanguage(0,"eng")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy");
    adm.audioSetDrc(0, 0)
    adm.audioSetShift(0, 0, 0)
    adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=0")
    adm.save(dir+sep+"Converted "+filename)
    print("Done")
   
#
# Main
#
inputFolder=gui.dirSelect("Select the source folder")
#
list=get_folder_content(inputFolder,ext)
#
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")

eumagga0x2a

Your script converts input mp4 to mkv as desired, it just doesn't change the file name extension.

T-Bauss

Thanks, can you point out what I am missing so change the file name extension, I have tried plying around with it further but the script breaks when when changing anything from mp4.

I'm also trying to figure out how i can change the script to allow me to choose a folder to save the new file in, so that way I can leave the output name the same and not have to edit them all manually.

Thanks again


eumagga0x2a

Quote from: T-Bauss on January 09, 2020, 02:23:08 PM
Thanks, can you point out what I am missing so change the file name extension, I have tried plying around with it further but the script breaks when when changing anything from mp4.

This is a task for a cmd.exe or PowerShell script (a batch file), not for tinyPy.

QuoteI'm also trying to figure out how i can change the script to allow me to choose a folder to save the new file in [...]

gui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "\\"
#
def convert(filein,outdir):
    filename = basename(filein)
    prefix = ""
    folder = dirname(filein)
    if(folder == outdir)
        prefix="Converted "
    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    adm.videoCodec("Copy")
    adm.audioClearTracks()
    adm.setSourceTrackLanguage(0,"eng")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy");
    adm.audioSetShift(0, 0, 0)
    adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=0")
    adm.save(outdir+sep+prefix+filename+".mkv")
    print("Done")
#
# Main
#
inputFolder = gui.dirSelect("Select the source folder")
if(inputFolder is None):
    raise
outputFolder = gui.dirSelect("Select the target folder")
if(outputFolder is None):
    outputFolder = inputFolder
#
list = get_folder_content(inputFolder,ext)
#
if(list is None):
    raise
for i in list:
    convert(i,outputFolder)
print("Done")


should do it (untested).

T-Bauss

Thanks, so now I am getting a prompt to save to a different folder but it still saves in the root.  They are now converting to .mkv but still have the title + .mp4 then the .mkv extension.

eumagga0x2a

Quote from: T-Bauss on January 10, 2020, 06:01:12 PM
so now I am getting a prompt to save to a different folder but it still saves in the root.

Did you select a different target? Because it saves to the old path with "Converted " as prefix only if you haven't selected any. Replace

if(outputFolder is None):
    outputFolder = inputFolder


with

if(outputFolder is None):
    raise


to be sure not to miss that (if I haven't missed something big).

QuoteThey are now converting to .mkv but still have the title + .mp4 then the .mkv extension.

This is expected and is not correctable with Avidemux scripting. Please use another tool for that, e.g. a batch script.

T-Bauss

I do get a prompt for 2 targets, first I select the input second target I select the output (A folder inside the directory called "done").  But due to the fact that i am unable to have the names with out the .mp4 saving to a different folder isn't to big of a deal.

Thanks

eumagga0x2a

My bad, I missed ":" after "if(folder == outdir)", the following fixed version should work fine (except of unavoidable ".mp4.mkv" double extension which should be treated with a batch rename script or tool):

gui = Gui()
adm = Avidemux()
ext = "mp4"
sep = "\\"
#
def convert(filein,outdir):
    filename = basename(filein)
    prefix = ""
    folder = dirname(filein)
    if(folder == outdir):
        prefix = "Converted "
    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    adm.videoCodec("Copy")
    adm.audioClearTracks()
    adm.setSourceTrackLanguage(0,"eng")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy");
    adm.audioSetShift(0, 0, 0)
    adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=0")
    adm.save(outdir+sep+prefix+filename+".mkv")
    print("Done")
#
# Main
#
inputFolder = gui.dirSelect("Select the source folder")
if(inputFolder is None):
    raise
outputFolder = gui.dirSelect("Select the target folder")
if(outputFolder is None):
    outputFolder = inputFolder
#
list = get_folder_content(inputFolder,ext)
#
if(list is None):
    raise
for i in list:
    convert(i,outputFolder)
print("Done")

dosdan

#8
To remove doubled filename extensions see https://superuser.com/questions/1120795/how-to-batch-remove-a-duplicate-file-extension-in-os

Here's my 1-line batchfile: dup_ext_renamer.bat
@for %%G in (%*) do if exist "%%~dpnG.mkv" ren %%G ??????????????????????.mkv

Here's a test set of filenames (including the batchfile itself):
dup_ext_renamer.bat
Test 1.mp4.mkv
Test 2.mp4.mkv
Test 3.mp4.mkv
Test 4.mp4.mkv
Test 5.mp4.mkv
Test 6.mp4
Test 7.mkv
test.mp4.mkv


You can see some have doubled extensions, some haven't, one is a MP4 and one isn't even a video file.  I only want .MKVs to be renamed.

I created a shortcut to the batchfile and placed the shortcut on my desktop. I then drag-and-dropped this selection of files onto this icon. Here is the resultant command-line argument list:
"C:\test directory\mkv\1\dup_ext_renamer.bat" "C:\test directory\mkv\1\Test 1.mkv" "C:\test directory\mkv\1\Test 2.mkv" "C:\test directory\mkv\1\Test 3.mkv" "C:\test directory\mkv\1\Test 4.mkv" "C:\test directory\mkv\1\Test 5.mkv" "C:\test directory\mkv\1\Test 6.mp4" "C:\test directory\mkv\1\Test 7.mkv" "C:\test directory\mkv\1\test.mkv"


And here is the filelist after processing:
dup_ext_renamer.bat
Test 1.mkv
Test 2.mkv
Test 3.mkv
Test 4.mkv
Test 5.mkv
Test 6.mp4
Test 7.mkv
test.mkv


In the batchfile here's the 9 filename being tested for existence and, if existing, being renamed:
if exist "C:\test directory\mkv\1\dup_ext_renamer.mkv" ren "C:\test directory\mkv\1\dup_ext_renamer.bat" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 1.mp4.mkv" ren "C:\test directory\mkv\1\Test 1.mp4.mkv" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 2.mp4.mkv" ren "C:\test directory\mkv\1\Test 2.mp4.mkv" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 3.mp4.mkv" ren "C:\test directory\mkv\1\Test 3.mp4.mkv" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 4.mp4.mkv" ren "C:\test directory\mkv\1\Test 4.mp4.mkv" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 5.mp4.mkv" ren "C:\test directory\mkv\1\Test 5.mp4.mkv" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 6.mkv" ren "C:\test directory\mkv\1\Test 6.mp4" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\Test 7.mkv" ren "C:\test directory\mkv\1\Test 7.mkv" ??????????????????????.mkv

if exist "C:\test directory\mkv\1\test.mp4.mkv" ren "C:\test directory\mkv\1\test.mp4.mkv" ??????????????????????.mkv



Dan.