How to use the prism-media.FFmpeg function in prism-media

To help you get started, we’ve selected a few prism-media examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github amishshah / ytdl-core-discord / index.js View on Github external
ytdl.getInfo(url, (err, info) => {
			if (err) return reject(err);
			// Prefer opus
			const format = info.formats.find(filter);
			const canDemux = format && info.length_seconds != 0;
			if (canDemux) options = { ...options, filter };
			else if (info.length_seconds != 0) options = { ...options, filter: 'audioonly' };
			if (canDemux) {
				const demuxer = new prism.opus.WebmDemuxer();
				return resolve(ytdl.downloadFromInfo(info, options).pipe(demuxer).on('end', () => demuxer.destroy()));
			} else {
				const transcoder = new prism.FFmpeg({
					args: [
						'-reconnect', '1',
						'-reconnect_streamed', '1',
						'-reconnect_delay_max', '5',
						'-i', nextBestFormat(info.formats).url,
						'-analyzeduration', '0',
						'-loglevel', '0',
						'-f', 's16le',
						'-ar', '48000',
						'-ac', '2',
					],
				});
				const opus = new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 });
				const stream = transcoder.pipe(opus);
				stream.on('close', () => {
					transcoder.destroy();
github discordjs / discord.js / src / client / voice / player / BasePlayer.js View on Github external
playUnknown(input, options) {
    this.destroyDispatcher();

    const isStream = input instanceof ReadableStream;

    const args = isStream ? FFMPEG_ARGUMENTS.slice() : ['-i', input, ...FFMPEG_ARGUMENTS];
    if (options.seek) args.unshift('-ss', String(options.seek));

    const ffmpeg = new prism.FFmpeg({ args });
    const streams = { ffmpeg };
    if (isStream) {
      streams.input = input;
      input.pipe(ffmpeg);
    }
    return this.playPCMStream(ffmpeg, options, streams);
  }

prism-media

Easy-to-use stream-based media transcoding

Apache-2.0
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis