View Full Version : Creating image only select I (intra) frame from source with FFmpegSource
siella
14th September 2013, 20:09
I used ffmpegsource (http://ffmpegsource.googlecode.com/svn/trunk/doc/ffms2-avisynth.html) filter
I try to get i-frame type screen shot from video clip. But i coundt do
i use this scritp
import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
Killaudio()
ConvertToRGB()
vid= last
fps=25
dk=3
i= Round(fps*60*dk)
vid2= imagewriter("E:\thumbs\",type="png")
#selectevery(i,0)
FFInfo(framenum = false, cfrtime=false, vfrtime=false)
ConditionalFilter(vid,vid2,"chr(FFPICT_TYPE)","equals","I")
#writefileif("framelog.txt","""chr(FFPICT_TYPE)=="I" ""","current_frame")
i get " i don't know what "FFPICT_TYPE" means
but when use it with writeif like this
writefileif("framelog.txt","""chr(FFPICT_TYPE)=="I" ""","current_frame")
its work but i dont know how can read framelog.txt with avisynth and selecting frame.
raffriff42
14th September 2013, 21:13
Does this help? This test script inserts a subtitle over I-frames, for testing. EDIT - and writes images.
import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
ConvertToRGB32()
global my_string = ""
FrameEvaluate("""my_string = Chr(Eval("FFPICT_TYPE")) """, after_frame=true)
vid = Last
#vid2 = Last.Subtitle("[I]", align=9, size=56) ## TEST
vid2 = ImageWriter("E:\thumbs\",type="png")
return ConditionalFilter(Last,
\ vid, vid2,
\ """my_string=="I" """, "==", "false")
Gavino
14th September 2013, 22:11
The real problem is that ConditionalFilter (unlike WriteFileIf) evaluates the condition before reading the frame, so FFPICT_TYPE is not defined on the first frame.
raffriff42's solution masks this by initialising 'my_string' (btw the 'global' is unnecessary), but the frames selected are still out by one, since the FFPICT_TYPE tested will each time be that of the previous frame.
I think it should work if you replace the ConditionalFilter(...) in the original script by:
ScriptClip("""chr(FFPICT_TYPE)=="I" ? vid2 : vid""", after_frame=true)
raffriff42
14th September 2013, 22:17
Thank you, Gavino -- confirmed I was off by one (aaargh) import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
ConvertToRGB32()
## EDIT deleted per Gavino (see post #7)
#global my_string = ""
#FrameEvaluate("""my_string = Chr(Eval("FFPICT_TYPE")) """, after_frame=true)
vid = Last
#vid2 = Last.Subtitle("[I]", align=9, size=56) ## TEST
vid2 = ImageWriter("E:\thumbs\",type="png")
return ScriptClip("""chr(FFPICT_TYPE)=="I" ? vid2 : vid""", after_frame=true)
siella
14th September 2013, 22:21
Does this help? This test script inserts a subtitle over I-frames, for testing. EDIT - and writes images.
import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
ConvertToRGB32()
global my_string = ""
FrameEvaluate("""my_string = Chr(Eval("FFPICT_TYPE")) """, after_frame=true)
vid = Last
#vid2 = Last.Subtitle("[I]", align=9, size=56) ## TEST
vid2 = ImageWriter("E:\thumbs\",type="png")
return ConditionalFilter(Last,
\ vid, vid2,
\ """my_string=="I" """, "==", "false")
Thanks your helping but it is not correctly working.
it gives wrong i frame, next frame is correct
example 12230 appear i-frame but correct i-frame is 12231
Thank you, Gavino -- confirmed I was off by one (aaargh) import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
ConvertToRGB32()
## EDIT deleted per Gavino (see post #7)
#global my_string = ""
#FrameEvaluate("""my_string = Chr(Eval("FFPICT_TYPE")) """, after_frame=true)
vid = Last
#vid2 = Last.Subtitle("[I]", align=9, size=56) ## TEST
vid2 = ImageWriter("E:\thumbs\",type="png")
return ScriptClip("""chr(FFPICT_TYPE)=="I" ? vid2 : vid""", after_frame=true)
That's works perfect
siella
14th September 2013, 22:34
### Movie Screenshot, thumbnails creator###
### Thanks to Gavino and raffriff42 for helping ##
###-----Selection Start----###
video ="F:\1.avi" #source path
path = "E:\thumbs\" #save image path
thumb = "no" # yes or no
wr = "no" # yes or no
type = "I" # I , P or B
img = "png" # png, jpg, bmp, etc.
###----Selection end-------###
import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFVideoSource(video)
ConvertToRGB32()
AssumeFrameBased()
ar = Float(width())/Float(height())
y = Round(300/ar)
type == "I" ? SelectRangeEvery(750,30): SelectEvery(3000, 0,100)
thumb == "yes" ? BicubicResize(300,y) : nop()
vid = Last
vid2 = (wr == "yes") ? Last.Subtitle("Frame Type:I", align=7, size=20).ImageWriter(path,type=img) : Last.ImageWriter(path,type=img)
return ScriptClip("""chr(FFPICT_TYPE) == type ? vid2 : vid""", after_frame=true)
I use this script creating random screeen shoot.
Maybe some one need that.
I added thumb function. If you change thumb = "yes" it will creat thumbnails.
If you input yes to wr variable will wite framet type on image files
You can change frame type I P or B but P and B frame will be much more so i added getting every about 5 minites.
I used Avsmeter (http://forum.doom9.org/showthread.php?t=165528) to run script
Also can use avs2avi (http://forum.doom9.org/showthread.php?t=71493) or avs2avi64 (http://forum.doom9.org/showthread.php?t=152800)I tried too. but must use with -c null o -n parameters.
Gavino
15th September 2013, 09:07
Thanks for posting your script, siella.
You can remove the lines 'global my_string ...' and 'FrameEvaluate(...)', which were part of raffriff42's solution and are unnecessary. (When I referred to the 'original' script in my earlier post, I meant your script from post #1.)
siella
15th September 2013, 14:46
That's right its not necessity. I've edited. Thanks Gavino
raffriff42
15th September 2013, 15:00
Thanks Gavino. For future Googlers, could this thread title be changed from "select 1 frame" to "select I (Intra) frame" ?
Guest
15th September 2013, 15:29
Done.
Actually the original title was incoherent and I tried to fix it, so blame me for the "1", not the original poster.
jmac698
15th September 2013, 19:55
Thanks, that was useful to me. I had an idea that you can take two recordings of the same material from digital TV and combine them for greater quality; and it's true. Especially for 24p material on a 60p stream, a P frame after an I frame which happens to be a film frame looks better. A TV stream is encoded continuously which means that two showings can have different "phases", or start at a different spot within a GOP. This is a rough explanation.
raffriff42
16th September 2013, 01:18
Here is a version that includes the frame number in the file name.
import("C:\Program Files (x86)\AviSynth 2.5\plugins\avs\FFMS2.avsi")
FFmpegSource2("F:\1.avi")
ConvertToRGB32()
return ScriptClip("""chr(FFPICT_TYPE)=="I"
\ ? Last.ImageWriter("E:\thumbs\filename_prefix-",
\ start=current_frame, end=current_frame, type="png")
\ : Last""",
\ after_frame=true) Output = "filename_prefix-<frame number>.png" -- of course, filename_prefix can be anything.
Gavino
16th September 2013, 09:01
Here is a version that includes the frame number in the file name.
Doesn't the previous version do that anyway?
@siella
I see you have edited your post#5, deleting the previous edit that said the solution actually worked. Was there a problem?
raffriff42
16th September 2013, 09:37
>Doesn't the previous version do that anyway?
Yes it does - sorry about that.
siella
16th September 2013, 10:13
Doesn't the previous version do that anyway?
@siella
I see you have edited your post#5, deleting the previous edit that said the solution actually worked. Was there a problem?
There is no problem. That answer for post 2 so it maybe confused.
siella
16th September 2013, 13:13
###-----Selection Start----###
video ="D:\1.mkv" #source path
global path = "D:\thumbs\" #save image path
thumb = "no" # yes or no
wr = "yes" # yes or no
type = "I" # I , P or B
img = "png" # png, jpg, bmp, etc.
###----Selection end-------###
import("C:\Program Files\AviSynth 2.5\plugins\FFMS2.avsi")
FFVideoSource(video)
ConvertToRGB32()
AssumeFrameBased()
FrameEvaluate("""asd= string(current_frame)""",after_frame=true)
wr == "yes" ? ScriptClip("""Subtitle("Frame Number:"+asd, align=7, size=20)""",after_frame=true) :nop()
ar = Float(width())/Float(height())
y = Round(300/ar)
type == "I" ? SelectRangeEvery(1000,20): SelectEvery(7500, 0)
thumb == "yes" ? BicubicResize(300,y) : nop()
vid = Last
vid2 = ScriptClip( """(wr == "yes") ? Last.Subtitle("Frame Type:I", align=9, size=20)
\.ImageWriter(path+asd+"-",type=img) : ImageWriter(path+ asd +"-",type=img)""",after_frame=true)
return ScriptClip("""chr(FFPICT_TYPE) == type ? vid2 : vid""", after_frame=true)
imagewrite give frame name as file name but it is not correct frame number because of frame number changed due to using SelectRangeEvery.
I add currently frames of source video to filename, thas's first is real frame name . Also if you choose wr = "yes" frame number will appear.
Guest
16th September 2013, 13:15
video ="D:\GALACTICA\Battlestar.Galactica.(1978).S01E04.The.Lost.Planet.of.the.Gods.part1.DVDRip.X264.AC3.PRoDJi.mkv" #source path
Closed for rule 6 violation.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.