damianociarla / node-ffmpeg

ffmpeg module for nodejs
MIT License
604 stars 140 forks source link

Metadata invalid when trying to read a file. #49

Open wbarahona opened 6 years ago

wbarahona commented 6 years ago

Basically I do this:

import FFmpeg from 'ffmpeg';

const res = './resources/video';
const output = './public';
const filename = 'newvideo';
const src = `${ res }/${ filename }.mp4`;

console.log('starting app');

const initVideo = async () => {
    let file = null;

    try {
        file = await new FFmpeg(src);
    } catch (error) {
        console.log(`there is an error: ${ error }`);
    }

    return file;
};

const initApp = async () => {
    let video = null;

    try {
        video = await initVideo();

        console.log(video.metadata);

        video.fnExtractFrameToJPG(`${ output }/thumbs/${ filename }/`, {
            frame_rate: 1,
            number: 5,
            file_name: 'my_frame_%t_%s'
        }, (error, files) => {
            console.log(error, files);
            if (!error) {
                console.log('Frames: ' + files);
            }
        });
    } catch (error) {
        console.log(error);
    }

    return video;
};

video.metadata log returns

{ filename: '',
  title: '',
  artist: '',
  album: '',
  track: '',
  date: '',
  synched: false,
  duration: { raw: '', seconds: 0 },
  video:
   { container: '',
     bitrate: 0,
     stream: 0,
     codec: '',
     resolution: { w: 0, h: 0 },
     resolutionSquare: { w: 0, h: NaN },
     aspect: {},
     rotate: 0,
     fps: 0,
     pixelString: '',
     pixel: 0 },
  audio:
   { codec: '',
     bitrate: '',
     sample_rate: 0,
     stream: 0,
     channels: { raw: '', value: '' } } }

and when trying to fnExtractFrameToJPG() it throws me this error:

{ Error: Command failed: ffmpeg -i ./resources/video/newvideo.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" ./public/thumbs/newvideo//my_frame_1524596748522_0x0_%d.jpg
/bin/sh: ffmpeg: command not found

    at ChildProcess.exithandler (child_process.js:273:12)
    at ChildProcess.emit (events.js:180:13)
    at maybeClose (internal/child_process.js:936:16)
    at Socket.stream.socket.on (internal/child_process.js:353:11)
    at Socket.emit (events.js:180:13)
    at Pipe._handle.close [as _onclose] (net.js:541:12)
  killed: false,
  code: 127,
  signal: null,
  cmd: 'ffmpeg -i ./resources/video/newvideo.mp4 -r 1 -s 0x0 -aspect NaN:NaN -vframes 5 -filter_complex "scale=iw*sar:ih, pad=max(iw\\,ih*(NaN/NaN)):ow/(NaN/NaN):(ow-iw)/2:(oh-ih)/2:black" ./public/thumbs/newvideo//my_frame_1524596748522_0x0_%d.jpg' } null

Just following your documentation. Further info: node -v >> v9.10.1 package.json

{
  "name": "video",
  "version": "1.0.0",
  "description": "video manipulation using nodejs",
  "main": "index.js",
  "scripts": {
    "start": "babel-watch index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "node",
    "video"
  ],
  "author": "Willmer Barahona",
  "license": "ISC",
  "devDependencies": {
    "@babel/preset-env": "^7.0.0-beta.46",
    "babel-cli": "^6.26.0",
    "babel-eslint": "^8.2.3",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-es2015-node5": "^1.2.0",
    "babel-preset-stage-3": "^6.24.1",
    "babel-watch": "^2.0.7",
    "eslint": "^4.19.1",
    "ffmpeg": "0.0.4"
  },
  "dependencies": {}
}
bayont commented 6 years ago

You must download ffmpeg from here: https://www.ffmpeg.org. And put this 3 binaries into project foler.

cooper1x commented 5 years ago

@bayont Thx!