Advertisement
Seedmanc

First pass - separate to keyframes

Apr 30th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #This is a first pass script, you don't need to encode it, just run it once from the beginning to the end via player or VDub. Don't seek while it is running.
  2. #It will dump all frames that are different into a folder along with timecodes file that will list all frames that are repeats of those dumped.
  3. ffmpegsource2("C:\Users\Seedmanc\Desktop\vector.mp4")           # your source unprocessed video here
  4. ConvertToY8( ).coloryuv(autogain=true,opt="") .converttorgb24   # autocontrast since images looked rather dim for some reason
  5.  
  6. global dir="c:\users\seedmanc\desktop\"                         # path to store images and logfile
  7. global filename="file.txt"                                      # name of logfile
  8.  
  9. function write(clip c, int s, int d){
  10.   global o= string(s)
  11.   global p=" "
  12.   global r=string(s-d)
  13.   writefile(c,dir+filename,"o","p","r",flush=false)
  14. }
  15.  
  16. imagewriter(dir+"%d.png",start=0,end=-1,type="png").trim(0,-1)+trim(1,0)
  17.   # writing 0th frame and number, since it is not considered a scene change, but we still need it
  18. writefilestart(last,dir+filename,""""TYPE int"""")
  19. writefilestart(last,dir+filename,""""DEFAULT 0"""",append=true)  # header of the logfile
  20.  
  21. global ext="png"
  22. global wildcard="%d."+ext
  23. global counter=-1
  24.  
  25. ScriptClip("""a=current_frame"""+chr(13)+ \
  26.  """(ConvertToY8.YDifferenceFromPrevious>10)? \
  27.  ScriptClip(" counter=0 \
  28.     write(last,a,counter) \                                                          
  29.     imagewriter(dir+wildcard,start=current_frame,end=-1 ,info=false,type=ext)" ): \  
  30.  ScriptClip("counter=counter+1 write(last, a,counter)") """)        
  31.  
  32. # Basically, what I do here is detect scenechange (by looking at difference between previous frame and current and when it is above threshold of 10 I write current frame and save it's number so that it will be used later as reference.
  33. # If there's no change, then I don't write image, and don't change reference frame number.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement