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 19th August 2012, 01:54   #1  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
Avisynth w/ GScript and ImageReader - open a series of images

Hi

I am trying to find out how to use GScript with ImageReader to open a series of images from a folder with the ability to process each image in a loop

".bilinearresize(1920,1080).converttoYUY2()" is just an example process

I tried this:

GScript("""
for (i=0,12) {
myfile="00"+string(i)+".bmp"
j=ImageReader(file="d:\Images\" + myfile).bilinearresize(1920,1080).converttoYUY2()
a=blankclip(24,1920,1080)
b=overlay(a,j,0,0)
b
}
""")

but this only shows 0012.bmp

I know I'm missing something here but I can't figure it out

TIA
wiseant is offline   Reply With Quote
Old 19th August 2012, 02:51   #2  |  Link
gyth
Registered User
 
Join Date: Sep 2011
Posts: 86
Is it overlaying them all on the same clip, so only the top one, 12, shows up?
gyth is offline   Reply With Quote
Old 19th August 2012, 03:02   #3  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
gyth:

Yes - only the last one -> 0012.bmp shows up
wiseant is offline   Reply With Quote
Old 19th August 2012, 03:59   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Code:
GScript("""    
    picclip = 0                         # dummy for now

    for (i=0,12) {                      # first make a 13 frame clip (not a one frame clip 13 times)

        myfile="00"+string(i)+".bmp"

        j=ImageReader(file="d:\Images\" + myfile)   # 1 Frame clip
        # here make all j same if not all same colorspace/size etc
        picclip = (IsClip(picclip)) ? picclip ++ j : j  # Append to  clip so far        
    }    
    # picclip is now a 13 frame clip
    # resize/blankclip etc
""")
EDIT: Is untested. ImageReader could do the above on its own using start and end, without the loop (provided all same colorspace/size etc).

When you have a problem like that, you need to remove the stuff that is nothing to do with the
problem, ie the blankclip and resize etc. Minimize the prob, and it seems and is less formidable (perhaps even obvious).
.
__________________
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; 19th August 2012 at 04:39.
StainlessS is offline   Reply With Quote
Old 19th August 2012, 05:03   #5  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
StainlessS:

Thanks for the info

The bmp's are not all the same size

What I am ultimately trying to do [if possible] is to open the first bitmap - determine its width and height - and based on this info choose a resize with borders that will = 1920x1080

(I'll do a preliminary check to make sure the width will not get resized to > 1920 and to make sure that the height will not get resize to > 1080

1. determine the width and height of the bmp
if image.height > 1080 then resize to 1080 - then resize image.width to new width = (1080/image.height) * image.width
2. then 1920-newwidth=y
borders to add = y/2

for example a bitmap 800x1200
I resize the height to 1080 - then make the width 1080/1200 * width = 720
y = 1920 - width
addborders(y/2,0,y/2,0)

In this case I would have a bmp that gets resized to 720x1080 then .addborders(600,0,600,0) = 1920x1080 bmp
wiseant is offline   Reply With Quote
Old 19th August 2012, 05:16   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Suggest either a separate Imagereader thing for 0000 to establish output size, before the loop, OR,
a condition within the loop for the first frame, eg if(i=0){ etc}
It may sound simplistic, but as far as programming is concerned, it is best to break down the problem
into its most basic parts, to the point it becomes obvious what to do.

EDIT: If you can repeatedly break down problems into two pieces or more, then you can become a master
programmer by doing the obvious.
__________________
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; 19th August 2012 at 05:46.
StainlessS is offline   Reply With Quote
Old 19th August 2012, 14:06   #7  |  Link
Filker
Registered User
 
Join Date: Dec 2008
Posts: 38
Is there a way of reading the EXIF info in jpegs and rotate&resize based on that? Or at least read this info from a csv or xml flat file?
This freeware program can export EXIF infos to xml:
http://www.matirsoft.com/main/folder_viewer.htm
Filker is offline   Reply With Quote
Old 19th August 2012, 22:30   #8  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
StainlessS:

I came up with this script, if you feel like testing it.
No loops as yet, just wanted to make sure that any bmp would get resized properly
Obviously, just change "k=ImageReader(file="d:\Images\" + myfile)" to the drive and directory of your bmp's
This example will open 0022.bmp in d:\Images\

GScript("""
i=22
myfile="00"+string(i)+".bmp"
k=ImageReader(file="d:\Images\" + myfile)
iHeight=k.height
iWidth=k.width
if (iHeight>iWidth) {
iHeight1=1080
iWidth1=(1080*iWidth)/iHeight
x=1920-iWidth1
x1=x/2
if (iWidth1 % 2 >0) {
x1=(x/2) +1
}
k=k.bilinearresize(iWidth1,1080).addborders(x1,0,x/2,0)
}
if (iWidth>iHeight) {
iWidth1=1920
iHeight1=(1920*iHeight)/iWidth
y=1080-iHeight1
y1=y/2
if (iHeight1 % 2 >0) {
y1=(y/2) +1
}
k=k.bilinearresize(iWidth1,iHeight1).addborders(0,y1,0,y/2)
}
if (iHeight1 > 1080) {
iHeight1=1080
iWidth1=(1080*iWidth)/iHeight
x=1920-iWidth1
x1=x/2
if (iWidth1 % 2 >0) {
x1=(x/2) +1
}
k=k.bilinearresize(iWidth1,iHeight1).addborders(x1,0,x/2,0)
}
k

""")
subtitle(last,"original width=" + string(iWidth) +" " + "original height=" + string(iHeight),20,20)
subtitle(last,"new width=" + string(iWidth1) +" " + "new height=" + string(iHeight1),50,50)
wiseant is offline   Reply With Quote
Old 20th August 2012, 02:36   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Have a play with the below script, I have not touched (or even looked at really) the resizing logic.

Myself, I cant stand looking at code that is not properly indented, next time you post some code,
try going Advanced and select the code and click on the '#' to wrap the code in CODE tags.

Code:
# Edit below to suit

DIR      = "D:\Images\"
BASENAME = ""       # Base Filename
EXT      = ".BMP"   # Filename Extension
PICMIN   = 1        # Start
PICMAX   = 74       # End
MINDIGS  = 4        # Minimum Digits
SUBS     = True
FPS      = 1.0
#DEBUG   = True

Function MakePicName(String BaseName,String Ext,int Digs,int n) {GScript(""" S=String(n) While(StrLen(s)<Digs) {S="0"+S} Return BaseName+S+Ext """)}


GScript("""
    picclip = 0                         # dummy for now
    For(i=PICMIN,PICMAX) {
        myfile=MakePicName(BASENAME,EXT,MINDIGS,i)
    
#if(DEBUG){RT_Debug("TEST:",String(i)+")","ImageReader:-",myfile)}
    
        k=ImageReader(file=DIR + myfile,end=0).ConvertToRGB24()     # With Bmap, some come up as RGB24 bit some RGB32.

        iHeight=k.height    iWidth=k.width

#if(DEBUG){RT_Debug("TEST:",String(i)+")",myfile,"Width="+String(iWidth),"Height="+String(iHeight))}

        if (iHeight > iWidth) {
            iHeight1    = 1080
            iWidth1     = (1080 * iWidth) / iHeight
            x           = 1920 - iWidth1
            x1          = x/2
            if (iWidth1 % 2 > 0) {
                x1      = (x/2) + 1
            }
            k           = k.bilinearresize(iWidth1,1080).addborders(x1 , 0 , x / 2,0)
        } else if (iWidth > iHeight) {
            iWidth1     = 1920
            iHeight1    = (1920*iHeight)/iWidth
            y           = 1080-iHeight1
            y1          = y/2
            if (iHeight1 % 2 >0) {
                y1      = (y/2) + 1
            }
            k           = k.bilinearresize(iWidth1,iHeight1).addborders(0,y1,0,y/2)
        }
        
        if (iHeight1 > 1080) {
            iHeight1    = 1080
            iWidth1     = (1080*iWidth)/iHeight
            x           = 1920-iWidth1
            x1          = x/2
            if (iWidth1 % 2 >0) {
                x1      = (x/2) + 1
            }
            k           = k.bilinearresize(iWidth1,iHeight1).addborders(x1,0,x/2,0)
        }

        if(SUBS) {
            k=k.subtitle(String(i))
            k=k.subtitle("original width=" + string(iWidth) +" " + "original height=" + string(iHeight)+ \
                   " FAR="+String(Float(iWidth)/iHeight,"%.2f"),20,20)
            k=k.subtitle("new width=" + string(iWidth1) +" " + "new height=" + string(iHeight1)+ \
                   " FAR="+String(Float(iWidth1)/iHeight1,"%.2f"),20,50)         
            k=k.subtitle("out width=" + string(k.Width) +" " + "out height=" + string(k.Height)+ \
                   " FAR="+String(Float(k.Width)/k.Height,"%.2f"),20,70)         
        }
        picclip = (IsClip(picclip)) ? picclip ++ k : k  # Append to  clip so far
    }
""")
PicClip
AssumeFPS(FPS)
EDITED:
__________________
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; 20th August 2012 at 04:40.
StainlessS is offline   Reply With Quote
Old 20th August 2012, 03:03   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Oops, You can comment out the RT_Debug() line (although it is handy to debug compile time code [in RT_Stats plug]).
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 20th August 2012, 03:18   #11  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
StainlessS:

[didn't see your last post re comment out - but I did this already]

I copied your script and pasted into AvsP

Doesn't work for me

1. Script error: there is no function named "RT_Debug"
GScript line 6
GScript line 48
New File line 61

comment out line 18 RT_Debug("TEST:",myfile)

2. error: Could not open file D:\Images\0001.jpg
so, change EXT= ".JPG" to EXT= ".bmp"

3. error: Could not open file D:\Images\0001.bmp

my images range from 000.bmp, 001.bmp, .. 0073.bmp

4. then I batch renamed them to 0001.bmp, 0002.bmp ..
error: Could not open file D:\Images\0010.bmp

Last edited by wiseant; 20th August 2012 at 03:20. Reason: update
wiseant is offline   Reply With Quote
Old 20th August 2012, 04:55   #12  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Yep, had already posted on the RT_Debug thing, the other starting defines were intended to be edited by you.

If you have both 3 and 4 digit names (as you described "my images range from 000.bmp, 001.bmp, .. 0073.bmp")
that would fail as it would look for 073.bmp not 0073.bmp (would fail in standard use ImageReader too even if all same size etc).

I converted/renamed my test jpg's as eg 0001.bmp to 0074.bmp, works just fine since I added a ConvertToRGB24,
some of my BMP's were coming up RGB24 and some RGB32.

Please try again with current script, has been edited.

Check that your bitmap is named as in error message (also check that you can load it in some viewer).
The error message was telling you that it is looking for a properly named file, ie 4 digits
(perhaps an imageReader problem, try a standard ImageReader call on that single file).

The RT_Debug thing is really rather handy to have if you are playing with compile time scripts, give it a whirl,
its in the RT_Stats thread last posted about a week ago.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 20th August 2012, 06:03   #13  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
StainlessS:

Yes, the new script works

I am using IranView in Batch Rename mode, so I can just use Name Pattern: 00##

These images of mine were jpg's that I edited in Photoshop and saved as 24-bit bmp's - so all of them show RGB24

I look into RT_Debug tomorrow . . .

Thanks StainlessS
wiseant is offline   Reply With Quote
Old 20th August 2012, 13:11   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Good.


Filker has a requirement for the EXIF reader thing, I was thinking of adding a sort of RT_ReadTxtFileIntoString() type plug
to read any file contents into a string for compile/runtime scripts. Anyways, I just remembered something written by
Gavino (I think) about Import being able to import anything from a file.
In a script function, After checking file exists (if not return ""), then eg Return String(Import(FileName))

You could then parse eg the EXIF stuff in GScript.

@Filker Can you post an example for the EXIF csv format (XML feels a bit too complicated to do easily in small code).

EDIT: Above is rubbish.
__________________
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; 20th August 2012 at 16:59.
StainlessS is offline   Reply With Quote
Old 20th August 2012, 17:15   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
Oh darn, previous post is rubbish, cannot use import to import as a string, I guess I misread/mis-remembered.
You can return a string from an imported script file but not the file itself, I guess I'll do the RT_ReadTxtFileIntoString() type plug.

Have just modded the RT_Stats RT_Debug plug, so that you could send eg a text file held in a string, to OutputDebugString,
it behaves as previously but parses linefeed carriage return to split the text into individual lines to be sent
to OutputDebugString. All other control codes are converted to space.
Was wanting to test it out by sending a good sized text file via the import thing, very disappointed that it dont work, so I'll
be getting straight into the RT_ReadTxtFileIntoString() type plug so I can test RT_Debug, should not take too long, probably
post some time within next 24.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 20th August 2012, 18:00   #16  |  Link
Filker
Registered User
 
Join Date: Dec 2008
Posts: 38
Thank you for looking into this, StainlessS.

csv with exif data in attachment.

For what I want to do the relevant field is Orientation.

I found this source code that can read exif info from the jpegs:
http://sylvana.net/jpegcrop/jpegexiforient.c

http://sylvana.net/jpegcrop/exif_orientation.html
Attached Files
File Type: 7z exifs.7z (790 Bytes, 18 views)
Filker is offline   Reply With Quote
Old 21st August 2012, 02:26   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
@Filker, looking forward to your attachment being approved.

Have nearly gotten that text reader plug working, see here:-
http://forum.doom9.org/showthread.php?t=165710

Once its working ok, it should be a doddle to parse your csv files.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 21st August 2012, 07:53   #18  |  Link
wiseant
Registered User
 
Join Date: May 2007
Posts: 143
yo StainlessS:

I did some tests and made a couple of changes to my script - just added two variables -> canvaswidth and canvasheight
so replacing values in the script of 1920 and 1080 with canvaswidth and canvasheight respectively - allows the user to choose any final canvas size and the images will maintain their AR

It doesn't work right now if the canvasheight is greater than the canvaswidth - it does, but only so far - it did 800x900 but after that got incorrect image size spice error
so I'll need to create a portrait mode

this way the script can easily make slideshows in any resolution and fps - resize to 720x480 for dvd - or do a bluray compliant slide show - or youtube

also, if ImageReader is changed to AviSource/DirectShowSource/Mpeg2Source/... the script should be able to read a bunch of videos and resize them to a common resolution [except mixing interlaced/progressive material]

I have a couple ideas of importing video filenames from a folder without having to rename them - is this where your text reader plugin would work?
wiseant is offline   Reply With Quote
Old 21st August 2012, 15:24   #19  |  Link
Filker
Registered User
 
Join Date: Dec 2008
Posts: 38
Quote:
Originally Posted by StainlessS View Post
@Filker, looking forward to your attachment being approved.

Have nearly gotten that text reader plug working, see here:-
http://forum.doom9.org/showthread.php?t=165710

Once its working ok, it should be a doddle to parse your csv files.
That's great, it should be useful for another million things.

Here's the csv content:

Filename,IMG_9611.JPG
Make,Canon
Model,Canon EOS 500D
Orientation,Left bottom
XResolution,72
YResolution,72
ResolutionUnit,Inch
DateTime,2012:03:16 16:25:24
Artist,
YCbCrPositioning,Co-Sited
Copyright,
ExifOffset,360
ExposureTime,1/60 seconds
FNumber,4.50
ExposureProgram,Normal program
ISOSpeedRatings,400
ExifVersion,0221
DateTimeOriginal,2012:03:16 16:25:24
DateTimeDigitized,2012:03:16 16:25:24
ComponentsConfiguration,YCbCr
ShutterSpeedValue,1/64 seconds
ApertureValue,F 4.56
ExposureBiasValue,0
MeteringMode,Multi-segment
Flash,Flash fired, Compulsory flash mode
FocalLength,32 mm
UserComment,
SubsecTime,52
SubsecTimeOriginal,52
SubsecTimeDigitized,52
FlashPixVersion,0100
ColorSpace,sRGB
ExifImageWidth,4752
ExifImageHeight,3168
InteroperabilityOffset,8380
FocalPlaneXResolution,5315.44
FocalPlaneYResolution,5342.33
FocalPlaneResolutionUnit,Inch
CustomRendered,Normal process
ExposureMode,Auto
White Balance,Auto
SceneCaptureType,Standard


Filename,IMG_9612.JPG
Make,Canon
Model,Canon EOS 500D
Orientation,Top left
XResolution,72
YResolution,72
ResolutionUnit,Inch
DateTime,2012:03:16 16:25:31
Artist,
YCbCrPositioning,Co-Sited
Copyright,
ExifOffset,360
ExposureTime,1/60 seconds
FNumber,5.60
ExposureProgram,Normal program
ISOSpeedRatings,400
ExifVersion,0221
DateTimeOriginal,2012:03:16 16:25:31
DateTimeDigitized,2012:03:16 16:25:31
ComponentsConfiguration,YCbCr
ShutterSpeedValue,1/64 seconds
ApertureValue,F 5.66
ExposureBiasValue,0
MeteringMode,Multi-segment
Flash,Flash fired, Compulsory flash mode
FocalLength,55 mm
UserComment,
SubsecTime,17
SubsecTimeOriginal,17
SubsecTimeDigitized,17
FlashPixVersion,0100
ColorSpace,sRGB
ExifImageWidth,4752
ExifImageHeight,3168
InteroperabilityOffset,8380
FocalPlaneXResolution,5315.44
FocalPlaneYResolution,5342.33
FocalPlaneResolutionUnit,Inch
CustomRendered,Normal process
ExposureMode,Auto
White Balance,Auto
SceneCaptureType,Standard
Filker is offline   Reply With Quote
Old 21st August 2012, 21:48   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,797
@Filker, if you wanna check out RT_Stats 1.02 try here (or medifire account in sig:

http://forum.doom9.org/showthread.php?t=165479
__________________
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; 23rd August 2012 at 01:40.
StainlessS 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 05:49.


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