Skip to content

Instantly share code, notes, and snippets.

@cuu
Created September 4, 2019 11:30
Show Gist options
  • Save cuu/1011367bb34d55d965ce30f9b2fdf03e to your computer and use it in GitHub Desktop.
Save cuu/1011367bb34d55d965ce30f9b2fdf03e to your computer and use it in GitHub Desktop.
微信小视频切割脚本
#!/bin/bash
FILENAME=${1}
MIN_FRAGMENT_LENGTH=300
if [ ! -f "${FILENAME}" ]; then
echo "FILE NOT FOUND: $FILENAME"
exit 1
fi
if [ ${2} ]; then
TARGET=$2
else
TARGET="/tmp"
fi
TIME=`ffprobe -i "${FILENAME}" -show_entries format=duration -of csv="p=0" 2>/dev/null | awk '{print int($1+0.5)}'`
if [ ${TIME} > ${MIN_FRAGMENT_LENGTH} ]; then
FNAME=0
for ((OFFSET = 0; OFFSET < ${TIME}; OFFSET=OFFSET+${MIN_FRAGMENT_LENGTH}))
do
TARGET_FILE="${TARGET}/${FNAME}.mp4"
ffmpeg -i "${FILENAME}" -c copy -ss ${OFFSET} -to $((OFFSET + $MIN_FRAGMENT_LENGTH)) -y "${TARGET_FILE}" 2>/dev/null
echo $TARGET_FILE CREATED
FNAME=$((FNAME+1))
done
else
echo "NO NEED TO CUT"
fi
open ${TARGET}
@cuu
Copy link
Author

cuu commented Sep 4, 2019

众所周知,微信对传输视频有5分钟限制,利用 ffmpeg 裁切视频, 以利于发车 - . -
WechatIMG99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment