Can ffmpeg burn in time code?

后端 未结 7 1646
天涯浪人
天涯浪人 2020-12-07 21:16

I have a need to burn in a time code to a video and am wondering if this is something that ffmpeg is capable of?

7条回答
  •  庸人自扰
    2020-12-07 22:02

    Here's my solution, and I believe it is the correct one, because it both avoids having to manually set the rate, and allows you to format the output.

    ffmpeg -i test.mp4 -vf \
        "drawtext=fontfile=arialbd.ttf:text='%{pts\:gmtime\:0\:%H\\\:%M\\\:%S}'" test.avi
    

    This produces a stamp in the HH:MM:SS format; you can change it to whatever you'd like, using strftime.

    It may look like it's going to put in a timestamp with gmtime, but that's not what happens. It actually feeds the video's current time, in seconds, to gmtime, producing a date which is 1/1/1970, and a time which is however many seconds after midnight. So you just discard the date portion and use the time portion.

    Take note of the triple escaped colons within the pts function, which you'll have to do if you enter it like I did above. Also you can see that I copied my font file for Arial Bold and dropped it right into the working directory for simplicity.

提交回复
热议问题