在Pi 3 B +上使用处理Pi的GLSL着色器

问题描述 投票:0回答:1

这是我第一次从Processing OSX移植到GLSL着色器,以便在Raspberry Pi 3 B +上运行的Processing Pi上运行。我有一个非常基本的着色器,可以在播放两个视频之间进行分解。它在我的Mac上运行完全正常,但是当将其移植到Processing Pi并更新为使用Processing视频库GLvideo时,它将抛出错误。

着色器最初是从ShaderToy帖子转换而来的,但我将其重新编写为纯GLSL,以确保不存在任何兼容性问题。我环顾四周,找不到任何我认为会导致此问题的具体信息。因此,任何引用,指针或帮助将不胜感激。

[我尝试了一些其他操作,将视频调整为较小的尺寸,将Pi的GPU内存更新为256mb等。我确保它仍可在OSX上使用,但是当它在Raspberry Pi 3B +上运行时,草图为空白屏幕。

我以为Pi处理GLSL的方式可能有所不同?或Pi GPU中的sampler2D纹理是否有限制?在处理方面,它越过了我。也许不支持在处理pi时将PGraphics从Processing设置为着色器中的sampler2D纹理?设置texture3D时,GLVideo图像可能有些问题。另外,也许是我在碎片和颜色着色器的工作方式之间混为一谈。目前,我认为我正在使用“处理颜色着色器”。

控制台中唯一的输出是:

Final caps: video/x-raw(memory:GLMemory), format=(string)RGBA, width=(int)640, height=(int)360, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)25/1, texture-target=(string)2D
Final caps: video/x-raw(memory:GLMemory), format=(string)RGBA, width=(int)640, height=(int)360, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)25/1, texture-target=(string)2D

shaderDisolveGLSL.pde

//import processing.video.*;
import gohai.glvideo.*;

PShader mixShader;  

PGraphics pg;
PGraphics pg2;

//Movie movie;
//Movie movie2;

GLMovie movie;
GLMovie movie2;

void setup() {
  size(640, 360, P2D);
  noSmooth();
  pg = createGraphics(640, 360, P2D);

  //movie = new Movie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie = new GLMovie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie.loop();

  //movie2 = new Movie(this, "_sm/LabspaceFireblur2.mp4");
  movie2 = new GLMovie(this, "_sm/LabspaceFireblur2.mp4");
  movie2.loop();

  pg = createGraphics(width, height, P2D);
  pg2 = createGraphics(width, height, P2D);

  mixShader = loadShader("fadeshader.glsl");
  mixShader.set("iResolution", float(width), float(height));
  mixShader.set("iTime", millis()/1000.);

  mixShader.set("iChannel0", pg);
  mixShader.set("iChannel1", pg2);

}  

//void movieEvent(Movie m) {
void movieEvent(GLMovie m) {
  m.read();
  redraw();
}

void draw() {

  pg.beginDraw();
    pg.image(movie, 0, 0, width, height);
  pg.endDraw();

  pg2.beginDraw();
    pg2.image(movie2, 0, 0, width, height);
  pg2.endDraw();

  shader(mixShader);
  rect(0, 0, width, height);

}

fadeshader.glsl

// Type of shader expected by Processing
#define PROCESSING_COLOR_SHADER

uniform float iTime;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform vec2 iResolution;

void main() {

    vec2 uv = gl_FragCoord.xy / iResolution.xy;
    vec4 mixColor = vec4(0.0);
    vec4 color0 = vec4(uv.x,uv.y,0.0,1.0);
    vec4 color1 = vec4(uv.x,uv.y,0.0,1.0);

    color0 = texture2D(iChannel0, uv);
    color1 = texture2D(iChannel1, uv);

    float duration = 10.0;
    float t = mod(float(iTime), duration) / duration;

    mixColor = mix(color0, color1, t);
    gl_FragColor = mixColor;
}

如果有人好奇,我在这里用较小的视频更新了示例草图的新版本:https://www.dropbox.com/sh/fu2plxmqhf7shtp/AADxqmW9zf73EsdzworCb5ECa?dl=0

任何关于可能出现的问题或在哪里开始进行更多调试的建议或想法,将不胜感激。

谢谢!

java raspberry-pi glsl processing shader
1个回答
0
投票

我不确定100%,但是错误可能与视频编码以及GLVideo库可以在Raspberry PI(取决于gstreamer)上解码的内容有关

我已经在旧系统的OSX上遇到错误:草图在灰色屏幕上冻结了几秒钟,然后崩溃,没有任何警告或错误。

我建议重新编码视频,如果不需要,请丢弃音频频道,并使用与处理过渡视频相同或相似的H.264编码器(例如示例>库>视频>电影>循环)

ffprobe -i /Users/George/Desktop/shaderDisolveGLSL/data/_sm/LabspaceDawn\ v1\ blur\ 2.mp4 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 7.0.0 (clang-700.0.72)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/George/Desktop/shaderDisolveGLSL/data/_sm/LabspaceDawn v1 blur 2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2020-03-15T14:03:48.000000Z
  Duration: 00:00:49.09, start: 0.000000, bitrate: 218 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 640x360 [SAR 1:1 DAR 16:9], 119 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2020-03-15T14:03:48.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/15/2020.
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2020-03-15T14:03:48.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/15/2020.

传输视频详细信息:

ffprobe -i /Users/George/Desktop/shaderDisolveGLSL/data/transit.mov 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 7.0.0 (clang-700.0.72)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/George/Desktop/shaderDisolveGLSL/data/transit.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2012-08-31T20:17:39.000000Z
  Duration: 00:00:12.38, start: 0.000000, bitrate: 731 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360, 727 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2012-08-31T20:17:44.000000Z
      handler_name    : Apple Alias Data Handler
      encoder         : H.264

似乎起作用:

Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x360, 727 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 1200 tbc (default)

似乎崩溃:

Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 640x360 [SAR 1:1 DAR 16:9], 119 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)

[在使用movieEvent时遇到了其他一些间歇性的JOGL错误:在.read()中潜入draw()调用似乎可以解决问题。

这是您设法在OSX上运行的代码的调整版本:

import processing.video.*;
//import gohai.glvideo.*;

PShader mixShader;  

PGraphics pg;
PGraphics pg2;

Movie movie;
Movie movie2;

//GLMovie movie;
//GLMovie movie2;

void setup() {
  size(640, 360, P2D);
  noSmooth();
  noStroke();

  //movie = new Movie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie = new Movie(this, "transit.mov");
  //movie = new GLMovie(this, "_sm/LabspaceDawnv1blur2.mp4");
  movie.loop();

  //movie2 = new Movie(this, "_sm/LabspaceFireblur2.mp4");
  movie2 = new Movie(this, "transit2.mov");
  //movie2 = new GLMovie(this, "_sm/LabspaceFireblur2.mp4");
  movie2.loop();

  pg = createGraphics(width, height, P2D);
  pg2 = createGraphics(width, height, P2D);

  mixShader = loadShader("fadeshader.glsl");
  mixShader.set("iResolution", float(width), float(height));
  mixShader.set("iChannel0", pg);
  mixShader.set("iChannel1", pg2);

}  

//void movieEvent(Movie m) {
//void movieEvent(GLMovie m) {
  //m.read();
  //redraw();
//}

void draw() {
  if(movie.available()){   movie.read(); }
  if(movie2.available()){   movie2.read(); }

  pg.beginDraw();
    // for testing only since both movies are the same
    movie.filter(GRAY);
    pg.image(movie, 0, 0, width, height);
  pg.endDraw();

  pg2.beginDraw();
    pg2.image(movie2, 0, 0, width, height);
  pg2.endDraw();

  // don't forget to update time
  mixShader.set("iTime", millis() * 0.01);

  shader(mixShader);
  rect(0, 0, width, height);
}

希望这可以与Raspberry Pi上的运输mov一起测试编解码器。一旦运行顺利,请重新编码您的视频(Handbreak可能对此有所帮助),然后重试。

© www.soinside.com 2019 - 2024. All rights reserved.