Skip to content

Instantly share code, notes, and snippets.

@offlinehacker
Last active February 25, 2021 08:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offlinehacker/5233631 to your computer and use it in GitHub Desktop.
Save offlinehacker/5233631 to your computer and use it in GitHub Desktop.
LD_LIBRARY_PATH=../lib64/ ./glc-capture --start -v 3 --disable-audio --uncompressed=1M -z none -o /dev/stdout -l /dev/stderr etracer | LD_LIBRARY_PATH=../lib64/ ./glc-play /dev/stdin -t -v 3 -y 1 --uncompressed=1M -o /dev/stdout | ffmpeg -i /dev/stdin -f yuv4mpegpipe -pix_fmt yuv420p -vcodec libx264 -vprofile baseline -preset ultrafast -tune zerolatency -x264opts "intra-refresh:vbv-maxrate=5000:vbv-bufsize=200:slice-max-size=1500:sliced-threads" -threads auto -f yuv4mpegpipe -o /dev/stdout | ../../scripts/video/example
gcc -g -std=gnu99 -Wall -I/usr/include -L/usr/lib -L/usr/lib/x86_64-linux-gnu/ test.c aveasy.c -lglut -lGL -lGLU -lGLEW -lglfw `pkg-config --cflags --libs libavcodec libavformat libavdevice libswscale` -o example
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glut.h>
#include "aveasy.h"
#define CAM_DESIRED_WIDTH 640
#define CAM_DESIRED_HEIGHT 480
AVEasyInputContext *camera_av;
char const *camera_path = "pipe:";
GLuint vbo=0;
GLuint pbo=0;
int use_pbo=0;
GLuint camera_texture=0
int open_camera(void)
{
AVEasyInputContext *ctx;
avcodec_register_all();
avdevice_register_all();
ctx = aveasy_input_open_v4l2(
camera_path,
CAM_DESIRED_WIDTH,
CAM_DESIRED_HEIGHT,
CODEC_ID_RAWVIDEO,
PIX_FMT_BGR24 );
camera_av = ctx;
if(!ctx) {
return 0;
}
}
void update_camera(void)
{
glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_TRUE );
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei( GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
AVEasyInputContext *ctx = camera_av;
void *buffer;
if(!ctx)
return;
if( !( buffer = aveasy_input_read_frame(ctx) ) )
return;
glBindTexture(GL_TEXTURE_2D, camera_texture);
glTexSubImage2D(
GL_TEXTURE_2D,
0,
0,
0,
aveasy_input_width(ctx),
aveasy_input_height(ctx),
GL_BGR,
GL_UNSIGNED_BYTE,
buffer);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
}
void close_cameras(void)
{
aveasy_input_close(camera_av);
camera_av=0;
}
int main(int argc, char **argv) {
/* interleaved vertex array: T2F_V2F */
static const GLfloat va[]={
0.0f, 1.0f, -1.0f, 1.0f,
0.0f, 0.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, -1.0f};
open_camera();
glutInitWindowSize(320,240);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
glutCreateWindow("TEST");
// Initialize GLEW
//glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
glfwSetWindowTitle( "Tutorial 01" );
/* setup vbo */
glGenBuffersARB(1, &vbo);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(va), va, GL_STATIC_DRAW_ARB);
glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), (char*)0);
glVertexPointer(2, GL_FLOAT, 4*sizeof(GLfloat), ((char*)0)+2*sizeof(GLfloat));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glGenTextures(1, &camera_texture);
/* OpenGL-2 or later is assumed; OpenGL-2 supports NPOT textures. */
glBindTexture(GL_TEXTURE_2D, camera_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGB,
aveasy_input_width(camera_av),
aveasy_input_height(camera_av),
0,
GL_BGR,
GL_UNSIGNED_BYTE,
NULL );
glEnable(GL_TEXTURE_2D);
while(1) {
update_camera();
glutSwapBuffers();
}
close_camera();
}
offlinehacker@offlinehacker-laptop:~/tmp/scripts/video$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment