Skip to content

Commit

Permalink
Merge pull request #170 from girlbymirror/master
Browse files Browse the repository at this point in the history
Support: Resize
  • Loading branch information
girlbymirror authored Aug 13, 2022
2 parents 01a888f + 62b7c00 commit e33b061
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
| 获取 音频采样率 || ---- |
| 追帧策略算法 || HTTP-FLV(no audio) |
| 倍速调整 || H.264/AV1 |
| Resize缩放 || ---- |

<br>

Expand Down
13 changes: 12 additions & 1 deletion README_EN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ Notice:

- [Play frame by frame(next frame)](#nextframe)

- [Resize](#resize)

- [Snapshot](#snapshot)

- [Release Player](#release)
Expand Down Expand Up @@ -251,6 +253,7 @@ Notice:
| Get Audio SampleRate | Y | ---- |
| Chase Frame | Y | HTTP-FLV(no audio) |
| PlayBackRate | Y | H.264/AV1 |
| Resize | Y | ---- |

<br>

Expand Down Expand Up @@ -860,10 +863,16 @@ player.closeFullScreen();

| Function | Return | Desc |
| ---- | ---- | ---- |
| playNextFrame() | - | play next frame |
| playNextFrame() | true/false | play next frame |

<br>

#### resize ####

| Function | Return | Desc |
| ---- | ---- | ----|
| resize(width, height) | true/false | resize |


#### snapshot ####

Expand Down Expand Up @@ -956,6 +965,8 @@ ffmpeg -ss 20 -t 10 -i ./res/xinxiaomen.mp4 \

| Update | Content |
| ---- | ---- |
| Time | 2022/08/13 |
| - | 0.Support: Resize |
| Time | 2022/07/27 |
| - | 0.Support: PlayBackRate |
| Time | 2022/07/12 |
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist-multi-thread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220801');
require('./h265webjs-v20220813');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220801');
require('./h265webjs-v20220813');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example_normal/dist-multi-thread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220801');
require('./h265webjs-v20220813');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example_normal/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220801');
require('./h265webjs-v20220813');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
2 changes: 1 addition & 1 deletion example_normal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<link rel="stylesheet" type="text/css" href='player-view/css/button.css'>
<link rel="stylesheet" type="text/css" href='player-view/css/progress.css'>
<script src="dist/missile.js"></script>
<script src="dist/h265webjs-v20220801.js"></script>
<script src="dist/h265webjs-v20220813.js"></script>
<script src="index.js"></script>

</head>
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example_vue/public/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220801');
require('./h265webjs-v20220813');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
4 changes: 2 additions & 2 deletions index-debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<meta charset="utf-8" name="github" content="https://github.com/numberwolf/h265web.js">

<script src="dist/missile.js"></script> <!-- IMPORTANT -->
<script src="dist/h265webjs-v20220801.js"></script> <!-- IMPORTANT -->
<script src="dist/h265webjs-v20220813.js"></script> <!-- IMPORTANT -->

<!--<script src="dist-multi-thread/missile-multi-thread.js"></script>
<script src="dist-multi-thread/h265webjs-v20220801.js"></script>-->
<script src="dist-multi-thread/h265webjs-v20220813.js"></script>-->

<style>
</style>
Expand Down
76 changes: 76 additions & 0 deletions src/src/h265webjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,82 @@ class H265webjsModule {
return false;
} // showNextFrame

resize(width, height) {
let _this = this;
// _this.playParam.size = {
// width : _this.player.mediaInfo.width,
// height : _this.player.mediaInfo.height
// };
if (this.player !== undefined && this.player !== null) {
if (!width ||
!height ||
!this.playParam.size.width ||
!this.playParam.size.height
) {
return false;
}

const mediaW = this.playParam.size.width;
const mediaH = this.playParam.size.height;

const isHEVC = this.playParam.videoCodec === 0;
const glCanvasBox = document
.querySelector('#' + this.configFormat.playerId);
glCanvasBox.style.width = width + "px";
glCanvasBox.style.height = height + "px";

if (isHEVC === true) {
// soft decoder
let resizeBase = (targetWidth, targetHeight) => {
// console.log('checkDisplaySize==========>', targetWidth, targetHeight, mediaW, mediaH);
let biggerWidth = mediaW / targetWidth > mediaH / targetHeight;
let fixedWidth = (targetWidth / mediaW).toFixed(2);
let fixedHeight = (targetHeight / mediaH).toFixed(2);
let scaleRatio = biggerWidth ? fixedWidth : fixedHeight;

let width = parseInt(mediaW * scaleRatio, 10);
let height = parseInt(mediaH * scaleRatio, 10);
// console.log(
// 'checkDisplaySize ==========>',
// targetWidth, targetHeight, mediaW, mediaH);
// console.log(
// 'checkDisplaySize ret ==========>', width, height);

console.log("debug resize => targetHeight:", targetHeight, ", height:", height);
console.log("debug resize => targetWidth:", targetWidth, ", width:", width);

let topMargin = parseInt((targetHeight - height) / 2, 10);
let leftMargin = parseInt((targetWidth - width) / 2, 10);
// console.log(topMargin, leftMargin);
// player.isCheckDisplay = true;
return [topMargin, leftMargin, width, height];
}; // end resizeBase

let glCanvas = glCanvasBox
.getElementsByTagName('canvas')[0];

let resizeData = resizeBase(width, height);
console.log("debug resize => resizeData:", resizeData);

glCanvas.style.marginTop = resizeData[0] + 'px';
glCanvas.style.marginLeft = resizeData[1] + 'px';
glCanvas.style.width = resizeData[2] + 'px';
glCanvas.style.height = resizeData[3] + 'px';
} else {
// native
let glCanvas = glCanvasBox
.getElementsByTagName('video')[0];

glCanvas.style.width = width + 'px';
glCanvas.style.height = height + 'px';
} // end check avc/hevc resize

return true;
}

return false;
}

/**********
Private
**********/
Expand Down
2 changes: 1 addition & 1 deletion src/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Github: https://github.com/numberwolf/h265web.js
*
**********************************************************/
require('./h265webjs-v20220801');
require('./h265webjs-v20220813');
export default class h265webjs {
static createPlayer(videoURL, config) {
return window.new265webjs(videoURL, config);
Expand Down
2 changes: 1 addition & 1 deletion src/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
# * Github: https://github.com/numberwolf/h265web.js
# *
# **********************************************************/
VERSION='v20220801' # output version + index.js
VERSION='v20220813' # output version + index.js
WASM_VERSION='v20220706'

0 comments on commit e33b061

Please sign in to comment.