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
f1b8ad1befd5dee7ef8231588ed771090cd2c110
f1b8ad1b
1 parent
477b3cc3
use ffmpeg to record video ok,need more improvement
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
90 行增加
和
11 行删除
main.js
package.json
main.js
查看文件 @
f1b8ad1
'use strict'
;
const
{
app
,
BrowserWindow
}
=
require
(
'electron'
);
const
ipc
=
require
(
'electron'
).
ipcMain
;
const
duplexer
=
require
(
'duplexer3'
);
const
{
spawn
}
=
require
(
'child_process'
);
var
streamIn
=
null
;
var
ffmpeg
=
null
;
function
quit
(){
if
(
streamIn
){
streamIn
.
end
();
streamIn
=
null
;
}
app
.
quit
();
}
ipc
.
on
(
'close-main-window'
,
function
()
{
quit
();
});
var
lastRenderTime
=
0
;
ipc
.
on
(
'to-main-timer'
,
function
()
{
if
(
Date
.
now
()
-
lastRenderTime
>=
10000
){
quit
();
}
});
var
subarg
=
require
(
'subarg'
);
...
...
@@ -17,11 +45,43 @@ if (argv.d) {
console
.
log
(
args
);
}
if
(
!
argv
.
u
){
if
(
!
argv
.
u
){
//url
console
.
log
(
"you must input the web url to record with : -u "
);
return
app
.
quit
();
}
if
(
!
argv
.
d
){
//duration
console
.
log
(
"you must set the record duration in seconds with : -d "
);
return
app
.
quit
();
}
if
(
!
argv
.
f
){
//framerate
argv
.
f
=
"20"
;
}
function
startFFmpeg
(
videosize
)
{
const
args
=
[
'-y'
,
'-f'
,
'rawvideo'
,
'-pix_fmt'
,
'bgra'
,
'-s'
];
var
size
=
videosize
.
width
+
'x'
+
videosize
.
height
args
.
push
(
size
);
args
.
push
.
apply
(
args
,
[
'-i'
,
'pipe:0'
]
);
args
.
push
(
'-c:v'
);
args
.
push
(
'libx264'
);
args
.
push
(
'-b:v'
);
args
.
push
(
'1024k'
);
args
.
push
(
'-r:v'
);
args
.
push
(
argv
.
f
);
args
.
push
(
'-an'
);
args
.
push
(
argv
.
_
[
0
]);
console
.
log
(
args
.
join
`
`
);
ffmpeg
=
spawn
(
'ffmpeg'
,
args
);
ffmpeg
.
stderr
.
on
(
'data'
,
chunk
=>
console
.
log
(
chunk
.
toString
()));
streamIn
=
duplexer
(
ffmpeg
.
stdin
,
ffmpeg
.
stdout
);
}
app
.
disableHardwareAcceleration
()
let
win
...
...
@@ -33,17 +93,34 @@ app.once('ready', () => {
})
win
.
loadURL
(
argv
.
u
)
var
now
=
Date
.
now
()
win
.
webContents
.
executeJavaScript
(
'const ipcToMain = require("electron").ipcRenderer;function timerToMain (){ ipcToMain.send("to-main-timer");}setInterval(timerToMain,10000);'
);
var
start
=
Date
.
now
()
var
duration
=
parseInt
(
argv
.
d
)
*
1000
win
.
webContents
.
on
(
"paint"
,
function
(
event
,
dirty
,
image
)
{
if
(
!
ffmpeg
)
{
startFFmpeg
(
image
.
getSize
());
}
lastRenderTime
=
Date
.
now
();
var
elapsed
=
lastRenderTime
-
start
if
(
elapsed
>
duration
)
{
if
(
streamIn
)
{
streamIn
.
end
();
streamIn
=
null
;
}
console
.
log
(
"done"
)
win
.
webContents
.
executeJavaScript
(
'require("electron").ipcRenderer.send("close-main-window")'
);
}
else
{
streamIn
.
write
(
image
.
getBitmap
());
}
win
.
webContents
.
on
(
"paint"
,
function
(
event
,
dirty
,
image
){
console
.
log
(
"painting"
,
Date
.
now
()
-
now
,
win
.
webContents
.
isOffscreen
(),
win
.
webContents
.
getFrameRate
()
)
//console.log("painting", elapsed, win.webContents.isOffscreen(), win.webContents.getFrameRate())
now
=
Date
.
now
()
})
win
.
webContents
.
setFrameRate
(
20
)
win
.
webContents
.
setFrameRate
(
parseInt
(
argv
.
f
));
})
...
...
package.json
查看文件 @
f1b8ad1
...
...
@@ -14,6 +14,8 @@
"author"
:
"hubin"
,
"license"
:
"MIT"
,
"dependencies"
:
{
"child_process"
:
"^1.0.2"
,
"duplexer3"
:
"^0.1.4"
,
"electron"
:
"^1.6.11"
,
"subarg"
:
"^1.0.0"
},
...
...
请
注册
或
登录
后发表评论