Passing values to a batchfile

spectrum
StarLounger
Posts: 56
Joined: 24 Jan 2012, 21:48

Passing values to a batchfile

Post by spectrum »

Is it possible to pass values to a batchfile?

@echo off
cd "G:\CCTV\camera"
for %%i in (*.mpg) do ffmpeg -i "%%i" -f mjpeg -t 0.001 -ss 3 -y "%%~ni.jpg"
exit /b

Regarding the code above currently in a batchfile, is it possible to make it a one off operation (ie not loop)? and is it possible to pass a variable/value into the line of code to replace (*.mpg) with a named file.mpg.

Trying to make a one off at a time thumnail. Thanks

User avatar
John Gray
PlatinumLounger
Posts: 5405
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Passing values to a batchfile

Post by John Gray »

Yes, of course! Probably something like:

cd "G:\CCTV\camera"
ffmpeg -i "%1" -f mjpeg -t 0.001 -ss 3 -y "output.jpg"


where %1 is something like input.mpg

Called as YourBATchFile input.mpg

Or do you want the output file variable, too?

In which case just pass the filename (without the .mpg, and use:

cd "G:\CCTV\camera"
ffmpeg -i "%1.mpg" -f mjpeg -t 0.001 -ss 3 -y "%1.jpg"


and call via

YourBATchFile input
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Passing values to a batchfile

Post by HansV »

And if you want to pass the filename including .mpg and have the batch file replace it with .jpg for the output file:

cd "G:\CCTV\camera"
ffmpeg -i "%1" -f mjpeg -t 0.001 -ss 3 -y "%~n1.jpg"
Best wishes,
Hans

spectrum
StarLounger
Posts: 56
Joined: 24 Jan 2012, 21:48

Re: Passing values to a batchfile

Post by spectrum »

Many thanks John. I hardcoded my mpeg filename into the line position where %1 currently is and it worked just as wanted. However how do I pass the filename to %1 in an Access code event, how do variables get passed over. Basically I have some code that checks if a videoclip is present in a database, if not add it and make a thumbnail. Do I have a string variable called %1? Thanks again

ffmpeg -i "%1" -f mjpeg -t 0.001 -ss 3 -y "output.jpg"

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Passing values to a batchfile

Post by HansV »

Say you save the batch file suggested by John Gray as ConvertOneFile.bat.
From your code, call it like this:

Shell "ConvertOneFile.bat MyFile.mpg"

or if the filename is stored in a variable strFile:

Shell "ConvertOneFile.bat " & strFile
Best wishes,
Hans

spectrum
StarLounger
Posts: 56
Joined: 24 Jan 2012, 21:48

Re: Passing values to a batchfile

Post by spectrum »

Thanks Hans. I think I must be doing something stupid. I added the path into strFileB as it said it could not find a file. Thanks

Private Sub Command16_Click()
Dim strFileB As String
strFileB = "G:\CCTV\CAMERA\20111003_043243_camera03.mpg"
Shell "G:\CCTV\Camera\CreateThumbs2.bat" & strFileB
End Sub

Batchfile:
cd "G:\CCTV\camera"
ffmpeg -i "%1" -f mjpeg -t 0.001 -ss 3 -y "output.jpg"

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Passing values to a batchfile

Post by HansV »

Try adding a space after .bat:

Shell "G:\CCTV\Camera\CreateThumbs2.bat " & strFileB

By the way, since you switch to the folder G:\CCTV\Camera in the batch file, it isn't strictly necessary to include this path in the file name:

Code: Select all

Private Sub Command16_Click()
    Dim strFileB As String
    strFileB = "20111003_043243_camera03.mpg"
    Shell "G:\CCTV\Camera\CreateThumbs2.bat " & strFileB
End Sub
Best wishes,
Hans

spectrum
StarLounger
Posts: 56
Joined: 24 Jan 2012, 21:48

Re: Passing values to a batchfile

Post by spectrum »

Hello Hans, that worked perfectly!! Many thanks once again