Log in

View Full Version : Help with generating video from cropped images


dark76
21st November 2020, 19:32
Hello,
Probably stupid question, I try to explain what I'm trying to do (my english is quite bad, sorry)
I have a folder with multiple images. I want to cut/split/crop them in 3 parts and then joining what I get to generate a video. For example let's say I have "picture1" and "picture2" in the folder (same height and width)... I want to generate a video from "top_picture1", "middle_picture1", "bottom_picture1", "top_picture2", "middle_picture2", "bottom_picture2".

I looked in the forum and imitating other scripts (basically from Stainless, i think) I came to the point that i wrote a function which work for a single picture but I'm not able to make it work recursevely.

The function is this,

function croppaunisci(clip immagine)
{
larghezza=Width(immagine) #width
altezza=Height(immagine) #height


croppato=altezza/3 #height/3

sopra1=crop(immagine,0,0,0,croppato) #top of the picture
centro2=crop(immagine,0,croppato,0,croppato) # middle of the picture
sotto3=crop(immagine,0,croppato*2,0,croppato) # bottom of the picture

sopra1++centro2++sotto3 # join the parts

}

Then I wrote this but it doesn't work cause I don't know how to append what I get from the cycle.

IN_FILES = "C:\pathwithimages\*.jpg" # Added '|' Pipe separator for multiple Wildcard in Extensions ONLY.
OUT_FILE = "FILE.List" # Dont need to change really, just a name.
result=RT_WriteFileList(IN_FILES,OUT_FILE) # Create a listing file of Pic files
Assert((result!=0), "No files found")
FILELIST=RT_ReadTxtFromFile(OUT_FILE) # Get list of files
FILES=RT_TxtQueryLines(FILELIST) # Query Number of lines in String ie number of files.


For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename
immagine=Imagesource(FN,end=0,fps=25)
a=croppaunisci(immagine)
return a + a


}


The part "return a+a" is obviously non-sense, i know, but how should i correct it?
Using avisynth+ 3.61, windows 7 32 bit.
Thx for the attention!

Frank62
21st November 2020, 23:37
Add all tops with +
Add all middles.
Add all bottoms.
Use interleave(t,m,b).

dark76
22nd November 2020, 00:05
Unfortunately this answer is too much cryptic for my avisynth level...

VoodooFX
22nd November 2020, 10:34
Unfortunately this answer is too much cryptic for my avisynth level...

He meant like this:

t=top_picture1+top_picture2
m=middle_picture1+middle_picture2
b=bottom_picture1+bottom_picture2
interleave(t,m,b)

dark76
22nd November 2020, 10:46
He meant like this:

t=top_picture1+top_picture2
m=middle_picture1+middle_picture2
b=bottom_picture1+bottom_picture2
interleave(t,m,b)

Oh, thx... i will try some test... anyway what i was explaining in first message was an example. I have many more images in the folders , not only 2 (a variable number usually between 50 and 200).
Thx for attention, now i will try to understand if your advices can fix my script :)

wonkey_monkey
22nd November 2020, 12:08
As long as the images are numbered sensibly you can use ImageSource (http://avisynth.nl/index.php/ImageSource) to load a folder's worth of images as one clip, and then interleave the three clips.

dark76
22nd November 2020, 12:17
Maybe i found a solution. I didn't change the function and i modified like this

IN_FILES = "C:\pathwithimages\*.*" # Added '|' Pipe separator for multiple Wildcard in Extensions ONLY.
OUT_FILE = "FILE.List" # Dont need to change really, just a name.
result=RT_WriteFileList(IN_FILES,OUT_FILE) # Create a listing file of Pic files
Assert((result!=0), "No files found")
FILELIST=RT_ReadTxtFromFile(OUT_FILE) # Get list of files
FILES=RT_TxtQueryLines(FILELIST) # Query Number of lines in String ie number of files.

tot=0
For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename
immagine=Imagesource(FN,end=0,fps=25)
v=croppaunisci(immagine)
tot = (tot.IsClip) ? tot ++ v : v # If tot is a clip, then add splice v else replace with v

}


return tot


Basically i added "tot = (tot.IsClip) ? tot ++ v : v" (copied from another stainless script, this is becoming a frankenstein-stainless monster :D ), and this way i can append the result of the function ;)


EDIT: "Final version" using first image as model for resizing the others.


IN_FILES = "c:\pathwithimages\*.*" # Added '|' Pipe separator for multiple Wildcard in Extensions ONLY.
OUT_FILE = "FILE.List" # Dont need to change really, just a name.
result=RT_WriteFileList(IN_FILES,OUT_FILE) # Create a listing file of Pic files
Assert((result!=0), "No files found")
FILELIST=RT_ReadTxtFromFile(OUT_FILE) # Get list of files
FILES=RT_TxtQueryLines(FILELIST) # Query Number of lines in String ie number of files.


primo=RT_TxtGetLine(FILELIST,0)
primo_larghezza=Width(Imagesource(primo)) #width
primo_altezza=Height (Imagesource(primo))#height
pr_lar_mod4 = primo_larghezza - (primo_larghezza % 4) # Round Down
pr_alt_mod6 = primo_altezza - (primo_altezza % 6) # Round Down



tot=0
For(i=0,FILES-1) {
FN=RT_TxtGetLine(FILELIST,i) # Filename
immagine=Imagesource(FN,end=500,fps=25).BlackmanResize(pr_lar_mod4,pr_alt_mod6)
v=croppaunisci(immagine)
tot = (tot.IsClip) ? tot ++ v : v # If tot is a clip, then add splice v else replace with v

}


return tot


ConvertBits(8)
ConvertToYV12()

StainlessS
22nd November 2020, 17:36
Combination of previous posts suggestions.

First My Demo creating whotsit,

# PIC folder MUST exist in current directory
W=64
H=64
S=64
T=$808080
DIGITS=6
TYPE="JPG"
###
A=BlankClip(Length=1,Width=W,Height=H*3,Color=$FF0000)
B=A.BlankClip(Color=$00FF00)
C=A.BlankClip(Color=$0000FF)
A=A.Subtitle("1",y=0*H,Text_Color=T,Size=S).Subtitle("2",y=1*H,Text_Color=T,Size=S).Subtitle("3",y=2*H,Text_Color=T,Size=S)
B=B.Subtitle("1",y=0*H,Text_Color=T,Size=S).Subtitle("2",y=1*H,Text_Color=T,Size=S).Subtitle("3",y=2*H,Text_Color=T,Size=S)
C=C.Subtitle("1",y=0*H,Text_Color=T,Size=S).Subtitle("2",y=1*H,Text_Color=T,Size=S).Subtitle("3",y=2*H,Text_Color=T,Size=S)
A++B++C
NAME=".\PIC\slide_%0"+String(DIGITS,"%.0f")+"d"+"."+TYPE
#RT_DebugF("NAME='%s",NAME,name="SomeInfo: ")
ImageWriter(NAME, start=0,end=2,type=TYPE)
Return last

EDIT: Above, Changed in BLUE, was "jpg"

Creates in PIC dir
slide_000000.JPG # Red
slide_000001.JPG # Grn
slide_000002.JPG # Blu

eg 1st one slide_000000.JPG # Red
https://i.postimg.cc/MGdQcX3N/slide-000000.jpg (https://postimages.org/)

Script for your use

PATH = ".\PIC\Slide_" # PIC directory relative to current dir, base filename node "Slide_"
TYPE = "jpg"
DIGITS = 6
### FIRST WANT FIND NUMBER OF IMAGE FILES FOR ImageReader(END)
IN_FILES = PATH + "*." + TYPE # ".\PIC\Slide_*.jpg"
OUT_FILE = ".\FILE.List" # TMP file
FILES = RT_WriteFileList(IN_FILES,OUT_FILE) # Create a listing file of Pic files
Assert((FILES!=0), "No files found")
RT_FileDelete(OUT_FILE) # We Are done with it
#RT_DebugF("IN_FILES='%s'\nFILES COUNT=%d",IN_FILES,FILES,name="SomeInfo: ")
IR_FILE = RT_String("%s%%0%dd.%s",PATH,DIGITS,TYPE) # ".\PIC\Slide_%06d.jpg" # NOTE, "%%" required for Literal '%' in format str
ImageReader(IR_FILE, end=FILES-1)
#RT_DebugF("READER_FILE='%s",IR_FILE,name="MoreInfo: ")
H=Height/3
T = CROP(0,0,0,H)
M = CROP(0,H,0,H)
B = CROP(0,2*H,0,0)
Interleave(T,M,B)
Return last


It is assumed that images will start at 000000 with 6 digits.
(If dont start at 0 will require script fix for Start and End)

EDIT:
If you add this before Return from 2nd Script will produce this, with all frames stacked and shown as single image,
where original frames as R, or G, or B, and 1=Top, 2=Mid, 3=Bot.

C=0
For(i=0,8) {
Z = Last.Trim(i,-1)
C=(C.IsClip) ? StackHorizontal(C,Z) : Z
}
C

https://i.postimg.cc/8PRsJjj4/cropings-2-Copy-00.jpg (https://postimages.org/)

dark76
22nd November 2020, 20:27
Thx also to you Stainless :) I will try your script next days. The one i posted little above is quite slow on my old pc (3.81 fps processing images sized around 1800x2400) and i'm curious to see if using the interleave will be little faster ;) I will let you know next days.