Need help with batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DaVidoSS
Posts: 2
Joined: 29 Jun 2018 06:20

Need help with batch file

#1 Post by DaVidoSS » 29 Jun 2018 06:32

Hi. I am new here.
After numerous count of hours i was able to write batch script for convert drag and drop video file to 60FPS.

Code: Select all

@ECHO OFF
setlocal EnableDelayedExpansion
set "filename=%~1"
for %%A in ("%filename%") do (
	SET workdir=%%~dpA
	SET myfile=%%~nxA
	SET myfilename=%%~nA
	SET filetype=%%~xA
	SET filesize=%%~zA
	SET convdir=%%~dpACONVERTED
)

echo "WORK PATH = %workdir%"
echo "FILE NAME = %myfilename%"
echo "FILE TYPE = %filetype%"
echo "FILE SIZE = %filesize%"



SET mpvopt= --no-audio --no-sub --no-sub-auto --input-ipc-server=mpvencodepipe --vf=vapoursynth:[E:\\ffff.py]:4:8 --ofps 59.940 --of=matroska --ovc=h264_nvenc --ovcopts=b=2752698,rc=vbr_hq,preset=slow,profile=high,gpu=any,level=auto,rc-lookahead=32,b_adapt=0,no-scenecut=1,spatial-aq=1,bf=4,aq-strength=15,temporal-aq=1,surfaces=64,coder=auto,threads=8
SET ffmopt= -map 1:v -map 0:a? -map 0:s? -vcodec copy -acodec copy -scodec copy


cd %workdir%
mkdir %convdir% 2> NUL

start /wait mpv "%filename%" -o "%convdir%\%myfilename%.mkv" %mpvopt%

start /wait ffmpeg -y -i "%filename%" -i "%convdir%\%myfilename%.mkv" %ffmopt% "%convdir%\%myfile%"

del "%convdir%\%myfilename%.mkv"

pause
This code works as predicted but i am sure that this could be written in better way.
Another thing what i need are such code where after execute bat file every video type file in bat file directory would be affected in cascade way (one after another)

Please help me to improve current script and make the another one.
Last edited by DaVidoSS on 29 Jun 2018 12:54, edited 1 time in total.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Need help with batch file

#2 Post by Squashman » 29 Jun 2018 08:13

You can start by changing this.

Code: Select all

@ECHO OFF
setlocal EnableDelayedExpansion
SET workdir=%~dp1
SET myfile=%~nx1
SET myfilename=%~n1
SET filetype=%~x1
SET filesize=%~z1
SET convdir=%~d1ACONVERTED

DaVidoSS
Posts: 2
Joined: 29 Jun 2018 06:20

Re: Need help with batch file

#3 Post by DaVidoSS » 30 Jun 2018 03:36

Well, maybe if i would knew how..

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Need help with batch file

#4 Post by Compo » 30 Jun 2018 13:06

If it works then it cannot really be made more efficient, other than not setting variables unnecessarily.

I suppose it may look tidier to some, by breaking those long lines down into smaller portions, and could possibly be made a little more robust:

Code: Select all

@Echo Off
CD /D "%~dp1" 2>Nul || Exit /B

Set "cdir=CONVERTED"

If Not Exist "%cdir%\" (MD "%cdir%" 2>Nul || Exit /B)

Echo "WORK PATH = %__CD__%"
Echo "FILE NAME = %~n1"
Echo "FILE TYPE = %~x1"
Echo "FILE SIZE = %~z1"

Set "mext=.mkv"
Set "mopt=--no-audio --no-sub --no-sub-auto --input-ipc-server=mpvencodepipe"
Set "mopt=%mopt% --vf=vapoursynth:[E:\\ffff.py]:4:8 --ofps 59.940 --of=matroska"
Set "mopt=%mopt% --ovc=h264_nvenc --ovcopts=b=2752698,rc=vbr_hq,preset=slow,"
Set "mopt=%mopt%profile=high,gpu=any,level=auto,rc-lookahead=32,b_adapt=0,"
Set "mopt=%mopt%no-scenecut=1,spatial-aq=1,bf=4,aq-strength=15,temporal-aq=1,"
Set "mopt=%mopt%surfaces=64,coder=auto,threads=8"
Set "fopt=-map 1:v -map 0:a? -map 0:s? -vcodec copy -acodec copy -scodec copy"

mpv "%~1" -o "%cdir%\%~n1%mext%" %mopt%
ffmpeg -y -i "%~1" -i "%cdir%\%~n1%mext%" %fopt% "%cdir%\%~nx1" 2>Nul && (
	Del "%cdir%\%~n1%mext%")

Pause

Post Reply