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.
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
[0:v]tblend=all_mode=average[v1]
Creates a stream with tblend
filter, and gives the output the temporary name [v1]
.[v1][0:v]interleave
applies interleave filter of [v1]
and the original video.setpts=N/50/TB
fixes the timestamps to apply 50fps output video.-r 50
sets the output frame rate to 50Hz.Note: I selected -pix_fmt bgr24
, because yuv422
is not played with MPC-HC.
Testing:
Build synthetic pattern (the -r 25
, rate=1
and setpts=N/25/TB
are used for creating counting number at 25Hz):
ffmpeg -y -f lavfi -r 25 -i testsrc=size=192x108:rate=1:duration=10 -vf setpts=N/25/TB -vcodec rawvideo -pix_fmt bgr24 in.avi
Execute the command:
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
Checking frame by frame:
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
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