File Conversion

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
infernus
Posts: 6
Joined: 05 Jul 2021 20:29

File Conversion

#1 Post by infernus » 05 Jul 2021 21:11

Hi all,
I'm trying to create a batch file that will do the following:
  • Read the contents of a particular source directory
  • Determine if the contents are audio or video file(s)
  • Determine if the contents are of a particular file type (audio or video) and run a file conversion program based on the determined file type
    • example: for audio files): if the file type is m4a, the program AVSAudioConverter is started using mp3 settings.xml.
    • example: for video files): if the file type is mkv, the program AVSVideoConverter is started using the mkv to mp4 settings.xml.
  • The converted result is saved to a different directory
  • The source file is moved to a third directory on conversion completion
  • The Filebot program is started to move the file to media directory based on its own sort script
  • The batch file resumes & repeats until the source directory has been emptied
  • The entire process is appended to a conversion log
Doing some research & experimentation, I've written the following code:

Code: Select all

@echo off

setlocal enabledelayedexpansion enableextensions

rem set variables
set workdir=D:\Downloads\Video

:F1
if exist %workdir%\*.avi ( echo convert avi ) && ( goto AVI ) else ( echo no *.avi file to process )
:F2
if exist %workdir%\*.flv ( goto FLV ) else ( echo no *.flv file to process )
:F3
if exist %workdir%\*.mkv ( goto MKV ) else ( echo no *.mkv file to process )
:F4
if exist %workdir%\*.mov ( goto MOV ) else ( echo no *.mov file to process )
:F5
if exist %workdir%\*.mp4 ( goto FILEBOT ) else ( echo no *.mp4 file to process )
:F6
if exist %workdir%\*.wmv ( goto WMV ) else ( echo no *.wmv file to process )
goto END

:FILEBOT

rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto END

:AVI
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\avi-to-mp4.xml"
move *.avi %workdir%\Processed\
goto F2

:FLV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\flv-to-mp4.xml"
move *.flv %workdir%\Processed\
goto F3

:MKV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mkv-to-mp4.xml"
move *.mkv %workdir%\Processed\
goto F4

:MOV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mov-to-mp4.xml"
move *.mov %workdir%\Processed\
goto F5

:WMV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\wmv-to-mp4.xml"
move *.wmv %workdir%\Processed\
goto F6

:END
This hangs the entire computer, however, if run on an individual basis, works fine. ie:

Code: Select all

@echo off

setlocal enabledelayedexpansion enableextensions

rem set variables
set workdir=D:\Downloads\Video

if exist %workdir%\*.avi ( echo convert avi ) && ( goto AVI ) else ( echo no *.avi file to process )
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\avi-to-mp4.xml"
move *.avi %workdir%\Processed\
I've no clue how to proceed. Help appreciated.

Also, here is the info.bat contents:

Code: Select all

 INFO.BAT version 1.5
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 10.0.19042.1052]
Product name           :  Windows 10 Pro, 64 bit
Performance indicators :  Processor Cores: 8      Visible RAM: 33466316 kilobytes

Date/Time format       :  (mm/dd/yy)  Mon 07/05/2021  22:37:54.87
__APPDIR__             :  C:\Windows\system32\
ComSpec                :  C:\Windows\system32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions             :  system: Enabled   user: Disabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  07/05/2021  05:54 PM     5,100,273,664 pagefile.sys
Permissions            :  Elevated Admin=Yes, Admin group=Yes

                          Missing from the tool collection:  debug

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: File Conversion

#2 Post by kwsiebert » 06 Jul 2021 09:49

If a .wmv file exists in the workdir, your code is potentially looping back on itself and checking for .wmv files again. I'd expect the .wmv files to have been moved to the Processed directory, so this doesn't happen more than once... unless they are still locked by the conversion program. There are several other issues that stand out as well:
  • Each of your file processing sections is attempting to move the files to the Processed directory, without waiting for the video converter to finish. This, combined with the loop I mentioned above, could result in .wmv files being converted over and over again, possibly simultaneously, depending on the specifics workings of the conversion program.
  • If an .mp4 file exists in the workdir, the check for .wmv files is not performed.
  • Your second example has a goto with no matching label.

infernus
Posts: 6
Joined: 05 Jul 2021 20:29

Re: File Conversion

#3 Post by infernus » 06 Jul 2021 12:50

I changed the 'goto end' on the mp4 to go back to check for wmv and the goto on the wmv to go back to the file check in case there are multiple files to convert.
rem placeholder for each wait point for conversion has also been added.
I was going to place a 'start /wait' instead of 'start "" for each conversion, but looking 'round the 'net, it *seems* like this wouldn't be a reliable method.
How else can i make the batch wait for program to convert before continuing safely?

The 2nd code example was simply to show the command line itself worked if there is just 1 file to convert, so i just copy/pasted without cleaning up the logic flow

EDIT: I just thought of a couple points: if there is more than one file of any type, I need to ascertain **which** file gets converted, then specify that file when moving it after conversion. How do I accomplish this?

NOTE: You may have noticed, I'm not much of a coder lol

Code: Select all

@echo off

setlocal enabledelayedexpansion enableextensions

rem set variables
set workdir=D:\Downloads\Video

:F1
if exist %workdir%\*.avi ( echo convert avi ) && ( goto AVI ) else ( echo no *.avi file to process )
:F2
if exist %workdir%\*.flv ( echo convert flv ) && ( goto FLV ) else ( echo no *.flv file to process )
:F3
if exist %workdir%\*.mkv ( echo convert mkv ) && ( goto MKV ) else ( echo no *.mkv file to process )
:F4
if exist %workdir%\*.mov ( echo convert mov ) && ( goto MOV ) else ( echo no *.mov file to process )
:F5
if exist %workdir%\*.mp4 ( echo run filebot ) && ( goto FILEBOT ) else ( echo no *.mp4 file to process )
:F6
if exist %workdir%\*.wmv ( echo convert wmv ) && ( goto WMV ) else ( echo no *.wmv file to process )
goto END

:FILEBOT

rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto F6

:AVI
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\avi-to-mp4.xml"
rem wait to finish conversion
move *.avi %workdir%\Processed\
goto F2

:FLV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\flv-to-mp4.xml"
rem wait to finish conversion
move *.flv %workdir%\Processed\
goto F3

:MKV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mkv-to-mp4.xml"
rem wait to finish conversion
move *.mkv %workdir%\Processed\
goto F4

:MOV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mov-to-mp4.xml"
rem wait to finish conversion
move *.mov %workdir%\Processed\
goto F5

:WMV
start "" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\wmv-to-mp4.xml"
rem wait to finish conversion
move *.wmv %workdir%\Processed\
goto F1

:END

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: File Conversion

#4 Post by kwsiebert » 06 Jul 2021 14:45

I changed the 'goto end' on the mp4 to go back to check for wmv and the goto on the wmv to go back to the file check in case there are multiple files to convert.
And does it still appear to hang the computer with this fix?
I was going to place a 'start /wait' instead of 'start "" for each conversion, but looking 'round the 'net, it *seems* like this wouldn't be a reliable method.
That is what I personally use. I can see circumstances where it would fail, depending on how the program being run operates, but I have no personal experience with the conversion program you are using so I can't comment on it in this situation.
I just thought of a couple points: if there is more than one file of any type, I need to ascertain **which** file gets converted, then specify that file when moving it after conversion. How do I accomplish this?
I took a quick look at the program's documentation and it seems like it might potentially convert all files with a single command, depending on the contents of each .xml file. Again, this is dependent on how the conversion program behaves, so I can't provide accurate advice.

infernus
Posts: 6
Joined: 05 Jul 2021 20:29

Re: File Conversion

#5 Post by infernus » 06 Jul 2021 16:41

kwsiebert wrote:
06 Jul 2021 14:45
And does it still appear to hang the computer with this fix?
It doesn't hang anymore so that's one good thing.

I tried "start /B /wait", "start /B" and "start /wait"; all three variations give the "The system cannot find the file -a.", the batch continues, files get moved & the batch finishes 'normally' except for the tiny fact that no conversion gets done. However the -a call to the individual filetype xml sheets are absolutely necessary.
I took a quick look at the program's documentation and it seems like it might potentially convert all files with a single command, depending on the contents of each .xml file. Again, this is dependent on how the conversion program behaves, so I can't provide accurate advice.
Yes, the xml files will load any & all files of X type to be converted sequentially so looping is unnecessary and the current wildcard file move is appropriate. Forgot about that briefly lol.

The only thing left to figure out, afaik, is getting the batch file to wait while conversion's in progress.

So the current iteration looks like this (I cleaned it up a bit as well):

Code: Select all

@echo off

setlocal enabledelayedexpansion enableextensions

rem set variables
set workdir=D:\Video

:F1
if exist %workdir%\*.avi ( echo convert avi ) && ( goto AVI ) else ( echo no *.avi file to process )

:F2
if exist %workdir%\*.flv ( echo convert flv ) && ( goto FLV ) else ( echo no *.flv file to process )

:F3
if exist %workdir%\*.mkv ( echo convert mkv ) && ( goto MKV ) else ( echo no *.mkv file to process )

:F4
if exist %workdir%\*.mov ( echo convert mov ) && ( goto MOV ) else ( echo no *.mov file to process )

:F5
if exist %workdir%\*.mp4 ( echo run filebot ) && ( goto MP4 ) else ( echo no *.mp4 file to process )

:F6
if exist %workdir%\*.wmv ( echo convert wmv ) && ( goto WMV ) else ( echo no *.wmv file to process )
goto END

:AVI
start /B "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\avi-to-mp4.xml"
move %workdir%\*.avi %workdir%\Processed\
goto F2

:FLV
start /B "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\flv-to-mp4.xml"
move %workdir%\*.flv %workdir%\Processed\
goto F3

:MKV
start /B "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mkv-to-mp4.xml"
move %workdir%\*.mkv %workdir%\Processed\
goto F4

:MOV
start /B "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mov-to-mp4.xml"
move %workdir%\*.mov %workdir%\Processed\
goto F5

:MP4
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto F6

:WMV
start /B "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\wmv-to-mp4.xml"
move %workdir%\*.wmv %workdir%\Processed\
goto END

:END
exit

infernus
Posts: 6
Joined: 05 Jul 2021 20:29

Re: File Conversion

#6 Post by infernus » 06 Jul 2021 17:34

I think I may have solved the wait issue, altho I'm pretty sure my syntax is faulty.
I've added a 1 minute pause loop w/ errorlevel check for each conversion with a continue goto on a successful check.

Code: Select all

@echo off

setlocal enabledelayedexpansion enableextensions

rem set variables
set workdir=D:\Video

:F1
if exist %workdir%\*.avi ( echo convert avi ) && ( goto AVI ) else ( echo no *.avi file to process )

:F2
if exist %workdir%\*.flv ( echo convert flv ) && ( goto FLV ) else ( echo no *.flv file to process )

:F3
if exist %workdir%\*.mkv ( echo convert mkv ) && ( goto MKV ) else ( echo no *.mkv file to process )

:F4
if exist %workdir%\*.mov ( echo convert mov ) && ( goto MOV ) else ( echo no *.mov file to process )

:F5
if exist %workdir%\*.mp4 ( echo run filebot ) && ( goto MP4 ) else ( echo no *.mp4 file to process )

:F6
if exist %workdir%\*.wmv ( echo convert wmv ) && ( goto WMV ) else ( echo no *.wmv file to process )
goto END

:AVI
start "avi" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\avi-to-mp4.xml" || goto END
goto LOOP

:CONTINUE
move %workdir%\*.avi %workdir%\Processed\
goto F2

:FLV
start "flv" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\flv-to-mp4.xml" || goto END
goto LOOP

:CONTINUE
move %workdir%\*.flv %workdir%\Processed\
goto F3

:MKV
start "mkv" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mkv-to-mp4.xml" || goto END
goto LOOP

:CONTINUE
move %workdir%\*.mkv %workdir%\Processed\
goto F4

:MOV
start "mov" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mov-to-mp4.xml" || goto END
goto LOOP

:CONTINUE
move %workdir%\*.mov %workdir%\Processed\
goto F5

:MP4
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto F6

:WMV
start "wmv" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\wmv-to-mp4.xml" || goto END
goto LOOP

:CONTINUE
move %workdir%\*.wmv %workdir%\Processed\
goto END

:LOOP
tasklist | find /i "AVSVideoConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  ECHO AVSVideoConverter is still running
  Timeout /T 60 /Nobreak
  GOTO LOOP
)

:END

Running a test. So far, working as intended, for the 1st sub-batch. I think I'll probably edit each loop/continue label with individual labels (ie: loop-avi, continue-avi etc) It won't be pretty, but if it works...

infernus
Posts: 6
Joined: 05 Jul 2021 20:29

Re: File Conversion

#7 Post by infernus » 07 Jul 2021 02:19

After a few hours of experimentation & testing, this is what I have thus far:

Code: Select all

:: Filename:	BFC.bat 
:: Name:		Batch File Conversion
:: Version:		1.26
:: Description:	Batch convert video and/or audio files to either mp4(video) or mp3 (audio)
:: Purpose:	File preparation for inclusion into Plex media library
:: Author:		Sacha Mercurio
:: Date:		July 2021

@echo off

setlocal enabledelayedexpansion enableextensions

REM set variables
set aworkdir=D:\Audio
set vworkdir=D:\Video

:F1
if exist %vworkdir%\*.avi ( echo convert avi ) && ( goto AVI ) else ( echo no avi file to process )

:F2
if exist %vworkdir%\*.flv ( echo convert flv ) && ( goto FLV ) else ( echo no flv file to process )

:F3
if exist %vworkdir%\*.mkv ( echo convert mkv ) && ( goto MKV ) else ( echo no mkv file to process )

:F4
if exist %vworkdir%\*.mov ( echo convert mov ) && ( goto MOV ) else ( echo no mov file to process )

:F5
if exist %vworkdir%\*.mp4 ( echo run filebot ) && ( goto MP4 ) else ( echo no mp4 file to process )

:F6
if exist %vworkdir%\*.wmv ( echo convert wmv ) && ( goto WMV ) else ( echo no wmv file to process )

:F7
if exist %aworkdir%\*.aac ( echo convert aac ) && ( goto AAC ) else ( echo no aac file to process )

:F8
if exist %aworkdir%\*.flac ( echo convert flac ) && ( goto FLAC ) else ( echo no flac file to process )

:F9
if exist %aworkdir%\*.m4a ( echo convert m4a ) && ( goto M4A ) else ( echo no m4a file to process )

:F10
if exist %aworkdir%\*.mp3 ( echo run filebot ) && ( goto MP3 ) else ( echo no mp3 file to process )

:F11
if exist %aworkdir%\*.ogg ( echo convert ogg ) && ( goto OGG ) else ( echo no ogg file to process )

:F12
if exist %aworkdir%\*.wav ( echo convert wav ) && ( goto WAV ) else ( echo no wav file to process )

:F13
if exist %aworkdir%\*.wma ( echo convert wma ) && ( goto WMA ) else ( echo no wma file to process )
goto END

:AVI
start "avi" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\avi-to-mp4.xml" || goto F2
goto VLOOP

:VCONTINUE
move %vworkdir%\*.avi %vworkdir%\Processed\
goto F2

:FLV
start "flv" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\flv-to-mp4.xml" || goto F3
goto VLOOP

:VCONTINUE
move %vworkdir%\*.flv %vworkdir%\Processed\
goto F3

:MKV
start "mkv" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mkv-to-mp4.xml" || goto F4
goto VLOOP

:VCONTINUE
move %vworkdir%\*.mkv %vworkdir%\Processed\
goto F4

:MOV
start "mov" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\mov-to-mp4.xml" || goto F5
goto VLOOP

:VCONTINUE
move %vworkdir%\*.mov %vworkdir%\Processed\
goto F5

:MP4
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto F6

:WMV
start "wmv" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\wmv-to-mp4.xml" || goto F7
goto VLOOP

:VCONTINUE
move %vworkdir%\*.wmv %vworkdir%\Processed\
goto F7

:AAC
start "aac" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\aac-to-mp3.xml" || goto F8
goto ALOOP

:ACONTINUE
move %aworkdir%\*.aac %aworkdir%\Processed\
goto F8

:FLAC
start "flac" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\flac-to-mp3.xml" || goto F9
goto ALOOP

:ACONTINUE
move %aworkdir%\*.flac %aworkdir%\Processed\
goto F9

:M4A
start "m4a" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\m4a-to-mp3.xml" || goto F10
goto ALOOP

:ACONTINUE
move %aworkdir%\*.ogg %aworkdir%\Processed\
goto F10

:MP3
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto ALOOP

:ACONTINUE
move %aworkdir%\*.mp3 %aworkdir%\Processed\
goto F11

:OGG
start "ogg" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\ogg-to-mp3.xml" || goto F12
goto ALOOP

:ACONTINUE
move %aworkdir%\*.ogg %aworkdir%\Processed\
goto F12

:WAV
start "wav" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\wav-to-mp3.xml" || goto F13
goto ALOOP

:ACONTINUE
move %aworkdir%\*.wav %aworkdir%\Processed\
goto F13

:WMA
start "wma" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\wma-to-mp3.xml" || goto END
goto ALOOP

:ACONTINUE
move %aworkdir%\*.wav %aworkdir%\Processed\
goto END

:ALOOP
tasklist | find /i "AVSAudioConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO ACONTINUE
) ELSE (
  ECHO AudioConverter is still running
  Timeout /T 30 /Nobreak
  GOTO ALOOP
)

:VLOOP
tasklist | find /i "AVSVideoConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO VCONTINUE
) ELSE (
  ECHO VideoConverter is still running
  Timeout /T 120 /Nobreak
  GOTO VLOOP
)

:END


I've used the timeout function to resolve the /wait issues I had earlier. I've also added the sections for audio file conversion. As things stand, all the conversions & interim pauses work as intended. The only problem I am seeing is some of the files are not being moved from the work into the processed directories; so the converters keep on running as long as they find a source file. I'm assuming a typo somewhere, but am not finding a cause for the discrepancy.

EDIT: It won't be pretty, but I'm going to individualize the loops & continue labels to each conversion. I *think* that's where the current problem lies. If someone can provide a more " elegant?" solution, it'd be appreciated.

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: File Conversion

#8 Post by kwsiebert » 07 Jul 2021 12:03

EDIT: It won't be pretty, but I'm going to individualize the loops & continue labels to each conversion. I *think* that's where the current problem lies.
Yes, I'm fairly certain your problem comes from having multiple identical labels.

There are several ways to make it more elegant, but before optimizing the batch the first thing I would ask is: Is there any significant difference in the .xml files being passed to the program, or could you make a single .xml that handles video formats at once? Then you'd have one line for the video converter and one for the audio converter, and could just move all files at the end regardless of extension.

infernus
Posts: 6
Joined: 05 Jul 2021 20:29

Re: File Conversion

#9 Post by infernus » 07 Jul 2021 13:07

... the first thing I would ask is: Is there any significant difference in the .xml files being passed to the program, or could you make a single .xml that handles video formats at once? Then you'd have one line for the video converter and one for the audio converter, and could just move all files at the end regardless of extension.
Honestly, I hadn't even considered if either converter had the capability to batch multiple formats at once. The only real difference between the various xml files was the file type. I made an edit for *.* in each folder (one for audio & one for video), edited the batch accordingly.

Code: Select all

@echo off

setlocal enabledelayedexpansion enableextensions

REM set variables
set aworkdir=D:\Audio
set vworkdir=D:\Video

:MP3
if exist %aworkdir%\*.mp3 ( echo send to filebot ) && ( goto AFileBot ) else ( echo no mp3 file to process )

:MP4
if exist %vworkdir%\*.mp4 ( echo send to filebot ) && ( goto VFileBot ) else ( echo no mp4 file to process )

:F1
if exist %aworkdir%\*.* ( echo convert audio ) && ( goto Audio ) else ( echo no audio file to process )

:F2
if exist %vworkdir%\*.* ( echo convert video ) && ( goto Video ) else ( echo no video file to process )

:AFileBot
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto MP4

:VFileBot
rem filebot -script fn:amc --output "x:/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%l" "ut_state=%s" "ut_title=%n" "ut_kind=%k" "ut_file=%f" "ut_dir=%d"
goto F1

:Audio
start "convert" "C:\Program Files (x86)\AVS4YOU\AVSAudioConverter\AVSAudioConverter.exe" -a "D:\Documents\Conversions\all-to-mp3.xml" || goto END
goto L1

:Video
start "convert" "C:\Program Files (x86)\AVS4YOU\AVSVideoConverter\AVSVideoConverter.exe" -a "D:\Documents\Conversions\all-to-mp4.xml" || goto END
goto L2

:L1
tasklist | find /i "AVSAudioConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO C1
) ELSE (
  ECHO AudioConverter is still running
  Timeout /T 10 /Nobreak
  GOTO L1
)

:C1
move %aworkdir%\*.* %aworkdir%\Processed\
goto F2

:L2
tasklist | find /i "AVSVideoConverter" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO C2
) ELSE (
  ECHO VideoConverter is still running
  Timeout /T 10 /Nobreak
  GOTO L2
)

:C2
move %vworkdir%\*.* %vworkdir%\Processed\
goto END

:END

This works. The only caveat is I need to ensure the two main directories are not populated with any non-audio/video files as they'll error out the converters, requiring user input at best, crashes at worst.

Post Reply