VideoHelp Forum




+ Reply to Thread
Results 1 to 5 of 5
  1. Member
    Join Date
    Dec 2011
    Location
    Russia
    Search Comp PM
    Does anyone have an idea on how to shift lines say {l1,l2,l3,l4} left or right by N pixels in YUY2 cap.
    Quote Quote  
  2. Yes it can be done in Avisynth. Install this program (version 2.6 is fine), then create a plain text file (can use Notepad), with the lines below, save it as shift.avs (make sure to change file type to all files *.*). Since installing Avisynth, *.avs files now play like a video, except they are actually running video adjustment commands.
    The first line in the file should reference your video. The next lines decide what lines to shift. You have to adjust the example to use your video file and to set the lines to shift.
    The command I made is shiftline(y,x) where y is the line #, starting at 0, and x is the shift, where x<0 shifts to the right. If the shift is always the same, you can write n=-50 then shiftline(1,n) shiftline(5,n) etc.
    If you want to understand a little about Avisynth, how it works, top will return the lines from 0 to y-1, bot returns the lines from y+1 to the bottom, getline returns line y, now I split the video into 3 parts, the top is unchanged, the line is shifted, and the bottom unchanged. These are stacked together.
    One more thing: the border pixels are made the same color as the last pixel, maybe you want the filler to be black? Also the shift can be subpixel like 5.5.

    Code:
    avisource("c:\MyVideos\test.avi")
    #test
    shiftline(10,-50)
    
    
    function shift(clip v, float x, float y) {
        v#shift an image, x>0 shifts left, y>0 shifts up
        bilinearresize(last.width,last.height,x,y,last.width,last.height)
    }
    
    function top(clip v, int y) {
        y<>0?v.crop(0,0,0,y):nop
    }
    
    function bot(clip v, int y) {
        y<>v.height-1?v.crop(0,y+1,0,0):nop
    }
    
    function getline(clip v, int y) {
        #return a line of height 1 from y
        v.crop(0,y,0,1)
    }
    
    function shiftline(clip v, int y, int x) {
      y==0?stackvertical(getline(v,y).shift(x,0),bot(v,y)): \
      y==v.height-1?stackvertical(top(v,y),getline(v,y).shift(x,0)): \
      stackvertical(top(v,y),getline(v,y).shift(x,0),bot(v,y))
    }
    
    function test{
        colorbars(height=256, pixel_type="YV12")
        mt_lutspa(mode="absolute",yexpr="y").converttoyuy2
    }
    Last edited by jmac698; 16th Dec 2011 at 20:00. Reason: Updated
    Quote Quote  
  3. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by jmac698 View Post
    Code:
    function bot(clip v, int y) {
        y<>v.height?v.crop(0,y+1,0,0):nop
    }
    Strictly, the guard condition should be y<>v.height-1 (or y+1<v.height), although the way it is used by shiftline ensures that this condition is always met anyway.

    It's worth pointing out to the OP that the script works only for RGB or YUY2 sources, not YV12.
    Quote Quote  
  4. Fixed. I caught that in shiftline, but didn't update bot. And (s)he did say it was YUY2.
    Quote Quote  
  5. Member
    Join Date
    Dec 2011
    Location
    Russia
    Search Comp PM
    Thanks guys. It works great!
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!