filterffmpegtimestampdrawtext

FFmpeg timestamp watermark beginning at a specified offset


I am trying to extract a portion of video from another video file.

I want the second video file to be timestamped with the time in the original file from which the excerpt was extracted.

Here is the command so far.

#FILE TIME WATERMARK
    ffmpeg -ss "$startSecond" -i "$inputFile" -to "$endSecond" -vf "drawtext=text='%{pts\:hms}':fontfile=FreeSerif.ttf:fontsize=20:x=40:y=60:box=1:boxcolor=white@0.5:boxborderw=5" -c:v libx264 -crf 23 -preset medium -c:a libmp3lame -q:a 2 "$outputFile"

That part already works but the timestamp begins at 0 seconds.

How do I modify the command to begin the timestamp at the value in $startSecond?

I tried the following command.

ffmpeg -ss "$startSecond" -i "$inputFile" -to "$endSecond" -vf "drawtext=text='%{pts+$startSecond\:hms}':fontfile=FreeSerif.ttf:fontsize=20:x=40:y=60:box=1:boxcolor=white@0.5:boxborderw=5" -c:v libx264 -crf 23 -preset medium -c:a libmp3lame -q:a 2 "$outputFile"

The only difference is that I added the value of $startSecond to pts.

I couldn't find the documentation on the timestamping method for the drawtext filter. If anyone can find it I would appreciate it.


Solution

  • Found the documentation on the ffmpeg website and figured it out.

    Here is the section containing the drawtext functions, pts is at the end.

    The pts function takes a second argument which is the offset in seconds.

    Also drawtext does not like it when you do not escape the apostrophes.

    The proper way to supply an offset is in the code snippet below. Just remember that you have to escape the apostrophes or the parameter won't work.

    ffmpeg -ss "$startSecond" -i "$inputFile" -to "$endSecond" -vf "drawtext=text=\'%{pts\:hms:$startSecond}\':fontfile=FreeSerif.ttf:fontsize=20:x=40:y=60:box=1:boxcolor=white@0.5:boxborderw=5" -c:v libx264 -crf 23 -preset medium -c:a libmp3lame -q:a 2 "$outputFile"
    

    Cheers