ffmpeg video to opengl texture

前端 未结 2 1461
梦如初夏
梦如初夏 2020-12-07 12:44

I\'m trying to render frames grabbed and converted from a video using ffmpeg to an OpenGL texture to be put on a quad. I\'ve pretty much exhausted google and not found an an

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 13:17

    The file being used is a .wmv at 854x480, could this be the problem? The fact I'm just telling it to go 512x256?

    Yes!

    The striped pattern is an obvious indication that you're mismatching data sizes (row-size.). (Since the colors are correct, RGB vs BGR vs BGRA and n-components is correct.)

    You're telling OpenGL that the texture you're uploading is 512x256 (which it isn't, AFAICT). Use the real dimensions (NPOT, your card ought to support it if it's not ancient).

    Otherwise, resize/pad your data before uploading it as a 1024x512 texture.

    Update

    I'm more familiar with OpenGL that the other functions you're calling.

    sxs_scale might to what you want (i.e. scaling the image down to a pot-size). However, scaling each frame might be slow.

    I'd use the padding instead (which means, copy a small image (your video) into a part of a big texture (opengl)

    Some other tips:

    • Do you really need mipmaps? Only generate them if you need to downscale your texture smoothly (usually only needed when it's on some 3d-geometry).
    • Avoid mipmap generation at runtime if you're rendering a video (especially, don't use gluBuildMipMaps2D, as that might run in software. There are other ways that is faster, if you need mipmapping (such as using GL_GENERATE_MIPMAP texture parameter). Seee this thread for more info.
    • Avoid calling glTexImage repeatedly, as that creates a new texture. glTexSubImage just updates a part of a texture, which might work be better for you.
    • If you want to upload the texture in a single step (which is preferable for performance reasons), but the data doesn't quite fit, look into glPixelStore to set pixel and row strides. I suspect that the data given from sxs_scale/wmw has some padding at the end of each row (the black line). Probably so that each row starts on an even 8-16-32-byte boundary.

提交回复
热议问题