video#

mediautils.video.rotate_video(path: str | PathLike, angle: int = 90, out_dir: str | PathLike = 'out', out_name: str | None = None) → Path[source]#

Write a rotated copy of a video.

Parameters:
  • path (str | os.PathLike) – Path to the source video.

  • angle (int) – Rotation angle in degrees (90, 180, or 270).

  • out_dir (str | os.PathLike) – Directory where the rotated video is saved. Created if it does not exist.

  • out_name (str | None) – Output file name. If None, the original file name is kept.

Returns:

Path to the output file.

Return type:

Path

mediautils.video.set_all_dates_video(path: str | PathLike, dt: datetime, out_dir: str | PathLike = 'out', out_name: str | None = None, tz: str = 'Europe/Paris', locked_shift: timedelta = datetime.timedelta(0)) → tuple[Path, dict[str, str]][source]#

Write a copy of a video with every date it carries set to dt.

Every date tag already present in the file (container and track dates, Keys/ItemList/XMP dates, …) is overwritten with dt; no tag is created, since an MP4/MOV always carries its container and track dates. The XMP “Pantry” of Adobe exports, a copy of the metadata of the source files of a montage (whose dates are not those of the video), is removed. Lists of dates are left as they are if known to be harmless (the save history of Adobe software, which gives the true dates of the editing work), and make the operation fail otherwise. The filesystem modification, access and (on Windows) creation times are set too. The tags are read back afterwards:

  • a tag holding dt is fine;

  • a tag exiftool cannot write (e.g. the EXIF block, Panasonic’s TimeStamp or the XML clip metadata of Lumix cameras) is first shifted by locked_shift, if any, directly in the file (see _patch_locked_dates()); it is then accepted if it denotes the wall-clock time dt, give or take one second (offset ignored; a tag stored in UTC by the camera is converted with the offset the camera recorded), and reported;

  • any other tag makes the whole operation fail, and no copy is left.

QuickTime dates are stored in UTC, as phones do; dt is converted using the UTC offset of tz at that date (daylight saving time included). Requires exiftool on PATH. Unlike set_time_video(), the video is not remuxed.

Parameters:
  • path (str | os.PathLike) – Path to the source video.

  • dt (datetime) – The datetime to write, naive, as local wall-clock time in tz.

  • out_dir (str | os.PathLike) – Directory where the modified copy is saved. Created if it does not exist.

  • out_name (str | None) – Output file name. If None, the original file name is kept.

  • tz (str) – IANA timezone in which dt is expressed.

  • locked_shift (timedelta) – Shift to apply to the date tags exiftool cannot write: the difference between dt and the datetime these tags hold (e.g. the correction of a camera clock that was off).

Returns:

Path to the output file, and the tags exiftool could not write, with their final values (name to value).

Return type:

tuple[Path, dict[str, str]]

Raises:

RuntimeError – If a date tag does not denote dt after writing (the copy is removed).

mediautils.video.set_time_video(path: str | PathLike, dt: datetime, out_dir: str | PathLike = 'out', out_name: str | None = None) → Path[source]#

Write a copy of a video with its timestamps set to dt.

Sets the filesystem modification/access times and the MP4 container creation_time metadata (via ffmpeg).

Parameters:
  • path (str | os.PathLike) – Path to the source video.

  • dt (datetime) – The datetime to write into the metadata.

  • out_dir (str | os.PathLike) – Directory where the modified copy is saved. Created if it does not exist.

  • out_name (str | None) – Output file name. If None, the original file name is kept.

Returns:

Path to the output file.

Return type:

Path

mediautils.video.write_precise_start(path: str | PathLike, start: datetime, frame_rate: float | None = None, tz: str = 'Europe/Paris', precise: bool = True) → None[source]#

Record, in place, the start of a video more precisely than to the second.

Writes in the XMP metadata of the file (xmpDM:shotDate) the start of the recording to the millisecond and, if frame_rate is given and supported, a time-of-day start timecode to the frame (xmpDM:startTimecode), which editing software can use to synchronize several cameras. Nothing else in the file changes (no remuxing). The name and the other dates of the file, which stay to the second, are left alone.

Parameters:
  • path (str | os.PathLike) – Path to the video, modified in place.

  • start (datetime) – Start of the recording, naive, as local wall-clock time in tz.

  • frame_rate (float | None) – Frame rate of the video, for the timecode (none if None).

  • tz (str) – IANA timezone in which start is expressed.

  • precise (bool) – If False (start only known to about a second), the date is written to the second and no timecode is written.