Q:

With FFMPEG, create thumbnails proportional to the video's ratio

I'm using the following command to create thumbnails with FFMPEG:
ffmpeg -itsoffset -1 -i video.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 240x180 image.png

And it works fine. However, when the video isn't 4:3 ratio, it will still create a 240x180 image, and the extra space will be painted black. Is there some variation of the command that will prevent this and give me an image proportional to the video's ratio? In other words, I want 240x180 to be the maximum size of the thumbnail, but not the minimum.
Extra points if the command creates a smaller image when the video is smaller than 240x180.

A:

Use the scale filter:
ffmpeg -itsoffset -1 -i video.avi -vframes 1 -filter:v scale="280:-1"  image.png

This will preserve the aspect ratio to achieve a width of 280 pixels. 
To increase the width to a maximum of 280 pixels but preserve the ratio, use:
scale='min(280\, iw):-1'

Here, we'll just assume that your video is in landscape format, so we can set the maximum width to 280 and forget about the height, which should be 180 for a 3:2 video and 158 for 16:9 content.
Notes:

-vcodec mjpeg doesn't make sense when you're writing to a PNG file
-f rawvideo doesn't do anything here either
-an is not needed because FFmpeg can't write audio to a PNG file

