I'm working on a project which works like that:
take a long video hard subtitled and cut it in a lot of smaller scenes and where each scene lasts the time that it lasts the subtitle to disappear
cut one only picture (maybe the first one or the last one) of each segment of the original video and do it automatically
repeat (copy and paste) the picture extracted as many times as the number of pictures that there are on each fragment that has been cut on the original video
join everything
I have already achieved the point 1) and 2), now I'm trying to achieve point 3) and I need your help, please. Let's say that I have achieved point 2) with this batch script (that I call a.bat) :
pushd %1
if not exist newfiles\ (
mkdir newfiles
)
if not exist newfiles2\ (
mkdir newfiles2
)
:start
for %%F in (*.mov) do (
md "%%~nF"
echo "%%~nF"
ffmpeg -i %%F -r 1 -f image2 -qscale:v 2 "%%~nF\%%~nF_image-%%3d.png"
copy "%%~nF\%%~nF_image-001.png" ".\newfiles"
)
popd
So, I have this situation:
It means that in each folder there is a variable number of images that have been extracted from the *.mov
files. Now, I want that the first image on the list of the images located on the relative folders is copied in another folder, as many times as many files there are in the same folder where it is. For example, let's take a look at this folder:
Here there are 4 images, right? I want to copy the first (or the last) image of the list for 4 times in this folder:
I would like that someone can help me to improve this batch script (that I call b.bat)...
@echo off
setlocal enabledelayedexpansion
set count=0
for %%x in (*.png) do set /a count+=1
echo %count%
FOR %%F IN (*.png) DO (
set filename=%%F
goto tests
)
:tests
echo "%filename%"
for /l %%i in (1,1,%count%) do copy %filename% ..\newfiles2\%%i.png
endlocal
pause
because I figured out that it works only if I put a copy of it in every/each folder,but then I have to enter in each folder to run it,wasting a lot of time. Let's say that I want to run it in the folder where all the others folders are located. How can I modify the script to do so ? This is what happens if I run it on the "root" folder :
EDIT : thanks to the suggestion of @AlexP I modified the script like this :
@echo off
setlocal enabledelayedexpansion
set count=0
for /d %%d in (render*) do set /a count+=1t
echo %count%
pause
for %%f IN ("%%~d\*") do (
set filename=%%F
goto tests
)
:tests
echo "%filename%"
for /l %%i in (1,1,%count%) do copy %filename% .\%%i.png
endlocal
pause
now the var "count" has value 4,but this is wrong. the value that i need is inside each folder that starts with the word render* ; so,since I have 4 pics inside the "render00003211" folder the value is 4; 5 pics under "render00003266" the value is 5 and so on..
UPDATE : I've ordered sequentially the names of the pictures by placing this script inside the Duplicates folder...
@echo off
setlocal enabledelayedexpansion
mkdir pics
copy *.png .\pics
del *.png
for /d /r %%a in (%1\*.*) do (
set /a counter=0
for %%b in ("%%a\*.*") do (
set /a counter += 1
set zcounter=0000!counter!
set source="%%~fb"
set target="pic!zcounter:~-4!%%~xb"
echo Renaming !source! to !target!
ren !source! !target!
)
)