如影随行忙着
24-11-11 11:53

手机录视频,一不小心文件就太大了,删了可惜,留着又占地方,怎么办?
把视频切割一下,删掉不要的,文件就小了。
下面是无损切割,程序自动的方法,省时间。
安卓,termux。
先安装ffmpeg,pkg install ffmpeg
再进视频目录,cd /sdcard
粘贴这行命令,
for file in *.mp4; do ffmpeg -i "$file" -c copy -map 0 -f segment -segment_time 600 -segment_format mp4 "${file%.mp4}_part%02d.mp4"; done

确定即可。
之后去文件夹删除大视频和不要点切割片段,留有用的。

600表示十分钟,这个可以自己改。

文件夹视频多,会跳过时长短的。

for file in *.mp4; do duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" | awk '{print int($1)}'); if [ "$duration" -gt 600 ]; then start=0; count=1; while [ "$start" -lt "$duration" ]; do let end=$start+600; if [ "$end" -gt "$duration" ]; then end=$duration; fi; ffmpeg -i "$file" -c copy -map 0 -ss "${start}" -to "${end}" -segment_format mp4 "${file%.mp4}_part${count}.mp4"; let start=$end; let count=$count+1; done; fi; done

发布于 江西