def read_one_ppm(f):
    """
    Read exactly one PPM file from a concatenated stream of PPM files.
    Designed to be used for ffmpeg vhook processing
    @return: PPM string
    """
    
    ppm=""
    formatDef=f.readline() # Read format definition from stream
    if formatDef=="":
        # Supposedly we've reached end of file
        raise NoMorePPM()

    format=re.match("P\d", formatDef, re.I)
    assert format is not None
    ppm+=formatDef
    sizeDef=f.readline()
    sizeMatch=re.match("(\d+)\s+(\d+)",sizeDef)
    assert sizeMatch is not None

    
    (x,y)=sizeMatch.groups()
    if DEBUG:
        sys.stderr.write("X: %s, Y: %s\n" % (x,y))
    ppm+=sizeDef
    maxCol=f.readline()
    ppm+=maxCol
    ppm+=f.read(int(x)*int(y)*3)    # Read 24bit units
    if DEBUG:
        sys.stderr.write("Len: %s\n" % str(ppm.__len__()))
    return ppm

    Read exactly one PPM file from a concatenated stream of PPM files.
    Designed to be used for ffmpeg vhook processing
    @return: PPM string
    
recipes/Python/572220_ffmpeg_ppmso_vhook_plugin/recipe-572220.py