cuda與gl互操作:
int decode(cucontext cucontext, char *szinfilepath)
nframe += nframereturned;
} while (nvideobytes);
std::cout << "total frame decoded: "
<< nframe << std::endl;
return 0
;}
// framepresentergl presenter(cucontext, demuxer.getwidth(), demuxer.getheight())
framepresentergl(cucontext cucontext, int nwidth, int nheight) :cucontext(cucontext), nwidth(nwidth), nheight(nheight)
}
void run()
int argc = 1;
const
char *argv = ;
/// glut初始化
glutinit(&argc, (char **)argv);
glutinitdisplaymode(glut_rgb | glut_double);
glutinitwindowsize(w, h);
glutcreatewindow("framepresentergl");
glutsetoption(glut_action_on_window_close, glut_action_continue_execution);
glviewport(0, 0, w, h);
glmatrixmode(gl_modelview);
glloadidentity();
glmatrixmode(gl_projection);
glloadidentity();
glortho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
// glew初始化
glewinit();
glgenbuffersarb(1, &pbo);
glbindbufferarb(gl_pixel_unpack_buffer_arb, pbo);
glbufferdataarb(gl_pixel_unpack_buffer_arb, nwidth * nheight * 4, null, gl_stream_draw_arb);
glbindbufferarb(gl_pixel_unpack_buffer_arb, 0);
// 設定紋理
glgentextures(1, &tex); // tex
glbindtexture(gl_texture_rectangle_arb, tex);
glteximage2d(gl_texture_rectangle_arb, 0, gl_rgba8, nwidth, nheight, 0, gl_rgba, gl_unsigned_byte, null);// 格式為rgba8,最後乙個為null,說明是從gpu裡傳資料
gltexparameteri(gl_texture_rectangle_arb, gl_texture_min_filter, gl_nearest);
gltexparameteri(gl_texture_rectangle_arb, gl_texture_mag_filter, gl_nearest);
glbindtexture(gl_texture_rectangle_arb, 0);
static
const
char *code =
"!!arbfp1.0\n"
"tex result.color, fragment.texcoord, texture[0], rect; \n"
"end";
glgenprogramsarb(1, &shader);
glbindprogramarb(gl_fragment_program_arb, shader);
glprogramstringarb(gl_fragment_program_arb, gl_program_format_ascii_arb, (glsizei)strlen(code), (glubyte *)code);
glutdisplayfunc(displayproc);// glutdisplayfunc函式用於註冊乙個繪圖函式,
glutclosefunc(closewindowproc);
ck(cuctxsetcurrent(cucontext));
ck(cumemalloc(&dpframe, nwidth * nheight * 4));
ck(cumemsetd8(dpframe, 0, nwidth * nheight * 4));
pinstance = this;
while (!bstop)
pinstance = null;
ck(cumemfree(dpframe));
gldeletebuffersarb(1, &pbo);
gldeletetextures(1, &tex);
gldeleteprogramsarb(1, &shader);
}
void display(void) ;
m.srcmemorytype = cu_memorytype_device;
m.srcdevice = dpframe; // source,解碼獲得的nv12轉成bgra8的指標
m.srcpitch = nwidth * 4;
m.dstmemorytype = cu_memorytype_device;
m.dstdevice = dpbackbuffer;// gl對映到cuda中的指標
m.dstpitch = nsize / nheight;
m.widthinbytes = nwidth * 4;
m.height = nheight;
ck(cumemcpy2dasync(&m, 0)); // 非同步拷貝
// 解除map
ck(cugraphicsunmapresources(1, &curesource, 0));
// 解除註冊
ck(cugraphicsunregisterresource(curesource));
// 繪圖
glbindbufferarb(gl_pixel_unpack_buffer_arb, pbo);
glbindtexture(gl_texture_rectangle_arb, tex);
gltexsubimage2d(gl_texture_rectangle_arb, 0, 0, 0, nwidth, nheight, gl_bgra, gl_unsigned_byte, 0);
glbindbufferarb(gl_pixel_unpack_buffer_arb, 0);
glbindprogramarb(gl_fragment_program_arb, shader);
glenable(gl_fragment_program_arb);
gldisable(gl_depth_test);
glbegin(gl_quads);
gltexcoord2f(0, (glfloat)nheight);
glvertex2f(0, 0);
gltexcoord2f((glfloat)nwidth, (glfloat)nheight);
glvertex2f(1, 0);
gltexcoord2f((glfloat)nwidth, 0);
glvertex2f(1, 1);
gltexcoord2f(0, 0);
glvertex2f(0, 1);
glend();
glbindtexture(gl_texture_rectangle_arb, 0);
gldisable(gl_fragment_program_arb);
if (!strtext.empty())
glutswapbuffers();
glutpostredisplay();
}
miscellaneous 硬解碼與軟解碼
在顯示卡技術日益成熟的今天,一些概念我們都不是很清楚了,那麼顯示卡硬體解碼功能是什麼意思呢?高畫質硬解和軟體有什麼不同呢?顯示卡配置需不需要考慮硬體解碼呢?電腦愛好者為您分析。什麼是硬體解碼?來做,而gpu的並行運算能力要遠遠高於cpu,這樣可以大大的降低對cpu的負載,cpu的佔用率較低了之後就可...
ffmpeg硬編譯碼
對不同的平台,有不同的命令。這裡介紹一下gpu及intel qsv quick sync vedio 1 gpu 檢視n卡做h264編碼時的引數 ffmpeg h encoder h264 nvenc 檢視n卡做h264解碼時的引數 ffmpeg h decoder h264 cuvid 例子 ff...
HEVC的軟解碼和硬解碼
2.歷史 3.解碼流程以及軟硬解碼的區別 4.軟解碼和硬解碼的應用 軟解碼主要在下列裝置廣泛應用 硬解碼主要應用於下列裝置 2 機頂盒。早期的機頂盒基本上是乙個mips架構的cpu 硬體解碼模組。所以在這種裝置上只存在硬解碼一種情形。不過最近比較新的機頂盒採用與智慧型手機相同檔次的晶元,但是基於成本...