windowsvideoffmpegblending

FFmpeg : How to apply a filter on custom frames and place output of them between mainframes


I have an interlaced video stream and need apply a filter (any filter that takes two frames as input , for example tblend or lut2) on custom video frames and place output of them between mainframes like this :

 Input frames:  [1]             [2]             [3]  .....  FPS=25   
                 |  \         /  |  \         /  |
                 |   \       /   |   \       /   |
Output frames:  [1]   [f(1,2)]  [2]   [f(2,3)]  [3]  .....  FPS=50 i/p

I think I need select filter + Expressions to select frames, but I don't know how to do it

Please help.

Note:

Input has no audio stream.
Output = uncompressed yuv422 8bits in AVI container
the output scan type can be interlaced or progressive
I have to do this with just one command.

I tried FFmpeg -i in.avi -vf tblend -vcodec rawvideo out.avi, but the output of this command is not what I want.


Solution

  • You may chain tblend, interleave and setpts filters, while the two inputs to interleave filter are the output of tblend and the original video:

    Example (assuming input framerate is 25Hz):

    ffmpeg -y -i in.avi -filter_complex "[0:v]tblend=all_mode=average[v1],[v1][0:v]interleave,setpts=N/50/TB" -r 50 -vcodec rawvideo -pix_fmt bgr24 out.avi
    

    Note: I selected -pix_fmt bgr24, because yuv422 is not played with MPC-HC.


    Testing:

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    As you can see, the frames 0 and 2 are the original frames, and 1 and 3 are blended output of two original frames.


    Examples for two cases of interlaced video frames:

    tinterlace filter is used for creating synthetic interlaced video.

    Simulating two fields that originated from a single video frame:

    'drop_even, 1'
    Only output odd frames, even frames are dropped, generating a frame with unchanged height at half frame rate.

      ------> time
    Input:
    Frame 1         Frame 2         Frame 3         Frame 4
    11111           22222           33333           44444
    11111           22222           33333           44444
    11111           22222           33333           44444
    11111           22222           33333           44444
    Output:
    11111                           33333
    11111                           33333
    11111                           33333
    11111                           33333
    
    ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=2:duration=10 -vf tinterlace=drop_even,fieldorder=tff -vcodec rawvideo -pix_fmt bgr24 in_drop_even.avi
    

    enter image description here

    Simulating two fields that captured at different times (not originated from the same video frame):

    'interleave_top, 4'
    Interleave the upper field from odd frames with the lower field from even frames, generating a frame with unchanged height at half frame rate.

      ------> time
    Input:
    Frame 1         Frame 2         Frame 3         Frame 4
    11111<-         22222           33333<-         44444
    11111           22222<-         33333           44444<-
    11111<-         22222           33333<-         44444
    11111           22222<-         33333           44444<-
    Output:
    11111                           33333
    22222                           44444
    11111                           33333
    22222                           44444
    
    ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=2:duration=10 -vf tinterlace=interleave_top,fieldorder=tff -vcodec rawvideo -pix_fmt bgr24 in_interleave_top.avi
    

    enter image description here