Skip to content

Commit

Permalink
wip: qoi image video
Browse files Browse the repository at this point in the history
  • Loading branch information
stergiotis committed Jul 14, 2024
1 parent f30191d commit 390d5af
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 42 deletions.
1 change: 1 addition & 0 deletions common/contrib/qoi
1 change: 1 addition & 0 deletions common/generate_links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ link ../../contrib/imgui_knobs contrib/imgui_knobs
link ../../contrib/imgui_toggle contrib/imgui_toggle
link ../../contrib/tracy contrib/tracy
link ../../contrib/sdl contrib/sdl3
link ../../contrib/qoi contrib/qoi
link ./contrib/imgui_toggle/imgui_toggle.cpp ./src/widgets/imgui_toggle/imgui_toggle.cpp
link ./contrib/imgui_toggle/imgui_toggle_palette.cpp ./src/widgets/imgui_toggle/imgui_toggle_palette.cpp
link ./contrib/imgui_toggle/imgui_toggle_presets.cpp ./src/widgets/imgui_toggle/imgui_toggle_presets.cpp
Expand Down
1 change: 1 addition & 0 deletions dhall/sourceTreeParts.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ let skiaVideo = \(asan : Bool) ->
, imgui.dir
, imguiImplot.dir
, render.dir
, "./contrib/qoi"
]
, global = [
, "${contribDir}"
Expand Down
1 change: 1 addition & 0 deletions scripts/install_3rd_party_git_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ getContribRepo "https://github.com/google/flatbuffers.git" "flatbuffers" "master
getContribRepo "https://github.com/google/skia" "skia" "chrome/m124" ""
getContribRepo "https://github.com/wolfpld/tracy" "tracy" "master" "0d5bd53be393b590da9c7b29079d919d488412c1"
getContribRepo "https://github.com/libsdl-org/SDL.git" "sdl" "main" "e049098733739664ffbeac6967568b2421a0cb2e"
getContribRepo "https://github.com/phoboslab/qoi.git" "qoi" "master" "bf7b41c2ff3f24a2031193b62aa76d35e8842b5a"
getMyRepo "https://github.com/stergiotis/boxer.git" "boxer" "main" ""
3 changes: 2 additions & 1 deletion skia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ SK_BUILD_FOR_UNIX)
target_include_directories(skiaVideo PUBLIC "${CMAKE_CURRENT_LIST_DIR}/./skia"
"${CMAKE_CURRENT_LIST_DIR}/./imgui"
"${CMAKE_CURRENT_LIST_DIR}/./src/widgets/imgui_implot"
"${CMAKE_CURRENT_LIST_DIR}/./src")
"${CMAKE_CURRENT_LIST_DIR}/./src"
"${CMAKE_CURRENT_LIST_DIR}/./contrib/qoi")
add_library(skiaVideo_imported OBJECT IMPORTED)
set_property(TARGET skiaVideo_imported PROPERTY IMPORTED_OBJECTS "${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/obj/../libskparagraph.a"
"${CMAKE_CURRENT_LIST_DIR}/./contrib/skia/out/Static/obj/../libsvg.a"
Expand Down
1 change: 1 addition & 0 deletions skia/contrib/qoi
1 change: 1 addition & 0 deletions skia/generate_links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ link ../common/contrib/imgui_implot/implot_demo.cpp ./implot/implot_demo.cpp
link ../common/contrib/imgui_ImGuiColorTextEdit/TextEditor.cpp ./imcolortextedit/TextEditor.cpp
link ../common/contrib/imgui_ImGuiColorTextEdit/TextEditor.h ./imcolortextedit/TextEditor.h
link ../common/contrib/sdl3 contrib/sdl3
link ../common/contrib/qoi contrib/qoi
115 changes: 75 additions & 40 deletions skia/skia/video/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@
#include "include/encode/SkWebpEncoder.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/gl/GrGLInterface.h"
#if defined(__linux__)
#include "include/gpu/gl/glx/GrGLMakeGLXInterface.h"
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <GL/gl.h>
#endif

#include "gpu/ganesh/gl/GrGLDirectContext.h"
#include "gpu/ganesh/SkSurfaceGanesh.h"
#include "gpu/ganesh/gl/GrGLBackendSurface.h"
#include "src/gpu/ganesh/gl/GrGLDefines.h"
#include "src/gpu/ganesh/gl/GrGLUtil.h"
//#include "SkBitmap.h"


#include "tracy/Tracy.hpp"

Expand All @@ -36,6 +24,22 @@
#include "marshalling/receive.h"
#include "marshalling/send.h"

#define QOI_IMPLEMENTATION
#define QOI_NO_STDIO
#define QOI_FREE static_assert(false && "free should never be called")
#define QOI_MALLOC(sz) qoi_malloc(sz)
static void *qoi_malloc(size_t sz) {
static void *qoiBuffer = nullptr;
static size_t lastSz = 0;
if(qoiBuffer == nullptr) {
lastSz = sz;
qoiBuffer = malloc(sz);
}
assert(lastSz == sz && "assuming constant width, height and depth of qoi images");
return qoiBuffer;
}
#include "qoi.h"

template <typename T>
static inline void applyFlag(int &flag,T val,bool v) {
if(v) {
Expand Down Expand Up @@ -342,41 +346,72 @@ int App::Run(CliOptions &opts) {
options.fQuality = 70.0f;
}
auto stream = SkFILEWStream(opts.videoRawFramesFile);
qoi_desc qd{
static_cast<unsigned int>(w),
static_cast<unsigned int>(h),
4,
QOI_SRGB
};
char pamHeader[4096];
snprintf(pamHeader, sizeof(pamHeader), "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", w, h);
auto pamHeaderLen = strlen(pamHeader);
while(!done) {
ImGui::NewFrame();

ImGui::ShowMetricsWindow();

sk_sp<SkImage> img(rasterSurface->makeImageSnapshot(SkIRect::MakeWH(w,h)));
if(true) {
{ ZoneScoped;
auto canvas = rasterSurface->getCanvas();
canvas->clear(clearColor);
Paint(rasterSurface.get(),w,h); // will call ImGui::Render();
}
{ ZoneScoped;
SkPixmap pixmap;
if(img->peekPixels(&pixmap)) {
if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) {
fprintf(stderr,"unable to encode frame as image. Skipping.\n");
{ ZoneScoped;
auto canvas = rasterSurface->getCanvas();
canvas->clear(clearColor);
Paint(rasterSurface.get(),w,h); // will call ImGui::Render();
}
switch(1) {
case 0:
{ ZoneScoped;
SkPixmap pixmap;
if(img->peekPixels(&pixmap)) {
if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) {
fprintf(stderr,"unable to encode frame as image. Skipping.\n");
}
}
}
}
} else {
Paint(nullptr,w,h); // will call ImGui::Render();

snprintf(pathBuffer,sizeof(pathBuffer),"/tmp/video/out_%09u.flatbuffers",frame);
SkFILEWStream stream(pathBuffer);

const ImDrawData* drawData = ImGui::GetDrawData();
fTotalVectorCmdSerializedSize = 0;
for (int i = 0; i < drawData->CmdListsCount; ++i) {
ImDrawList* drawList = drawData->CmdLists[i];
const uint8_t *buf;
size_t sz;
drawList->serializeFB(buf,sz);
stream.write(buf,sz);
}
break;
case 1:
{ ZoneScoped;
SkPixmap pixmap;
if (img->peekPixels(&pixmap)) {
int imgLen;
auto const imgMem = qoi_encode(pixmap.addr(), &qd, &imgLen);
stream.write(imgMem, static_cast<size_t>(imgLen));
stream.flush();
}
}
break;
case 2:
{ ZoneScoped;
SkPixmap pixmap;
if (img->peekPixels(&pixmap)) {
stream.write(pamHeader, pamHeaderLen);
stream.write(pixmap.addr(),pixmap.computeByteSize());
stream.flush();
}
}
break;
case 3:
{ ZoneScoped;
const ImDrawData* drawData = ImGui::GetDrawData();
fTotalVectorCmdSerializedSize = 0;
for (int i = 0; i < drawData->CmdListsCount; ++i) {
ImDrawList* drawList = drawData->CmdLists[i];
const uint8_t *buf;
size_t sz;
drawList->serializeFB(buf,sz);
stream.write(buf,sz);
}
stream.flush();
}
break;
}

{
Expand Down
2 changes: 1 addition & 1 deletion skia/video.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pid=$!
#-loglevel debug \
ffmpeg -hide_banner \
-re -fflags +genpts \
-f image2pipe -i transferRawFrames \
-f image2pipe -vcodec qoi -i transferRawFrames \
-flags +global_header -r 30000/1001 \
-an \
-vaapi_device /dev/dri/renderD128 \
Expand Down
20 changes: 20 additions & 0 deletions skia/video_null.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
rm -f transferRawFrames
mkfifo transferRawFrames

resW=1920
resH=1080

./imgui_skia_exe -fffiInterpreter off -ttfFilePath ./SauceCodeProNerdFontPropo-Regular.ttf -backdropFilter off -videoRawFramesFile transferRawFrames -videoResolutionWidth $resW -videoResolutionHeight $resH &
pid=$!
cat transferRawFrames | tee out.raw | \
mpv --no-cache --untimed --no-demuxer-thread -
#ffplay -hide_banner \
# -threads 1 -filter_threads 1 \
# -probesize 32 -sync ext \
# -fpsprobesize 0 -framedrop -fast -infbuf \
# -f nut -fflags '+nobuffer' -flags2 '+fast' -i "pipe:0" \
# -vf "drawtext=text='%{localtime\:%S-%6N}':fontsize=144:box=1:boxcolor=black:fontcolor=red:y=(main_h/2)+text_h"

#mpv --no-cache --untimed --no-demuxer-thread --video-sync=audio \
kill $pid

0 comments on commit 390d5af

Please sign in to comment.