def read_config(config_filename):
    """Read the config file

    Return the input filename and a list of segments times

    Each time segment is a pair (start_time, duration) in seconds

    The format of the input file is:

    input_filename
    start_time_1,end_time_1
    start_time_2,end_time_2
    .
    .
    .
    start_time_N,end_time_N

    You may comment out lines with #

    """

    def time2seconds(t):
        components = t.split(':')
        seconds = 0
        for i, c in enumerate(components):
            seconds += int(c) * 60 ** (len(components) - i - 1)
        return seconds

    lines = open(config_filename).read().split('\n')
    input_file = lines[0]
    segment_times = []
    for line in lines[1:]:
        if line.startswith('#') or line == '':
            continue
        times = [time2seconds(x) for x in line.split(',')]
        duration = times[1] - times[0]
        if duration <= 0:
            raise RuntimeError('Start time > end time: ', line)
        segment_times.append((times[0], duration))

    return input_file, segment_times