mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
lavd: add opengl device
It can render to OpenGL context provided by application or into SDL window Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
This commit is contained in:
parent
102bd64168
commit
ded6b3af41
@ -21,6 +21,7 @@ version <next>
|
|||||||
- framepack filter
|
- framepack filter
|
||||||
- XYZ12 rawvideo support in NUT
|
- XYZ12 rawvideo support in NUT
|
||||||
- Exif metadata support in WebP decoder
|
- Exif metadata support in WebP decoder
|
||||||
|
- OpenGL device
|
||||||
|
|
||||||
|
|
||||||
version 2.1:
|
version 2.1:
|
||||||
|
13
configure
vendored
13
configure
vendored
@ -251,6 +251,7 @@ External library support:
|
|||||||
--enable-libzvbi enable teletext support via libzvbi [no]
|
--enable-libzvbi enable teletext support via libzvbi [no]
|
||||||
--enable-openal enable OpenAL 1.1 capture support [no]
|
--enable-openal enable OpenAL 1.1 capture support [no]
|
||||||
--enable-opencl enable OpenCL code
|
--enable-opencl enable OpenCL code
|
||||||
|
--enable-opengl enable OpenGL rendering [no]
|
||||||
--enable-openssl enable openssl [no]
|
--enable-openssl enable openssl [no]
|
||||||
--enable-x11grab enable X11 grabbing [no]
|
--enable-x11grab enable X11 grabbing [no]
|
||||||
--disable-zlib disable zlib [autodetect]
|
--disable-zlib disable zlib [autodetect]
|
||||||
@ -1311,6 +1312,7 @@ EXTERNAL_LIBRARY_LIST="
|
|||||||
libzvbi
|
libzvbi
|
||||||
openal
|
openal
|
||||||
opencl
|
opencl
|
||||||
|
opengl
|
||||||
openssl
|
openssl
|
||||||
x11grab
|
x11grab
|
||||||
zlib
|
zlib
|
||||||
@ -1554,6 +1556,7 @@ HAVE_LIST="
|
|||||||
dxva_h
|
dxva_h
|
||||||
ebp_available
|
ebp_available
|
||||||
ebx_available
|
ebx_available
|
||||||
|
ES2_gl_h
|
||||||
fast_64bit
|
fast_64bit
|
||||||
fast_clz
|
fast_clz
|
||||||
fast_cmov
|
fast_cmov
|
||||||
@ -1570,6 +1573,7 @@ HAVE_LIST="
|
|||||||
getservbyport
|
getservbyport
|
||||||
gettimeofday
|
gettimeofday
|
||||||
glob
|
glob
|
||||||
|
glXGetProcAddress
|
||||||
gnu_as
|
gnu_as
|
||||||
gnu_windres
|
gnu_windres
|
||||||
gsm_h
|
gsm_h
|
||||||
@ -1603,6 +1607,7 @@ HAVE_LIST="
|
|||||||
mprotect
|
mprotect
|
||||||
nanosleep
|
nanosleep
|
||||||
openjpeg_1_5_openjpeg_h
|
openjpeg_1_5_openjpeg_h
|
||||||
|
OpenGL_gl3_h
|
||||||
PeekNamedPipe
|
PeekNamedPipe
|
||||||
perl
|
perl
|
||||||
pod2man
|
pod2man
|
||||||
@ -1656,6 +1661,7 @@ HAVE_LIST="
|
|||||||
vdpau_x11
|
vdpau_x11
|
||||||
vfp_args
|
vfp_args
|
||||||
VirtualAlloc
|
VirtualAlloc
|
||||||
|
wglGetProcAddress
|
||||||
windows_h
|
windows_h
|
||||||
winsock2_h
|
winsock2_h
|
||||||
xform_asm
|
xform_asm
|
||||||
@ -2262,6 +2268,7 @@ libcdio_indev_deps="libcdio"
|
|||||||
libdc1394_indev_deps="libdc1394"
|
libdc1394_indev_deps="libdc1394"
|
||||||
libv4l2_indev_deps="libv4l2"
|
libv4l2_indev_deps="libv4l2"
|
||||||
openal_indev_deps="openal"
|
openal_indev_deps="openal"
|
||||||
|
opengl_outdev_deps="opengl"
|
||||||
oss_indev_deps_any="soundcard_h sys_soundcard_h"
|
oss_indev_deps_any="soundcard_h sys_soundcard_h"
|
||||||
oss_outdev_deps_any="soundcard_h sys_soundcard_h"
|
oss_outdev_deps_any="soundcard_h sys_soundcard_h"
|
||||||
pulse_indev_deps="libpulse"
|
pulse_indev_deps="libpulse"
|
||||||
@ -4498,6 +4505,12 @@ enabled opencl && { check_lib2 OpenCL/cl.h clEnqueueNDRangeKernel -Wl
|
|||||||
{ check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" ||
|
{ check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" ||
|
||||||
check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ||
|
check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ||
|
||||||
die "ERROR: opencl must be installed and version must be 1.2 or compatible"; }
|
die "ERROR: opencl must be installed and version must be 1.2 or compatible"; }
|
||||||
|
enabled opengl && { check_lib GL/glx.h glXGetProcAddress "-lGL" ||
|
||||||
|
check_lib2 windows.h wglGetProcAddress "-lopengl32 -lgdi32" ||
|
||||||
|
check_lib2 OpenGL/gl3.h glGetError "-Wl,-framework,OpenGL" ||
|
||||||
|
check_lib2 ES2/gl.h glGetError "-isysroot=${sysroot} -Wl,-framework,OpenGLES" ||
|
||||||
|
die "ERROR: opengl not found."
|
||||||
|
}
|
||||||
enabled openssl && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
|
enabled openssl && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
|
||||||
check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
|
check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
|
||||||
check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
|
check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
|
||||||
|
@ -149,6 +149,41 @@ ffmpeg -re -i INPUT -vcodec rawvideo -pix_fmt bgra -f fbdev /dev/fb0
|
|||||||
|
|
||||||
See also @url{http://linux-fbdev.sourceforge.net/}, and fbset(1).
|
See also @url{http://linux-fbdev.sourceforge.net/}, and fbset(1).
|
||||||
|
|
||||||
|
@section opengl
|
||||||
|
OpenGL output device.
|
||||||
|
|
||||||
|
To enable this output device you need to configure FFmpeg with @code{--enable-opengl}.
|
||||||
|
|
||||||
|
Device allows to render to OpenGL context.
|
||||||
|
Context may be provided by application or default SDL window is created.
|
||||||
|
|
||||||
|
When device renders to external context, application must implement handlers for following messages:
|
||||||
|
@code{AV_CTL_MESSAGE_CREATE_WINDOW_BUFFER} - create OpenGL context on current thread.
|
||||||
|
@code{AV_CTL_MESSAGE_PREPARE_WINDOW_BUFFER} - make OpenGL context current.
|
||||||
|
@code{AV_CTL_MESSAGE_DISPLAY_WINDOW_BUFFER} - swap buffers.
|
||||||
|
@code{AV_CTL_MESSAGE_DESTROY_WINDOW_BUFFER} - destroy OpenGL context.
|
||||||
|
Application is also required to inform a device about current resolution by sending @code{AV_DEVICE_WINDOW_RESIZED} message.
|
||||||
|
|
||||||
|
@subsection Options
|
||||||
|
@table @option
|
||||||
|
|
||||||
|
@item background
|
||||||
|
Set background color. Black is a default.
|
||||||
|
@item no_window
|
||||||
|
Disables default SDL window when set to non-zero value.
|
||||||
|
Application must provide OpenGL context and both @code{window_size_cb} and @code{window_swap_buffers_cb} callbacks when set.
|
||||||
|
@item window_title
|
||||||
|
Set the SDL window title, if not specified default to the filename specified for the output device.
|
||||||
|
Ignored when @option{no_window} is set.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@subsection Examples
|
||||||
|
Play a file on SDL window using OpenGL rendering:
|
||||||
|
@example
|
||||||
|
ffmpeg -i INPUT -f opengl "window title"
|
||||||
|
@end example
|
||||||
|
|
||||||
@section oss
|
@section oss
|
||||||
|
|
||||||
OSS (Open Sound System) output device.
|
OSS (Open Sound System) output device.
|
||||||
|
@ -29,6 +29,7 @@ OBJS-$(CONFIG_IEC61883_INDEV) += iec61883.o
|
|||||||
OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o timefilter.o
|
OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o timefilter.o
|
||||||
OBJS-$(CONFIG_LAVFI_INDEV) += lavfi.o
|
OBJS-$(CONFIG_LAVFI_INDEV) += lavfi.o
|
||||||
OBJS-$(CONFIG_OPENAL_INDEV) += openal-dec.o
|
OBJS-$(CONFIG_OPENAL_INDEV) += openal-dec.o
|
||||||
|
OBJS-$(CONFIG_OPENGL_OUTDEV) += opengl_enc.o
|
||||||
OBJS-$(CONFIG_OSS_INDEV) += oss_audio.o
|
OBJS-$(CONFIG_OSS_INDEV) += oss_audio.o
|
||||||
OBJS-$(CONFIG_OSS_OUTDEV) += oss_audio.o
|
OBJS-$(CONFIG_OSS_OUTDEV) += oss_audio.o
|
||||||
OBJS-$(CONFIG_PULSE_INDEV) += pulse_audio_dec.o \
|
OBJS-$(CONFIG_PULSE_INDEV) += pulse_audio_dec.o \
|
||||||
|
@ -56,6 +56,7 @@ void avdevice_register_all(void)
|
|||||||
REGISTER_INDEV (JACK, jack);
|
REGISTER_INDEV (JACK, jack);
|
||||||
REGISTER_INDEV (LAVFI, lavfi);
|
REGISTER_INDEV (LAVFI, lavfi);
|
||||||
REGISTER_INDEV (OPENAL, openal);
|
REGISTER_INDEV (OPENAL, openal);
|
||||||
|
REGISTER_OUTDEV (OPENGL, opengl);
|
||||||
REGISTER_INOUTDEV(OSS, oss);
|
REGISTER_INOUTDEV(OSS, oss);
|
||||||
REGISTER_INOUTDEV(PULSE, pulse);
|
REGISTER_INOUTDEV(PULSE, pulse);
|
||||||
REGISTER_OUTDEV (SDL, sdl);
|
REGISTER_OUTDEV (SDL, sdl);
|
||||||
|
1221
libavdevice/opengl_enc.c
Normal file
1221
libavdevice/opengl_enc.c
Normal file
File diff suppressed because it is too large
Load Diff
176
libavdevice/opengl_enc_shaders.h
Normal file
176
libavdevice/opengl_enc_shaders.h
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 Lukasz Marek
|
||||||
|
*
|
||||||
|
* This file is part of FFmpeg.
|
||||||
|
*
|
||||||
|
* FFmpeg is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FFmpeg is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with FFmpeg; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AVDEVICE_OPENGL_SHADERS_H
|
||||||
|
#define AVDEVICE_OPENGL_SHADERS_H
|
||||||
|
|
||||||
|
#include "libavutil/pixfmt.h"
|
||||||
|
|
||||||
|
const char *FF_OPENGL_VERTEX_SHADER =
|
||||||
|
"uniform mat4 u_projectionMatrix;"
|
||||||
|
"uniform mat4 u_modelViewMatrix;"
|
||||||
|
|
||||||
|
"attribute vec4 a_position;"
|
||||||
|
"attribute vec2 a_textureCoords;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"gl_Position = u_projectionMatrix * (a_position * u_modelViewMatrix);"
|
||||||
|
"texture_coordinate = a_textureCoords;"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment shader for packet RGBA formats.
|
||||||
|
*/
|
||||||
|
const char *FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET =
|
||||||
|
#if defined(GL_ES_VERSION_2_0)
|
||||||
|
"precision mediump float;"
|
||||||
|
#endif
|
||||||
|
"uniform sampler2D u_texture0;"
|
||||||
|
"uniform mat4 u_colorMap;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"gl_FragColor = texture2D(u_texture0, texture_coordinate) * u_colorMap;"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment shader for packet RGB formats.
|
||||||
|
*/
|
||||||
|
const char *FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET =
|
||||||
|
#if defined(GL_ES_VERSION_2_0)
|
||||||
|
"precision mediump float;"
|
||||||
|
#endif
|
||||||
|
"uniform sampler2D u_texture0;"
|
||||||
|
"uniform mat4 u_colorMap;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"gl_FragColor = vec4((texture2D(u_texture0, texture_coordinate) * u_colorMap).rgb, 1.0);"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment shader for planar RGBA formats.
|
||||||
|
*/
|
||||||
|
const char *FF_OPENGL_FRAGMENT_SHADER_RGBA_PLANAR =
|
||||||
|
#if defined(GL_ES_VERSION_2_0)
|
||||||
|
"precision mediump float;"
|
||||||
|
#endif
|
||||||
|
"uniform sampler2D u_texture0;"
|
||||||
|
"uniform sampler2D u_texture1;"
|
||||||
|
"uniform sampler2D u_texture2;"
|
||||||
|
"uniform sampler2D u_texture3;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
|
||||||
|
"texture2D(u_texture1, texture_coordinate).r,"
|
||||||
|
"texture2D(u_texture2, texture_coordinate).r,"
|
||||||
|
"texture2D(u_texture3, texture_coordinate).r);"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment shader for planar RGB formats.
|
||||||
|
*/
|
||||||
|
const char *FF_OPENGL_FRAGMENT_SHADER_RGB_PLANAR =
|
||||||
|
#if defined(GL_ES_VERSION_2_0)
|
||||||
|
"precision mediump float;"
|
||||||
|
#endif
|
||||||
|
"uniform sampler2D u_texture0;"
|
||||||
|
"uniform sampler2D u_texture1;"
|
||||||
|
"uniform sampler2D u_texture2;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
|
||||||
|
"texture2D(u_texture1, texture_coordinate).r,"
|
||||||
|
"texture2D(u_texture2, texture_coordinate).r,"
|
||||||
|
"1.0);"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment shader for planar YUV formats.
|
||||||
|
*/
|
||||||
|
const char *FF_OPENGL_FRAGMENT_SHADER_YUV_PLANAR =
|
||||||
|
#if defined(GL_ES_VERSION_2_0)
|
||||||
|
"precision mediump float;"
|
||||||
|
#endif
|
||||||
|
"uniform sampler2D u_texture0;"
|
||||||
|
"uniform sampler2D u_texture1;"
|
||||||
|
"uniform sampler2D u_texture2;"
|
||||||
|
"uniform float u_chroma_div_w;"
|
||||||
|
"uniform float u_chroma_div_h;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"vec3 yuv;"
|
||||||
|
|
||||||
|
"yuv.r = texture2D(u_texture0, texture_coordinate).r - 0.0625;"
|
||||||
|
"yuv.g = texture2D(u_texture1, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
|
||||||
|
"yuv.b = texture2D(u_texture2, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
|
||||||
|
|
||||||
|
"gl_FragColor = clamp(vec4(mat3(1.1643, 1.16430, 1.1643,"
|
||||||
|
"0.0, -0.39173, 2.0170,"
|
||||||
|
"1.5958, -0.81290, 0.0) * yuv, 1.0), 0.0, 1.0);"
|
||||||
|
|
||||||
|
"}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fragment shader for planar YUVA formats.
|
||||||
|
*/
|
||||||
|
const char *FF_OPENGL_FRAGMENT_SHADER_YUVA_PLANAR =
|
||||||
|
#if defined(GL_ES_VERSION_2_0)
|
||||||
|
"precision mediump float;"
|
||||||
|
#endif
|
||||||
|
"uniform sampler2D u_texture0;"
|
||||||
|
"uniform sampler2D u_texture1;"
|
||||||
|
"uniform sampler2D u_texture2;"
|
||||||
|
"uniform sampler2D u_texture3;"
|
||||||
|
"uniform float u_chroma_div_w;"
|
||||||
|
"uniform float u_chroma_div_h;"
|
||||||
|
|
||||||
|
"varying vec2 texture_coordinate;"
|
||||||
|
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
"vec3 yuv;"
|
||||||
|
|
||||||
|
"yuv.r = texture2D(u_texture0, texture_coordinate).r - 0.0625;"
|
||||||
|
"yuv.g = texture2D(u_texture1, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
|
||||||
|
"yuv.b = texture2D(u_texture2, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
|
||||||
|
|
||||||
|
"gl_FragColor = clamp(vec4(mat3(1.1643, 1.16430, 1.1643,"
|
||||||
|
"0.0, -0.39173, 2.0170,"
|
||||||
|
"1.5958, -0.81290, 0.0) * yuv, texture2D(u_texture3, texture_coordinate).r), 0.0, 1.0);"
|
||||||
|
"}";
|
||||||
|
|
||||||
|
#endif /* AVDEVICE_OPENGL_SHADERS_H */
|
Loading…
x
Reference in New Issue
Block a user