0

I'm doing a time lapse video using an IPCAM. I take photos every 15/20secs from dusk to dawn. Each folder is labelled with a date each and every day etc etc.

I make a timelapse video using all the files for each day using lots of files, currently 3750.

I also would like to make 3 separate time lapse videos using a set number of images.

equations are

(total files) / (25 fps) / (3 seconds long) = how many files to skip

example

3750 / 25 / 3 = 50 files to skip

So i'm using this code at the moment

mkdir "3"

@echo off
set Counter=0
for %%f in (*.jpg) do call :p "%%f"
goto :p

:p
    set /a Counter+=1
    set /a X=Counter %% "50"
    if %X%==0 copy %1 "3"

goto :eof

This creates the directory "3" and copies every 50th file to the folder. Then i can make the timelapse video using the files in folder.

I then have to do edit the batch file for 10 seconds and also for 30 images and run then each separately.

how can i add all the lines into one batch file so i only have to edit one file each time ?

mkdir "10"

@echo off
set Counter=0
for %%f in (*.jpg) do call :p "%%f"
goto :p

:p
    set /a Counter+=1
    set /a X=Counter %% "15"
    if %X%==0 copy %1 "10"

goto :eof

&

mkdir "30"

@echo off
set Counter=0
for %%f in (*.jpg) do call :p "%%f"
goto :p

:p
    set /a Counter+=1
    set /a X=Counter %% "125"
    if %X%==0 copy %1 "30"

goto :eof

Hope thats makes some sort of sense.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
John Ewing
  • 5
  • 1
  • 4

2 Answers2

0

I'd also use batch to count the files and do the calculations.

@echo off
:: get total number of files
for /f %%A in ('dir /b *.jpg ^| find /v /c ""') do set /A total=%%A

:: create subfolders and calculate skip
for %%A in (3 10 30) Do (
  mkdir "%%A"
  if %%A neq 30 (
    Set /A "skip%%A=total/25/%%A
  ) Else (
    Set /A "skip%%A=total/%%A
  )
)

set Counter=0
for %%f in (*.jpg) do call :p "%%f"
goto :EOF

:p
set /a "Counter+=1,X=Counter%%skip3,Y=Counter%%skip10,Z=Counter%%skip30"
if %X%==0 copy %1 "3"
if %Y%==0 copy %1 "10"
if %Z%==0 copy %1 "30"
goto :eof

Edited Changed folder 30 to contain 30 jpg's.

  • Edited the batch to include the calculations (untested) –  May 10 '17 at 22:46
  • this works very well. just as i needed. Ill try and automate the calculations using the link above and hopefully work even easier :) – John Ewing May 10 '17 at 22:59
  • Thanks so much, this is working better than i imagined it would. Both 3 and 10 are spot on The folder "30" is actually just 30 original photos that i want to keep and not a 30 second clip. I tried modifying it myself but i'm getting nowhere. Rather than divide by 25 then divide by seconds. It just needs to be divided by 30. Do you think its possible to save just 30 files into that particular folder and keep the 3 and 10 folders as they are. Once again thanks so much, you dont realise how much time this will save me – John Ewing May 11 '17 at 19:38
  • Changed folder 30 to contain 30 jpg's –  May 11 '17 at 20:48
  • Absolute legend, Thanks so much for your expertise :):):) Works like a dream !! – John Ewing May 11 '17 at 21:16
0

You could try something like this where you have to enter the number of seconds for each directory that you want to create and the number of files you want to skip. (Assuming the batch file is located in the same directory as the the JPG files and the current directory is set to this directory as well.)

@echo off

:MainLoop {
  cls

  setlocal enabledelayedexpansion
  set fileCount=0
  set /p "duration=Seconds: "
  set /p "interval=Files to skip: "

  mkdir "%duration%"

  for %%f in (*.jpg) do (
    set /a fileCount+=1
    set /a frame=fileCount%%interval
    if !frame! == 0 (
      copy "%%f" "%duration%"
    )
  )
  pause
  endlocal
  goto :MainLoop
}

The number of files to skip could be calculated by obtaining the number of JPG files located in the current directory, dividing it by the frames per second (which could be defined as a constant variable within the script) and the number of seconds that the user has entered. I wasn't sure if this what you wanted because the "125" in your last example seemed to be off.

The following answer by dbenham shows how to obtain the number files in a directory: https://stackoverflow.com/a/11005300/7107236

Community
  • 1
  • 1
303
  • 2,417
  • 1
  • 11
  • 25
  • thanks, i was going to ask about calculating the file also which is great. There would be a 3 second clip, a 10 second clip and the final one "30" is not a clip but i want to save 30 original files from that day so i can delete the rest of the files in the folder to save space. Currently getting around 10gb/day so soon adds up. Saving the smaller clips and only 30 photos cuts this dramtically. Once a whole month/year has gone by i can make a timelapse of the whole month/year picking from the 30 originals – John Ewing May 10 '17 at 22:27