VideoHelp Forum
+ Reply to Thread
Results 1 to 6 of 6
Thread
  1. Hi,

    I'm using ffmpeg command line tool with libfdk_aac & x265 to encode HEVC 1080p 10-bit which perfectly works fine except for one thing and it is "crop".

    I need to remove black borders/bars (top & bottom) and find handrake does it automatically. but I can't find such thing in ffmpeg. I tried "cropdetect" to get values but it shows many different values. IF I can get correct crop values then I can use "-filter:v "crop=A:B:X:Y" in ffmpeg while encoding.

    Could anyone please suggest on how to get correct values / auto-crop?

    Thanks!
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    unless there is something differnet with x265 codec crop should work but has a threshold setting. Below is a sample to detectcrop show, using a setting of 30% for threshold:

    Code:
    LoadPlugin("C:\Users\Bud\Desktop\MEGA_Trimmed_Tabbed_2_2\bin\Debug\AutoCrop.dll")
    DirectShowSource(("C:\Users\Bud\Desktop\[dp]Manjandani-1.mp4"), Pixel_Type="yuy2").AutoCrop(mode=1, threshold=30)
    Subtitle("C:\Users\Bud\Desktop\[dp]Manjandani-1.mp4", x=864, y=204, font="Arial", size=24, text_color=$ff0000, align=3)
    Subtitle("This is Anamorphic video", font="Arial", size=24, text_color=$ff0000, align=5)
    ShowFrameNumber(scroll=true, x=560, y=27, font="Arial", size=24, text_color=$ffff80)
    ShowTime(x=622, y=44, font="Arial", size=24, text_color=$ffff80)
    ShowSMPTE(fps=23.976, x=618, y=61, font="Arial", size=24, text_color=$ffff80)
    Image
    [Attachment 48142 - Click to enlarge]

    It has a lot of extra stuff spit out from my auto program, but alter as necessary.

    Crop using the following format:
    Code:
    ffmpeg -i "C:\Users\Bud\Desktop\Manjandani unCropped.mp4" -ss 00:00:00.000 -to 99:00:00.000 -vf crop=564:228:60:60,scale=684:348,setdar=1.966 -vcodec libx264 -crf 22 -r 23.976  -acodec aac -ac 2 -ar 44.1k -b:a 128k  "C:\Users\Bud\Desktop\Manjandani_Cropped.mp4"
    again, -ss and -to are not necessary but I include in case future editing needs it. In this example they do not alter at all.
    Image
    [Attachment 48141 - Click to enlarge]
    Quote Quote  
  3. If you run cropdetect, it outputs the crop values for each frame it looks at, same with the Avisynth script Budman1 posted.
    -> so depending on the frames you look at you will see different values
    Handbrake and other guis on the other hand analyse X frames throughout the video and only output the crop values with the largest area.
    There is no direct 'autocrop' in ffmpeg, so you would need to:
    a. make sure you analyse multiple sections throughout your clip
    b. filter the output to only use the value with the largest resolution
    -> if you don't manually select the scene to analyse and filter the output a lot can go wrong
    (for example if you only analyse X frames 5min into the film and for one film those 5min are basically all black )
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  4. Thank you Budman1 & Selur.

    I'm using latest ffmpeg on Ubuntu 18.10.

    My source is 1920x1080 Blu-ray Remux (35GB) and the cropdetect shows below. I'm confused as to why it shows very low values compared to 1920x1080. Please see below and clarify what values I need to use with crop for ffmpeg? THANKS!


    root@ubuntu:# ffmpeg -i title_t00.mkv -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }'
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    crop=192:112:866:460
    root@ubuntu:#
    Quote Quote  
  5. Next, start with what OS you are on.
    Code:
    ffmpeg -i title_t00.mkv -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }'
    if you change that call to:
    Code:
    ffmpeg -i title_t00.mkv -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1
    you only get the last crop as output.
    Also note that you are only running the crop detection on the first second of your clip, depending on your clips that might be okay or not,.. (if your clips start will a 4:3 intro and then switch to 16:9 crop will 'fail')

    Cu Selur
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  6. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Perhaps your threshold is set too wrong for cropdetect. Interesting 2x866=1732+192=1924 and 2x460=920+112=1032 , both approximately the original size
    Quote Quote  



Similar Threads

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