View Full Version : how to add jpg and video file in Avisynth?
em_dai_kho
25th July 2010, 14:07
I have a *. jpg file and a video format *.divx, I want to merge files *.jpg in front of a video file with Avisynth, use what code would help.
pandy
26th July 2010, 12:47
http://avisynth.org/mediawiki/Overlay
em_dai_kho
26th July 2010, 14:56
Oh no, I mean add a picture into video clips in front of it, such as the introduction of image content of a movie.
PS: sorry, my english is not good :P
pandy
26th July 2010, 17:11
Don't worry my English is probably worse than Yours.
http://avisynth.org/mediawiki/ImageReader
then if this is possible encode small stream with jpg and join WITHOUT re-encoding with video (so question is: if any tool that allow to join seamlessly two .divx files exist - assume that both have same HxV size, framerate etc)
If there is no tool for seamless joining two.divx files then You need to re-encode WHOLE video anyway... (this is worst solution)
So if You can encode Yours jpg video with exactly same parameters like following video then try to use method described in http://www.divx-digest.com/articles/joinavi.html
But everything depend from the container (*.divx can be any container like AVI etc with changed suffix).
em_dai_kho
28th July 2010, 03:39
Well I get it, it must convert *.jpg to *.divx format with the same frame and connect them together using VirtualDub, right?
And I also found a tutorial on youtube on how to use Avisynth for this job but I have not succeeded
http://www.youtube.com/watch?v=r-nLArs7WCk
Gavino
28th July 2010, 10:29
I also found a tutorial on youtube on how to use Avisynth for this job but I have not succeeded
That tutorial is for appending two video clips.
Appending a still image in Avisynth is harder than you might think, since you have to convert the image into a clip whose dimensions, frame rate, color space and audio track all match the other clip.
Example code:
n = ... # no of frames for still
v = DirectShowSource("xxx.divx")
ImageSource("yyy.jpg", end=n-1)
Spline36Resize(v.width, v.height) # or some other resizer
AssumeFPS(v)
ConvertToYV12()
AudioDub(BlankClip(v, length=n))
last ++ v # append clips
pandy
28th July 2010, 15:55
Well I get it, it must convert *.jpg to *.divx format with the same frame and connect them together using VirtualDub, right?
Yes - You must create additional clip that can be joined to that one that You already have. If You create exactly same format then probably they can be join together without re-encoding original video which i think is preferable (less time used for operation, higher quality due lack of re-encoding already encoded video - each time new re-compression affect quality).
And I also found a tutorial on youtube on how to use Avisynth for this job but I have not succeeded
http://www.youtube.com/watch?v=r-nLArs7WCk
So yes, this is one of the method however in my opinion not recommended - sufficient shall be method that one of clips is re-encoded to format of the second one and both are joined at the elementary stream level (assume that this is possible -for example tools are available for such operation - this should be faster and affect quality only for the one of clips - re-encoded one.)
em_dai_kho
30th July 2010, 06:48
That tutorial is for appending two video clips.
Appending a still image in Avisynth is harder than you might think, since you have to convert the image into a clip whose dimensions, frame rate, color space and audio track all match the other clip.
Example code:
n = ... # no of frames for still
v = DirectShowSource("xxx.divx")
ImageSource("yyy.jpg", end=n-1)
Spline36Resize(v.width, v.height) # or some other resizer
AssumeFPS(v)
ConvertToYV12()
AudioDub(BlankClip(v, length=n))
last ++ v # append clips
thank's for good code :D :thanks:
pandy
30th July 2010, 16:34
for aspect ratio corrected image clip only or with joined image and video clip - this is extended Gavino script - if You wish You can go further and improve script by Your self
picsrc="yyy.jpg"
vidsrc="test.avi"
t=10.0 #[time in sec]
vd=DirectShowSource(vidsrc)
fc=Round(t*FrameRate(vd))
fv=ImageSource(picsrc).AssumeFPS(vd).Loop().Trim(0,fc-1).ConvertToRGB32()
fa=Tone(length=t, type="Silence", samplerate=AudioRate(vd), channels=AudioChannels(vd))
AudioDubEx(fv,fa)
vasr=float(vd.Height)/float(vd.Width)
pasr=float(fv.Height)/float(fv.Width)
nW=INT(fv.Width*(pasr*vasr))
xx=(vd.Width-nW)
Spline36Resize(nW, vd.Height).AddBorders(xx/2,0,xx/2,0)
#ConvertToYV12()
#last ++ vd #joining both clips
last #only for picture clip
Gavino
30th July 2010, 18:06
nW=INT(fv.Width*(pasr*vasr))
This isn't right. It should be:
nW=round(vd.Width*(vasr/pasr))
Note also that this is only appropriate when vasr <= pasr, ie the photo is narrower than the video. When the photo is wider, you want to add borders on the top and bottom instead of the sides. (Left as an exercise for the reader :))
pandy
1st August 2010, 00:33
This isn't right. It should be:
nW=round(vd.Width*(vasr/pasr))
Note also that this is only appropriate when vasr <= pasr, ie the photo is narrower than the video. When the photo is wider, you want to add borders on the top and bottom instead of the sides. (Left as an exercise for the reader :))
Heh, Yes - You have absolutely right - i don't even try to complicate this script more - i assumed (maybe wrongly) that usually videos are 16:9 and pictures 4:3 (sometimes videos 4:3 and pictures also 4:3), also proper colorspace should be detected and maybe modulo calculation - anyway - good starting point for play with avisynth for newcomer.
regards!
em_dai_kho
1st August 2010, 07:04
for aspect ratio corrected image clip only or with joined image and video clip - this is extended Gavino script - if You wish You can go further and improve script by Your self
picsrc="yyy.jpg"
vidsrc="test.avi"
t=10.0 #[time in sec]
vd=DirectShowSource(vidsrc)
fc=Round(t*FrameRate(vd))
fv=ImageSource(picsrc).AssumeFPS(vd).Loop().Trim(0,fc-1).ConvertToRGB32()
fa=Tone(length=t, type="Silence", samplerate=AudioRate(vd), channels=AudioChannels(vd))
AudioDubEx(fv,fa)
vasr=float(vd.Height)/float(vd.Width)
pasr=float(fv.Height)/float(fv.Width)
nW=INT(fv.Width*(pasr*vasr))
xx=(vd.Width-nW)
Spline36Resize(nW, vd.Height).AddBorders(xx/2,0,xx/2,0)
#ConvertToYV12()
#last ++ vd #joining both clips
last #only for picture clip
I use this code but not working
Gavino
1st August 2010, 18:49
I use this code but not working
In what way is it not working?
Did you include my correction to pandy's post?
nW=round(vd.Width*(vasr/pasr))
tin3tin
2nd August 2010, 07:41
Just to spoil all the fun of coding I like to mention that DVD slideshow GUI can do that for you(generate the script).
All you need to do is saving this line as an avisynth script(.avs) DirectShowSource("xxx.divx") and then you can import it into DVD slideshow GUI and that image can be imported too.
Then you can render directly from DSG to various formats or export as Avisynth script for further editing. :)
pandy
2nd August 2010, 12:42
I use this code but not working
It works - maybe need additional explanation - not very well comented...
What error You receive?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.