--- a/hedgewars/uVideoRec.pas Sun Mar 20 01:16:11 2016 -0400
+++ b/hedgewars/uVideoRec.pas Sun Mar 20 03:08:51 2016 -0400
@@ -58,7 +58,7 @@
filename, desc, soundFile, format, vcodec, acodec: PChar;
width, height, framerateNum, framerateDen, vquality: LongInt): LongInt; cdecl; external AvwrapperLibName;
function AVWrapper_Close: LongInt; cdecl; external AvwrapperLibName;
-function AVWrapper_WriteFrame( pY, pCb, pCr: PByte ): LongInt; cdecl; external AvwrapperLibName;
+function AVWrapper_WriteFrame(rgb: PByte): LongInt; cdecl; external AvwrapperLibName;
type TFrame = record
realTicks: LongWord;
@@ -121,15 +121,6 @@
true) then exit(false);
numPixels:= cScreenWidth*cScreenHeight;
- YCbCr_Planes[0]:= GetMem(numPixels);
- YCbCr_Planes[1]:= GetMem(numPixels div 4);
- YCbCr_Planes[2]:= GetMem(numPixels div 4);
-
- if (YCbCr_Planes[0] = nil) or (YCbCr_Planes[1] = nil) or (YCbCr_Planes[2] = nil) then
- begin
- AddFileLog('Error: Could not allocate memory for video recording (YCbCr buffer).');
- exit(false);
- end;
RGB_Buffer:= GetMem(4*numPixels);
if RGB_Buffer = nil then
@@ -147,9 +138,6 @@
procedure StopVideoRecording;
begin
AddFileLog('StopVideoRecording');
- FreeMem(YCbCr_Planes[0], numPixels);
- FreeMem(YCbCr_Planes[1], numPixels div 4);
- FreeMem(YCbCr_Planes[2], numPixels div 4);
FreeMem(RGB_Buffer, 4*numPixels);
Close(cameraFile);
if AVWrapper_Close() < 0 then
@@ -159,36 +147,13 @@
SendIPC(_S'v'); // inform frontend that we finished
end;
-function pixel(x, y, color: LongInt): LongInt;
-begin
- pixel:= RGB_Buffer[(cScreenHeight-y-1)*cScreenWidth*4 + x*4 + color];
-end;
-
procedure EncodeFrame;
-var x, y, r, g, b: LongInt;
- s: shortstring;
+var s: shortstring;
begin
// read pixels from OpenGL
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_RGBA, GL_UNSIGNED_BYTE, RGB_Buffer);
- // convert to YCbCr 4:2:0 format
- // Y
- for y := 0 to cScreenHeight-1 do
- for x := 0 to cScreenWidth-1 do
- YCbCr_Planes[0][y*cScreenWidth + x]:= Byte(16 + ((16828*pixel(x,y,0) + 33038*pixel(x,y,1) + 6416*pixel(x,y,2)) shr 16));
-
- // Cb and Cr
- for y := 0 to cScreenHeight div 2 - 1 do
- for x := 0 to cScreenWidth div 2 - 1 do
- begin
- r:= pixel(2*x,2*y,0) + pixel(2*x+1,2*y,0) + pixel(2*x,2*y+1,0) + pixel(2*x+1,2*y+1,0);
- g:= pixel(2*x,2*y,1) + pixel(2*x+1,2*y,1) + pixel(2*x,2*y+1,1) + pixel(2*x+1,2*y+1,1);
- b:= pixel(2*x,2*y,2) + pixel(2*x+1,2*y,2) + pixel(2*x,2*y+1,2) + pixel(2*x+1,2*y+1,2);
- YCbCr_Planes[1][y*(cScreenWidth div 2) + x]:= Byte(128 + ((-2428*r - 4768*g + 7196*b) shr 16));
- YCbCr_Planes[2][y*(cScreenWidth div 2) + x]:= Byte(128 + (( 7196*r - 6026*g - 1170*b) shr 16));
- end;
-
- if AVWrapper_WriteFrame(YCbCr_Planes[0], YCbCr_Planes[1], YCbCr_Planes[2]) < 0 then
+ if AVWrapper_WriteFrame(RGB_Buffer) < 0 then
halt(-1);
// inform frontend that we have encoded new frame