我需要从视频中创建 12 个缩略图,但在开头和结尾跳过 10%。我发现了 this 的东西,但它只需要每 1000 帧。就我而言,这个范围是可变的,如果以秒为单位会更好。不知道如何使用 ffmpeg 做到这一点,不要经常使用它。
ffmpeg -ss $skip_time -i $input_path -vframes 1 -vf select=isnan(prev_selected_t)+gte(t-prev_selected_t\,$screenshot_time), scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih),pad=($width):($height):($width-iw)/2):($height-ih)/2),tile=3x4 -vcodec mjpeg $output_filename
$skip_time
- 从头开始跳过的时间
$screenshot_time
- 截图的时间间隔
这些值应该是预先计算好的,我使用
ffprobe
来获取视频时长。
我正在解决这个完全相同的问题,所以我将分享我的解决方案:
#!/bin/bash
thumb=160:90
tiles=4x3
for filename; do
duration=$(ffprobe \
-hide_banner \
-select_streams v \
-show_entries stream=duration \
-of csv \
"$filename" \
| cut -d, -f2)
interval=$(bc -e "scale=6;$duration/(${tiles/x/*}+1)")
select_filter="if(isnan(prev_selected_t),floor(t/$interval),floor(t/$interval)-floor(prev_selected_t/$interval))"
ffmpeg -i "$filename" \
-hide_banner \
-vframes 1 \
-vf select="${select_filter//,/\,},scale=$thumb,tile=$tiles" \
-update 1 \
-y "${filename%.*}.png"
done
我也尝试过使用
-r
选项,但发现它不太准确。