Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Windows batch file to renumber image files - please!

Hardware/software/hints and tips/discussion/webcam links etc
Post Reply
User avatar
gwheelo
Posts: 453
Joined: Wed 11 Jun 2008 7:36 pm
Weather Station: WMR-88
Operating System: Windows 8.1
Location: L'Estartit, Spain
Contact:

Windows batch file to renumber image files - please!

Post 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
Image
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

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

Post 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
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

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

Post 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!
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

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

Post 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.
Last edited by beteljuice on Mon 10 Feb 2014 12:14 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

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

Post 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...
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

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

Post 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
User avatar
gwheelo
Posts: 453
Joined: Wed 11 Jun 2008 7:36 pm
Weather Station: WMR-88
Operating System: Windows 8.1
Location: L'Estartit, Spain
Contact:

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

Post 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
Image
User avatar
gwheelo
Posts: 453
Joined: Wed 11 Jun 2008 7:36 pm
Weather Station: WMR-88
Operating System: Windows 8.1
Location: L'Estartit, Spain
Contact:

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

Post 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
Image
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

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

Post by beteljuice »

As with someone elses 'video' style embed I get "No video with supported format and MIME type found"

Ye Olde XP3
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

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

Post 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???
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
gwheelo
Posts: 453
Joined: Wed 11 Jun 2008 7:36 pm
Weather Station: WMR-88
Operating System: Windows 8.1
Location: L'Estartit, Spain
Contact:

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

Post 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
Image
User avatar
gwheelo
Posts: 453
Joined: Wed 11 Jun 2008 7:36 pm
Weather Station: WMR-88
Operating System: Windows 8.1
Location: L'Estartit, Spain
Contact:

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

Post 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
Image
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

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

Post 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
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

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

Post 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..
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
Post Reply