首页 > 解决方案 > 提取帧上的 ffmpeg 时间戳错误/提取帧的时间戳相等

问题描述

我有一组具有不同长度、大小、fps 等的视频,并从每个视频中准确提取 60 帧作为图像,并在每帧上加上时间戳。

为此,我将每个视频的长度除以 60,并用于fps=1/x从视频中提取甚至几秒钟的帧。

这工作正常,但打印的时间戳略有偏差。

这是我使用的代码(bash 脚本的一部分)。

  1. 计算间隔:
output_frame_count=60
video_duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i file.mp4)
capture_distance=$(bc <<< "scale=0; ($video_duration / $output_frame_count)")
  1. 然后使用参数运行 ffmpeg
ffmpeg -i file.mp4 -vf "fps=1/$capture_distance,scale=-1:$height,drawtext=fontfile=/usr/...: text='%{pts\:gmtime\:0\:%H\\\\\:%M\\\\\:%S}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" frames%04d.png

我检查了图像,与提取它们的原始图像相比,所有时间戳都是错误的。

有没有人有一种更可靠的方法来从一个印有正确时间戳的视频中准确提取 60 帧?

标签: bashffmpeg

解决方案


推荐阅读