Skip to content

Commit 59da775

Browse files
committed
wip: direct video output
1 parent 8185c18 commit 59da775

File tree

5 files changed

+37
-28
lines changed

5 files changed

+37
-28
lines changed

skia/run_pipe.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ rm -f transfer
44
mkfifo transfer
55
font="./martian/MartianMono-StdRg.ttf"
66
font="./SauceCodeProNerdFontMono-Regular.ttf"
7-
./main_go --logFormat console demo --mainFontTTF "$font" --mainFontSizeInPixels 13 "$@" < transfer | ./imgui_exe -ttfFilePath "$font" -fffiInterpreter on -skiaBackendType gl -vsync on -backdropFilter on > transfer
7+
./main_go --logFormat console demo --mainFontTTF "$font" --mainFontSizeInPixels 13 "$@" < transfer | \
8+
./imgui_exe -ttfFilePath "$font" -fffiInterpreter on -skiaBackendType gl -vsync on -backdropFilter off \
9+
-videoRawFramesFile transferRawFrames -videoResolutionWidth 1920 -videoResolutionHeight 1080 > transfer
810
rm -f transfer

skia/skia/cliOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void CliOptions::parse(int argc,char **argv,FILE *logChannel) {
120120

121121
videoRawFramesFile = findFlagValueDefault(logChannel,u, argc, argv,"-videoRawFramesFile",videoRawFramesFile);
122122
videoResolutionWidth = static_cast<uint32_t>(findFlagValueDefaultInt(logChannel, u, argc, argv, "-videoResolutionWidth", "1920"));
123-
videoResolutionWidth = static_cast<uint32_t>(findFlagValueDefaultInt(logChannel, u, argc, argv, "-videoResolutionHeight", "1080"));
123+
videoResolutionHeight = static_cast<uint32_t>(findFlagValueDefaultInt(logChannel, u, argc, argv, "-videoResolutionHeight", "1080"));
124124

125125
if(std::popcount(u) != (argc-1)) {
126126
for(int i=1;i<argc;i++) {

skia/skia/cliOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <cstdio>
3+
#include <cstdint>
34
auto constexpr defaultTtfFilePath = "./SauceCodeProNerdFontPropo-Regular.ttf";
45
struct CliOptions {
56
const char *ttfFilePath = defaultTtfFilePath;

skia/skia/video/app.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,18 @@ int App::Run(CliOptions &opts) {
268268
fVectorCmdSkiaRenderer.changeRenderMode(mode);
269269
}
270270

271-
int w = opts.videoResolutionWidth;
272-
constexpr auto wf = static_cast<float>(w);
273-
int h = opts.videoResolutionHeight;
274-
constexpr auto hf = static_cast<float>(h);
271+
const int w = opts.videoResolutionWidth;
272+
const auto wf = static_cast<float>(w);
273+
const int h = opts.videoResolutionHeight;
274+
const auto hf = static_cast<float>(h);
275+
if(w == 0 || h == 0) {
276+
fprintf(stderr, "invalid video resolution: %ux%u\n", w,h);
277+
exit(1);
278+
}
275279

276280
IMGUI_CHECKVERSION();
277281
ImGui::CreateContext();
278-
ImVec4 clear_color;
282+
ImVec4 clearColorImVec4;
279283
ImGuiIO &io = ImGui::GetIO();
280284
{
281285
applyFlag(io.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard, opts.imguiNavKeyboard);
@@ -298,7 +302,7 @@ int App::Run(CliOptions &opts) {
298302
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
299303
}
300304

301-
clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
305+
clearColorImVec4 = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
302306

303307
io.DisplaySize.x = wf;
304308
io.DisplaySize.y = hf;
@@ -328,7 +332,7 @@ int App::Run(CliOptions &opts) {
328332
bool done = false;
329333
char pathBuffer[4096];
330334
uint32_t frame = 0;
331-
auto clearColor = SkColorSetARGB(clear_color.w*255.0f,clear_color.x*255.0f,clear_color.y*255.0f,clear_color.z*255.0f);
335+
auto clearColor = SkColorSetARGB(clearColorImVec4.w * 255.0f, clearColorImVec4.x * 255.0f, clearColorImVec4.y * 255.0f, clearColorImVec4.z * 255.0f);
332336
SkWebpEncoder::Options options;
333337
if(true) {
334338
options.fCompression = SkWebpEncoder::Compression::kLossless;
@@ -337,8 +341,7 @@ int App::Run(CliOptions &opts) {
337341
options.fCompression = SkWebpEncoder::Compression::kLossy;
338342
options.fQuality = 70.0f;
339343
}
340-
auto stream = SkDynamicMemoryWStream();
341-
auto buffer = malloc(10*1024*1024);
344+
auto stream = SkFILEWStream(opts.videoRawFramesFile);
342345
while(!done) {
343346
ImGui::NewFrame();
344347

@@ -352,17 +355,12 @@ int App::Run(CliOptions &opts) {
352355
Paint(rasterSurface.get(),w,h); // will call ImGui::Render();
353356
}
354357
{ ZoneScoped;
355-
//snprintf(pathBuffer,sizeof(pathBuffer),"/tmp/video/out_%09u.webp",frame);
356-
//SkFILEWStream stream(pathBuffer);
357358
SkPixmap pixmap;
358359
if(img->peekPixels(&pixmap)) {
359-
if (SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) {
360-
//fprintf(stderr,"successfully written %d Bytes to %s\n",(int)stream.bytesWritten(), pathBuffer);
360+
if (!SkWebpEncoder::Encode(static_cast<SkWStream *>(&stream), pixmap, options)) {
361+
fprintf(stderr,"unable to encode frame as image. Skipping.\n");
361362
}
362363
}
363-
auto sz = stream.bytesWritten();
364-
stream.copyToAndReset(buffer);
365-
fwrite(buffer,sz,1,stdout);
366364
}
367365
} else {
368366
Paint(nullptr,w,h); // will call ImGui::Render();

skia/video.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
rm -f transferRawFrames
3+
mkfifo transferRawFrames
4+
25
#./imgui_skia_exe -fffiInterpreter off -ttfFilePath ./SauceCodeProNerdFontPropo-Regular.ttf -backdropFilter off | \
36
# ffmpeg -readrate 1 \
47
# -report \
@@ -51,19 +54,24 @@
5154
## -f nut -i "pipe:0"
5255

5356
# needs apt install intel-media-va-driver-non-free
54-
./imgui_skia_exe -fffiInterpreter off -ttfFilePath ./SauceCodeProNerdFontPropo-Regular.ttf -backdropFilter off | \
57+
58+
#./imgui_skia_exe -fffiInterpreter off -ttfFilePath ./SauceCodeProNerdFontPropo-Regular.ttf -backdropFilter off -videoRawFramesFile transferRawFrames -videoResolutionWidth 1024 -videoResolutionHeight 768 &
59+
./run_pipe.sh &
60+
pid=$!
5561
ffmpeg -hide_banner \
56-
-loglevel debug \
57-
-re -fflags +genpts \
58-
-f image2pipe -i - \
59-
-flags +global_header -r 30000/1001 \
60-
-vaapi_device /dev/dri/renderD128 \
61-
-vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' \
62-
-c:v h264_vaapi -qp:v 26 -bf 0 -tune zerolatency \
63-
-c:a aac -ar 48000 -b:a 96k \
64-
-f nut "pipe:1" | \
62+
-loglevel debug \
63+
-re -fflags +genpts \
64+
-f image2pipe -i transferRawFrames \
65+
-flags +global_header -r 30000/1001 \
66+
-vaapi_device /dev/dri/renderD128 \
67+
-vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' \
68+
-c:v h264_vaapi -qp:v 26 -bf 0 -tune zerolatency \
69+
-c:a aac -ar 48000 -b:a 96k \
70+
-f nut "pipe:1" | \
6571
mpv --no-cache --untimed --no-demuxer-thread --video-sync=audio \
6672
--vd-lavc-threads=1 -
73+
kill $pid
74+
6775
#ffplay -hide_banner \
6876
# -analyzeduration 1 -fflags -nobuffer -probesize 32 -sync ext \
6977
# -f nut -i "pipe:0"

0 commit comments

Comments
 (0)