Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

c# - Can ffmpeg burn in time code?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

FFMPEG's drawtext filter works for me, you specify the starting timecode and its format thusly:

-vf drawtext="fontsize=15:fontfile=/Library/Fonts/DroidSansMono.ttf:
timecode='00:00:00:00':rate=25:text='TCR:':fontsize=72:fontcolor='white':
boxcolor=0x000000AA:box=1:x=860-text_w/2:y=960"

you have to specify timecode format in the form hh:mm:ss[:;,]ff. Note that you have to escape the colons in the timecode format string, and you have to specify a timecode rate (here 25fps). You can also specify additional text - here it's "TCR:"

You can get the frame rate with ffprobe and a bit of shell fu:

frame_rate=$(ffprobe -i "movie.mov" -show_streams 2>&1|grep fps|sed "s/.*, ([0-9.]*) fps,.*/1/")

So you could easily plug it all together in a batch - processing script, eg

for i in *.mov
frame_rate=$(ffprobe -i "$i" -show_streams 2>&1|grep fps|sed "s/.*, ([0-9.]*) fps,.*/1/")
clipname=${(basename "$i")/.*/}
ffmpeg -i "$i" -vcodec whatever -acodec whatever 
-vf drawtext="fontsize=15:fontfile=/Library/Fonts/DroidSansMono.ttf:
timecode='00:00:00:00':rate=$frame_rate:text='$clipname' TCR:':
fontsize=72:fontcolor='white':boxcolor=0x000000AA:
box=1:x=860-text_w/2:y=960" "${i/.mov/_tc.mov}"
done

That would add the clip's name and rolling timecode in a semi-opaque box at the bottom center of a 1920x1080 frame

Edit Since I've come to the dark side I now do this in a Windows Powershell environment, and this is what I use:

ls -R -File -filter *.M*|%{
ffmpeg -n -i $_.fullname -vf drawtext="fontsize=72:x=12:y=12:`
timecode='00:00:00:00':rate=25:fontcolor='white':`
boxcolor=0x000000AA:box=1" `
("c:pathodestination{0}" -F ($_.name -replace 'M[OPT][V4S]', 'mp4'))}

This creates mp4s given a folder containing .MOV, .MP4 and .MTS files (using the -filter command it looks for files with *.M* in the name, which you would have to change if you were doing .AVI files), and it's a bit more minimal, it just uses libx264 with default settings as output codec and doesn't specify font etc. The timecode in this case is burnt in at the top left of the frame.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...