def get_timecode(td):
    """Convert a timedelta to an ffmpeg compatible string timecode.

    A timecode has the format HH:MM:SS, with decimals if needed.
    """
    seconds = td.total_seconds()

    hours = int(seconds // 3600)
    seconds %= 3600

    minutes = int(seconds // 60)
    seconds %= 60

    str_seconds, str_decimals = str(float(seconds)).split(".")

    timecode = "{:02d}:{:02d}:{}".format(hours, minutes, str_seconds.zfill(2))
    if str_decimals != "0":
        timecode += ".{}".format(str_decimals)

    return timecode