import re


def _parse_ffmpg_results(stderr):
    """ Extract number of channels and sample rate from
    the given FFMPEG STDERR output line.

    :param stderr: STDERR output line to parse.
    :returns: Parsed n_channels and sample_rate values.
    """
    # Setup default value.
    n_channels = 0
    sample_rate = 0
    # Find samplerate
    match = re.search(r'(\d+) hz', stderr)
    if match:
        sample_rate = int(match.group(1))
    # Channel count.
    match = re.search(r'hz, ([^,]+),', stderr)
    if match:
        mode = match.group(1)
        if mode == 'stereo':
            n_channels = 2
        else:
            match = re.match(r'(\d+) ', mode)
            n_channels = match and int(match.group(1)) or 1
    return n_channels, sample_rate