Batch ffmpeg auto convert

  • central10
  • Born
  • Born
  • central10
  • Posts: 3

Post 3+ Months Ago

Hello everyone,

Over the past few days I have been trying to automate the ffmpeg conversion process to save my self some time.

I have a monitoring program that automatically executes/runs a program every time a video file is added to a folder. What I have done is created a bat file named “auto.bat” which is being run automatically by the program every time a file is added to the folder.

The bat file looks like this:

Code: [ Select ]
C:\ffmpeg\ffmpeg.exe -y -i %1 -vcodec flv -b 250k -r 14.985 -acodec libmp3lame -ab 40k -ar 22050 -ac 1 -vol 276 -qscale 5 %1.flv


This bat file works if I drag and drop the avi file into it however this isn’t how I want it to function. I would like the batch file to automatically grab the new file in the folder and start ffmpeg. I’ve poked around on the Internet and can’t seem to find a solution. I’m new to writing batch files so I don’t have the expertise to finish this off. I’m wondering if someone can guide me in the right direction.

Any help would be greatly appreciated.
Regards,
Dave
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

I didn't think of this when I responded to your PM before, but where are you entering the name of the *.bat file that your program executes ?

Does this program have some sort of argument tokens for the filename ?

I'm wondering if you could replace the %1 in that piece of code you have there, with whatever tokens your application would have you passing to the *.bat file, and then just point your monitoring application at that command instead of the *.bat file.
  • central10
  • Born
  • Born
  • central10
  • Posts: 3

Post 3+ Months Ago

Hello,

I am entering the name of the “auto.bat” file in the required field in the program. This program doesn’t have any arguments for the file and simply runs any program upon addition of a new file. So I am unable to replace the %1 with any arguments that might allow me to “use” the newly added file.

Any other ideas?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

If your monitor doesn't pass the filename to the scheduled program in some way shape or form, you're going to need a different monitoring program. :)
  • central10
  • Born
  • Born
  • central10
  • Posts: 3

Post 3+ Months Ago

Hello,

So I've almost got this batch file working now. The problem I am having is that the batch script is grabbing files in the folder based on the modification date. I need it to grab files based on it's creation date. For instance “fileone.avi” was modified on 5/12/2010 1:33 PM while “filetwo.avi” was modified on 5/11/2010 11:33 AM. Regardless if “filetwo.avi” was created after fileone.avi, fileone.avi will be taken by ffmpeg because it’s modification date was more recent.

Can someone finish this off for me please?

Code: [ Select ]
@echo off

SETLOCAL EnableDelayedExpansion
set "latestFile="
call :findlatestfile latestFile
echo the latest file is "%latestFile%"
::###############################
:monitor

if "%currentlatestFile%" NEQ "%latestFile%" (
 echo new file "%currentlatestFile%"
 set "latestFile=%currentlatestFile%"
 call :openFile %latestFile%

)
rem to preseve the cpu usage
call :sleep
goto :monitor

::###############################
:openFile <file>
echo Start ffmpeg with -y -i %~n1.avi -vcodec flv -b 250k -r 14.985 -acodec libmp3lame -ab 40k -ar 22050 -ac 1 -vol 276 -qscale 5 %~n1.flv
start C:\ffmpeg\ffmpeg.exe -y -i %~n1.avi -vcodec flv -b 250k -r 14.985 -acodec libmp3lame -ab 40k -ar 22050 -ac 1 -vol 276 -qscale 5 %~n1.flv

exit

::###############################
:findlatestfile
set "%~1=NO FILE"
for /F "delims=" %%a in ('dir /b /od *.avi 2^> nul') DO (
  set %~1=%%a
)

goto :eof

::###############################
:sleep
ping -n 2 localhost > nul

exit
  1. @echo off
  2. SETLOCAL EnableDelayedExpansion
  3. set "latestFile="
  4. call :findlatestfile latestFile
  5. echo the latest file is "%latestFile%"
  6. ::###############################
  7. :monitor
  8. if "%currentlatestFile%" NEQ "%latestFile%" (
  9.  echo new file "%currentlatestFile%"
  10.  set "latestFile=%currentlatestFile%"
  11.  call :openFile %latestFile%
  12. )
  13. rem to preseve the cpu usage
  14. call :sleep
  15. goto :monitor
  16. ::###############################
  17. :openFile <file>
  18. echo Start ffmpeg with -y -i %~n1.avi -vcodec flv -b 250k -r 14.985 -acodec libmp3lame -ab 40k -ar 22050 -ac 1 -vol 276 -qscale 5 %~n1.flv
  19. start C:\ffmpeg\ffmpeg.exe -y -i %~n1.avi -vcodec flv -b 250k -r 14.985 -acodec libmp3lame -ab 40k -ar 22050 -ac 1 -vol 276 -qscale 5 %~n1.flv
  20. exit
  21. ::###############################
  22. :findlatestfile
  23. set "%~1=NO FILE"
  24. for /F "delims=" %%a in ('dir /b /od *.avi 2^> nul') DO (
  25.   set %~1=%%a
  26. )
  27. goto :eof
  28. ::###############################
  29. :sleep
  30. ping -n 2 localhost > nul
  31. exit

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 91 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.