Log in

View Full Version : FFMpeg and cropping


fabje
29th June 2013, 15:51
I have a tv capture that is 1920x1080 pixels.

I want to use FFMPeg libx264 to convert it to 1280x720, but I need to crop the video with. 2 pixels at the left, right and the bottom and 6 pixels at the top.
When I use avisynth with x264 it looks like this: Crop(2,6,-2,-2), but how does it looks when I want to use FFMpeg libx264?

Selur
29th June 2013, 21:11
-vf crop=1916:1072:2:6,scale=1280:716,pad=1280:720:0:2
this crops like you wanted (2,6,2,2), then resizes to 1280x716 and finally adds letterboxing to end up with 1280x720

fabje
29th June 2013, 22:59
-vf crop=1916:1072:2:6,scale=1280:716,pad=1280:720:0:2
this crops like you wanted (2,6,2,2), then resizes to 1280x716 and finally adds letterboxing to end up with 1280x720
That doesn't work. I use this line.
ffmpeg.exe -ss "00:20:32" -i "D:\test.ts" -c:v libx264 -vf crop=1916:1072:2:6,scale=1280:716,pad=1280:720:0:2 -vf yadif=3:-1:1 -profile:v high -level 4.1 -preset fast -b:v 4500k -minrate 2500k -maxrate 14000k -bufsize 3670k -acodec copy -map 0 -map -0:s -refs 4 -deblock -1:-2 -me_method umh -me_range 20 -subq 7 -trellis 0 -x264opts weightb:colormatrix=bt709 -sws_flags lanczos D:\test.mkv

Selur
30th June 2013, 07:29
That doesn't work.
not surprised:
a. you didn't mention your content is interlaced
b. you deinterlace after resizing&cropping. Blindly cropping&resizing interlaced content ofter causes problems. Aside from color modifications, deinterlacing normally should be the first thing to do.
-> have you tried using "-vf yadif=3:-1:1,crop=1916:1072:2:6,scale=1280:716,pad=1280:720:0:2" ?

fabje
30th June 2013, 16:06
Ok thank you that works, but now when I one the encoded video file and check the properties I see this:
1280x720 (AR 427:240)

How can I get rid of that?

Selur
30th June 2013, 21:26
How can I get rid of that?
your material has a pixel aspect ratio of 1:1 and a resolution of 1280:720 so the display aspect ratio is also 1280:720 and the software you use divides 1280 and 720 by 3 and ends up with 1280/3 = 426,66... = 427 and 720/3 = 240.
-> this is kind for like it's ment to be,.. no clue what you want it to say other than this,...

kabelbrand
3rd July 2013, 11:12
Try to add setsar to your filter chain:
-vf yadif=3:-1:1,crop=1916:1072:2:6,scale=1280:716,pad=1280:720:0:2,setsar=1/1