gpt4 book ai didi

ffmpeg - 准确的 FFmpeg 捕获开始时间

转载 作者:行者123 更新时间:2023-12-01 06:50:37 29 4
gpt4 key购买 nike

我正在使用命令行中的 ffmpeg 使用以下命令从网络摄像头捕获到文件:

ffmpeg -y -rtbufsize 702000k -f dshow -s 320x240 -r 25 -i video="<device name>" -t 10 -vcodec mjpeg -q:v 2 out.mp4

执行命令和开始捕获之间有一点延迟(~0.5 秒)。
我正在尝试找到一种方法来准确确定捕获的开始时间(UTC/GMT)。

我最初的想法是使用文件创建时间,因为这可能准确反射(reflect)第一帧的编码时间(而不是执行命令的时间)。不幸的是,文件创建时间仅精确到秒,这不够精确(而且我不确定这是否会给出准确的结果)。

我的下一个想法是使用 ffmpegs 时间戳选项。根据文档( http://www.ffmpeg.org/ffmpeg.html ):

‘-timestamp time (output)’

Set the recording timestamp in the container. The syntax for time is:

now|([(YYYY-MM-DD|YYYYMMDD)[T|t| ]]((HH:MM:SS[.m...])|(HHMMSS[.m...]))[Z|z])

If the value is "now" it takes the current time. Time is local time unless ’Z’ or ’z’ is appended, in which case it is interpreted as UTC. If the year-month-day part is not specified it takes the current year-month-day.



所以我添加了选项:
ffmpeg -y -rtbufsize 702000k -f dshow -s 320x240 -r 25 -i video="<device name>" -t 10 -vcodec mjpeg -q:v 2 -timestamp now out.mp4

不幸的是,ffmpeg 似乎不喜欢这样:

Option timestamp (set the recording timestamp ('now' to set the current time)) cannot be applied to output file out.mp4 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.

Error parsing options for output file out.mp4.

Error opening output files: Error number -22 occurred



文档说 -timestamp 是一个输出选项,它似乎应用于输出文件,所以我对这个错误感到困惑。

任何人都可以提出一种准确确定捕获开始时间的方法吗?

有谁知道为什么 -timestamp 选项会出错?

最佳答案

设置您的 PC 操作系统时间显示为 YYYYmmdd时间如 hhmmss然后更容易在批处理文件中获取时间并将其分配给第一帧,然后使用帧号除以帧速率将每个帧添加到原始时间戳。这是我能够获得流水账以在视频中显示时间的唯一方法。

 REM ## GETTIME ##
SET DTG1=Reserved
SET DT1=%DATE%%TIME%
IF "%DT1:~8,1%" EQU " " (SET DTG1=%DT1:~0,8%_0%DT1:~9,5%UTC) ELSE (SET DTG1=%DT1:~0,8%_%DT1:~8,6%UTC)
REM ## END GETTIME ##

@START /I /MIN /REALTIME c:\ff\FFmpeg.exe -y -loglevel error -rtbufsize 2.0e+009 -f dshow -r:v 10.000 -s 1920x1080 -vcodec mjpeg -i "video=Logitech HD Pro Webcam C920" -vf "fps=10.000,drawtext=fontfile=ocra.ttf:text=%DTG1%+%%{n}/10sec:fontsize=24:fontcolor=orange:x=999:y=19:box=0:boxcolor=black" -q 0 -f image2 B:\(%%d).jpg 1> nul 2> nul
@TIMEOUT /T 3 /NOBREAK 1> nul 2> nul
@START /I /MIN /REALTIME /W FFmpeg.exe -y -loglevel error -f dshow -ac 2 -r:a 44100 -i "audio=Line In (VIA HD Audio)" -f s16le -fs 63504000 B:\a.raw 1> nul 2> nul
@TASKKILL /F /IM FFmpeg.exe /T 1> nul 2> nul
@TASKKILL /F /IM FFmpeg.exe /T 1> nul 2> nul

至少我是这样做的。

关于ffmpeg - 准确的 FFmpeg 捕获开始时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21262786/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com