Is there an app that can Cut, crop, and resize video in 1 encode like imagemagick for video?

Looking for something that accepts a command like this:

videoapp cut 0:20 0:40 crop 4:3 resize 240 320

Outputs as h.264 mp4.

I have a mac with the mac video apps and can get any app that's recommended. Thanks.


ffmpeg will do it. You can either compile it from source, available here. Or more likely, download a precompiled binary for Macs from here. I don't use Macs so I can't vouch for the binary source.

You will have to use the trim, crop and scale filters in a filterchain to accomplish what you want.

The actual corresponding command for your pseudo command would be

ffmpeg -i input -vf "trim=20:40, setpts=PTS-STARTPTS, crop="'if(gte(a*sar,4/3),4*ih/3*sar,iw)':'if(gte(a*sar,4/3),ih,3*iw*sar/4)'", scale=320x240, setsar=1" -c:v libx264 -an output.mp4

You can find the (terse) explanation for all the parameters at the ffmpeg documentation site, but here's a quick run-through, in order:

-i input - Specify the input file.

-vf - this indicates a video filter follows, or a chain of them (separated by commas). If there are multiple filters specified in sequence, then each filter in a chain works on the output generated by the previous filter in the chain. The first filter works, of course, on the original input.

trim=20:40 - trims the video by retaining from the 21st to the 40th second

setpts=PTS-STARTPTS - video is a sequence of images displayed in time, so the frames of a video stream have timestamps associated with them for playback purposes. PTS is presentation timestamp. This clause generates new timestamps for the trimmed video stream so that the first frame of the trimmed stream has PTS of 0 (seconds) and all subsequent frames are accordingly offset as well (I've simplified a bit here).

crop="'if(gte(a*sar,4/3),4*ih/3*sar,iw)':'if(gte(a*sar,4/3),ih,3*iw*sar/4)'" - in short, this crops the input video to 4:3, but based on the input video's effective display ratio, so that the cropped image doesn't contain any blank padding. Video can contain "non-square" pixels so that a 100x100 image with pixel aspect (SAR) 2.5 will effectively display as 250x100 and SAR 0.5 will display as 50x100. My expression evaluates the effective input ratio and sets the output crop window accordingly.

scale=320x240 - scale to the stated resolution

setsar=1 - the crop and scale filters effectively produced a square pixel output, so the SAR metadata should be set as 1 to overwrite the original SAR so that players don't distort the image during playback.

-c:v libx264 - this says, use x264 to encode the video stream. There are many parameters that can be specified in addition , but by itself, it will use the default settings.

-an - leave audio out of the output. If you want to leave the corresponding audio in. replace this by

-af "atrim=20:40, asetpts=PTS-STARTPTS" -c:a aac -strict -2
| improve this answer | |
  • I get this error: [AVFilterGraph @ 0x7fd560f00820] No such filter: '4/3)' Error opening filters! – Harry Nov 13 '15 at 19:21
  • Sounds like '/' may not be allowed on Macs. Replace 4/3 with 1.333 – Gyan Nov 13 '15 at 19:26
  • And 4 * ih / 3 * sar with 1.333*ih and 3 * iw * sar / 4 with 0.75 * iw * sar – Gyan Nov 13 '15 at 19:27
  • Thank you, is there a way to get trim to accept minutes and not just seconds? – Harry Nov 13 '15 at 19:43
  • setpts=PTS-STARTPTS doesn't seem like it's enough to get the correct metadata for the video file. For example I'm trimming a 20 minute video to 20 seconds but the seekbar still shows 20 minute long video. – Harry Nov 13 '15 at 19:47

Apple compressor can do all of this in the GUI. If you need to use the command line, I think you'll find the relevant information here.

| improve this answer | |

Avisynth is a powerful frameserver for Windows with which you can write small scriptlets that dictate how you want to manipulate your video. You can do simple transforms such as scaling, cropping, adding borders, resizing, resampling, deinterlacing, etc. If you are comfortable with writing code then it can be very powerful, but there is a bit of a learning curve in getting to know how to use it. As far as I know there is no GUI for it.

There is also a port to Linux OSes called avxsynth, which I haven't used.

It processes the frames all at once and then you feed the output of the synth to a compressor such as xvideo or ffmpeg.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.