Skip to main content

Package Name

Visual and audio engine of Choi Gunhyuk

Installation

Install the package from PyPI:

pip install chgnhyk

ffmpeg

  • required to generate video

csound libcsnd6-6.0v5

  • required to generate audio

Installation options

pip install chgnhyk[audio]
  • requires csound
pip install chgnhyk[window]
  • installs moderngl_window
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:

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, 1., 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()

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
  • moderngl
  • moderngl_window
  • csound

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Choi Gunhyuk

Links

  • PyPI:
  • GitHub:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chgnhyk-0.0.13.tar.gz (379.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chgnhyk-0.0.13-py3-none-any.whl (384.8 kB view details)

Uploaded Python 3

File details

Details for the file chgnhyk-0.0.13.tar.gz.

File metadata

  • Download URL: chgnhyk-0.0.13.tar.gz
  • Upload date:
  • Size: 379.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for chgnhyk-0.0.13.tar.gz
Algorithm Hash digest
SHA256 28a22e047fc78f4f27eede2bc78297a2399e50e1575e06b2f85b23b7b062cd3a
MD5 521440a207c16c74d15212e3c27b6a07
BLAKE2b-256 91e616ec3a5c5039af51fbefebce50023373db5f50d29d2dcc3abcba1e8aa93f

See more details on using hashes here.

File details

Details for the file chgnhyk-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: chgnhyk-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 384.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for chgnhyk-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a9fbc8365606790dfd102cbc75c64d1a4abae4f4147e1ca3734dab587fdc424d
MD5 d71a2131bc7dd94eff1518573b7e6061
BLAKE2b-256 942ddca3d2d7c3f08007b0e0ba23d2e0c35ef8c4cc7e35b4fa55c2bb67a32386

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page