sciapp / gr

GR framework: a graphics library for visualisation applications
Other
328 stars 54 forks source link

Low video export quality #85

Closed li012589 closed 5 years ago

li012589 commented 5 years ago

Hi,

I'm trying to create a 3D animation using gr. I learned from this example that I can use gr3.drawimage(0, 1, 0, 1, 500, 500, gr3.GR3_Drawable.GR3_DRAWABLE_GKS) to create each frame and use export GKS_WSTYPE=mov to output a video file.

But the problem is that the image quality of the output video is too low. I can export each frame by replacing gr3.drawimage with gr3.export, and the output image quality is pretty good. I also tried adding gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_16X_SSAA), but it only seems to work with gr3.export.

So, is there a way to improve the output image quality? Or is it me that doing something wrong?

The following is the samples of different ways of output.

The output of "drawimage": test12 The output of "export": testdf100

danielkaiser commented 5 years ago

Hi,

the resolution of your video output is basically limited in two places. First I would recommend to change the resolution when calling gr.drawimage, for example to

gr3.drawimage(0, 1, 0, 1, 2000, 2000, gr3.GR3_Drawable.GR3_DRAWABLE_GKS)

This will render your 3D scene to a 2000 x 2000 pixel bitmap instead of 500 x 500 pixel and should already result in a better video quality.

The next limiting factor is the video resolution. Currently the GR uses a nearest neighbor approach to resample bitmaps for rasterized output formats (like images and videos), so that the resulting video should still look "pixelated". To avoid this you can increase the video resolution by setting the environment variable GKS_VIDEO_OPTS, which defines the video resolution and framerate. If you set it to GKS_VIDEO_OPTS=2000x2000 the generated video file now should also have a resolution of 2000 x 2000 pixel. When you play this video on a screen (that is probably smaller than this size) the video player takes care of resampling the individual frames which should result in a smoother looking video because the video player should use a different resampling method than nearest neighbor.

The drawback is that a video resolution of 2000 x 2000 pixel will result in rather large video files. So you could also try creating individual png files for each frame by setting GKS_WSTYPE=png and manually render the resulting files to a video (for example using ffmpeg), which gives you a more fine grained control over video resolution, framerate, bitrate, codecs, resampling etc.

li012589 commented 5 years ago

Hi, thanks for the reply!

I have just tried what you said, and the image quality did improve much better. I think my problem has been solved so I'll just close this issue.