我正在尝试创建一个能够正确显示源视频的 TC 的 TC 烧入。
我当前的 FFMPEG 过滤器系列是:
-filter_complex "[0:1][0:2] amerge" -preset ultrafast -vf scale=960:540:in_range=tv:out_range=pc,"drawtext=\timecode='00\:00\:00\:00':timecode_rate=25:x=(w-tw)/2:y=h-(2*lh):fontcolor=white@1:fontsize=30:box=1:[email protected]" -c:v libx264 -pix_fmt yuv420p -crf 27 -c:a aac -ar 48000 -b:a 128k
这当然会在 00:00:00:00 开始烧录,但我宁愿插入文件的 TC(在本例中,它从 10:00:00:00 开始)——从 MediaInfo 获取的数据:
Other #1
ID : 1-Material
Type : Time code
Format : MXF TC
Frame rate : 25.000 FPS
Time code of first frame : 10:00:00:00
Time code of last frame : 10:02:34:20
Time code settings : Material Package
Time code, stripped : Yes
Title : Timecode
Other #2
ID : 0-Source
Type : Time code
Format : MXF TC
Frame rate : 25.000 FPS
Time code of first frame : 10:00:00:00
Time code of last frame : 10:02:34:20
Time code settings : Source Package
Time code, stripped : Yes
Other #3
Type : Time code
Format : SMPTE TC
Muxing mode : SDTI
Frame rate : 25.000 FPS
Time code of first frame : 10:00:00:00
我还没有找到让 FFMPEG 读取 TC 并将其用于 Burn-In 的方法。你们有人知道如何做到这一点吗?
谢谢 克里斯蒂安
以防万一有人遇到同样的问题:ffmpeg 本身无法读取文件的 TC 并用它来刻录 TC(截至 2023 年 1 月)。
我使用的编码工作流程工具(FFAStrans - 它是免费的,而且很棒)可以实现此目的:https://ffastrans.com/frm/forum/viewtopic.php?f=5&t=1442
它是可以制作的。
您可以使用 ffprobe 获取时间码值,然后将该字符串注入到drawtext的
timecode='00\:00\:00\:00'
中。
我为此编写了一个小 shell 脚本:
INPUT=myinputfile.mp4
OUTPUT=myoutputfile.mp4
# Parse Start TC of data stream with ffprobe:
# > video stream (v) also has a timecode tag, always the same?
TC=$(ffprobe -v error -select_streams d -show_entries stream_tags=timecode -of default=noprint_wrappers=1:nokey=1 $INPUT)
if [[$TC = ""]]; then
TC="00:00:00:00"
fi
echo "TC: "$TC
# Parse Frame Rate of video stream with ffprobe :
FPS=$(ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate $INPUT)
if [[$FPS = ""]]; then
FPS="25/1"
fi
echo "FPS: "$FPS
# String replacement:
TCR=${TC//:/\\:}
echo $TCR
# TODO: padding around box
# TODO: use space character in text
DRAW="fontfile=/Library/Fonts/DroidSansMono.ttf:timecode='$TCR':rate=$FPS:text='TC_':fontsize=72:[email protected]:[email protected]:box=1:x=W/2-tw/2:y=H-(H*0.12)"
echo $DRAW
# Finished command:
ffmpeg -i $INPUT -vf drawtext=$DRAW -y $OUTPUT
不幸的是,有常见的 shell 字符串转义骗局,并且可能有更简洁的编写方式。但它有效。