Log in

View Full Version : Import ImageWriter images back in but differently


TCmullet
1st May 2021, 03:42
I've successfully used ImageWriter to extract individual images from a video that is largely a simple slide show. Here's a sample of my script:

frame=426
ImageWriter("slides\myProject.",frame,frame,"jpg")
frame=522
ImageWriter("slides\myProject.",frame,frame,"jpg")

It creates (in this fragment) 2 .jpg files. (in reality my script has made many dozens of individual "slides" for future use.) Now in a different script, I want to overlay the image of frame 426 over frames 20 to 30 in another video whose video clip is myClip, leaving all the other frames intact. And likewise with many other INVIDUAL images (.jpg). In fact, when I'm done, most of the original frames of the video will have been replaced by some slide from the slide collection.

I can't figure out how to do this. ImageSource appears to use as it's sole video source, the standalone images. I already have a video with audio, but want to replace a range of the video frames only (not touching the audio) with a single "slide" from one of my .jpgs. Then do this all over again for a different slide and target frame range. (Sorry if this is not as succinct as it might have been.)

patul
1st May 2021, 04:30
A n00b way to do it

A = FFVideoSource("D:\App\youtube-dl\S2_E09_clip.mkv").TFM().TDecimate().ConvertToRGB32(matrix = "Rec601")
B = ImageSource("D:\App\AVS\AVSMeter290\flintstones.png", start=0, end=10, fps=A.FrameRate, pixel_type="RGB32")

Afin = A.Trim(0, 20)
Afovr = A.Trim(20, 30)
Afout = A.Trim(30, A.FrameCount-1)
Ovr = Overlay(Afovr, B, mask=B.ShowAlpha(), opacity=0.5)

AudioDub(Afin ++ Ovr ++ Afout, FFAudioSource("D:\App\youtube-dl\S2_E09_clip.mkv"))

TCmullet
4th May 2021, 03:51
I guess there's no way to do it directly, even though snatching the slides was simple. So I've written a function to do it. It works (and was a good exercise, I guess).


function Insert1ImageRange(clip c, string fname, int fstart, int fend)
{ # Insert 1 image into a video clip replacing
# the target range of frames
holdaud=c
before = c.trim(0, fstart-1).killaudio()
after = c.trim(fend+1, 0).killaudio()
inserted = \
imageSource(fname,start=fstart,end=fend,fps=framerate(c)).Spline36Resize(width(c),height(c))
vid = before ++ inserted.ConvertToYV12() ++ after
return audiodub(vid, holdaud)
}