[SOLVED] ofDirectShowPlayer : getPixels() problem

Having trouble using the getPixels() method and no luck in tracking down exactly why.

VS debugger is throwing an error at processPixels(), specifically:
dstPixel[1] = srcPixel[1]
in the “if(src.getPixelFormat() == OF_PIXELS_BGR)” block.

I had thought that it was possible that since ‘dst’ is being reallocated in that block, that dstLine and endLine needed to be reset. Didn’t help. It’s odd to me that it’s got a problem at 'pixel[1] and not 'pixel[0].

Only other error:
ERROR: SampleCB<> - buffer sizes do not match 6220800 8294400

I’m loading ‘standard’ 1080p mp4 videos that did not cause a problem before the recent github update.

referencing https://github.com/openframeworks/openFrameworks/issues/4679
and the recent commit that closed it

Any help is very appreciated as I’ll need to try to revert back before the end of the day if I can’t figure this out. Thanks!!

It could be that, that is the issue.
could you try duplicating the lines above after that allocate call and see if that fixes it?

I created a GH issue as it seems like a regression:
https://github.com/openframeworks/openFrameworks/issues/4716

Any sample code or info on the video format / dimensions etc that you could post to the issue could be helpful.

Thanks!!
Theo

yes that seems to be the problem i think i refactored out those lines since they were duplicated but i didn’t realized that the dst could be reallocated in that line, can you move these 3 lines:

auto dstLine = dst.getLines().begin();
auto srcLine = --src.getLines().end();     
auto endLine = dst.getLines().end();

inside the if and else right after dst.allocate?

if that works and you want to send a PR that would be great, otherwise i’ll fix it later

My code is using getPixels() to access a single pixel color which controls the color of a button which sits on top of the video as it’s playing. It’s within the check to player.isFrameNew().

Duplicating the assignment of dstLine and endLine didn’t solve it.

The videos I’m using are either 1080p, 720p, or an odd size (to me): 1920x1072. Nearly all were encoded with Adobe Media Encoder. I’ve tried with 5-6 different videos with the same result.

MPEG-4, mp42, variable bit rate
AVC/Advanced Video Codec. Some are Baseline@L4, others are Main@L4.1
NTSC / YUV / 4:2:0

Thank you for looking into it!

Checked it again with the suggested fix and the issue persists.

One thing I noticed in the debugger in the ‘Autos’ tab:
dstLine – seems fine
dstPixel – seems fine
endPixel – seems fine
srcLine – “Error reading characters of string.” for _begin only. _end appears to be fine.
srcPixel – “Error reading characters of string.”. …for ‘pixel’. it shows componentsPerPixel = 4, and pixelFormat = OF_PIXELS_BGRA (5)

ahh - if it is showing it as a BGRA video could you try adding the same lines below this line:

are you setting BGRA explicitly? the error in the debugger is normal, it’s just trying to interpret the unsigned char * as a string but since it’s not some chars are not valid and errors out but has nothing to do with the crash

Nope, not setting as BGRA. But your question reminded me that I had looked at DirectShowVideo::getPixels() and wondered about the switch statement. There are no ‘breaks’ in the switch(pixelFormat) block, so the srcBuffer was being set to BGR, then again to BGRA every time.

I added breaks (along with the previous suggestion), and it now runs just fine! I could be imagining a small performance hit in Debug mode, as don’t think I’m seeing it in Release, but I wasn’t paying a ton of attention to that while debugging (and dealing with 20fps vs 60fps in release).

Anyway - thanks gents for the assistance. I’d be happy to submit a PR, but I wouldn’t be able to until Friday, as this app is getting deployed tomorrow! :wink:

Seriously, thanks again.

oh thanks, not sure how i missed that probably some last minute change and i was testing then with rgba. i’ve fixed it in master