gs_ffmpeg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README

commit 060f06d1e9e53ed116a3f6a936e351369bd9e505
parent 1653030857b162fc8218b44c2080f3a56230bf2b
Author: halvard samdal <halvard@hp.localdomain>
Date:   Fri,  2 Dec 2022 17:12:38 +0100

add propper transparency with libvpx

Diffstat:
M.gitignore | 1+
Dbin/.obj/gs.d | 70----------------------------------------------------------------------
Dbin/.obj/gs.o | 0
Dbin/.obj/main.d | 1-
Dbin/.obj/main.o | 0
Dbin/.obj/main2.d | 1-
Dbin/.obj/main2.o | 0
Dbin/App | 0
Msource/gs_avdecode.h | 25+++++++++++++++++--------
Msource/main.c | 2+-
10 files changed, 19 insertions(+), 81 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -3,3 +3,4 @@ *.mov *.m4v *.webm +bin/* diff --git a/bin/.obj/gs.d b/bin/.obj/gs.d @@ -1,70 +0,0 @@ -../../bin/.obj/gs.o: ../../source/gs.c ../../source/../third_party/include/gs/gs.h \ - ../../source/../third_party/include/gs/external/minicoro/minicoro.h \ - ../../source/../third_party/include/gs/impl/gs_platform_impl.h \ - ../../source/../third_party/include/gs/impl/../external/glad/glad_impl.h \ - ../../source/../third_party/include/gs/impl/../external/glad/glad.h \ - ../../source/../third_party/include/gs/impl/../external/glad/../KHR/khrplatform.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/glfw_impl.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/glfw3.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/context.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/internal.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/x11_platform.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/posix_thread.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/posix_time.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/xkb_unicode.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/glx_context.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/egl_context.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/osmesa_context.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/linux_joystick.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/init.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/mappings.h \ - ../../source/../third_party/include/gs/impl/../external/glfw/input.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/monitor.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/vulkan.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/window.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/x11_init.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/x11_monitor.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/x11_window.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/glx_context.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/linux_joystick.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/posix_thread.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/posix_time.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/xkb_unicode.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/egl_context.c \ - ../../source/../third_party/include/gs/impl/../external/glfw/osmesa_context.c \ - ../../source/../third_party/include/gs/impl/gs_graphics_impl.h \ - ../../source/../third_party/include/gs/impl/gs_audio_impl.h \ - ../../source/../third_party/include/gs/impl/../external/stb/stb_vorbis.c \ - ../../source/../third_party/include/gs/impl/../external/dr_libs/dr_wav.h \ - ../../source/../third_party/include/gs/impl/../external/dr_libs/dr_mp3.h \ - ../../source/../third_party/include/gs/impl/../external/miniaudio/miniaudio.h \ - ../../source/../third_party/include/gs/external/sg_noise/sg_noise.h \ - ../../source/../third_party/include/gs/external/stb/stb_truetype.h \ - ../../source/../third_party/include/gs/external/stb/stb_image.h \ - ../../source/../third_party/include/gs/external/cgltf/cgltf.h \ - ../../source/../third_party/include/gs/util/gs_idraw.h \ - ../../source/../third_party/include/gs/util/gs_gui.h \ - ../../source/../third_party/include/gs/util/gs_physics.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_vec3.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_compiler.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_config.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_export.h \ - ../../source/../third_party/include/gs/util/../external/ccd/libccd.c \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_vec3.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_quat.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_vec3.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_vec3.c \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_vec3.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_dbg.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_support.c \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_support.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_polytope.c \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_polytope.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_list.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd/ccd_compiler.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_alloc.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_mpr.c \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd_simplex.h \ - ../../source/../third_party/include/gs/util/../external/ccd/src/ccd.c diff --git a/bin/.obj/gs.o b/bin/.obj/gs.o Binary files differ. diff --git a/bin/.obj/main.d b/bin/.obj/main.d @@ -1 +0,0 @@ -../../bin/.obj/main.o: ../../source/main.c ../../source/gs_avdecode.h diff --git a/bin/.obj/main.o b/bin/.obj/main.o Binary files differ. diff --git a/bin/.obj/main2.d b/bin/.obj/main2.d @@ -1 +0,0 @@ -../../bin/.obj/main2.o: ../../source/main2.c diff --git a/bin/.obj/main2.o b/bin/.obj/main2.o Binary files differ. diff --git a/bin/App b/bin/App Binary files differ. diff --git a/source/gs_avdecode.h b/source/gs_avdecode.h @@ -101,6 +101,7 @@ open_codec_context( int *stream_idx, AVCodecContext **dec_ctx, AVFormatContext *fmt_ctx, + int* alpha, enum AVMediaType type ) { int ret, stream_index; @@ -116,8 +117,18 @@ open_codec_context( stream_index = ret; st = ctx->fmt_ctx->streams[stream_index]; - /* find decoder for the stream */ - dec = avcodec_find_decoder(st->codecpar->codec_id); + int a = 0; + if (alpha) { + AVDictionaryEntry* tag = NULL; + tag = av_dict_get(st->metadata, "ALPHA_MODE", tag, 0); + a = tag && atoi(tag->value); + *alpha = a; + } + + // find decoder for the stream + // use libvpx for transparent video + dec = a ? avcodec_find_decoder_by_name("libvpx-vp9") + : avcodec_find_decoder(st->codecpar->codec_id); if (!dec) { fprintf(stderr, "gs_avdecode.h: Failed to find %s codec\n", av_get_media_type_string(type)); @@ -175,21 +186,19 @@ gs_avdecode_init(const char* path, gs_avdecode_ctx_t* ctx, gs_graphics_texture_d } int ret = 0; - if (open_codec_context(ctx, &ctx->video_stream_idx, &ctx->video_dec_ctx, ctx->fmt_ctx, AVMEDIA_TYPE_VIDEO) >= 0) { + if (open_codec_context(ctx, &ctx->video_stream_idx, &ctx->video_dec_ctx, ctx->fmt_ctx, &ctx->alpha, AVMEDIA_TYPE_VIDEO) >= 0) { ctx->video_stream = ctx->fmt_ctx->streams[ctx->video_stream_idx]; ctx->width = ctx->video_dec_ctx->width; ctx->height = ctx->video_dec_ctx->height; ctx->pix_fmt = ctx->video_dec_ctx->pix_fmt; - if (ctx->pix_fmt == AV_PIX_FMT_YUVA420P || - ctx->pix_fmt == AV_PIX_FMT_ARGB || - ctx->pix_fmt == AV_PIX_FMT_RGBA) - ctx->alpha = 1; + if (ctx->alpha && ctx->pix_fmt == AV_PIX_FMT_YUV420P) + ctx->pix_fmt = AV_PIX_FMT_YUVA420P; ctx->sws = sws_getContext(ctx->width, ctx->height, ctx->pix_fmt, ctx->width, ctx->height, ctx->alpha ? AV_PIX_FMT_RGBA : AV_PIX_FMT_RGB24, SWS_BICUBIC, 0, 0, 0); } - if (open_codec_context(ctx, &ctx->audio_stream_idx, &ctx->audio_dec_ctx, ctx->fmt_ctx, AVMEDIA_TYPE_AUDIO) >= 0) { + if (open_codec_context(ctx, &ctx->audio_stream_idx, &ctx->audio_dec_ctx, ctx->fmt_ctx, NULL, AVMEDIA_TYPE_AUDIO) >= 0) { ctx->audio_stream = ctx->fmt_ctx->streams[ctx->audio_stream_idx]; } diff --git a/source/main.c b/source/main.c @@ -24,7 +24,7 @@ void app_update() gsi_defaults(&gsi); gsi_camera2D(&gsi, fb.x, fb.y); - gsi_rectvd(&gsi, gs_v2s(0.0f), fb, gs_v2s(0.f), gs_v2s(1.f), GS_COLOR_WHITE, GS_GRAPHICS_PRIMITIVE_TRIANGLES); + //gsi_rectvd(&gsi, gs_v2s(0.0f), fb, gs_v2s(0.f), gs_v2s(1.f), GS_COLOR_WHITE, GS_GRAPHICS_PRIMITIVE_TRIANGLES); int res = gs_avdecode_next_frame(&video); if (res) gs_quit();