FFmpeg用于根据参考日期标记时间视频 [英] FFmpeg for marking time video based on a reference date

查看:126
本文介绍了FFmpeg用于根据参考日期标记时间视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 drawtext 过滤器标记视频中的时间戳.FFmpeg可以轻松地基于 localtime gmtime 甚至是 PTS 标记时间戳.但是,我想为时间戳分配一个参考时间(开始时间),以表示视频被录制(未编码)的时间.

I am trying to mark a timestamp in a video using drawtext filter. FFmpeg easily marks timestamps based on localtime, gmtime or even PTS. However, I want to assign a reference time (start time) for the timestamp in order to represent the time the video was recorded (not encoded).

在阅读文档时,我发现选项 basetime 可以用于此目的.但是,似乎无法正常工作,或者我缺少了一些东西.

Reading the documentation, I found that option basetime can be used for this purpose. However it seems that is not working or I am missing something.

我正在使用的命令行是:

The command line I am using is:

ffmpeg -y -i input.mp4 -filter_complex drawtext="fontfile=/tmp/UbuntuMono-B.ttf: fontsize=36: fontcolor=yellow: box=1: boxcolor=black@0.4: text='Wall Clock Time\: %{gmtime\:%Y-%m-%d %T}': basetime=1456007118" output.mp4

通过使用 basetime = 1456007118 ,可以将开始时间设置为"02/20/2016 20:25:18",因为1456007118是该时间和日期的UTC时间:

By using basetime=1456007118, it was expected the start time was set to '02/20/2016 20:25:18' since 1456007118 is the UTC time for that time and date:

date -d '02/20/2016 20:25:18' +"%s" # format MM/DD/AAAA hh:mm:ss
1456007118

但是,FFmpeg不会发出任何错误,并且视频会标​​记为当前GMT,而忽略了 basetime 选项.

However, no error is issued by FFmpeg and the video is marked with current GMT, ignoring basetime option.

有任何提示吗?谢谢.

有关FFmpeg版本和输出的完整信息是:

Complete information about FFmpeg version and output is:

ffmpeg -y -i /home/denio/Videos/Interstellar_2014_Trailer_4_5.1-1080p-HDTN.mp4 -filter_complex drawtext="fontfile=/tmp/UbuntuMono-B.ttf: fontsize=36: fontcolor=yellow: box=1: boxcolor=black@0.4: text='Wall Clock Time\: %{gmtime\:%Y-%m-%d %T}': basetime=1470226363" /tmp/x.mp4 
ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.3.1 (Ubuntu 5.3.1-14ubuntu2.1) 20160413
  configuration: --enable-libxavs --enable-bzlib --enable-libfaac --enable-libfreetype --enable-libfontconfig --enable-libmp3lame --enable-libschroedinger --enable-libspeex --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-zlib --enable-x11grab --enable-static --enable-pthreads --enable-gpl --enable-nonfree --enable-version3 --disable-ffserver --enable-libgsm --enable-librtmp --enable-libvpx --enable-libschroedinger --enable-libopencore-amrnb --enable-libopenjpeg
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
...
...

推荐答案

我在源代码中看到了 basetime ,但在Web文档中却没有看到,因此不确定该如何工作.

I see the basetime in the source code, but not in the web documentation, so not sure how it's supposed to work.

您可以改为使用 pts 函数.

ffmpeg -y -i input.mp4 -vf "drawtext=fontfile=/tmp/UbuntuMono-B.ttf:
                            fontsize=36:fontcolor=yellow:
                            box=1:boxcolor=black@0.4:
                            text='Wall Clock Time\: %{pts\:gmtime\:1456007118}'"
   output.mp4

您可能需要在绘制文本之前重置PTS( setpts = PTS-STARTPTS ).

You may need to reset PTS (setpts=PTS-STARTPTS) before the drawtext.

这篇关于FFmpeg用于根据参考日期标记时间视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆