

ffmpeg -i input.mp4 -codec copy -bsf:v h264_metadata=crop_left=200:crop_right=1240:crop_top=200:crop_bottom=610 output.mp4.For the OP's 480×270 area at position (200,200) from the top left in a 1920×1080 full HD frame, we get: The syntax slightly differs, though, because you can only set the amount of cropping from the four edges, not the target rectangle size. Unlike filters like crop and cropdetect, this does not require decoding. This will result in no loss, but you will be restricted to the ancient MJPEG format.įor some video formats at least, the soft solution based on metadata should be possible with FFmpeg as well by using bitstream filters from libavcodec, e.g. Stream copy the individual images with ffmpeg, crop them losslessly with jpegtran, then remux them with ffmpeg. Note: Your player may not support this method.

The output will be lossless but the output file will be huge. Note that some sizes may not be representable if the chroma is subsampled or the stream is interlaced (see H.264 section 7.4.2.1.1).įfmpeg can encode with several lossless encoders: ffv1, huffyuv, ffvhuff, utvideo, libx264 (using -crf 0 or -qp 0). These values will replace the current ones if the stream is already cropped. Sets the frame cropping offsets in the SPS. Note: Your player may not support this method.Įxample for H.264 video: ffmpeg -i input.mp4 -c copy -bsf:v h264_metadata=crop_left=100:crop_right=20:crop_top=10:crop_bottom=10 output.mp4 The h264_metadata and hevc_metadata bitstream filters can set crop dimensions without modifying the video itself. See FFmpeg Wiki: H.264 Video Encoding Guide for more info. Give it enough bits and you may not be able to tell there is a quality difference: ffmpeg -i input -vf "crop=480:270:200:100" -c:v libx264 -crf 17 -c:a copy ouput.mp4 Accept some quality loss (you may not even notice a difference) Or you could crop with the VLC GUI: Tools → Effects & Filters → Video Effects → Crop. With ffplay and crop filter: ffplay -vf "crop=480:270:200:100" input.mp4 See one of the other methods below if you want an output file. This will use your video player to crop while it is playing. This method will not create an output file. Crop with your playerĪ possible solution would be to crop during playback, so you don't even need to re-encode. You can't perform any filtering without losing quality when encoding to a lossy format, but you have some options.
