You can watermark a video with two distinct timestamps by using FFmpeg's drawtext filter. This allows you to overlay one timestamp in UTC and another in AEST simultaneously. By specifying separate x and y coordinates for each text instance, you create a professional dual-time display without complex editing software.
Understanding the Drawtext Filter
The core of this solution relies on FFmpeg's powerfuldrawtext filter. This tool enables you to render text directly onto video frames during the encoding process. It supports various formatting options, including fonts, colors, and dynamic expressions that update every frame. For our specific use case, we need to leverage time-based expressions to ensure the timestamps remain accurate throughout the video duration.
When working with multiple overlays, it is crucial to understand that each instance of the drawtext filter must be defined as a separate expression within the filter chain. You cannot simply stack the same filter twice; instead, you chain them together or define them as separate filters linked in sequence. This approach ensures that the rendering engine processes each text element independently, allowing for precise positioning and distinct content.
Constructing the Command Line
To achieve the desired result, you will construct a command that includes two separatedrawtext definitions. The first definition handles the UTC timestamp, while the second manages the AEST timestamp. Both filters are combined into a single filter string separated by a comma.
Here is the basic structure of the command:
ffmpeg -i input.mp4 -vf "drawtext=text='%{localtime:%Y-%m-%d %H:%M:%S UTC}':x=10:y=10:fontsize=24:fontcolor=white, drawtext=text='%{localtime+8:%Y-%m-%d %H:%M:%S AEST}':x=10:y=50:fontsize=24:fontcolor=white" output.mp4
In this example, the first drawtext instance places the UTC time at the top-left corner (x=10, y=10). The format string %{localtime:%Y-%m-%d %H:%M:%S} generates the date and time in a readable hyphenated format. The second instance shifts the position to y=50 to avoid overlapping with the first timestamp. The key difference here is the addition of +8 to the localtime variable, which adjusts the base time to Australian Eastern Standard Time (AEST), assuming the source video is already in UTC. If your source video is not in UTC, you may need to adjust this offset accordingly.
For more advanced customization, consider exploring other video manipulation techniques such as Watermark Video with Two Timestamps. This related guide offers additional insights into layering visual elements effectively.
Positioning and Styling Options
Precise positioning is essential when displaying two timestamps. Thex and y parameters control the horizontal and vertical placement of the text, respectively. These values represent pixels from the top-left corner of the video frame. Using relative positioning is also possible by employing expressions like w-tw-10 for right-aligned text, where w is the video width and tw is the text width.
Styling the text enhances readability against various backgrounds. The fontsize parameter controls the size of the font, while fontcolor sets the color. You can use hex codes for specific colors, such as 0xFFFFFF for white. Adding a shadow or outline can improve visibility on bright or busy video segments. Although drawtext does not natively support drop shadows, you can achieve this effect by combining it with other filters like boxblur or by pre-rendering the text with transparency.
If you are dealing with large files, optimizing the encoding process is vital. Check out Resizing Video with FFmpeg: Two Passes, Without Aspect Ratio, Without Black Borders to learn how to maintain quality while managing file sizes efficiently.
Font Selection and Availability
FFmpeg requires a valid font file to render text. By default, it searches for common system fonts. However, for consistent results across different operating systems, it is recommended to specify the full path to a font file using thefontfile parameter. For example, fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf. Ensure that the font supports the characters you intend to display, especially if you are using special symbols or non-Latin scripts.
Handling Time Zones Correctly
Accurate time zone conversion is critical for dual-timestamp watermarks. Thelocaltime expression in FFmpeg uses the system's local time zone settings unless modified. To convert UTC to AEST, adding 8 hours is standard for standard time. However, during daylight saving periods, some regions in Australia observe AEDT (UTC+10). Therefore, a static offset might not always be correct depending on the date of the video recording.
For most security or surveillance applications, a fixed offset is often acceptable due to simplicity. If precise daylight saving awareness is required, you may need to calculate the offset dynamically using external tools or scripts before passing the value to FFmpeg. Alternatively, you can hardcode the specific offset for the known date range of the video footage.
Performance Considerations
Rendering text overlays in real-time can impact performance, especially on lower-end hardware. The CPU usage depends on the complexity of the filter graph and the resolution of the video. Using hardware acceleration, such as NVENC for NVIDIA GPUs or QSV for Intel, can significantly speed up the encoding process. When using hardware encoders, ensure that the filter graph is compatible with the chosen codec. Some advanced filters may not work seamlessly with all hardware acceleration profiles. Testing the command on a short segment of the video first is highly recommended. This allows you to verify the positioning, timing, and styling without waiting for a full-length encode to complete. Adjust the parameters iteratively until the output meets your visual requirements.Frequently Asked Questions
Why do my timestamps appear pixelated?
Pixelation usually occurs when the font size is too large relative to the video resolution or when scaling down the output. Ensure that the fontsize value is appropriate for the target resolution. Additionally, check if the output video is being downscaled incorrectly after the filter application.
Can I use a custom font for the timestamps?
Yes, you can specify any TrueType or OpenType font by providing its absolute path using the fontfile parameter. Make sure the font is accessible to the user running the FFmpeg command and that it supports the necessary character set for your language.
How do I align the text to the center?
To center the text horizontally, use an expression for the x coordinate such as (w-tw)/2, where w is the video width and tw is the text width. For vertical centering, use (h-th)/2, where h is height and th is text height.
What if my video is not in UTC?
If the source video's metadata does not reflect UTC, the localtime expression will use the system's local time. You must manually adjust the offset in the expression to match the intended time zone. For example, subtract hours if converting from a later time zone to UTC.
Does this method work with MP4 containers?
Yes, FFmpeg can apply these filters to MP4 containers provided the codec supports the resulting stream. H.264 and H.265 codecs are commonly used with MP4 and handle drawtext overlays without issue. Ensure the final container format is compatible with your playback devices.