pythonvideonumpyffmpeglibvpx

Green Stripe Artifacts When Encoding Video With FFMPEG & Python


I'm attempting to encode (VP8 codec) and write a video using FFMPEG (version 2.3.3) and Python. However, I get these diagonal green stripe artifacts after I've finished encoding my video and I cannot find why.

I have a sequence of frames in memory in the form of numpy ndarrays, which I generate synthetically for test purposes using a method:

def _generate_test_images(self, samples=50):
    '''
    Creates an image array gradually changing from black to white
    '''
    pixelValues = np.linspace(0, 255, samples)

    imageList = [np.full((100, 100, 3), pixelValue, dtype=np.uint8)
                 for pixelValue in pixelValues]

    return np.array(imageList)

I then use the Python subprocess module to open a pipe to FFMPEG and write the image data. I have tried using stdin.write and communicate but both produce the green stripe problem. Here is how I interact with FFMPEG:

    import subprocess as sp
    params = get_params() #provides info like threads, frame size, etc.

    command = list()
    command.extend(['/opt/ffmpeg/bin/ffmpeg'])
    command.extend(['-y'])
    command.extend(['-f', 'rawvideo'])
    command.extend(['-vcodec', 'rawvideo'])
    command.extend(['-s', params['frameSize']])
    command.extend(['-pix_fmt', 'bgr24'])
    command.extend(['-r', '1'])
    command.extend(['-an'])
    command.extend(['-i', '-'])
    command.extend(['-an'])
    command.extend(['-codec:v', 'libvpx'])
    command.extend(['-quality', 'good'])
    command.extend(['-cpu-used', '0'])
    command.extend(['-b:v', params['bitrate']])
    command.extend(['-qmin', '4'])
    command.extend(['-qmax', '42'])
    command.extend(['-maxrate', '1M'])
    command.extend(['-bufsize', '2M'])
    command.extend(['-threads', params['threads']])
    command.extend(['-f', 'webm'])
    command.extend([params['target']])

    pipe = sp.Popen(command, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE, bufsize=-1)
    pipe.communicate(input=frameArray.tostring())

However when my video is done encoding, this is what I see:

Image with green stripe artifacts

What is causing this?


Solution

  • This usually has to do with width not divisible by 4 or 8 or some other similar number.