#!/bin/sh ## ## SCRIPT: 00_ffmpeg_mp4_CROP.sh ## ## PURPOSE: Crop an area out of a '.mp4' movie file --- based on a user-specified ## width, height, and upper-left corner of the area. ## ## Example crop parms: ## out_w:out_h:x:y ## where ## ## - out_w is the width of the output rectangle ## - out_h is the height of the output rectangle ## - x and y specify the top left corner of the output rectangle ## ## METHOD OF USE: ## 1) Put this script in the directory of '.mp4' movie files ## that you want to crop. ## 2) Edit this script to set the input & output filenames and crop parms. ## 3) Run the script in a terminal window positioned at the directory ## that holds this script and the movie files. ## ## REFERENCE: ## https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg ## ## Examples: ## ## 1) ## To crop a 80×60 section, starting from position (200, 100): ## ## ffmpeg -i in.mp4 -filter:v "crop=80:60:200:100" -c:a copy out.mp4 ## ## The audio is stream copied in this example, so re-encoding is avoided. ## ## 2) ## To crop 20 pixels from the top, and 20 from the bottom: ## ## ffmpeg -i in.mp4 -filter:v "crop=in_w:in_h-40" -c:a copy out.mp4 ## ## The filter will automatically center the crop if x and y are omitted ## such as in this example. ## ## NOTE: You can refer to the input image size with in_w and in_h ## as shown in this example. ## ## 3) ## You can preview a crop with ffplay: ## ## ffplay -i input -vf "crop=in_w:in_h-40" ## ## This way you can experiment and adjust your cropping without ## the need to encode, view, repeat. ## ## -vf is short for -filter:v ## ## Script started: 2021jul10 ## ffmpeg \ -i input_40sec_640x360_h264-aac.mp4 \ -filter:v \ "crop=in_w:in_h-60" \ -c:a copy \ output_40sec_640x300_h264-aac.mp4 # 00_temp_crop.mp4 # totem 00_temp.mp4 # ffplay 00_temp.mp4 exit