An interface for Node.js allowing you to have multiple omxplayer instances and control them in-process via the low-latency interprocess communication protocol, D-Bus.
You don't have to know anything about D-Bus. Just send commands using JavaScript, and the library handles the communication and logic internally.
npm install omx-players
Remember that the omxplayer
only works on the Raspberry Pi (and similar hardware?). Performance is great on the Pi 3.
omxplayer
is installed by default on the "Raspbian with Desktop" version of Raspbian but if you have installed the "Lite" version (console only) then you might need to install it manually:
sudo apt-get install omxplayer
take advantage of newer functions available in the latest versions of the omxplayer. This requires removing the default Raspbian version of omxplayer and installing the latest version ... See https://github.com/popcornmix/omxplayer
sudo apt-get remove omxplayer
git clone https://github.com/popcornmix/omxplayer.git
cd omxplayer
./prepare-native-raspbian.sh
make ffmpeg
make -j$(nproc)
sudo make install
const omx = require('omx-players');
let player = new omx({
audioOutput: 'local',
blackBackground: true,
disableKeys: true,
disableOnScreenDisplay: true,
});
Then play a clip like this:
player.open('foreground-clip.mp4', false);
const omx = require('omx-players');
let players = [];
const numPlayers = 2;
for (var i=0; i<numPlayers; i++) {
players.push(
new omx({
audioOutput: 'local',
blackBackground: i === 0,
disableKeys: true,
disableOnScreenDisplay: true,
player: i,
layer: i
})
);
}
Find the clip with the player you want, and play:
// Assume that an array has been set up with 2 players.
// Let's say you wanted to play a clip on player 2 ...
players[1].open('foreground-clip.mp4', true);
This seems to be very dependent on the resolutions and data rates for the video files. file sizes also plays a role.
If your player appears to quit video files without even trying to play them, you should try to increase the memory available to the GPU using sudo rasp-config
> Advanced Options > Memory Split. 128MB should be good; 256MB might be better.
audioOutput
: 'hdmi' | 'local' | 'both'blackBackground
: boolean, false by defaultbackgroundARGB
: a hexadecimal colour value for Alpha, Red, Green, Blue - this is an alternative to using the default black.startPos
: Start position (hh:mm:ss) if omitted clips will start at 00:00:00loop
: boolean, false by defaultlayer
: 1 - ?, if omitted clips will automatically play on layer 0alpha
: 0 - 255, if omitted clips will automatically play full alpha (255)volume
: 0.0 to 1.0 millibels, if omitted clips will automatically play full volume (1.0)disableKeys
: boolean, false by defaultdisableOnScreenDisplay
: boolean, false by defaultdisableGhostbox
: boolean, false by defaultprogressInterval
: milliseconds, 1000 by defaultaspectMode
: type, letterbox, fill, stretch. Default: stretch if win is specified, letterbox otherwise
player.getCurrentDuration();
player.getCurrentPosition();
Get current position via D-Bus (if currently playing) in milliseconds.
player.getCurrentVolume();
player.open(path, holdMode)
Open a clip at the given path and either start playing (default) or put in hold mode.
Hold mode sets the alpha to 0 and playback in a paused state.
player.seekRelative(milliseconds);
player.seekAbsolute(milliseconds);
It may take a few milliseconds for the clip to actually start playing after you call player.open
. The onStart
callback is fired once the clip has been confirmed to have actually started playback.
This is called when the clip finishes playing (and the omxplayer instance stops/quits).
The onProgress
callback is called every second (by default) or however often you need (just set progressInterval
in settings).
The callback sends a single object containing position
, duration
and playStatus
(either playing
, paused
or error
).
Example:
player.onProgress( (info) => {
console.log(`player is at ${info.position} / ${info.duration}; currently ${info.status}`);
// will output something like: player is at 2500 / 10000; currently playing
})
player.stop();
This seems to be the same thing as quitting! See popcornmix/omxplayer#564
player.quit();
player.pause();
Pauses the clip; ignored if already paused.
player.resume();
Resumes a clip if paused; ignored if already playing, and will generate an error in the logs if clip is already stopped/done but is essentially ignored.
player.setVolume(vol);
Set volume to a fraction of the max volume (0.0 - 1.0)