Page 1 of 1

Windows batch file to renumber image files - please!

Posted: Mon 10 Feb 2014 4:53 am
by gwheelo
Yawcam uses a circular file to number a set number of files. This is a feature I really like as it permits me to access the latest set at any time. However this file naming scheme creates a numbering system which begins at the most recent image (image0.jpg, image1.jpg, image3.jpg...) and ends with the oldest image ( in my case image240.jpg). What I want to do is rename the files in reverse number order - so that image0.jpg becomes image240.jpg, image1.jpg becomes image239.jpg ..... and so on.

I am looking for a Windows batch file to renumber the image files to include in my bat process that converts the .jpg image files to a mp4 video file and ftps the resulting video to my web server. Any help or suggestions will be very welcome!

gwheelo

Re: Windows batch file to renumber image files - please!

Posted: Mon 10 Feb 2014 10:06 am
by mcrossley
I'm always up for a batch challenge - can't resist the 'old' technology :lol:

Edit: Oops, I'd left a pause in the main loop!

Code: Select all

@echo off
setlocal enabledelayedexpansion enableextensions
rem cd <path>
rem create a working sub-directory
md work
rem Find the number of image files to rename
set count=0
for %%A in (image*.jpg) do set /a count=!count!+1
rem we start at 0 so subtract 1 from total
set /a count=%count%-1
for /L %%N in (0, 1, %count%) do (
	copy image%%N.jpg work\image!count!.jpg
	set /a count=!count!-1
)
rem delete originals
del /q image*.jpg
rem copy back images
copy work\image*.jpg image*.jpg
rd /s /q work
endlocal

Re: Windows batch file to renumber image files - please!

Posted: Mon 10 Feb 2014 10:13 am
by mcrossley
BTW, as that script deletes your original files, be very sure it works 100% before letting it loose on any files you haven't backed up!

Re: Windows batch file to renumber image files - please!

Posted: Mon 10 Feb 2014 11:27 am
by beteljuice
Wait a minute .........

That could only be of use as a one-shot !

What happens when the 'next' picture comes in ?

You need to create a seperate set of (renumbered) files which you then process / ftp.

Re: Windows batch file to renumber image files - please!

Posted: Mon 10 Feb 2014 11:30 am
by ace2
I'm about to setup my web cam, ok if I steal that as well!!!!

I was hoping to make the cam upload a snap shot to my ftp server every 30 seconds.

I wonder if a script can be used by comulus to upload the newest shot to my web site say every 5-10 mins???

get my cam in a few days...

Re: Windows batch file to renumber image files - please!

Posted: Mon 10 Feb 2014 11:52 am
by mcrossley
beteljuice wrote:Wait a minute .........

That could only be of use as a one-shot !

What happens when the 'next' picure comes in ?

You need to create a seperate set of (renumbered) files which you then process / ftp.
Ah, lack of requirements!

If you need to keep the originals, then just use the copies in the 'work' folder, and delete them once you are done (or at the start of the rename script)

Code: Select all

@echo off
setlocal enabledelayedexpansion enableextensions
rem cd <path>
rem Clean out the work folder if already exists
rd /s /q work
rem Create a working sub-directory
md work
rem Find the number of image files to rename
set count=0
for %%A in (image*.jpg) do set /a count=!count!+1
rem we start at 0 so subtract 1 from total
set /a count=%count%-1
for /L %%N in (0, 1, %count%) do (
   copy image%%N.jpg work\image!count!.jpg
   set /a count=!count!-1
)
rem *** do your stuff with the renamed images in the work folder here or after the script exits ***
endlocal

Re: Windows batch file to renumber image files - please!

Posted: Tue 11 Feb 2014 3:30 am
by gwheelo
Looks as if all the bases are covered now!

Here is what I put together on my own - it works great and creates the mp4. I will take on board the "professional" code from Mark et al. to produce the final script.

Betel caught the "one shot" and Mark, of course immediately had the solution.

cd c:\yawcam_images

set cnt=1
for %%A in (*) do set /a cnt+=1
rem echo File count = %cnt%

SET /a num=10000+cnt
For %%I IN (C:\yawcam_images\*.jpg) DO (
SET /a num-=1
SETLOCAL EnableDelayedExpansion
RENAME "%%I" !num:~-4!.*
ENDLOCAL
)
c:\ffmpeg\bin\ffmpeg -y -f image2 -r 20 -i c:\yawcam_images\%%04d.jpg -vcodec libx264 -preset medium -crf 24 c:\FFmpeg\cam%FD%.mp4
rem @DEL /S /Q /F "c:\yawcam_images\*"

By the way the"FFmpeg" script is cutesy of Nitrx and replaces my old script which produced an .avi - now I can use HTML5 "video" tags.

Now all that is left is to get back to the WebCam which is having a hardware issue and is about 5000 km from my current location. So nothing to show until about March 16. I will post the final script then and include the code to ftp using the Windows 'built-in' ftp client.

My thanks to all,

gwheelo

Re: Windows batch file to renumber image files - please!

Posted: Fri 28 Mar 2014 10:25 pm
by gwheelo
Now all that is left is to get back to the WebCam which is having a hardware issue and is about 5000 km from my current location. So nothing to show until about March 16. I will post the final script then and include the code to ftp using the Windows 'built-in' ftp client.
Better late than never! There were a few things more pressing than the webcam when I got back in country. MedesCam is now back up and running just fine with the new script and help from Mark, Beteljuice, and the rest of the forum.

Now using HTML Video tags so let me know if it doesn't work on your platform.

See it here: http://www.wheelocknet.net/medes_cam/medes_home.html

I am using Yawcam for the capture, ftp upload of still images and "live" video. Windows Task Schedular handles the image manipulation and processing by FFmpeg sending the result to Windows ftp client via the ftp script. Here is the bat file and ftp parameter txt file. The schedular runs every two hours.

Now no one should be shy here. I am ready for critisism and improvements - stylistically and functionally. I don't know enough to know if any of this is correct other than it works.

Here are the scripts:

cd c:\temp

copy c:\temp\*.jpg c:\temp\yawcam_work

cd c:\temp\yawcam_work

set cnt=0
for %%A in (*) do set /a cnt+=1
rem echo File count = %cnt%

SET /a num=10000+cnt
For %%I IN (C:\temp\yawcam_work\*.jpg) DO (
SET /a num-=1
SETLOCAL EnableDelayedExpansion
RENAME "%%I" !num:~-4!.*
ENDLOCAL
)

ffmpeg -y -f image2 -r 10 -i c:\temp\yawcam_work\%%04d.jpg -vcodec libx264 -preset medium -crf 24 c:\temp\cam.mp4
@DEL /S /Q /F "c:\temp\yawcam_work\*"

cd c:\windows\system32


ftp -i -s:"c:\temp\put_ftp_video.txt"


Ftp script (put_ftp_video.txt)
open wheelocknet.net
*******user_id*******
*******password*****
cd medes_cam
binary
put "c:\temp\cam.mp4"
close
quit


gwheelo

Re: Windows batch file to renumber image files - please!

Posted: Fri 28 Mar 2014 11:04 pm
by beteljuice
As with someone elses 'video' style embed I get "No video with supported format and MIME type found"

Ye Olde XP3

Re: Windows batch file to renumber image files - please!

Posted: Sat 29 Mar 2014 6:40 am
by ace2
gwheelo wrote:
Now all that is left is to get back to the WebCam which is having a hardware issue and is about 5000 km from my current location. So nothing to show until about March 16. I will post the final script then and include the code to ftp using the Windows 'built-in' ftp client.


ffmpeg -y -f image2 -r 10 -i c:\temp\yawcam_work\%%04d.jpg -vcodec libx264 -preset medium -crf 24 c:\temp\cam.mp4
@DEL /S /Q /F "c:\temp\yawcam_work\*"

cd c:\windows\system32


ftp -i -s:"c:\temp\put_ftp_video.txt"


Ftp script (put_ftp_video.txt)
open wheelocknet.net
*******user_id*******
*******password*****
cd medes_cam
binary
put "c:\temp\cam.mp4"
close
quit


gwheelo
Interesting, I to do the same thing with script but converted to exe plus not other programs used, solely done by scripts..
What output file size is yours???

Re: Windows batch file to renumber image files - please!

Posted: Sat 29 Mar 2014 11:52 am
by gwheelo
beteljuice wrote:As with someone elses 'video' style embed I get "No video with supported format and MIME type found"

Ye Olde XP3
I am disapointed! Particularly as you contributed! But I suspect the 'Ye olde XP3' might need a 'modern' browser. Yes - HTML5 won't work for every one but it does seem to work with Android, Apple, and up to date Chrome, Safari, IE, and Firefox browsers.

gwheelo

Re: Windows batch file to renumber image files - please!

Posted: Sat 29 Mar 2014 11:57 am
by gwheelo
Interesting, I to do the same thing with script but converted to exe plus not other programs used, solely done by scripts..
What output file size is yours???
mp4 file size size is 3,822 kb.

Would you mind sharing your FFmpg script?

gwheelo

Re: Windows batch file to renumber image files - please!

Posted: Sun 30 Mar 2014 12:14 am
by ace2
gwheelo wrote:
mp4 file size size is 3,822 kb.
Would you mind sharing your FFmpg script?
Yeah sure, sharing is caring..
My final output size with the music is around 22Mb, i have Jpegs stills taken every 17 seconds using my Foscam software to a NAS drive, Then my Media center takes care of the rest, every dos script is converted to a silent exe so it doesn't interfere with Tv/movie playback.
Excuse my messy ish scripting and removal of single line ftp passwords.

Code: Select all

echo off
cls

rem delete old tool pictures from C
c:
cd\
cd cumulus\scripts\TOOLS\
DEL /F /Q /A "c:\Cumulus\scripts\TOOLS\*.jpg"

rem delete snapshot jpg only delete from U before convert
u:
cd\
cd snap
DEL /F /Q /A "u:\snap\snapshot.jpg"

rem copy current working jpgs to tools folder
copy *.jpg c:\cumulus\scripts\TOOLS\
c:
cd\
cd cumulus\scripts\TOOLS\

rem delete old timelapse video for conversion
DEL /F /Q /A "myfile1.mp4"


rem rename all jpg's in tools folder and execute video convertion
..\TOOLS\BRC32.EXE /PATTERN:"*.jpg *.JPG" /REMOVENAME /AUTONUMBER:1:1:S:FRAME:10:4 /EXECUTE

..\TOOLS\ffmpeg -i FRAME%%04d.JPG -i music.mp3 -r 24 -threads 7 -s hd480 -b 1300k -vcodec libx264 -shortest myfile1.mp4 -y

rem upload offline upload/delete all jpg's from U + copy default offline jpg(11pm) + delete myfile 3, rename 2 to 3 & rename 1 to 2
ncftpput -C -u ******** -p ****************** ftp.users.on.net C:\Cumulus\scripts\video\upload\video.htm /video.htm

ftp -s:renameftp.txt
DEL /F /Q /A "u:\snap\*.jpg"

Rem copy offline still
copy "c:\temp\snapshot.jpg" u:\snap\snapshot.jpg /y

rem copy to web
ncftpput -C -u *********** -p **************** ftp.users.on.net c:\cumulus\scripts\TOOLS\myfile1.mp4 /myfile1.mp4

rem send online video.htm
ncftpput -C -u ************ -p ************************ ftp.users.on.net c:\cumulus\scripts\video\online\video.htm /video.htm


rem copy mp4 to U for archive and rename
c:
cd\
cd cumulus\scripts\tools\
copy "c:\Cumulus\scripts\TOOLS\myfile1.mp4" "u:\Time Lapse videos\myfile1.mp4" /y
u:
cd\
cd\Time Lapse videos\

rename to current date for archive
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "myfile1.mp4" %%d-%%e-%%f.mp4


I know i can simplify my pathing to locations and stuff, but hey, if it works, i won't attempt to break it!!
I also run another script every 10 mins to upload the latest camera stills to web using

Code: Select all

echo off
rem find latest file
FOR /F "delims=|" %%I IN ('DIR "u:\snap\*.jpg" /B /O:D') DO SET NewestFile=%%I

rem copy new file to c:temp snap
xcopy "u:\snap\%NewestFile%" c:\temp\snapshot.jpg /y

rem copy to web server
ncftpput -C -u ****** -p ********* ftp.users.on.net c:\temp\snapshot.jpg /snapshot.jpg
hope the above is useful for you in some way..
Should note, i had to use NCFTP due to my ISP not allowing Dos FTP cause of Passive mode....

substituted your script (-vcodec libx264 -preset medium -crf 24)
made a output file of 139Mb

Re: Windows batch file to renumber image files - please!

Posted: Mon 31 Mar 2014 7:03 am
by ace2
just added to the main script.

Now it creates two videos, one for website(20Mb) and one very large one(140Mb) for youtube site as a archive.

Unable to find a way of uploading to youtube via command line, so i'll cheat and copy to USB to upload at work on a very ultra fast fiber line..