in mapillary_tools/sample_video.py [0:0]
def extract_video_start_time(video_path: str) -> datetime.datetime:
streams = ffmpeg.probe_video_streams(video_path)
if not streams:
raise exceptions.MapillaryVideoError(
f"Failed to find video streams in {video_path}"
)
if 2 <= len(streams):
LOG.warning(
"Found more than one (%s) video streams -- will use the first stream",
len(streams),
)
stream = streams[0]
duration_str = stream["duration"]
try:
duration = float(duration_str)
except (TypeError, ValueError) as exc:
raise exceptions.MapillaryVideoError(
f"Failed to find video stream duration {duration_str} from video {video_path}"
) from exc
LOG.debug("Extracted video duration: %s", duration)
time_string = stream.get("tags", {}).get("creation_time")
if time_string is None:
raise exceptions.MapillaryVideoError(
f"Failed to find video creation_time in {video_path}"
)
try:
video_end_time = datetime.datetime.strptime(time_string, TIME_FORMAT)
except ValueError:
try:
video_end_time = datetime.datetime.strptime(time_string, TIME_FORMAT_2)
except ValueError:
raise exceptions.MapillaryVideoError(
f"Failed to parse {time_string} as {TIME_FORMAT} or {TIME_FORMAT_2}"
)
LOG.debug("Extracted video end time (creation time): %s", video_end_time)
return video_end_time - datetime.timedelta(seconds=duration)