ofXVideoRecorder with yuv420p pixel format

I have an encoding problem here.

I’m trying to use ofxVideoRecorder to create a video with ofPixels obtained from a webcam with ofxVideoGrabber.

Using default ffmpeg4 video codec and rgb24 pixel format generates a video that is playable in QuickTime and Safari, but not in Google Chrome.

Changing the video codec to libx264 (using default rgb24 pixel format) generates a video that cannot be reproduced in QT nor in Safari and mobile version of Chrome (Android).

Doing some research, I found that to make the video compatible with most players, yuv420p pixel format must be set. When I set these parameters to ofxVideoRecorder, the generated video looks like hell, but this ugly video plays everywhere (desktop and mobile Chrome, Safari, QuickTime).
Generated video looking like hell is understandable, because the pixels grabbed by ofxVideoGrabber are in rgb pixel format. What I don’t understand is why the generated video is played everywhere.

The most important for me is that the video can be played in mobile browsers.

What should I do to make this work? Any ideas are welcome.

I found a solution.

I didn’t realize that the -pix_fmt option could also be set to the output of ffmpeg.

I added support ofxVideoRecorder to optionally set the output pixel format. I made a pull request (already merged) to the ofxVideoRecorder repository adding it the capability to set this parameter.

ofxVideoRecorder vidRecorder;