Package Name
Visual engine of Choi Gunhyuk
Installation
Install the package from PyPI:
pip install chgnhyk
- Details: chgnhyk installation doc
ffmpeg
- required to generate video with moviepy
- not required when using
render_pyav()function inClipRenderer
csound libcsnd6-6.0v5
- required to generate audio
Installation options
pip install "chgnhyk[video]"
- installs av, moviepy
pip install "chgnhyk[window]"
- installs moderngl_window
pip install "chgnhyk[audio]"
- requires csound
pip install "chgnhyk[mediapipe]"
- installs mediapipe
- downgrades numpy to 1.26.4
pip install "chgnhyk[opencv]"
- install with opencv
pip install "chgnhyk[audio, window, mediapipe]"
- install with three options
Usage
Basic example 1:
- moviepy(ffmpeg needed) as video encoding backend
from chgnhyk import FBO, ClipRenderer
from moderngl import create_context
CTX = create_context(require=(330), standalone=True)
SIZE = (1080, 1080)
shader = '''
#version 330
out vec4 outputColor;
in vec2 UV;
uniform sampler2D bckbuffer;
uniform vec2 resolution;
uniform float timer;
uniform float loop_timer;
uniform float duration;
void main() {
vec2 uv = UV;
vec2 rs = resolution;
outputColor = vec4(uv, loop_timer, 1.);
}
'''
scene = FBO(
ctx = CTX, size = (1080, 1080), shader = shader
)
clip = ClipRenderer(duration=2, fps=30, rest_time=0.)
clip.addFBOPass("", scene)
clip.render_frame_sample(clip.duration * 0.0)
clip.extractImage((f"test_{clip.t}.jpg"))
vid = clip.render()
vid.write_videofile(str("test.mp4"), fps=clip.fps)
clip.release()
CTX.release()
Basic example 2:
- pyav as video encoding backend
from chgnhyk import FBO, ClipRenderer
from moderngl import create_context
CTX = create_context(require=(330), standalone=True)
SIZE = (1080, 1080)
shader = '''
#version 330
out vec4 outputColor;
in vec2 UV;
uniform sampler2D bckbuffer;
uniform vec2 resolution;
uniform float timer;
uniform float loop_timer;
uniform float duration;
void main() {
vec2 uv = UV;
vec2 rs = resolution;
outputColor = vec4(uv, loop_timer, 1.);
}
'''
scene = FBO(
ctx = CTX, size = (1080, 1080), shader = shader
)
clip = ClipRenderer(duration=2, fps=30, rest_time=0.)
clip.addFBOPass("", scene)
clip.render_frame_sample(clip.duration * 0.0)
clip.extractImage((f"test_{clip.t}.jpg"))
clip.render_pyav("test.mp4")
clip.release()
CTX.release()
Video example:
- create "sample" folder
- create "shaders" folder and put shader files there
shader file in "shaders" folder
#version 330
out vec4 outputColor;
in vec2 UV;
uniform sampler2D bckbuffer;
uniform vec2 resolution;
uniform sampler2D VID;
uniform vec2 VID_res;
uniform float timer;
uniform float loop_timer;
uniform float duration;
#define PI 3.14159265
float rand(vec3 p){
float sd1 = dot(p, vec3(31.3131,23.2323,17.1717));
float sd2 = dot(p, vec3(13.1313,15.1515,19.1919));
float sv = sin(sd1) + sin(sd2);
return fract(sv * 45678.654321);
}
vec2 rotate(vec2 p, float a){
return vec2(
p.x * cos(a) - p.y * sin(a),
p.x * sin(a) + p.y * cos(a)
);
}
float sd_segment(vec2 p, vec2 a, vec2 b, float w){
vec2 ba = b - a;
vec2 pa = p - a;
vec2 dr = normalize(ba);
float l = length(ba);
float dt = dot(pa, dr);
vec2 h = a + dt * dr;
float dst = length(h-p)-w;
if(dt <= .0){
dst = length(p-a)-w;
}
if(dt >= l){
dst = length(p-b)-w;
}
return dst;
}
void main() {
vec2 uv = UV;
vec2 rs = resolution;
uv = (uv-.5);
uv *= rs/rs.y;
vec2 sc = vec2(40.);
vec2 iuv = floor(uv*sc);
if(mod(iuv.y,2.) == .0){
uv.x -= .5/sc.x;
}
iuv = floor(uv*sc);
vec2 fuv = fract(uv*sc)-.5;
vec2 vtc = (iuv/sc)*rs.y/rs + .5;
vec4 vsamp = texture(VID, vtc);
vec4 ovsamp = texture(VID, UV);
float h = length(vsamp.rgb)/length(vec3(1.));
h = floor(h * 8.)/8.;
fuv = rotate(fuv, h * PI * 2.);
float sh = sd_segment(fuv, vec2(-.4,.0), vec2(.4,.0), .02);
sh = 1.-smoothstep(.0,.001 * sc.x,sh);
vec3 col;
col = mix(vsamp.rgb, vec3(.1,1.,.1), sh);
outputColor = vec4(col, 1.);
}
main python script
from chgnhyk import FBO, load_shader, ClipRenderer
from moderngl import create_context
from pathlib import Path
work_path = Path(__file__).parent
shader_path = work_path.joinpath("shaders/")
sample_path = work_path.joinpath("sample/")
CTX = create_context(require=(330), standalone=True)
ratio = 1
SIZE = (1080, 1080) # change to match video file
scene = FBO(ctx=CTX, size=SIZE, shader=load_shader(shader_path.joinpath("scene.glsl")))
clip = ClipRenderer(duration=5, fps=30, rest_time=0.) #8 #30
scene.set_uniform("duration", clip.duration)
clip.addFBOPass(name = 'scene', render_pass = scene)
clip.addVideo(sample_path.joinpath("video.mp4"), "VID", 8)
clip.render_frame_sample(clip.duration * 0.0)
clip.extractImage(sample_path.joinpath(f"test_{clip.t}.jpg"))
vid = clip.render()
vid.write_videofile(str(sample_path.joinpath("test.mp4")), fps=clip.fps)
clip.release()
CTX.release()
Requirements
- Python 3.9 or later
License
This project is licensed under the MIT License.
Author
Choi Gunhyuk
Links
- Pypi: https://pypi.org/project/chgnhyk
- GitHub: https://github.com/chgnhyk
Metadata
Release files for chgnhyk 0.0.27
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chgnhyk-0.0.27.tar.gz | 380.6 kB | Without provenance | Details for chgnhyk-0.0.27.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chgnhyk-0.0.27-py3-none-any.whl | Python 3 | none | any | Details for chgnhyk-0.0.27-py3-none-any.whl |
Total release size: 767.1 kB
Release files / chgnhyk-0.0.27.tar.gz
| Download URL | chgnhyk-0.0.27.tar.gz |
|---|---|
| Size | 380.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8da92490bf439d96888b9bb1157d66dd61d22c82d1c19cfcd18559c1f9561bed
|
|
BLAKE2b-256 checksum How to use checksums |
dd6493154a427f7e07b95cc29e8fead9464a274399057f77bb3db129af281f2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.12
|
Release files / chgnhyk-0.0.27-py3-none-any.whl
| Download URL | chgnhyk-0.0.27-py3-none-any.whl |
|---|---|
| Size | 386.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e75190afbac6bd173ff7f642a4ed5a0b0e5f6e565910210a5936c9923405283
|
|
BLAKE2b-256 checksum How to use checksums |
09aa0ba21b8de6a62b17b7c73c269d63d16880cf224ec819cf87dd8ca0c688f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.12
|
Security for chgnhyk 0.0.27
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.