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 26th March 2006, 22:01   #1  |  Link
t1dUs
Registered User
 
Join Date: Jan 2006
Location: Spain
Posts: 15
replace frame with picture file

Since I cannot access avisynt.org then I'll ask it here: what is the function to replace a frame of a clip for a picture file? The thing is that I took one of the frames in my clip and repaired it with paintshop pro. Also, are all the picture formats equally good?

If possible do it with this example in order to see the syntax of the function:
the picture -> c:\picture.bmp
frame to replace -> 300

TIA
t1dUs is offline   Reply With Quote
Old 26th March 2006, 22:04   #2  |  Link
Tripx
Registered User
 
Join Date: Jul 2005
Posts: 13
ReplaceFrame
Tripx is offline   Reply With Quote
Old 26th March 2006, 22:28   #3  |  Link
t1dUs
Registered User
 
Join Date: Jan 2006
Location: Spain
Posts: 15
thnx Tripx, but isn't there a built in function inside avysinth already? I'd prefer to know that one instead of having to install new dlls in windows' system folder.

PS: I'm gettin external exception E06D7363, so I need somethin else

Last edited by t1dUs; 26th March 2006 at 22:39.
t1dUs is offline   Reply With Quote
Old 27th March 2006, 01:34   #4  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
try this: i haven't used it for a while, but i use this for replacing splats with photoshopped fixes (tedious work...)

Code:
function imagesplice (clip c, string "filename", int "frameno")
{
frame=imagesource(filename)
frame=frame.selectevery(frame.framecount,0).assumefps(c.framerate).converttoyv12()
c.trim(0,frameno-1)++frame++c.trim(frameno+1,0)
}
usage:

imagesplice("blurt.png",1200)

would replace frame 1200 with the picture "blurt.png". works for yv12 for now, but it's a trivial matter to modify it for yuy2 or rgb.

just stick that code block in your script, or whack it in a new text file called imagesplice.avsi in your plugins directory.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 27th March 2006, 01:35   #5  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
System folder? You should be putting them in avisynth's plugin folder. You can also add jdl-util.avsi and jdl-range.avsi to the folder instead, and use jdl_replacerange with the same start & end. Something like:

Code:
avisource("stuff.avi")
JDL_ReplaceRange(imagesource("picture.bmp").converttoyv12,300,300)
[edit] *shakes fist at Mug Funky*
foxyshadis is offline   Reply With Quote
Old 27th March 2006, 03:13   #6  |  Link
t1dUs
Registered User
 
Join Date: Jan 2006
Location: Spain
Posts: 15
thnx a lot to Mug Funky and foxyshadis, both ways work like a charm , but I think I'll stick to Mug Funky's since it requires less typing :P
t1dUs is offline   Reply With Quote
Old 9th February 2010, 00:40   #7  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
ya, I know the thread is old, but the problem is related to the function posted by Mug Funky.

Im using it in my script together a call function when required loading an avs with all the imagesplice frames list.

Everything works correctly until I put a trim function in the script, which corrupts the framenumber. I would like to know how to make the frame order based on the untrimed video so it keeps consistency.

Code:
DirectShowsource("mysource.mp4",audio = false)

trim(1688,1787)

Import("LoadRef.avs")

function imagesplice (clip c, string "filename", int "frameno")
{
frame=imagesource(filename)
frame=frame.selectevery(frame.framecount,0).assumefps(c.framerate).converttoyv12()
c.trim(0,frameno-1)++frame++c.trim(frameno+1,0)
}
Code:
LoadRef.avs

imagesplice("1162.jpg",1162)
imagesplice("1347.jpg",1347)
imagesplice("1485.jpg",1485)
imagesplice("1508.jpg",1508)
(...)
Dogway is offline   Reply With Quote
Old 9th February 2010, 00:50   #8  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
Do the trim AFTER the imagesplice's.
Guest is offline   Reply With Quote
Old 9th February 2010, 01:08   #9  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
I wished it was that simple. I have tried to put it in every place I could imagine. I dont understand the declaration in the function, but maybe indicating there to read from the original source, and not trimmed version.
Dogway is offline   Reply With Quote
Old 9th February 2010, 10:33   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Putting the Trim at the end of the script does make the splices work on the original untrimmed source.

But of course the splices to frames 1162, 1347, 1485 and 1508 will be trimmed out of the final result. Is that what you want?
Gavino is offline   Reply With Quote
Old 9th February 2010, 18:50   #11  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,361
ups, sorry. It seemed to be my fault. I took the framenumbers based on ffmpegsource, and after when I changed the call function to DirectShowSource, the framenumbers changed and I didnt realize.

I dont understand why it happens, which of them do you suggest me to use? Sorry for the mistake.

Hola Gavino, me alegro de ver mas espaņoles por aqui.
Dogway is offline   Reply With Quote
Old 9th February 2010, 19:49   #12  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Hola, Dogway.
Quote:
Originally Posted by Dogway View Post
I took the framenumbers based on ffmpegsource, and after when I changed the call function to DirectShowSource, the framenumbers changed and I didnt realize.
I dont understand why it happens, which of them do you suggest me to use?
DirectShowSource does not always provide frame-accurate seeking, so ffmpegsource is probably better for this source.
Gavino is offline   Reply With Quote
Old 8th November 2014, 04:59   #13  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
Sorry to revive this topic.
A while ago I met the helpful script Mug Funky's ImageSplice, and unfortunately noticed two problems:

- You can't replace the first frame (frame 0)
- Incompatibilities with the audio.

This led me, based on ImageSplice, create gradually a single script to that meets the same idea but in a more functional way...

Last edited by GMJCZP; 8th November 2014 at 05:26.
GMJCZP is offline   Reply With Quote
Old 8th November 2014, 05:06   #14  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
RescueFrame

RescueFrame

The plan in RescueFrame is the following:

- Add to the original video as a first frame the modified frame, that is, as a sort of header record.
- Then, know the frame or frames to replace to use internally the Freezeframe function, by taking the modified frame or "header record".
- Finally, the first frame is removed, all while preserving the original audio, if be present.

Here the script:

Code:
###
#
# RescueFrame is a function dedicated for replace undesirable frames
# with frames captured and/or edited previously. For AVS+ only.
#
# Written by GMJCZP
#
# - Initial release (07/11/2014)
#
# - Version 2.0 (24/05/2021)
# Now it works in HBD! (AVS+ only!).
#
# - Version 2.1 (26/05/2021)
# Better handling of Overlay.
#
# - Version 3.0 (06/06/2021)
# Optimization of the entire function, including the elimination of
# Overlay, resulting in a increase in speed; fix in audio handling.
#
###

###
# USAGE / SUGGESTIONS
###
#
# In case of restoration, to capture the frame to edit, making sure that it is
# identical to the original.
# A sure method can be to place this sentence before to call RescueFrame:
# ConverttoRGB24().ImageWriter("", frame, frame, "bmp").ConverttoYV12()
# and then to go to frame. It will be generated a bmp file in the same folder where
# is the Avisynth script. In that instant one already can it erases the sentence of up.
#
# Another sure method is using VirtulDub for Copy frames.
#
# NEVER to use VirtualDubMod for copy/snapshot frames!
#
# Once made the capture can use your favorite program of edition of images
# for its edition and then call this function.
#
###

###
# PARAMETERS
###
#
# "FileName"
# Name of the file of the edited frame. Example: "MyRestoredFrame000.bmp"
#
# "FrameNumber"
# Number of frame to replace.
#
# "NumRep"
# Number of times that the frame will repeat, replacing the successive frames.
#
####

function RescueFrame (clip video, string FileName, int FrameNumber, int "NumRep")
{
   NumRep = Default(NumRep, 0)

	edit_frame = ImageSource(FileName,use_DevIL=true,end=0,fps=framerate(video)).converttoYV12().convertbits(video.BitsPerComponent())
	clp = edit_frame + video.KillAudio()
	clp = clp.Freezeframe(FrameNumber+1,FrameNumber+1+NumRep,0).Deleteframe(0)
	clp = (HasAudio(video) == false) ? clp : AudioDubEx(clp,video)
	return clp
}
EDIT: For some reason I do not know, if StackHorizontal (or StackVertical) is used BEFORE the RescueFrame, the frame to the right (or below) is black, so the call order must be reversed.

Last edited by GMJCZP; 7th June 2021 at 05:05. Reason: Release version 3.0
GMJCZP is offline   Reply With Quote
Old 18th May 2015, 00:30   #15  |  Link
Mounir
Registered User
 
Join Date: Nov 2006
Posts: 773
I like this RescueFrame script above but i'd need to work with avisource instead of imagesource (that i've figured it out you only replace source = avisource(FileName) but then come my desire to use a Trim for this avisource to select the wanted frame, here i'm hiting a rock; if you can guide me...
Mounir is offline   Reply With Quote
Old 18th May 2015, 00:52   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Just as in above script, to trim a single frame use
Code:
     vFrame = Trim(vClip,FrameNo,-1)
-2 trims 2 frames etc.

Also note, In RescueFrame, FileName and FrameNumber are given as Optional (in quotes) but they do not have defaults and so will
error if called without them.
Either provide defaults or remove quotes.

Also note, FrameSel/Rep can extract any number of frames and then replace them again later.

EDIT: Here:- http://forum.doom9.org/showthread.ph...light=framesel
__________________
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; 18th May 2015 at 00:59.
StainlessS is offline   Reply With Quote
Old 24th May 2021, 04:22   #17  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
See post # 14

Currently RescueFrame only operates in 8 bits, the culprit is in the Overlay call, is there any way to bring the script to HBD?

Fortunately it is not a serious matter but academically speaking it would be interesting to resolve it.
__________________
By law and justice!

GMJCZP's Arsenal

Last edited by GMJCZP; 24th May 2021 at 04:38.
GMJCZP is offline   Reply With Quote
Old 24th May 2021, 13:56   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
It would be a better function if supplied as arg, frames clip instead of a filename.
And the clip being required to be in a colorspace compatible with the source clip (and Overlay or Layer).
In AVS+ Overlay/Layer, (I think) colorspace has to be same type, ie Interleaved/Planar, and same bit depth.

This is some code from Work In Progress script to match colorspace exactly. [also some required support functions not posted]

Code:
    Function ExL_MatchCS(clip c,clip matchto,String "matrix",Bool "fulls",bool "fulld") { # Match c clip to matchto clip colorspace
        RT_DebugF("ExL_MatchCS: IN c=%s MatchTo=%s",c.X_PixelType,matchto.X_PixelType)
        if(c.X_PixelType != matchto.X_PixelType) {
            # currently (avs+ 3.5) fulld must equal fulls
            mat=Default(matrix,"PC.601") # Matrix default no change ie full range matrix : fulls=auto ie undefined, true for RGB else false.
            matchto.IsYV12?c.ConvertToYV12(matrix=Mat):matchto.IsYUY2?c.ConvertToYUY2(matrix=Mat):matchto.IsRGB24?c.ConvertToRGB24(matrix=Mat)
                \ : matchto.IsRGB32?c.ConvertToRGB32(matrix=Mat):matchto.IsYV16?c.ConvertToYV16(matrix=Mat):matchto.IsYV24?c.ConvertToYV24(matrix=Mat)
                \ : matchto.IsY8?c.ConvertToY8(matrix=Mat):matchto.IsRGB48?c.ConvertToRGB48(matrix=Mat):matchto.IsRGB64?c.ConvertToRGB64(matrix=Mat):Undefined
            if(!Defined) { # Is Avs+ AND MatchTo == Planar, Can use AVS+ functions directly here.
                c
                if(matchto.IsRGB) {
                    matchto.HasAlpha == HasAlpha ? NOP : matchto.HasAlpha ? ConvertToPlanarRGBA(matrix=Mat) : ConvertToPlanarRGB(matrix=Mat)
                } else if(matchto.IsY) {
                    RT_DebugF("Match to IsY")
                    ConvertToY(matrix=Mat)
                } else {
                    RT_DebugF("Match to IsYUVA=%s or ISYUV=%s",matchto.IsYUVA,matchto.IsYUV)
                    if(matchto.Is444)        { ConvertToYUV444(matrix=Mat) }
                    else if(matchto.Is422)   { ConvertToYUV422(matrix=Mat) }
                    else if(matchto.Is420)   { ConvertToYUV420(matrix=Mat) }
                }
                mbpc=matchto.BitsPerComponent  bpc=BitsPerComponent
                if(mbpc!=bpc) {
                    RT_debugF("Converting Bits from %d to %d",X_Bpc,matchto.X_Bpc)
                    ConvertBits(mbpc) #,fulls=fulls,fulld=fulld)
                }
                (matchto.HasAlpha==HasAlpha) ? NOP : HasAlpha ? RemoveAlphaPlane : AddAlphaPlane
            }
        } else { c }
        RT_DebugF("ExL_MatchCS: OUT c=%s matchto=%s",X_PixelType,matchto.X_PixelType)
        return last
    }
It can be a real pain.

Alternative to the orginal mug_funky style function

Code:
# NOT HBD aware for FrameSel/FrameRep SHOW=TRUE.
# When Not Showing Text(ie not changing frame content), does not require knowledge of HBD, ie works OK.
Colorbars.ShowFrameNumber.ConvertToYV24.ConvertBits(10).KillAudio
ORG=Last                           # Original, with/without audio
F=FlipVertical                     # Flipped, or maybe from ImageSource
R=F.FrameSel(10,20,30)             # 3 flipped frames, 10, 20, 30, into R clip frames 0,1,2
                                   # Equivalent to 3 frames read from file and converted to same colorspace as source.

Framerep(Last,R, 10,20,30)         # Replace 3 frames, 10, 20, 30 (From R clip frames 0,1,2)

#Framerep(Last,R,SCmd="10;20;30")  # Replace 3 frames 10,20,30, SCMD using command in string. CMD using command File.
AudioDubEx(Last,ORG)               # Restore Audio from source, if present
Info

#convertToRGB32                     # To view. Not needed for some players eg PotPlayer

return Last
EDIT: Above added AudioDubEx

EDIT: FrameSel/FrameRep, does not support Audio, AudioDubEx with original audio from source clip.



EDIT: FrameSel/Framerep supports thousands of frame replacements [commands in text file], timed when plugin first written
to be about 40,000 frames indexes read from text file in about 2 seconds, before frameserving starts.
During frameserving, overhead not much different to a trim and splce of a single frame.
__________________
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; 24th May 2021 at 16:11.
StainlessS is offline   Reply With Quote
Old 24th May 2021, 16:03   #19  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
Quote:
Originally Posted by StainlessS View Post
It would be a better function if supplied as arg, frames clip instead of a filename.
And the clip being required to be in a colorspace compatible with the source clip (and Overlay or Layer).
In AVS+ Overlay/Layer, (I think) colorspace has to be same type, ie Interleaved/Planar, and same bit depth.

This is some code from Work In Progress script to match colorspace exactly. [also some required support functions not posted]

Code:
    Function ExL_MatchCS(clip c,clip matchto,String "matrix",Bool "fulls",bool "fulld") { # Match c clip to matchto clip colorspace
        RT_DebugF("ExL_MatchCS: IN c=%s MatchTo=%s",c.X_PixelType,matchto.X_PixelType)
        if(c.X_PixelType != matchto.X_PixelType) {
            # currently (avs+ 3.5) fulld must equal fulls
            mat=Default(matrix,"PC.601") # Matrix default no change ie full range matrix : fulls=auto ie undefined, true for RGB else false.
            matchto.IsYV12?c.ConvertToYV12(matrix=Mat):matchto.IsYUY2?c.ConvertToYUY2(matrix=Mat):matchto.IsRGB24?c.ConvertToRGB24(matrix=Mat)
                \ : matchto.IsRGB32?c.ConvertToRGB32(matrix=Mat):matchto.IsYV16?c.ConvertToYV16(matrix=Mat):matchto.IsYV24?c.ConvertToYV24(matrix=Mat)
                \ : matchto.IsY8?c.ConvertToY8(matrix=Mat):matchto.IsRGB48?c.ConvertToRGB48(matrix=Mat):matchto.IsRGB64?c.ConvertToRGB64(matrix=Mat):Undefined
            if(!Defined) { # Is Avs+ AND MatchTo == Planar, Can use AVS+ functions directly here.
                c
                if(matchto.IsRGB) {
                    matchto.HasAlpha == HasAlpha ? NOP : matchto.HasAlpha ? ConvertToPlanarRGBA(matrix=Mat) : ConvertToPlanarRGB(matrix=Mat)
                } else if(matchto.IsY) {
                    RT_DebugF("Match to IsY")
                    ConvertToY(matrix=Mat)
                } else {
                    RT_DebugF("Match to IsYUVA=%s or ISYUV=%s",matchto.IsYUVA,matchto.IsYUV)
                    if(matchto.Is444)        { ConvertToYUV444(matrix=Mat) }
                    else if(matchto.Is422)   { ConvertToYUV422(matrix=Mat) }
                    else if(matchto.Is420)   { ConvertToYUV420(matrix=Mat) }
                }
                mbpc=matchto.BitsPerComponent  bpc=BitsPerComponent
                if(mbpc!=bpc) {
                    RT_debugF("Converting Bits from %d to %d",X_Bpc,matchto.X_Bpc)
                    ConvertBits(mbpc) #,fulls=fulls,fulld=fulld)
                }
                (matchto.HasAlpha==HasAlpha) ? NOP : HasAlpha ? RemoveAlphaPlane : AddAlphaPlane
            }
        } else { c }
        RT_DebugF("ExL_MatchCS: OUT c=%s matchto=%s",X_PixelType,matchto.X_PixelType)
        return last
    }
It can be a real pain.

Alternative to the orginal mug_funky style function

Code:
# NOT HBD aware for FrameSel/FrameRep SHOW=TRUE.
# When Not Showing Text(ie not changing frame content), does not require knowledge of HBD, ie works OK.
Colorbars.ShowFrameNumber.ConvertToYV24.ConvertBits(10).KillAudio
ORG=Last                           # Original, with/without audio
F=FlipVertical                     # Flipped, or maybe from ImageSource
R=F.FrameSel(10,20,30)             # 3 flipped frames, 10, 20, 30, into R clip frames 0,1,2
                                   # Equivalent to 3 frames read from file and converted to same colorspace as source.

Framerep(Last,R, 10,20,30)         # Replace 3 frames, 10, 20, 30 (From R clip frames 0,1,2)

#Framerep(Last,R,SCmd="10;20;30")  # Replace 3 frames 10,20,30, SCMD using command in string. CMD using command File.
AudioDubEx(Last,ORG)               # Restore Audio from source, if present
Info

#convertToRGB32                     # To view. Not needed for some players eg PotPlayer

return Last
EDIT: Above added AudioDubEx

EDIT: FrameSel/FrameRep, does not support Audio, AudioDubEx with original audio from source clip.

I have already mentioned this to you before, it is difficult for me to follow up on certain issues. Thanks.

The filename thing is because ImageSource needs the image file, which is the one that will replace the frame or group of frames.

The error message says:

"Overlay: input and overlay clip must have the same bit depths!"
__________________
By law and justice!

GMJCZP's Arsenal

Last edited by GMJCZP; 24th May 2021 at 16:20.
GMJCZP is offline   Reply With Quote
Old 24th May 2021, 16:19   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Well as I said, the function is not very well defined/implemented.
Scrap it and re-write taking clip arg instead of filename. Unless you want to implement
additional code which auto converts to same colorspace as source.
It is a lot easier for the user to just do a convert than to auto convert.
I'm not really quite sure what the requirements are, both have to be interleaved, or both planar,
and same bit depth, may be the minimum requirements for Overlay and Layer.

EDIT: Also may need to use eg Conversion Matrix.

EDIT: I think Overlay did originally work with any colorspace [pre AVS+],
but currently needs same bit depth and same interleaved/planar format,
so not going be an easy drop-in fix for your function.
__________________
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; 24th May 2021 at 16:26.
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 03:08.


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