rachpt / AutoSeed

全自动发种姬 [流程图 https://www.processon.com/view/link/5c088855e4b0ca4b40c93a49 ]

Home Page:https://rachpt.cn/AutoSeed/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ffmpeg 截图优化

rachpt opened this issue · comments

目前的实现方式如下:

$ffmpeg -ss "$start" -i "$file" -frames 1 -vf "framestep=$step,scale=$size:-1,tile=${column}x${row}:nb_frames=0:padding=5:margin=5:color=random" "$screen_file" -y

使用 framestep 几乎遍历整个文件 取帧,然后使用 tile 合在一张jpg图片里面。
优点是代码较简洁,缺点相当突出: 相当于 快进播放一遍视频,对 cpu占用加大,时间 10-40秒不等,和视频时长与质量正相关。

改进思路:

  1. 先计算等分截图时间点 帧转 秒,
  2. 使用循环,ffmpeg -ss "$each_time" -i "$file" -frames 1 outfile...,-ss 在 -i 前面,截取单张耗时 0.5 秒左右。
  3. 最后将 上面得到的图片 3x3 或则 3x4 使用 ffmpeg tile 合并到一起。

最近忙,此坑下学期填!欢迎 pull requests。


一样的效果,现在的方案 小于 5 秒。

#! /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

参考链接.