Skip to content

Commit

Permalink
feat: Add support for ffprobe method
Browse files Browse the repository at this point in the history
  • Loading branch information
drawcall committed Jul 25, 2024
1 parent e82eb7c commit 87bf7a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19,400 deletions.
6 changes: 5 additions & 1 deletion lib/node/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ class FFGifImage extends FFImage {
let fps = null;
try {
const info = await this.geGifInfo();
fps = Number(info.fps);
const { streams = [{}] } = info;
const { avg_frame_rate = '24/1' } = streams[0];
const fpsFraction = avg_frame_rate.split('/');
const afps = fpsFraction[0] / fpsFraction[1];
fps = Math.round(Number(info.fps || afps));
} catch (e) {
console.log(this.getPath());
console.log(e);
Expand Down
8 changes: 5 additions & 3 deletions lib/utils/materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class Materials {
getSourceRect(width, height) {
if (!this.info) return new Rectangle(0, 0, width, height);

const { streams = [{ width: 0, height: 0 }] } = this.info;
let w, h, x, y;
const ow = this.info.width;
const oh = this.info.height;
const ow = this.info.width || streams[0].width;
const oh = this.info.height || streams[0].height;
const s1 = width / height;
const s2 = ow / oh;
if (s1 >= s2) {
Expand All @@ -62,7 +63,8 @@ class Materials {
getDuration() {
if (!this.info) return 0;

let duration = this.info.duration;
const { streams = [{ duration: 10 }] } = this.info;
let duration = this.info.duration || parseFloat(streams[0].duration) * 1000;
if (typeof duration === 'string') {
if (duration.indexOf(':') > 0) duration = DateUtil.hmsToSeconds(duration);
else duration = parseInt(duration);
Expand Down
Loading

0 comments on commit 87bf7a0

Please sign in to comment.