I've tried to figure this out myself, but the myriad of options just baffles me.I want to use ideally either ffmpeg or mencoder (or something else, but those two I know I have working) to convert any incoming video to a fixed screen size.If the video is wider or too short for it, then centre crop the video.  If it's then not the right size, the resize up or down to make it exactly the fixed screen size.The exact final thing I need is 720x480 in a XVid AVI with an MP3 audio track.I've found lots of pages showing how to resize to a maximum resolution, but I need the video to be exactly that resolution (with extra parts cropped off, no black bars).Can anyone tell me the command line to run - or at least get me some/most of the way there?  If it needs to be multiple command lines (run X to get the resolution, do this calculation and then run Y with the output of that calculation) I can script that.
Convert a video to a fixed screen size by cropping and resizing
video;ffmpeg;video encoding;mencoder
I'm no ffmpeg guru, but this should do the trick.First of all, you can get the size of input video like this:ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width in.mp4With a reasonably recent ffmpeg, you can resize your video with these options:ffmpeg -i in.mp4 -vf scale=720:480 out.mp4You can set the width or height to -1 in order to let ffmpeg resize the video keeping the aspect ratio. Actually, -2 is a better choice since the computed value should even. So you could type:ffmpeg -i in.mp4 -vf scale=720:-2 out.mp4Once you get the video, it may be bigger than the expected 720x480 since you let ffmpeg compute the height, so you'll have to crop it. This can be done like this:ffmpeg -i in.mp4 -filter:v crop=in_w:480 out.mp4Finally, you could write a script like this (can easily be optimized, but I kept it simple for legibility):#!/bin/bashFILE=/tmp/test.mp4TMP=/tmp/tmp.mp4OUT=/tmp/out.mp4OUT_WIDTH=720OUT_HEIGHT=480# Get the size of input video:eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width ${FILE})IN_WIDTH=${streams_stream_0_width}IN_HEIGHT=${streams_stream_0_height}# Get the difference between actual and desired sizeW_DIFF=$[ ${OUT_WIDTH} - ${IN_WIDTH} ]H_DIFF=$[ ${OUT_HEIGHT} - ${IN_HEIGHT} ]# Let's take the shorter side, so the video will be at least as big# as the desired size:CROP_SIDE=nif [ ${W_DIFF} -lt ${H_DIFF} ] ; then  SCALE=-2:${OUT_HEIGHT}  CROP_SIDE=welse  SCALE=${OUT_WIDTH}:-2  CROP_SIDE=hfi# Then perform a first resizingffmpeg -i ${FILE} -vf scale=${SCALE} ${TMP}# Now get the temporary video sizeeval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width ${TMP})IN_WIDTH=${streams_stream_0_width}IN_HEIGHT=${streams_stream_0_height}# Calculate how much we should cropif [ z${CROP_SIDE} = zh ] ; then  DIFF=$[ ${IN_HEIGHT} - ${OUT_HEIGHT} ]  CROP=in_w:in_h-${DIFF}elif [ z${CROP_SIDE} = zw ] ; then  DIFF=$[ ${IN_WIDTH} - ${OUT_WIDTH} ]  CROP=in_w-${DIFF}:in_hfi# Then crop...ffmpeg -i ${TMP} -filter:v crop=${CROP} ${OUT}