Created
June 5, 2025 19:16
-
-
Save Ben754444/82b9add7ec1a27fb566d3b54811cec49 to your computer and use it in GitHub Desktop.
add timestamp to video using ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ffmpeg -i "SB25 Timelapse.MP4" -filter_complex "[0:v]sendcmd=f=test.cmd,drawtext=fontfile='C\:/Users/benja/Downloads/droid-sans-mono/DroidSansMono.ttf':text='': fontcolor=white:fontsize=96:fontcolor=white:box=1:boxcolor=black@0.5:x=10:y=10" output.mp4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime, timedelta | |
| def create_cmd_file(start_time, fps, interval_seconds, output_file, duration): | |
| frame = 0 | |
| with open(output_file, 'w') as f: | |
| current_time = start_time | |
| total_frames = int(duration * fps) | |
| while frame <= total_frames: | |
| n = frame / fps | |
| next_n = (frame + 1) / fps | |
| time_str = current_time.strftime('%Y-%m-%d %H:%M:%S').replace(':', '\\:') | |
| cmd = f"{n:.6f}-{next_n:.6f} drawtext reinit 'text={time_str}';\n" | |
| f.write(cmd) | |
| current_time += timedelta(seconds=interval_seconds) | |
| frame += 1 | |
| print("success") | |
| if __name__ == "__main__": | |
| START_TIME = datetime(2025, 5, 30, 13, 1, 0) | |
| FPS = 29.97003 | |
| INTERVAL_SECONDS = 15 | |
| DURATION = (7 * 60) + 21 + 1 | |
| OUTPUT_FILE = "sendcmd.cmd" | |
| create_cmd_file(START_TIME, FPS, INTERVAL_SECONDS, OUTPUT_FILE, DURATION) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment