将日期时间转换为unix后,无法从FFMPEG获得准确的时间戳

发布于 2025-02-08 23:56:28 字数 802 浏览 1 评论 0原文

我正在创建视频编辑应用程序。我创建了一个ObservableCollection,其中包含有关每个帧的信息,每秒30个。我已经将DateTime每帧计算为VideocreationDate + Framenumber / 29.97。当我用文本块覆盖每个帧的当前时间和日期时,时间是完全准确的。但是,一旦我将日期时间转换为UNIX时间并将其用作ffmpeg绘制文本过滤器中的参数,时间就会略有关闭。前几个帧是准确的,并且在我通过框架擦洗的情况越多。我正在检查每个帧上的UNIX时间戳,这是正确的,但是由于某种原因,当我渲染FFMPEG命令时,它会将时间戳转换为日期时间不准确。

以下是将DateTime转换为UNIX的方法:

public long ToUnixTimestamp(DateTime value)
    {
        var dateTimeOffset = new DateTimeOffset(value);
        var unixDateTime = dateTimeOffset.ToUnixTimeSeconds();
        Debug.WriteLine(unixDateTime);
        return unixDateTime;
    }

以下是包含DrawText过滤器的FFMPEG字符串的一部分:

drawtext=text=\'%{pts\:localtime\:" + ToUnixTimestamp(CurrentFrame.FrameTime) + @"\:'%#I\:%M%p'}\'

我不确定我是否在做错了什么,或者这是否是FFMPEG的缺陷。有什么想法吗?

I am creating a video editing application. I have created an ObservableCollection which contains information regarding every frame, 30 per second. I have computed the DateTime per frame as VideoCreationDate + FrameNumber / 29.97. When I display the current time and date with a TextBlock overlaying each frame, the time is perfectly accurate. However, once I convert the date time to Unix time and use it as parameters in the FFMPEG DrawText filter, the time is slightly off. The first few frames are accurate and progressively get worse off the more I scrub through the frames. I am checking the Unix timestamp on each frame and it is correct but for some reason, when I render the FFMPEG command, it converts the timestamp to date time inaccurately.

Below is the method to convert DateTime to Unix:

public long ToUnixTimestamp(DateTime value)
    {
        var dateTimeOffset = new DateTimeOffset(value);
        var unixDateTime = dateTimeOffset.ToUnixTimeSeconds();
        Debug.WriteLine(unixDateTime);
        return unixDateTime;
    }

Below is part of the FFMPEG string containing the DrawText filter:

drawtext=text=\'%{pts\:localtime\:" + ToUnixTimestamp(CurrentFrame.FrameTime) + @"\:'%#I\:%M%p'}\'

I am not sure if I am doing something wrong or if this is a flaw with FFMPEG. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文