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 25th July 2010, 14:07   #1  |  Link
em_dai_kho
Registered User
 
Join Date: May 2010
Posts: 5
how to add jpg and video file in Avisynth?

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.
em_dai_kho is offline   Reply With Quote
Old 26th July 2010, 12:47   #2  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,044
http://avisynth.org/mediawiki/Overlay
pandy is offline   Reply With Quote
Old 26th July 2010, 14:56   #3  |  Link
em_dai_kho
Registered User
 
Join Date: May 2010
Posts: 5
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
em_dai_kho is offline   Reply With Quote
Old 26th July 2010, 17:11   #4  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,044
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).
pandy is offline   Reply With Quote
Old 28th July 2010, 03:39   #5  |  Link
em_dai_kho
Registered User
 
Join Date: May 2010
Posts: 5
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

Code:
http://www.youtube.com/watch?v=r-nLArs7WCk
em_dai_kho is offline   Reply With Quote
Old 28th July 2010, 10:29   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,405
Quote:
Originally Posted by em_dai_kho View Post
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:
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
Gavino is offline   Reply With Quote
Old 28th July 2010, 15:55   #7  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,044
Quote:
Originally Posted by em_dai_kho View Post
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).

Quote:
Originally Posted by em_dai_kho View Post
And I also found a tutorial on youtube on how to use Avisynth for this job but I have not succeeded

Code:
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.)
pandy is offline   Reply With Quote
Old 30th July 2010, 06:48   #8  |  Link
em_dai_kho
Registered User
 
Join Date: May 2010
Posts: 5
Quote:
Originally Posted by Gavino View Post
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:
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
em_dai_kho is offline   Reply With Quote
Old 30th July 2010, 16:34   #9  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,044
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

Code:
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
pandy is offline   Reply With Quote
Old 30th July 2010, 18:06   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,405
Quote:
Originally Posted by pandy View Post
Code:
nW=INT(fv.Width*(pasr*vasr))
This isn't right. It should be:
Code:
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 )
Gavino is offline   Reply With Quote
Old 1st August 2010, 00:33   #11  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,044
Quote:
Originally Posted by Gavino View Post
This isn't right. It should be:
Code:
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!
pandy is offline   Reply With Quote
Old 1st August 2010, 07:04   #12  |  Link
em_dai_kho
Registered User
 
Join Date: May 2010
Posts: 5
Quote:
Originally Posted by pandy View Post
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

Code:
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
em_dai_kho is offline   Reply With Quote
Old 1st August 2010, 18:49   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,405
Quote:
Originally Posted by em_dai_kho View Post
I use this code but not working
In what way is it not working?
Did you include my correction to pandy's post?
Code:
nW=round(vd.Width*(vasr/pasr))
Gavino is offline   Reply With Quote
Old 2nd August 2010, 07:41   #14  |  Link
tin3tin
Registered User
 
tin3tin's Avatar
 
Join Date: Mar 2005
Posts: 365
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)
Quote:
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.
__________________
DVD slideshow GUI(Freeware).
tin3tin is offline   Reply With Quote
Old 2nd August 2010, 12:42   #15  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,044
Quote:
Originally Posted by em_dai_kho View Post
I use this code but not working
It works - maybe need additional explanation - not very well comented...

What error You receive?
pandy 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 01:00.


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