Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
webpage_recorder
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
胡斌
8 years ago
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e89112f4aed19cf77e490ecc300a28368af3180f
e89112f4
1 parent
7935136a
use timer to feed captured bitmap to ffmpeg,to avoid locking of frame
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
58 行增加
和
12 行删除
main.js
main.js
查看文件 @
e89112f
...
...
@@ -22,13 +22,32 @@ ipc.on('close-main-window', function () {
var
lastRenderTime
=
0
;
var
contentBitmap
=
null
;
var
duration
=
10000
;
//set duration 10s
var
start
=
Date
.
now
()
ipc
.
on
(
'to-main-timer'
,
function
()
{
if
(
Date
.
now
()
-
lastRenderTime
>=
10000
)
{
/* if(lastMainTimerCalledTime){
var now = Date.now();
console.log("time-diff:",now - lastMainTimerCalledTime);
lastMainTimerCalledTime = now;
}
else{
lastMainTimerCalledTime = Date.now();
}
*/
if
(
contentBitmap
&&
streamIn
){
streamIn
.
write
(
contentBitmap
);
}
if
(
Date
.
now
()
-
start
>=
duration
)
{
if
(
streamIn
)
{
streamIn
.
end
();
streamIn
=
null
;
}
if
(
Date
.
now
()
-
lastRenderTime
>=
15000
)
{
if
(
Date
.
now
()
-
start
>=
duration
+
10000
)
{
//quit after duration + 10s
quit
();
}
}
...
...
@@ -73,17 +92,29 @@ if(!argv.h){//width
argv
.
h
=
"600"
;
}
if
(
!
argv
.
b
){
//bitrate
argv
.
b
=
"1000k"
;
}
if
(
!
argv
.
o
){
//offscreen
argv
.
o
=
true
;
}
function
startFFmpeg
(
videosize
)
{
const
args
=
[
'-y'
,
'-f'
,
'rawvideo'
,
'-pix_fmt'
,
'bgra'
,
'-s'
];
var
size
=
videosize
.
width
+
'x'
+
videosize
.
height
args
.
push
(
size
);
args
.
push
(
'-r'
);
args
.
push
(
argv
.
f
);
args
.
push
.
apply
(
args
,
[
'-i'
,
'pipe:0'
]
);
args
.
push
(
'-vf'
)
args
.
push
(
'fps=fps='
+
argv
.
f
)
args
.
push
(
'-c:v'
);
args
.
push
(
'libx264'
);
args
.
push
(
'-b:v'
);
args
.
push
(
'1024k'
);
args
.
push
(
argv
.
b
);
args
.
push
(
'-r:v'
);
args
.
push
(
argv
.
f
);
args
.
push
(
'-an'
);
...
...
@@ -92,8 +123,13 @@ function startFFmpeg(videosize) {
console
.
log
(
args
.
join
`
`
);
ffmpeg
=
spawn
(
'ffmpeg'
,
args
);
ffmpeg
.
stderr
.
on
(
'data'
,
chunk
=>
console
.
log
(
chunk
.
toString
()));
streamIn
=
duplexer
(
ffmpeg
.
stdin
,
ffmpeg
.
stdout
);
if
(
ffmpeg
)
{
ffmpeg
.
stderr
.
on
(
'data'
,
chunk
=>
console
.
log
(
chunk
.
toString
()));
streamIn
=
duplexer
(
ffmpeg
.
stdin
,
ffmpeg
.
stdout
);
}
else
{
console
.
log
(
"can't start ffmpeg,please make sure ffmpeg is avaiable"
);
}
}
app
.
disableHardwareAcceleration
()
...
...
@@ -104,22 +140,27 @@ app.once('ready', () => {
width
:
argv
.
w
,
height
:
argv
.
h
,
webPreferences
:
{
offscreen
:
true
offscreen
:
argv
.
o
}
})
win
.
loadURL
(
argv
.
u
)
win
.
webContents
.
executeJavaScript
(
'const ipcToMain = require("electron").ipcRenderer;function timerToMain (){ ipcToMain.send("to-main-timer");}setInterval(timerToMain,10000);'
);
var
intervalms
=
1000
/
parseInt
(
argv
.
f
);
var
injectScript
=
'const ipcToMain = require("electron").ipcRenderer;function timerToMain (){ ipcToMain.send("to-main-timer");}setInterval(timerToMain,'
+
intervalms
+
');'
;
win
.
webContents
.
executeJavaScript
(
injectScript
);
var
start
=
Date
.
now
()
var
duration
=
parseInt
(
argv
.
d
)
*
1000
duration
=
parseInt
(
argv
.
d
)
*
1000
win
.
webContents
.
on
(
"paint"
,
function
(
event
,
dirty
,
image
)
{
if
(
!
ffmpeg
)
{
start
=
Date
.
now
();
startFFmpeg
(
image
.
getSize
());
if
(
!
ffmpeg
){
sendQuit
();
}
}
lastRenderTime
=
Date
.
now
();
var
elapsed
=
lastRenderTime
-
start
...
...
@@ -130,11 +171,12 @@ win.webContents.executeJavaScript('const ipcToMain = require("electron").ipcRend
}
console
.
log
(
"done"
)
if
(
elapsed
>
duration
+
5000
){
//delay 5s after closingSgit l pipe ,then close
win
.
webContents
.
executeJavaScript
(
'require("electron").ipcRenderer.send("close-main-window")'
);
sendQuit
(
);
}
}
else
{
streamIn
.
write
(
image
.
getBitmap
());
// streamIn.write(image.getBitmap());
contentBitmap
=
image
.
toBitmap
();
}
//console.log("painting", elapsed, win.webContents.isOffscreen(), win.webContents.getFrameRate())
...
...
@@ -142,3 +184,7 @@ win.webContents.executeJavaScript('const ipcToMain = require("electron").ipcRend
})
win
.
webContents
.
setFrameRate
(
parseInt
(
argv
.
f
));
})
function
sendQuit
(){
win
.
webContents
.
executeJavaScript
(
'require("electron").ipcRenderer.send("close-main-window")'
);
}
...
...
请
注册
或
登录
后发表评论