Skip to content

Commit

Permalink
Merge pull request #44 from ordinall/master
Browse files Browse the repository at this point in the history
added dynamic cmd
  • Loading branch information
agsh authored Jul 16, 2024
2 parents 64784a7 + 5ca02bd commit 6a19b02
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rtsp-ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const spawn = require('child_process').spawn
* @param {string} [options.resolution] Resolution in WxH format
* @param {string|number} [options.quality] JPEG quality
* @param {Array<string>} [options.arguments] Custom arguments for ffmpeg
* @param {string} [options.cmd] use custom binary path instead of 'ffmpeg' in path
* @constructor
*/
var FFMpeg = function(options) {
Expand All @@ -29,6 +30,7 @@ var FFMpeg = function(options) {
this.quality = (options.quality === undefined || options.quality === "") ? 3 : options.quality;
this.arguments = options.arguments || [];
this.buffs = []; // Store the entire data image into this variable. This attribute is replaced each time a full image is received from the stream.
this.cmd = options.cmd || FFMpeg.cmd || 'ffmpeg';

this.on('newListener', newListener.bind(this));
this.on('removeListener', removeListener.bind(this));
Expand Down Expand Up @@ -65,6 +67,10 @@ function observer(changes) {
}
}

FFMpeg.prototype._cmd = function() {
return this.cmd;
}

FFMpeg.prototype._args = function() {
return this.arguments.concat([
'-loglevel', 'quiet',
Expand All @@ -87,7 +93,7 @@ FFMpeg.prototype._args = function() {
*/
FFMpeg.prototype.start = function() {
var self = this;
this.child = spawn(FFMpeg.cmd, this._args());
this.child = spawn(this._cmd(), this._args());
this.child.stdout.on('data', function(data){
//The image can be composed of one or multiple chunk when receiving stream data.
//Store all bytes into an array until we meet flag "FF D9" that mean it's the end of the image then we can send all data in order to display the full image.
Expand Down

0 comments on commit 6a19b02

Please sign in to comment.