How can I make these into a batch command? - batch-file

How can I make a batch file to do this for all the different files in a Directory?
drg2sbg.exe file.drg -o file.sbg
drg2sbg.exe file.drg -t file.txt
drg2sbg.exe file.drg -b file.bmp
Thanks,

for %%a in (*.drg) do (
drg2sbg.exe "%%~a" -o "%%~na.sbg"
drg2sbg.exe "%%~a" -t "%%~na.txt"
drg2sbg.exe "%%~a" -b "%%~na.bmp"
)
where %%a is set to each name of the *.drg file in turn and %%~na extracts the name part.
(as lines in a batch file - reduce %% to % to operate directly from the prompt)

Related

FFmpeg - Batch file bulk editing

I have started a huge video project which I am trying to automate. So far, I made good progress, but now I am stuck. I have searched in Google and here, in Stack OverFlow for answers, but can’t find the solution to my problem.
For completion I will explain my full project.
First step of my project is to convert all of my files to *.mp4 and in the same run burn my logo and website in the video. I do this with this code:
for %%a in ("*.*") do ffmpeg -i "%%a" -i "C:\Users\PC03\Desktop\Video test\Overlay.png" -filter_complex "[0:v][1:v] overlay" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k "newfiles\%%~na.mp4"
pause
After that, I will place all the video files in their relevant subfolder. This way I have almost a hundred subfolders, with 2 or 3 files in them. Per submap I want a video with an intro (not in the submap) the video’s in the submap, and an outro (not in the submap).
I can do the above with this code:
ffmpeg -f concat -i intro.mp4 -i mylist.txt -outro.png -c copy total.mp4
To automate everything, I have this code to make a mylist.txt file per subfolder:
>output.txt (
echo C:\Users\PC03\Desktop\Video test\vast\intro.mp4
(for %%i in (*.mp4) do #echo file '%%i')
echo C:\Users\PC03\Desktop\Video test\vast\outro.mp4
)
Now the only thing which I have to do is automate the following code:
ffmpeg -f concat -i intro.mp4 -i mylist.txt -outro.png -c copy total.mp4
to go through all the subfolders.
I have made this code:
FOR /R "C:\Users\PC03\Desktop\Video test" %%F IN (.) DO (
> %%F\output.txt (
echo "C:\Users\PC03\Desktop\Video test\vast\intro.mp4"
(for %%i in (*.mp4) do (
#echo file '%%i'
))
echo "C:\Users\PC03\Desktop\Video test\vast\outro.mp4"
)
)
This codes provides me with a mylist.txt file in every subfolder, but the content is not what I want. It takes the content of the parentmap instead of the subfolders. I have a strong feeling that somewhere in this code I have to make another FOR /R but I can’t make it work.
Does someone have a suggestion on how to do this?
The FOR /R will iterate the folders but you try to iterate the *.mp4 files without referring to the currently processed (sub)folder.
#Echo off
Set "Base=C:\Users\PC03\Desktop\Video test"
Set "Ext=*.mp4"
FOR /R "%Base%" %%F IN (.) DO (
PushD "%%F"
if exist "%Ext%" (
> "%%~fF\output.txt" (
echo "%Base%\vast\intro.mp4"
For %%I in (%Ext%) do #echo file '%%~fI'
echo "%Base%\vast\outro.mp4"
)
Echo created "%%~fF\output.txt"
)
PopD
)

Batch script that will get files name and rename those files in Linux

I was trying to create a batch script that will get all the files (using ls command) and append those files in a text file. After that, it will look for each filename available in text file and check if those file names have .abc.ms at the end of the file name. If .abc.ms is available, then it will do nothing; if it is not available, then it will rename them (on Linux server using mv) with "file name".abc.ms .
Below is my code and I am unable to rename those files:
E:\plink -i E:\abc.ppk user#linuxserver ls /xyz/vc/dt/bbb/toy/ >> %filetemp%
FOR /f %%F IN (%filetemp%) DO (
echo %%F >>C:\temp1.txt
::if "*lock.processed"=="%%F"
find /i "lock.processed" C:\GE_RESTRICTED\RITM\NewTask\temp1.txt
if not %errorlevel%==0 (
E:\plink -i E:\abc.ppk user#linuxserver mv %%F %%F.lock.processed
)
)
...where %filetemp% is a text file used to store all the names from linux server.
If you open an SSH shell (which is effectively what you are doing when using plink.exe), you start off in the home directory of the user you are connecting with, probably something like /home/user. Since the files you want to rename reside somewhere else (Looking at your ls command, the location is /xyz/vc/dt/bbb/toy/), I think you just need to prepend that full path to files you want to rename:
E:\plink -i E:\abc.ppk user#linuxserver ls /xyz/vc/dt/bbb/toy/ >> %filetemp%
FOR /f %%F IN (%filetemp%) DO (
echo %%F >>C:\temp1.txt
::if "*lock.processed"=="%%F"
find /i "lock.processed" C:\GE_RESTRICTED\RITM\NewTask\temp1.txt
if not %errorlevel%==0 (
E:\plink -i E:\abc.ppk user#linuxserver mv /xyz/vc/dt/bbb/toy/%%F /xyz/vc/dt/bbb/toy/%%F.lock.processed
)
)
following is the solution for my question:
pushd C:\JobTest\src
for /f "delims=" %%f in ('dir /b /a-d-h-s') do (
echo %%f >>C:\NewTask\temp.txt
)
FOR /f %%a IN (C:\NewTask\temp.txt) DO (
::set FileName=%%~nxa
if not "%%~xa"==".processed" E:\plink -i E:\abc.ppk user#linuxserver mv /xyz/vc/dt/bbb/toy/%%~fa /xyz/vc/dt/bbb/toy/%%~nxa.processed
)
popd

Batch script for ffmpeg to extract images from several video files

On Windows cmd trying this code to convert all .mp4 files in directory to set of images named "filename_imagenumber.jpeg"
pushd %1
if not exist Images\ (
mkdir Images
)
for %%F in (*.mp4) do (
ffmpeg -i %%F -r 1 -f image2 -qscale:v 2 "Images\%%~nF_image-%3d.jpeg"
)
popd
However ffmpeg's argument %3d is not interpreted by Windows cmd.
Any suggestions? Thank you

deleting the input file after handbraking in batch-file

I wrote this code for HandBrakeCLI as a batch file to manipulate my videos. This code creates output files with input file name plus a "_conv" suffix.
for /R .\test %%F in (*.mov) do HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~pF%%~nF_conv.mp4
Then I want to delete the original file and then remove _conv part of the output file. What should be added to the code above?
I want to delete each file just after converting it, or at least when going from its containing folder to another folder, not wholly after converting all of the file (because lots of files must be converted and I may run out of space)
By the way, how can I add other formats in addition of *.mov in the code?
for /R .\test %%F in (*.mov) do (
HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~dpF%%~nF_conv.mp4"
if exist "%%~dpF%%~nF_conv.mp4" (
del "%%~fF"
ren "%%~dpF%%~nF_conv.mp4" "%%~nxF"
)
)
All the information is inside your original code. All that is needed is to wrap the set of commands in parenthesis so the three commands are executed for each of the input files. Also, an aditional if has been included to only delete the source file if the converted file exists.

Batch convert all files in a directory with spaces in filename

I've done this batch file that should convert all mp3 files in given folder but, I dont know why, it doesn't work...
Here is the code:
#echo off
title Converting...
set fold=C:\Users\Username\Music\Music to convert\
set ext=*.mp3
set dest=C:\Users\Username\Music\Converted Music\
for %%f in (%fold%%ext%) do ffmpeg -i %%f -b 192k %dest%%%f
pause>nul
exit
I think it's because of the spaces in the files names and in the folder name but i don't actually know... can someone verify and find out the right code?
Thanks...
Easy.
for %%f in ("%fold%%ext%") do ffmpeg -i "%%f" -b 192k "%dest%%%~nxf"
(modified version)
Here's my test batch
#echo OFF
SETLOCAL
REM title Converting...
set fold=U:\Users\Username\Music\Music to convert\
set ext=*.mp3
set dest=U:\Users\Username\Music\Converted Music\
:: This makes the directories, then creates two dummy files
:: only used for testing.
MD "%fold%"
MD "%dest%"
dir>"%fold%file1.mp3"
dir>"%fold%file two.mp3"
for %%f in ("%fold%%ext%") do ECHO ffmpeg -i "%%f" -b 192k "%dest%%%~nxf"
The ECHO in the last line is to show what would be executed. After verification, remove the ECHO keyword to activate the FFMPEG command.
%%~nxf is the name+extension of the file %%f
results:
ffmpeg -i "U:\Users\Username\Music\Music to convert\file1.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file1.mp3"
ffmpeg -i "U:\Users\Username\Music\Music to convert\file two.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file two.mp3"
Hmmm...perhaps you need to replace USERNAME when you're setting FOLD and DEST with %username%
revised to add processing for multiple filetypes
#echo OFF
SETLOCAL
REM title Converting...
set fold=U:\Users\Username\Music\Music to convert\
set ext=*.mp3 *.wma *.m4a
set dest=U:\Users\Username\Music\Converted Music\
:: This makes the directories, then creates dummy files
MD "%fold%"
MD "%fold%subdir"
MD "%dest%"
dir>"%fold%file1.mp3"
dir>"%fold%file two.mp3"
dir>"%fold%file3.wma"
dir>"%fold%subdir\file four.wma"
for /r "%fold%" %%f in (%ext%) do ECHO ffmpeg -i "%%~ff" -b 192k "%dest%%%~nxf"
Noting that I haven't changed the FFMPEG command - you are aware of the parameters you require. Command echoed as usual.
If you want to use a constant output extension, say .MP3, change "%dest%%%~nxf" to "%dest%%%~nf.MP3"
Revised batch output:
ffmpeg -i "U:\Users\Username\Music\Music to convert\file1.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file1.mp3"
ffmpeg -i "U:\Users\Username\Music\Music to convert\file two.mp3" -b 192k "U:\Users\Username\Music\Converted Music\file two.mp3"
ffmpeg -i "U:\Users\Username\Music\Music to convert\file3.wma" -b 192k "U:\Users\Username\Music\Converted Music\file3.wma"
ffmpeg -i "U:\Users\Username\Music\Music to convert\subdir\file four.wma" -b 192k "U:\Users\Username\Music\Converted Music\file four.wma"

Resources