Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Compression Techniques ffmpeg scaling issue

  • ffmpeg scaling issue

    Posted by Jack Passmore on September 29, 2010 at 6:43 pm

    Hi all,

    I’m trying to convert a large 1920×1080 .avi file (8-bit mjpeg Blackmagic codec) to an h246 encoded mp4 file using ffmpeg at the command line. The 1920×1080 original image is a pillar-boxed 4:3 image, so I’m trying to crop the sides off to eventually create a 640×480, 4:3, H264, .mp4 video.

    The problem is, when I use ffmpeg, I can successfully crop the sides, but the .mp4 output is only the top left corner (640×480) of the original 1920×1080 video. I want to crop the original video and then scale the cropped 4:3 video (1440×1080) down to 640×480. Any suggestions? This is the ffmpeg code I’m using:

    ffmpeg -i videos.avi -cropleft 240 -cropright 240 -vcodec libx264 -vpre normal video.mp4

    John

    Jack Passmore replied 15 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Michael Rampe

    September 29, 2010 at 8:50 pm

    I am not sure why you are getting a 640×480 output at all without using the size flag (-s).

    What version are you using? In the newer SVN versions, libavfilter is a better option for cropping and scaling (-vf).

    Please post full output and I can work on a string to suit.

    Michael

  • Jack Passmore

    September 30, 2010 at 9:31 pm

    Hi Michael,

    You are correct I wasn’t getting a 640×480 image, I must have left that out. I was unaware of the -vf command, so thank you. However, I’m still having some problems.

    This command will change the 1920×1080 letterboxed video to a 1140×1080 4:3 video correctly:

    ffmpeg -i video.avi -vf “crop=240:0:1440:1080” video_crop.mp4

    But when go back to the original file and try to also scale the image, it creates a 640×480 image that is stretched vertically and letterboxed:

    ffmpeg -i video.avi -vf “crop=240:0:1440:1080” -vf “scale=640:480” video_crop_resize.mp4

    I can’t figure out why I’m not getting a 4:3 630×480 video file without letterboxing…

  • Michael Rampe

    October 1, 2010 at 1:57 am

    [Jack Passmore]
    ffmpeg -i video.avi -vf “crop=240:0:1440:1080” -vf “scale=640:480” video_crop_resize.mp4
    I can’t figure out why I’m not getting a 4:3 630x480 video file without letterboxing…”

    [Jack Passmore] “This command will change the 1920×1080 letterboxed video to a 1140x1080 4:3 video correctly:
    ffmpeg -i video.avi -vf “crop=240:0:1440:1080″ video_crop.mp4”

    (careful with number typos, it can get very confusing;-)

    Your command line will only use the last instance of -vf as it is only meant to be specified once per input.

    The correct usage of -vf is comma separated commands with branches separated by semi-colons.

    In your case (no branches):
    ffmpeg -i video.avi -vf “crop=240:0:1440:1080,scale=640:480” video_crop_resize2.mp4

    BONUS TIP:
    …using libavfilter for a watermark (with a branch):
    (bug1.tif=50×100 file saved with transparency from p-shop)

    Using SoC libavfilter [1.20. 0]
    -vf “movie=0:tiff:bug1.tif [watermark];\
    [in] [watermark]overlay=1600:700:1[out]”

    or the hack using SVN libavfilter [1.39. 0] if you get an error with the overlay:
    -vf “movie=0:tiff:logo5.tif,pad=1920:1080:1600:700:0x00000000 [watermark];\
    [in] [watermark]overlay=0:0:1[out]”

    …and it works with multiple separate or nested branches as well.

    Michael

  • Jack Passmore

    October 1, 2010 at 3:12 pm

    Awesome, it works. Apologies for my typos! Now I just have to find the correct h264 presets for decent web viewing.
    Cheers,
    John

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy