linux - 使用 ffmpeg 截取多个屏幕截图

标签 linux bash shell video ffmpeg

我正在使用下面的代码在某个时间从视频中截取屏幕截图,但我想知道如何在 1 个命令中从视频中截取多个屏幕截图(4-5 或更多)。它可以在特定时间或随机时间/时间间隔。

#!/bin/bash



for f in *.mkv

 do
    
    ffmpeg  -i "$f" -ss 00:02:05 -frames:v 1 -q:v 2 "done/${f%.*}.jpg"

done
按照用户@kesh 的建议尝试了以下命令,但收到错误
    #!/bin/bash

    for f in *.mkv

 do
    
    ffmpeg  -vsync vfr  -i "$f"  -vf select=\"'eq(n,2988)+eq(n,4302)'\" "done/${f%.*}.jpg"
done
错误:
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[Parsed_select_0 @ 0x55e693319c80] [Eval @ 0x7ffcd4efd840] Missing ')' or too many args in '"eq(n'
[Parsed_select_0 @ 0x55e693319c80] Error while parsing expression '"eq(n'
[AVFilterGraph @ 0x55e693df0d00] Error initializing filter 'select' with args '"eq(n'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

最佳答案

如果您知道帧速率(并且它是恒定的),那么您可以使用 the select filter和帧索引。

ffmpeg -vsync vfr -i input -vf select='eq(n,3750)+eq(n,5400)' capture_%d.jpg
在这里,假设 fps=30, 0:02:05 * 30 = 125 * 30 = 3750 和 00:03:00 = 180 * 30 = 5400。+or逻辑运算符。见 expression docs
如果您只在视频的前半部分进行捕捉,您可能需要添加 -t输入选项以在较早时停止运行。
[更新:]
  • 原版遗漏-vsync vfr :必须具备,否则你会得到一堆重复以保持输入帧率
  • 修复了丢失的 .用于输出扩展
  • 关于linux - 使用 ffmpeg 截取多个屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72311860/

    相关文章:

    linux - 关于 fork 和 execve 系统调用

    Bash - 返回一个 bool 检查

    linux - 比较文件系统空间使用情况随时间的变化

    linux - 我想使用 "awk"或 sed 打印文件中所有以 "comm="开头的行

    linux - 在数据文件中查找唯一值

    bash - SH脚本根据文件名将文件从一个目录移动到另一个目录

    c - 当我尝试在 Linux 上编译而不是在 Mac 上编译时,为什么会收到 "error: implicit declaration of function ‘fileno’

    linux - Linux 的/dev/usb/lp0 的 OSX 版本是什么?

    c - pthread_create 可以创建的最大线程数是多少?

    c - 下面的 bash 程序调用做了什么?