Reputation: 375
I need a bunch of video to be EXACTLY 1024x512 ( power of 2 video ), not a pixel less, not a pixel more..
I'm scaling them first to 1024 width
Then cropping them to 1024x512
Problem is..
result always ends up with 1 pixel more or 2 less pixels in width etc...
Source dimension : 1624 × 1080
Output dimension : 1022 × 512
Source dimension : 1264 × 720
Output dimension : 1025 × 512
rm -R ./output
mkdir output
cd input
for i in *.mp4;
do name=`echo "$i" | cut -d'.' -f1`
FILE="${name}"
TMP="temp.mp4"
INPUT="${FILE}.mp4"
OUT_PUT="../output/${FILE}.mp4"
JPEG_OUTPUT="../output/${FILE}.jpg"
echo FILE
echo INPUT
ffmpeg -i $INPUT -filter:v scale=1024:-2 -c:a copy ${TMP}
ffmpeg -i ${TMP} -filter:v "crop=1024:512:exact=1" -c:a copy ${OUT_PUT}
# ffmpeg -loglevel panic -i $OUT_PUT -vframes 1 -f image2 $JPEG_OUTPUT
rm ${TMP}
done
Upvotes: 0
Views: 847
Reputation: 93329
Use
ffmpeg -i $INPUT -filter:v "scale=1024:-2,crop=1024:512:exact=1,setsar=1" -c:a copy ${TMP}
Due to an adjustment by the scale filter to SAR, it's likely that your media checker is reporting a resolution corrected by a non-unit SAR. The setsar filter resets SAR to 1 to prevent that.
Upvotes: 1