Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st November 2020, 19:32   #1  |  Link
dark76
Registered User
 
Join Date: Sep 2016
Location: Rome, Italy
Posts: 18
Help with generating video from cropped images

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,

Code:
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.

Code:
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!

Last edited by dark76; 21st November 2020 at 21:18. Reason: typo
dark76 is offline   Reply With Quote
Old 21st November 2020, 23:37   #2  |  Link
Frank62
Registered User
 
Join Date: Mar 2017
Location: Germany
Posts: 234
Add all tops with +
Add all middles.
Add all bottoms.
Use interleave(t,m,b).
Frank62 is offline   Reply With Quote
Old 22nd November 2020, 00:05   #3  |  Link
dark76
Registered User
 
Join Date: Sep 2016
Location: Rome, Italy
Posts: 18
Unfortunately this answer is too much cryptic for my avisynth level...
dark76 is offline   Reply With Quote
Old 22nd November 2020, 10:34   #4  |  Link
VoodooFX
Banana User
 
VoodooFX's Avatar
 
Join Date: Sep 2008
Posts: 985
Quote:
Originally Posted by dark76 View Post
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)
VoodooFX is offline   Reply With Quote
Old 22nd November 2020, 10:46   #5  |  Link
dark76
Registered User
 
Join Date: Sep 2016
Location: Rome, Italy
Posts: 18
Quote:
Originally Posted by VoodooFX View Post
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
dark76 is offline   Reply With Quote
Old 22nd November 2020, 12:08   #6  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
As long as the images are numbered sensibly you can use ImageSource to load a folder's worth of images as one clip, and then interleave the three clips.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 22nd November 2020, 12:17   #7  |  Link
dark76
Registered User
 
Join Date: Sep 2016
Location: Rome, Italy
Posts: 18
Maybe i found a solution. I didn't change the function and i modified like this

Code:
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 ), and this way i can append the result of the function


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

Code:
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()

Last edited by dark76; 22nd November 2020 at 15:35.
dark76 is offline   Reply With Quote
Old 22nd November 2020, 17:36   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Combination of previous posts suggestions.

First My Demo creating whotsit,
Code:
# 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


Script for your use
Code:
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.
Code:
C=0
For(i=0,8) {
    Z = Last.Trim(i,-1)
    C=(C.IsClip) ? StackHorizontal(C,Z) : Z
}
C
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 22nd November 2020 at 17:55.
StainlessS is offline   Reply With Quote
Old 22nd November 2020, 20:27   #9  |  Link
dark76
Registered User
 
Join Date: Sep 2016
Location: Rome, Italy
Posts: 18
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.
dark76 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:33.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.