Installations
npm install stream-transcoder
Score
94.9
Supply Chain
99
Quality
75.1
Maintenance
100
Vulnerability
99.5
License
Releases
Unable to fetch releases
Developer
trenskow
Developer Guide
Module System
CommonJS
Min. Node Version
>=0.10.15
Typescript Support
No
Node Version
NPM Version
2.0.0-alpha-5
Statistics
189 Stars
35 Commits
34 Forks
17 Watching
1 Branches
6 Contributors
Updated on 11 Sept 2024
Bundle Size
6.05 kB
Minified
2.08 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
2,061,848
Last day
5.9%
4,474
Compared to previous day
Last week
48.9%
28,204
Compared to previous week
Last month
-24.5%
104,174
Compared to previous month
Last year
2,579.5%
1,769,802
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
#stream-transcoder.js
FFmpeg based media transcoder that supports streams.
##Introduction Flexible media transcoding using FFmpeg. Stream media in and out - converting it on the fly.
I created this, because the current FFmpeg transcoders for node.js did not properly support streams as I needed.
Along with the stream-body-parser.js, this makes a great companion for doing stuff like this.
1 var express = require('express'), 2 StreamBodyParser = require('stream-body-parser'), 3 Transcoder = require('stream-transcoder'); 4 5 var app = express(); 6 7 var bodyParser = new StreamBodyParser(app); 8 9 bodyParser.process('video/*', function(stream, req, next) { 10 11 var myGridFSWriteStream = (Some MongoDB GridFS stream) 12 13 new Transcoder(stream) 14 .maxSize(320, 240) 15 .videoCodec('h264') 16 .videoBitrate(800 * 1000) 17 .fps(25) 18 .audioCodec('libfaac') 19 .sampleRate(44100) 20 .channels(2) 21 .audioBitrate(128 * 1000) 22 .format('mp4') 23 .on('finish', function() { 24 next(); 25 }) 26 .stream().pipe(myGridFSWriteStream); 27 28 }); 29 30 app.post('/', function(req, res) { 31 res.send(200); // File uploaded 32 }); 33 34 app.listen(3000);
In the above example the video is transcoded as it is being uploaded, and then piped directly into the database. So when the route is being called, the video is transcoded and stored.
Installing FFmpeg
FFmpeg is not installed with this package. So before usage, install FFmpeg using your favorite package manager or download it at ffmpeg.org.
Configure FFmpeg binary path
Set the FFMPEG_BIN_PATH
env var. (ffmpeg
by default)
Class: Transcoder
Transcoder
is an EventEmitter.
This class transcodes from one media format to another. It supports both files and streams as input and/or output. Some formats are not suited for streaming, in which case the Transcoder
will emit an error
, but most formats are.
new Transcoder(stream)
stream
Object - A readable stream.
Prepares a new Transcoder with a stream as its input.
new Transcoder(file)
file
String - The path of the file to be transcoded.
Prepares a new Transcoder with a file as its input.
Event: 'metadata'
metadata
Object - Metadata of input and output streams.
Emitted when metadata is available for both input and output streams. If no output is specified (by using transcoder.exec()
), only input streams will be described.
This an example of a transcoding process metadata.
1 { 2 "input": { 3 "streams": [ 4 { 5 "type": "video", 6 "codec": "h264", 7 "bitrate": 10131000, 8 "fps": 25, 9 "size": { 10 "width": 1280, 11 "height": 720 12 }, 13 "aspect": 1.7777777777777777, 14 "colors": "yuv420p" 15 }, 16 { 17 "type": "audio", 18 "codec": "aac", 19 "samplerate": 44100, 20 "channels": 2, 21 "bitrate": 106000 22 } 23 ], 24 "duration": 250068, 25 "synched": true 26 }, 27 "output": { 28 "streams": [ 29 { 30 "type": "video", 31 "codec": "h264", 32 "bitrate": 800000, 33 "size": { 34 "width": 320, 35 "height": 180 36 }, 37 "aspect": 1.7777777777777777, 38 "colors": "yuv420p" 39 }, 40 { 41 "type": "audio", 42 "codec": "aac", 43 "samplerate": 44100, 44 "channels": 2, 45 "bitrate": 128000 46 } 47 ] 48 } 49 }
Event: 'progress'
progress
Object - Object describing current progress.
Emitted when progress has been made in the transcoding.
This is an example of the progress
object. Where progress.progress
is a percentage of the total transcoding job.
1 { 2 "frame": 508, 3 "fps": 253, 4 "quality": 16, 5 "size": 1553408, 6 "time": 20041, 7 "bitrate": 608000, 8 "progress": 0.08014220132124063 9 }
Event: 'finish'
Emitted when transcoding is complete.
Event: 'error'
error
Error - The error that occured.
Emitted when FFmpeg exits with an error.
transcoder.videoCodec(codec)
codec
String - Name of the video codec. As an exampleh264
.
Sets the video codec.
Returns transcoder object.
Notice: Supported video codecs depends on your FFmpeg installation. Running ffmpeg -codecs
from your terminal will list the supported codecs.
transcoder.videoBitrate(bitrate)
bitrate
Number or String - The bitrate of the encoded video. Both1280000
or128 kbit
can be passed.
Sets the video bitrate.
Returns transcoder object.
transcoder.fps(fps)
fps
Number - Frames per second.
Sets the number of frames per second.
Returns transcoder object.
transcoder.format(format)
format
String - Output format.
Sets the output format.
Returns transcoder object.
Notice: Supported formats also depends on you FFmpeg installation. Running ffmpeg -formats
from your terminal will list the supported formats.
transcoder.maxSize(width, height)
width
Number - Maximum width of video.height
Number - Miximum height of video.
Sets the output video size, shrinking to fit the size to maintain aspect ratio. The output video will be within the defined size, but with aspect ratio is preserved.
Returns transcoder object.
transcoder.minSize(width, height)
width
Number - Minimum width of video.height
Number - Minimum height of video.
Sets the output video size, scaling it to have a minimum of both directions, while maintaining aspect ratio.
transcoder.size(width, height)
width
Number - Minimum width of video.height
Number - Minimum height of video.
Sets the output video size, not maintaining aspect ratio if it doesn't fit.
Returns transcoder object.
transcoder.passes(passes)
passes
Number - The number of encoder passes.
Sets the number of encoder passes.
Returns transcoder object.
transcoder.aspectRatio(ratio)
ratio
Number - The desired aspect ratio. As an example1.7777777
.
Sets the video aspect ratio.
Returns transcoder object.
transcoder.audioCodec(codec)
codec
String - Name of the audio codec. As an examplemp3
oraac
.
Sets the audio codec.
Returns transcoder object.
Notice: Supported audio codecs depends on your FFmpeg installation. Running ffmpeg -codecs
from your terminal will list the supported codecs.
transcoder.sampleRate(rate)
rate
Number - Audio sample rate. As an example44100
.
Sets the audio sample rate.
Returns transcoder object.
transcoder.channels(channels)
channels
Number - Number of audio channels.
Sets the number of audio channels.
Returns transcoder object.
transcoder.audioBitrate(bitrate)
bitrate
Number - The audio bitrate.
Sets the audio bitrate.
Returns transcoder object.
transcoder.captureFrame(time)
time
Number - Time of frame in milliseconds.
Capture a single frame at time
. Sets up transcoder to jpeg output.
Returns transcoder object.
transcoder.stream()
Returns a writeable stream that will emit the transcoded media data.
transcoder.writeToFile(file)
file
String - Path of filename.
Writes transcoded media data to file
.
Returns transcoder object.
transcoder.exec()
Executes the transcoder without outputting any data. This is useful if you only need metadata for a media file.
Returns child process.
transcoder.custom(key, value)
key
String - The key for the parametervalue
String [optional] - The value for the parameter.
Adds a custom parameter to the FFmpeg command line - this is for all your special needs that is currently not implemented as a function in the Transcoder.
As an example:
.custom('ss', '00:30:00')
Translates to on the FFmpeg command line:
ffmpeg -ss 00:30:00
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 8/25 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Score
3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to stream-transcoder
level-transcoder
Encode data with built-in or custom encodings
@aws-sdk/client-elastic-transcoder
AWS SDK for JavaScript Elastic Transcoder Client for Node.js, Browser and React Native
@google-cloud/video-transcoder
Transcoder client for Node.js
readable-stream
Node.js Streams, a user-land copy of the stream library from Node.js