ffmpeg 截图优化
rachpt opened this issue · comments
rachpt commented
目前的实现方式如下:
Line 27 in 96510bf
使用
framestep
几乎遍历整个文件 取帧,然后使用 tile
合在一张jpg图片里面。优点是代码较简洁,缺点相当突出: 相当于 快进播放一遍视频,对 cpu占用加大,时间 10-40秒不等,和视频时长与质量正相关。
改进思路:
- 先计算等分截图时间点 帧转 秒,
- 使用循环,
ffmpeg -ss "$each_time" -i "$file" -frames 1 outfile...
,-ss 在 -i 前面,截取单张耗时 0.5 秒左右。 - 最后将 上面得到的图片 3x3 或则 3x4 使用
ffmpeg tile
合并到一起。
最近忙,此坑下学期填!欢迎 pull requests。
rachpt commented
#! /usr/bin/env bash
ratio="$(mediainfo "$1" --Output="Video;%FrameRate%")"
total="$(mediainfo "$1" --Output="Video;%FrameCount%")"
step=$(echo "($total - 3000)/(12 * $ratio)"|bc)
for ((i=0;i<12;i++)); do
( ffmpeg -ss "$(echo "(1500/$ratio)+($step * $i)"|bc)" -i "$1" -vframes 1 -vf "scale=500:-1" "out-${i}.jpg" -y 2>/dev/null ) &
#ffmpeg -ss "$(echo "(1500/$ratio)+($step * $i)"|bc)" -i "$1" -vframes 1 -vf "scale=500:-1" "out-${i}.jpg" -y 2>/dev/null
done
wait
ffmpeg -i "out-%d.jpg" -filter_complex "tile=3x4:nb_frames=0:padding=5:margin=5:color=random" out-put.jpg -y 2>/dev/null
rm -f out-[0-9]*.jpg
参考链接.