Log in

View Full Version : BMP/PNG/TGA Importing


Asrial
16th October 2003, 07:57
Is there any way to import an external picture into AVISYNTH? I have some frames that I think the only way they can be fixed is manual editing of the frame itself.

sh0dan
16th October 2003, 08:48
ImageReader (http://www.avisynth.org/index.php?page=Image)

Asrial
16th October 2003, 18:30
Thanks sh0dan :)

Asrial
18th October 2003, 06:05
I just can't get this to work (and I've spent a good long time trying).

I'm trying to get 1 TIF file put into the middle of a clip but it's not happening.

Any ideas guys?

I've been playing around with ImageReader and the stuff stickboy posted with regards to trim and everything else.

ApplyRange(clip,10703,10703,"ImageReader","H:\Complicated\Futurama\1-4\000000.tif",0,0,24,false)

That is what I want to do but the -> "pathname" <- is what's messing it up I think. If ImageReader didn't require the pathname to be in " then it'd be all fine and dandy I'd wager.

Richard Berg
18th October 2003, 06:33
I've never tried ImageReader with ApplyRange, but you will probably need to use Chr().

Asrial
18th October 2003, 08:08
Originally posted by Richard Berg

I've never tried ImageReader with ApplyRange, but you will probably need to use Chr(). I can't find any information on this CHR() function. Can you point me in the right direction on learning how to use it and what it does?

stickboy
18th October 2003, 10:28
Chr() is one of the internal functions (not a filter). It's documented under "Getting Started" in the documentation included with AviSynth.

Even then, I'm not confident that ImageReader behaves well when used with ApplyRange.

Using ImageReader separately and then splicing in that frame explicitly should be better.

(My JDL_ImageSource and JDL_ReplaceRange functions might be useful.)

Asrial
18th October 2003, 16:45
Import("applyrange.avs")

JDL_ApplyFrame(10703,"ImageReader("H:\Complicated\Futurama\1-4\000000.tif",0,0,24,false)")

JDL_ImageSource("H:\Complicated\Futurama\1-4\000000.tif",0,0,24)

function min(val a, val b) { return (a < b) ? a : b }
function max(val a, val b) { return (a > b) ? a : b }
function clamp(val n, val a, val b) { return max(a, min(n, b)) }

function Trim2(clip c, int start, int "end", int "length")
{
assert(!(defined(end) && defined(length)),
\ "Trim2: end and length parameters cannot be used together")
assert(!defined(length) || length >= 0,
\ "Trim2: invalid length: " + String(length))

end = defined(end)
\ ? ((end < 0) ? (c.FrameCount() + end) : end)
\ : max(start, c.FrameCount())
end = defined(length) ? (start + length) : end

assert(start >= 0, "Trim2: start frame out of bounds: " + String(start))
assert(end >= start, "Trim2: end frame out of bounds: " + String(end))

start = min(start, c.FrameCount())
end = min(end, c.FrameCount())

# we can't use Trim(start, end - 1) in case end == 1
return (start == end)
\ ? c.NullClip()
\ : c.Trim(start, -(end - start))
}


function JDL_ApplyRange(clip c, int start, int end, string thunk)
{
assert(start >= 0 && start < c.FrameCount(), "JDL_ApplyRange: start frame out of bounds")
assert(end >= start && end < c.FrameCount(), "JDL_ApplyRange: invalid end frame")

c
filtered = Eval(thunk)

seg1 = c.Trim2(0, start)
seg2 = filtered.Trim2(start, end + 1)
seg3 = c.Trim2(end + 1)

return seg1 + seg2 + seg3
}

function JDL_ApplyFrame(clip c, int frame, string thunk)
{
return JDL_ApplyRange(c, frame, frame, thunk)
}

function Trim3(clip c, int start, int "end", int "length")
{
assert(!(defined(end) && defined(length)),
\ "Trim3: end and length parameters cannot be used together")
assert(!defined(length) || length > 0,
\ "Trim3: invalid length: " + String(length))

end = defined(length) ? (start + length) : default(end, c.FrameCount())
end = (end < 0) ? (c.FrameCount() + end) : end

assert(start >= 0 && start < c.FrameCount(),
\ "Trim3: start frame out of bounds: " + String(start))
assert(end > start && end <= c.FrameCount(),
\ "Trim3: end frame out of bounds:" + String(end))

return c.Trim2(start, end)
}

function JDL_ImageSource(string filenameTemplate, int start, int end, float "fps")
{
assert(start >= 0 && start <= end, "ImageSource: invalid start frame")
assert(end >= 0, "ImageSource: invalid end frame")
fps = default(fps, 29.97)

ImageReader(filenameTemplate, start, end, 1, true)
Trim3(start, length=(end - start + 1))
AssumeFPS(fps)
}

This is what I've tried with your stuff stickboy and it's still not working. My knowledge of the functions is very limited so be gentle when explaining it :P

stickboy
18th October 2003, 21:38
Don't use ApplyRange (or JDL_ApplyRange, JDL_ApplyFrame, etc.) with ImageReader or JDL_ImageSource. The function you pass to ApplyRange needs to take a clip as its first argument. ApplyRange and its ilk should be used with filters that modify existing clips, not filters that generate clips (such as AVISource, ImageReader, etc.).

Load the image as a separate clip and splice it in.

Try this:image = JDL_ImageSource("H:\Complicated\Futurama\1-4\000000.tif",0,0,24)
JDL_ReplaceRange(last, image, 10703, 10703)

Asrial
21st October 2003, 05:50
I'm getting closer but now I'm getting a damn '1290' error with the DevIL Library (even when using ImageWriter).

:angry:

ConvertToRGB24()

ImageWriter("H:\Complicated\Futurama\1-4\",13378,13378,"tif")

#import("applyrange.avs")

#image = JDL_ImageSource("H:\Complicated\Futurama\1-4\test.tif",0,0,29.97)

#JDL_ReplaceRange(last, image, 13378, 13378)

Frame 13378 is the frame I want to edit and test.tif is the version I saved with MSPAINT.

WarpEnterprises
21st October 2003, 22:14
* try another format (BMP MUST work)
* try alternatively ImageSequence as source, maybe the image format is strange.

(OT?) Question to all:
What is the real reason for using Apply or JDL_Apply and not plain Trim's on the final video? Are there so many events where to use a GENERIC range-apply function?
When is it NOT appropriate to use:

AviSource
FilterChain
Trim() ++ Trim() ++ ...

If you use Apply (regardless which flavour) you create

AviSource
Trim.FilterChain ++ Trim.FilterChain ++ ...

which will make many instances of the filters and this makes only sense if you have different args for each filterchain.

Any comments?

Asrial
21st October 2003, 22:58
I don't know what happened but it's working now. The problem was probably that I was trying to play with it at 4am when I was wanting to be in bed at 2am :p

[EDIT: figured out what was happening -- if you get an error while doing what I was doing (IE: video formats do not match, frame sizes do not match, etc) you have to close vdubmod and go back into it or else you'll get the DevIL errors]

I changed it to BMP and I didn't get the DevIL error so I changed it back to TIF and I still didn't get the DevIL error. It's all working bueno now!

One last question...

Anyone know of an EBMP editor? I'd like to avoid the YV12->RGB24->YV12 color changing.

Asrial
21st October 2003, 23:04
To summarize, the problem was that I had 1 frame that had artifacts that could ONLY be fixed through manually editing the frame (the artifact was on the source frame and was a large abnormal coloration of an anime character's skin tone).

What I needed to be able to do was export the frame, fix it, and import it back in. Steps 1 and 2 were easy, step 3 was not.

Here's how I got it all to work (biiiiig thank you to everyone!):

ConvertToRGB24()

import("applyrange.avs")

image = JDL_ImageSource("H:\Complicated\Futurama\1-4\013378.tif",0,0,29.97)

JDL_ReplaceRange(last,image,13378,13378)

..and these are the functions I used (thanks stickboy!):

function min(val a, val b) { return (a < b) ? a : b }
function max(val a, val b) { return (a > b) ? a : b }
function clamp(val n, val a, val b) { return max(a, min(n, b)) }

function Trim2(clip c, int start, int "end", int "length")
{
assert(!(defined(end) && defined(length)),
\ "Trim2: end and length parameters cannot be used together")
assert(!defined(length) || length >= 0,
\ "Trim2: invalid length: " + String(length))

end = defined(end)
\ ? ((end < 0) ? (c.FrameCount() + end) : end)
\ : max(start, c.FrameCount())
end = defined(length) ? (start + length) : end

assert(start >= 0, "Trim2: start frame out of bounds: " + String(start))
assert(end >= start, "Trim2: end frame out of bounds: " + String(end))

start = min(start, c.FrameCount())
end = min(end, c.FrameCount())

# we can't use Trim(start, end - 1) in case end == 1
return (start == end)
\ ? c.NullClip()
\ : c.Trim(start, -(end - start))
}

function Trim3(clip c, int start, int "end", int "length")
{
assert(!(defined(end) && defined(length)),
\ "Trim3: end and length parameters cannot be used together")
assert(!defined(length) || length > 0,
\ "Trim3: invalid length: " + String(length))

end = defined(length) ? (start + length) : default(end, c.FrameCount())
end = (end < 0) ? (c.FrameCount() + end) : end

assert(start >= 0 && start < c.FrameCount(),
\ "Trim3: start frame out of bounds: " + String(start))
assert(end > start && end <= c.FrameCount(),
\ "Trim3: end frame out of bounds:" + String(end))

return c.Trim2(start, end)
}

function JDL_ImageSource(string filenameTemplate, int start, int end, float "fps")
{
assert(start >= 0 && start <= end, "ImageSource: invalid start frame")
assert(end >= 0, "ImageSource: invalid end frame")
fps = default(fps, 29.97)

ImageReader(filenameTemplate, start, end, 1, true)
Trim3(start, length=(end - start + 1))
AssumeFPS(fps)
}

function JDL_ReplaceRange(clip baseClip, clip newClip, int start, int "end")
{
assert(start >= 0 && start < baseClip.FrameCount(), "JDL_ReplaceRange: start frame out of bounds")
end = default(end, start + newClip.FrameCount() - 1)
length = end - start + 1
assert(end >= start && end < baseClip.FrameCount() && length <= newClip.FrameCount(),
\ "JDL_ReplaceRange: end frame out of bounds")

c = baseClip.Trim2(0, start) ++ newClip.Trim3(0, length=length) ++ baseClip.Trim2(end + 1)

assert(c.FrameCount() == baseClip.FrameCount(), "JDL_ReplaceRange: length mismatch")
return c
}