API Reference
DJIMetadataEmbedder
Embed DJI telemetry data into video files.
The embedder scans a directory for MP4 videos and their matching SRT files
and writes processed copies with subtitle tracks and metadata. A DAT flight
log can be merged if provided or automatically discovered. Processed files
are written to output_dir.
Parameters
directory: path to folder containing MP4/SRT pairs output_dir: destination directory for processed files (ignored if overwrite=True) overwrite: if True, write embedded video over the original file (in-place) dat_path: optional path to a DAT flight log dat_autoscan: search for DAT logs matching each video redact: GPS redaction mode ("none", "drop", "fuzz") time_offset: time offset in seconds to align SRT with MP4 resample_strategy: resampling strategy for SRT↔MP4 alignment ("linear", "nearest", "cubic")
Usage
embedder = DJIMetadataEmbedder("/videos", time_offset=0.5) embedder.process_directory()
Source code in src/dji_metadata_embedder/embedder.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
embed_metadata_exiftool(video_path, telemetry)
Use exiftool to embed GPS metadata (alternative/additional method).
Source code in src/dji_metadata_embedder/embedder.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
embed_metadata_ffmpeg(video_path, srt_path, telemetry, output_path, audio_path=None)
Embed SRT as subtitle track and add metadata using ffmpeg.
When audio_path is given (Neo 2 records audio to a separate .m4a,
issue #246), it is added as a third input and its audio stream is muxed
into the output. Audio is appended last so the SRT keeps input index 1
and the existing -map 1 subtitle mapping stays correct.
Source code in src/dji_metadata_embedder/embedder.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
parse_dji_srt(srt_path)
Parse DJI SRT file and extract telemetry data.
Source code in src/dji_metadata_embedder/embedder.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
process_directory(use_exiftool=False, on_progress=None)
Process all MP4/SRT pairs in the directory.
on_progress(index, total, name) is called (1-based) as each video
is picked up; passing it also disables the interactive progress bar
(the caller owns the display).
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing processing results and statistics |
Source code in src/dji_metadata_embedder/embedder.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
discover_video_files(directory)
Return the video files in directory the embedder can process.
Globs each supported extension in both cases (*.mp4 and *.MP4) so
discovery works on case-sensitive file systems too, then returns a sorted,
de-duplicated list. On case-insensitive file systems the two globs would
otherwise yield the same path twice, hence the set.
Source code in src/dji_metadata_embedder/embedder.py
109 110 111 112 113 114 115 116 117 118 119 120 121 | |
run_doctor(online=None)
Print system and dependency information.
online forces the opt-in update check on/off for this run (and
persists the choice); None uses the remembered consent, prompting
once on interactive terminals.
Source code in src/dji_metadata_embedder/embedder.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 | |
Conversion utilities for DJI SRT telemetry files.
This module contains helper functions for extracting telemetry data from DJI subtitle (SRT) files. The data can be converted to GPX tracks or CSV logs, and directories of SRT files can be processed in batch. A small CLI wrapper is provided for convenience.
batch_convert_to_csv(directory)
Convert all SRT files in a directory to CSV files.
Source code in src/dji_metadata_embedder/telemetry_converter.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
batch_convert_to_gpx(directory)
Convert all SRT files in a directory to GPX files.
Source code in src/dji_metadata_embedder/telemetry_converter.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
convert_to_csv(srt_file, output_file=None)
Wrapper for backwards compatibility.
Converts srt_file to CSV using :func:extract_telemetry_to_csv.
Source code in src/dji_metadata_embedder/telemetry_converter.py
520 521 522 523 524 525 | |
convert_to_gpx(srt_file, output_file=None)
Wrapper for backwards compatibility.
Converts srt_file to GPX using :func:extract_telemetry_to_gpx.
Source code in src/dji_metadata_embedder/telemetry_converter.py
512 513 514 515 516 517 | |
extract_telemetry_to_csv(srt_file, output_file=None, tz_offset=None, extract_home=False, redact='none')
Extract all telemetry data from a DJI SRT file to CSV.
When blocks carry an absolute wall-clock datetime, three extra columns are
filled: datetime_utc (ISO 8601; local->UTC via tz_offset or mtime
auto-detect) and the solar sun_azimuth / sun_elevation for that
instant and position. Formats without an absolute datetime leave those three
columns blank.
Source code in src/dji_metadata_embedder/telemetry_converter.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
extract_telemetry_to_gpx(srt_file, output_file=None, tz_offset=None, extract_home=False, redact='none')
Extract GPS telemetry from a DJI SRT file and create a GPX file.
DJI SRT timestamps are local wall-clock time with no timezone. When a block
carries an absolute datetime, its <time> is emitted as proper UTC
ISO 8601. The local-to-UTC offset is taken from tz_offset when given,
otherwise auto-detected from the SRT file's mtime (see
:func:estimate_utc_offset). Formats without an absolute datetime fall back
to the raw subtitle cue timestamp, as before.
Source code in src/dji_metadata_embedder/telemetry_converter.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
load_gps_points(path)
Return GPS points (_parse_gps_points shape) and whether they are UTC.
SRT: parse the text (datetimes are local wall-clock) -> is_utc=False.
Video: read via load_samples (ExifTool GPSDateTime is absolute UTC)
-> is_utc=True, so callers apply a zero local->UTC offset.
Source code in src/dji_metadata_embedder/telemetry_converter.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
summarize_sun(srt_file, tz_offset=None)
Summarise the sun's track over a clip for footage verification.
Resolves each GPS point's UTC time (via tz_offset or mtime auto-detect),
computes solar azimuth/elevation, and returns aggregate stats plus flags:
night (peak elevation below the horizon), very_low_sun (peak under
5 degrees), or sun_not_computable (no resolvable UTC time). Angular stats
are None when nothing could be computed.
Source code in src/dji_metadata_embedder/telemetry_converter.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
Home
dataclass
The drone's recorded HOME (launch) point — the operator's location.
Extracted only on explicit opt-in (--extract-home) and always passed
through :func:redact_home. Never written into the embedded MP4.
Source code in src/dji_metadata_embedder/utilities.py
288 289 290 291 292 293 294 295 296 297 298 | |
TelemetrySample
dataclass
One GPS-fixed SRT block: position, raw cue time, absolute datetime, and optional footprint inputs (relative altitude, 35mm-equivalent focal length, gimbal yaw/pitch) when the format carries them.
Source code in src/dji_metadata_embedder/utilities.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
apply_redaction(telemetry, mode)
Modify telemetry in place according to the redaction mode.
Source code in src/dji_metadata_embedder/utilities.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
check_dependencies()
Return (True, []) if external tools are available.
Source code in src/dji_metadata_embedder/utilities.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
estimate_utc_offset(first_local, last_local, file_mtime_utc)
Estimate the UTC offset of naive DJI SRT timestamps.
DJI SRT wall-clock timestamps are local with no timezone, while the source
file's mtime is UTC. We don't know whether the mtime marks the start or the
end of the recording, so both hypotheses are tested: for each anchor the
raw offset anchor - file_mtime_utc is rounded to the nearest quarter
hour (covering offsets such as UTC+5:30 and UTC+5:45), and the residual
distance from that boundary is kept. The hypothesis with the smaller
residual wins, since a genuine offset lands cleanly on a quarter hour.
Returns None when the best hypothesis falls outside the plausible
UTC-12..UTC+14 range (clamped symmetrically to +/-14h): the mtime then
cannot be the recording time — typically reset by a zip or cloud transfer
(#259). Callers fall back to raw cue timestamps.
All three datetimes must be naive (file_mtime_utc expressed in UTC).
Re-implemented from the heuristic described in GPStitch (https://github.com/Romancha/GPStitch, GPLv3) — idea only, no code copied.
Source code in src/dji_metadata_embedder/utilities.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
get_tool_versions()
Get versions of external tools if available.
Source code in src/dji_metadata_embedder/utilities.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
is_gps_fix(lat, lon)
Return True when (lat, lon) is a real GPS fix.
DJI firmware emits [latitude: 0.000000] [longitude: 0.000000] for every
frame recorded before the receiver acquires a fix. That exact (0, 0)
sentinel (Null Island) is never a genuine drone location, so it must be
excluded from geotagging and exported tracks.
Source code in src/dji_metadata_embedder/utilities.py
148 149 150 151 152 153 154 155 156 | |
iso6709(lat, lon, alt=0.0)
Return an ISO 6709 location string for QuickTime metadata.
Source code in src/dji_metadata_embedder/utilities.py
143 144 145 | |
load_samples(path)
Load telemetry samples from a DJI .SRT or a video (MP4/MOV) source.
SRT files are parsed directly; videos are read via the ExifTool-backed
:mod:dji_metadata_embedder.mp4_telemetry extractor. Imported lazily to
avoid a module-load cycle (mp4_telemetry imports from this module).
Source code in src/dji_metadata_embedder/utilities.py
254 255 256 257 258 259 260 261 262 263 264 265 266 | |
parse_dji_srt(srt_path)
Standalone wrapper around :class:DJIMetadataEmbedder parsing.
Source code in src/dji_metadata_embedder/utilities.py
536 537 538 539 540 541 | |
parse_home(text)
Return the first HOME point in SRT text, or None.
The caller is responsible for gating on the opt-in flag; this function does not check it. HOME is constant within a file, so the first match is used.
Source code in src/dji_metadata_embedder/utilities.py
310 311 312 313 314 315 316 317 318 319 320 | |
parse_telemetry_points(srt_path)
Parse an SRT file into a list of (lat, lon, alt, timestamp).
Backwards-compatible 4-tuple view over :func:parse_telemetry_samples.
Source code in src/dji_metadata_embedder/utilities.py
269 270 271 272 273 274 | |
parse_telemetry_samples(srt_path)
Parse an SRT file into :class:TelemetrySample records.
Same GPS extraction as the legacy 4-tuple parser (bracket format, GPS(...)
compact form, M300 altitude unit suffix, (0,0) no-fix filtering) plus the
block's absolute wall-clock datetime when present.
Source code in src/dji_metadata_embedder/utilities.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
parse_utc_offset(value)
Parse a CLI UTC-offset string into a :class:timedelta.
Returns None (meaning "auto-detect") for None, an empty string, or
"auto". Otherwise accepts a signed HH or HH:MM form such as
"+05:30", "5:45" or "-8". Raises :class:ValueError on any
other input.
Source code in src/dji_metadata_embedder/utilities.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
redact_coords(coords, mode)
Redact or fuzz coordinate list based on mode.
Source code in src/dji_metadata_embedder/utilities.py
277 278 279 280 281 282 283 284 285 | |
redact_home(home, mode)
Apply GPS redaction to a HOME point: drop -> None; fuzz ->
coordinates rounded to 3 decimals (~100 m); none -> unchanged.
Source code in src/dji_metadata_embedder/utilities.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
resolve_utc_offset(abs_datetimes, tz_offset, file_mtime_utc)
Resolve the single local->UTC offset for an SRT file.
Returns None when the file carries no absolute datetime (callers then
fall back to the raw cue time). An explicit tz_offset wins; otherwise the
offset is auto-detected from the file mtime via :func:estimate_utc_offset.
Source code in src/dji_metadata_embedder/utilities.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
setup_logging(verbose=False, quiet=False, json_logs=False)
Configure application wide logging.
All log output goes to stderr (issue #282): stdout is reserved for real
command output — summaries, exported data, --progress jsonl events.
The json_logs branch already logs to stderr (logging's default); the
Rich branch needs an explicit stderr console because RichHandler's
default console writes to stdout.
Source code in src/dji_metadata_embedder/utilities.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |