Skip to content

Commit

Permalink
V1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Mar 10, 2021
1 parent ec18268 commit 9f06db6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ console.log(image)
```

### Playing Videos
To play a video, there are 3 different functions. All functions below are prefixed with `video`. The reason for 3 functions is that "framifying" takes time depending on the video length, and you might already have frames ready for rendering.
Video playing contains 4 different functions. The first 2 or `framify` and `render`. They are split into 2 different functions for speed reasons. Becuase, you can already have frames ready, and have no need to run `framify`. The third function is called `runall`, and it runs `framify`, then `render`. Now, the 4th function is a special version of `render` called `advrender`.

#### 1. framify
The `framify` function takes a video input and converts it to a folder full of frames. The folder is located in the current working directory. ***NOTE***: Please create a `frames` folder in the current working directory before running.
Expand All @@ -70,6 +70,9 @@ The `runall` function runs both of the functions.
await tools.video.runall("sample.mp4")
```

#### 4. advrender
The `advrender` function renders the frames in 2 parts, first it pre-renders ***ALL*** the frames, then it renders them. The reason for this is it increases the speed of the video, by processing the frames before playback, instead of during

### Loader
There are currently 2 loaders available.
#### 1. line
Expand Down
31 changes: 26 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terminaltools",
"version": "1.5.1",
"version": "1.6.0",
"description": "terminaltools allows you to do tricks in the terminal like play videos, show images and more.",
"main": "tools.js",
"scripts": {
Expand Down Expand Up @@ -41,7 +41,8 @@
"ansi-escapes": "^4.3.1",
"cli-frames": "^2.2.10",
"ffmpeg": "^0.0.4",
"jimp": "^0.16.1"
"jimp": "^0.16.1",
"terminaltools": "^1.5.1"
},
"homepage": "https://github.com/redyetidev/terminaltools"
}
26 changes: 26 additions & 0 deletions tools/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async function framify(video) {
var process = new ffmpeg(video);
process.then(function (video) {
fps = video.metadata.fps
console.log("Framifying...")
video.fnExtractFrameToJPG("frames", {
every_n_frames : 1
}, function() {
Expand Down Expand Up @@ -44,6 +45,30 @@ async function render(frames) {
return resolve("Rendered")
})
}
async function advrender(frames) {
fps = fps || frames || 30;
var pf = [];
return new Promise(async(resolve, reject) => {
var frames = await fs.readdirSync("frames")
var fn = frames[0].split(/_\d+.jpg/)[0] + "_"
frames.sort((a, b) => parseInt(a.split(fn)[1].split(".jpg")) - parseInt(b.split(fn)[1].split(".jpg")));
frames.forEach((item, i) => {
frames[i] = path.join("frames", item)
});
process.stdout.write("\033[" + process.stdout.columns + "Prerendering Frames")
for (var i in frames) {
var frame = await specialrender(frames[i])
pf.push(frame)
process.stdout.write("\033[" + process.stdout.columns + "D" + i + " out of " + frames.length + " frames prepared")
}
process.stdout.write("\033[" + process.stdout.columns + "DRendering...")
for (var i in pf) {
process.stdout.write("\033[0;0H" + pf[i])
await delay(fps)
}
return resolve("Rendered")
})
}
// Full
async function full(video) {
return new Promise(async(resolve, reject) => {
Expand All @@ -52,5 +77,6 @@ async function full(video) {
})
}
module.exports.render = render
module.exports.advrender = advrender
module.exports.framify = framify
module.exports.runall = full

0 comments on commit 9f06db6

Please sign in to comment.