Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video quality issue when using OpenGL renderer #12

Open
shujaatak opened this issue Apr 10, 2020 · 18 comments
Open

Video quality issue when using OpenGL renderer #12

shujaatak opened this issue Apr 10, 2020 · 18 comments

Comments

@shujaatak
Copy link

Playing a same video using both ffplayer and hplayer, I noticed that the hplayer video quality is different than the official ffplayer.c video quality.

Video quality of ffplayer:
screenshot1

Video quality of hplayer:
screenshot2

I noticed that the network / streaming and local video quality played by hplayer is poor.
hplayer is an amazing project, it deserves high-quality video playback capabilities.

@shujaatak
Copy link
Author

The above screenshot is from the following video https://www.youtube.com/watch?v=qw--VYLpxG4

I have a downloaded file of the above video on which I did comparison of the video quality of both ffplayer and hplayer.

@shujaatak
Copy link
Author

The video in fullscreen mode looks more distorted. The colors do not match with the original video too!

@ithewei
Copy link
Owner

ithewei commented Apr 10, 2020

The scaling of picture caused distortion, I changed GL_NEAEST => GL_LINEAR,this can help to reduce distortion, although it consumes more computing resources.
See HGLWidget.cpp:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

@shujaatak
Copy link
Author

Great! Now there is no distortion!
but the color difference is still there!

Video quality of ffplayer:
screenshot1

Video quality of hplayer:
screenshot2

The colors of hplayer video are dim/lighter while the colors of the ffplayer are bright/darker. I noticed that VLC and other media players also play same like ffplayer i.e. brighter and darker, this means there is still some issue which degrades the hplayer video quality.

@shujaatak
Copy link
Author

The official ffplay has some sdl_texture_format_map which could be something needed for accurate colors?

static const struct TextureFormatEntry {
    enum AVPixelFormat format;
    int texture_fmt;
} sdl_texture_format_map[] = {
    { AV_PIX_FMT_RGB8,           SDL_PIXELFORMAT_RGB332 },
    { AV_PIX_FMT_RGB444,         SDL_PIXELFORMAT_RGB444 },
    { AV_PIX_FMT_RGB555,         SDL_PIXELFORMAT_RGB555 },
    { AV_PIX_FMT_BGR555,         SDL_PIXELFORMAT_BGR555 },
    { AV_PIX_FMT_RGB565,         SDL_PIXELFORMAT_RGB565 },
    { AV_PIX_FMT_BGR565,         SDL_PIXELFORMAT_BGR565 },
    { AV_PIX_FMT_RGB24,          SDL_PIXELFORMAT_RGB24 },
    { AV_PIX_FMT_BGR24,          SDL_PIXELFORMAT_BGR24 },
    { AV_PIX_FMT_0RGB32,         SDL_PIXELFORMAT_RGB888 },
    { AV_PIX_FMT_0BGR32,         SDL_PIXELFORMAT_BGR888 },
    { AV_PIX_FMT_NE(RGB0, 0BGR), SDL_PIXELFORMAT_RGBX8888 },
    { AV_PIX_FMT_NE(BGR0, 0RGB), SDL_PIXELFORMAT_BGRX8888 },
    { AV_PIX_FMT_RGB32,          SDL_PIXELFORMAT_ARGB8888 },
    { AV_PIX_FMT_RGB32_1,        SDL_PIXELFORMAT_RGBA8888 },
    { AV_PIX_FMT_BGR32,          SDL_PIXELFORMAT_ABGR8888 },
    { AV_PIX_FMT_BGR32_1,        SDL_PIXELFORMAT_BGRA8888 },
    { AV_PIX_FMT_YUV420P,        SDL_PIXELFORMAT_IYUV },
    { AV_PIX_FMT_YUYV422,        SDL_PIXELFORMAT_YUY2 },
    { AV_PIX_FMT_UYVY422,        SDL_PIXELFORMAT_UYVY },
    { AV_PIX_FMT_NONE,           SDL_PIXELFORMAT_UNKNOWN },
};

@shujaatak
Copy link
Author

hplayer is about to be the best player, it's only one step away from being the best player! It only needs to have some algorithm for displaying accurate colors and that's it!

hplayer is neat, simple, fast and has appropriate features that no other player has!

By the way, QtAV project also displays accurate colors and they manage it like this.

@shujaatak
Copy link
Author

May be it's due to some issues in OpenGL code?

@shujaatak
Copy link
Author

OK, I found that setting dst_pix_fmt to BGR24 resolves the issue but hplayer doubles the CPU and GPU usage while ffplayer plays the same video with same quality at lower CPU and GPU usage.

@ithewei
Copy link
Owner

ithewei commented Apr 14, 2020

ffplay uses ffmpeg and sdl,sdl uses d3d on Windows,OpenGL on Linux.
OpenGL cross-platform, but d3d is more efficient on Windows.
If set dst_pix_fmt = BGR24, sws_scale convert yuv -> rgb via CPU.

@ithewei
Copy link
Owner

ithewei commented Apr 14, 2020

Set draw_fps = false when you test.

@ithewei
Copy link
Owner

ithewei commented Apr 14, 2020

Maybe we can try to integrate SDL into hplayer, renderer is too complex.

@shujaatak
Copy link
Author

SDL looks good, it's easy to use and also efficient.

By the way, for windows and linux, VLC uses Qt https://code.videolan.org/videolan/vlc/-/tree/master/modules/gui/qt and I have noticed that VLC plays videos with lowest CPU and GPU usage. I know VLC uses it's own libraries alongwith ffmpeg but for rendering it uses Qt and OpenGL(by default).

@shujaatak
Copy link
Author

By the way, ffplay(ffmpeg) is the best! VLC is only good for playing local videos. I compared both ffplay and VLC for streaming videos and I noticed that ffplay uses comparatively less CPU and GPU and also ffplay plays the videos smoothly with much less delay!
VLC can play local videos efficiently because VLC loads a portion of the video to the RAM and then plays video from there rather than fetching each frame from the drive.

@shujaatak
Copy link
Author

If you wonder how to integrate SDL2 with Qt then see this:
https://github.com/Qt-Widgets/SDL2_Widget_Qt5

@shujaatak
Copy link
Author

ffplay is SDL based and QtAV is Qt OpenGL(default) based.
I noticed that both ffplay and QtAV has almost same CPU and GPU usage. This means that there is no issue with OpenGL whereas hplayer is missing something due to which it's efficiency is not as good as ffplay.
However I have also noticed that QtAV is laggy for streaming videos.

@ithewei
Copy link
Owner

ithewei commented Apr 24, 2020

Try hplayer.conf renderer = sdl

@shujaatak
Copy link
Author

renderer = sdl works perfect! but somehow the aspect ratio configs are not working now. I tried both aspect_ratio = w:h # ORIGINAL_RATIO and aspect_ratio = wxh # ORIGINAL_SIZE but the aspect ratio does not change.

@shujaatak shujaatak changed the title Video quality issue Video quality issue when using OpenGL renderer Apr 24, 2020
@shujaatak
Copy link
Author

I am going to create separate aspect ratio and freeze related issues to avoid cluttering this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants