All Projects → gkozlenko → Node Video Lib

gkozlenko / Node Video Lib

Licence: mit
Node.js Video Library / MP4 & FLV parser / MP4 builder / HLS muxer

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Video Lib

demuxer
A tool for demux ts/mp4/flv by typescript. Support HEVC/AVC/AAC codec
Stars: ✭ 108 (-59.09%)
Mutual labels:  h264, mp4, hls, hevc, h265
Testing Video
Generator of test video files for testing your media playback devices and calibrate TV sets
Stars: ✭ 70 (-73.48%)
Mutual labels:  mp4, h264, hevc, h265
smart rtmpd
RTMP server, smart, compact, high performance(c, c++), high concurrency, easy to maintain, easy to deploy, (supports multiple operating systems Windows and Linux, ARM, FreeBSD)
Stars: ✭ 159 (-39.77%)
Mutual labels:  h264, hls, hevc, h265
flvAnalyser
FLV v1.0 analyser
Stars: ✭ 76 (-71.21%)
Mutual labels:  h264, flv, hevc
ZLMediaKit
WebRTC/RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181/SRT server and client framework based on C++11
Stars: ✭ 7,790 (+2850.76%)
Mutual labels:  mp4, hls, flv
Awesome Video
A curated list of awesome streaming video tools, frameworks, libraries, and learning resources.
Stars: ✭ 397 (+50.38%)
Mutual labels:  mp4, hevc, hls
Ott Packager
OTT/ABR streaming encoder (H264/HEVC) and packager for DASH and HLS
Stars: ✭ 148 (-43.94%)
Mutual labels:  h264, hevc, hls
Ffmpeg
Mirror of https://git.ffmpeg.org/ffmpeg.git
Stars: ✭ 27,382 (+10271.97%)
Mutual labels:  mp4, hevc, hls
Node Media Server
Node.js Media Server / VOD / HLS / DRM
Stars: ✭ 49 (-81.44%)
Mutual labels:  mp4, flv, hls
Jmuxer
jMuxer - a simple javascript mp4 muxer that works in both browser and node environment.
Stars: ✭ 222 (-15.91%)
Mutual labels:  mp4, h264, hls
Chimee
a video player framework aims to bring wonderful experience on browser
Stars: ✭ 2,332 (+783.33%)
Mutual labels:  mp4, flv, hls
Swiftffmpeg
A Swift wrapper for the FFmpeg API
Stars: ✭ 243 (-7.95%)
Mutual labels:  mp4, h264, hevc
rrtsp client
Rust high level RTSP client
Stars: ✭ 12 (-95.45%)
Mutual labels:  h264, mp4, h265
Zlmediakit
WebRTC/RTSP/RTMP/HTTP/HLS/HTTP-FLV/WebSocket-FLV/HTTP-TS/HTTP-fMP4/WebSocket-TS/WebSocket-fMP4/GB28181 server and client framework based on C++11
Stars: ✭ 5,248 (+1887.88%)
Mutual labels:  mp4, flv, hls
Xgplayer
A HTML5 video player with a parser that saves traffic
Stars: ✭ 4,792 (+1715.15%)
Mutual labels:  mp4, flv, hls
Nodeplayer.js
Pure JavaScrip HTML5 live stream player
Stars: ✭ 157 (-40.53%)
Mutual labels:  h264, flv, h265
Wxinlineplayer
🤟Super fast H.264/H.265 FLV player
Stars: ✭ 873 (+230.68%)
Mutual labels:  h264, flv, h265
Digital video introduction
A hands-on introduction to video technology: image, video, codec (av1, vp9, h265) and more (ffmpeg encoding).
Stars: ✭ 12,184 (+4515.15%)
Mutual labels:  h264, h265, hls
Media Server
RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
Stars: ✭ 1,363 (+416.29%)
Mutual labels:  mp4, flv, hls
uci
Ultra Compact Image (UCI)
Stars: ✭ 79 (-70.08%)
Mutual labels:  h264, hevc, h265

node-video-lib

Build Status npm Version Maintainability Test Coverage GitHub License Donate using PayPal Buy me a Coffee

Node.js Video Library / MP4 & FLV parser / MP4 builder / HLS muxer

Limitations

This library works only with MP4 and FLV video files encoded using H.264/H.265 video codecs and AAC audio codec.

Installation

$ npm install node-video-lib

Usage

Parse video file

const fs = require('fs');
const VideoLib = require('node-video-lib');

fs.open('/path/to/file', 'r', function(err, fd) {
    try {
        let movie = VideoLib.MovieParser.parse(fd);
        // Work with movie
        console.log('Duration:', movie.relativeDuration());
    } catch (ex) {
        console.error('Error:', ex);
    } finally {
        fs.closeSync(fd);
    }
});

Create MPEG-TS chunks

const fs = require('fs');
const VideoLib = require('node-video-lib');

fs.open('/path/to/file', 'r', function(err, fd) {
    try {
        let movie = VideoLib.MovieParser.parse(fd);
        let fragmentList = VideoLib.FragmentListBuilder.build(movie, 5);
        for (let i = 0; i < fragmentList.count(); i++) {
            let fragment = fragmentList.get(i);
            let sampleBuffers = VideoLib.FragmentReader.readSamples(fragment, fd);
            let buffer = VideoLib.HLSPacketizer.packetize(fragment, sampleBuffers);
            // Now buffer contains MPEG-TS chunk
        }
    } catch (ex) {
        console.error('Error:', ex);
    } finally {
        fs.closeSync(fd);
    }
});

Build MP4 file

const fs = require('fs');
const VideoLib = require('node-video-lib');

fs.open('/path/to/file', 'r', function(err, fd) {
    try {
        let movie = VideoLib.MovieParser.parse(fd);
        fs.open('/path/to/output.mp4', 'w', function(err, fw) {
            try {
                VideoLib.MP4Builder.build(movie, fd, fw);
            } catch (ex) {
                console.error('Error:', ex);
            } finally {
                fs.closeSync(fw);
            }
        }
    } catch (ex) {
        console.error('Error:', ex);
    } finally {
        fs.closeSync(fd);
    }
});

Create index file

const fs = require('fs');
const VideoLib = require('node-video-lib');

fs.open('/path/to/file', 'r', function(err, fd) {
    try {
        let movie = VideoLib.MovieParser.parse(fd);
        let fragmentList = VideoLib.FragmentListBuilder.build(movie, 5);
        console.log('Duration:', fragmentList.relativeDuration());
        fs.open('/path/to/index.idx', 'w', function(err, fdi) {
            try {
                VideoLib.FragmentListIndexer.index(fragmentList, fdi);
            } catch (ex) {
                console.error('Error:', ex);
            } finally {
                fs.closeSync(fdi);
            }
        });
    } catch (ex) {
        console.error('Error:', ex);
    } finally {
        fs.closeSync(fd);
    }
});

Create MPEG-TS chunks using index file

const fs = require('fs');
const VideoLib = require('node-video-lib');

fs.open('/path/to/file', 'r', function(err, fd) {
    fs.open('/path/to/index.idx', 'r', function(err, fdi) {
        try {
            let fragmentList = VideoLib.FragmentListIndexer.read(fdi);
            console.log('Duration:', fragmentList.relativeDuration());
            for (let i = 0; i < fragmentList.count(); i++) {
                let fragment = fragmentList.get(i);
                let sampleBuffers = VideoLib.FragmentReader.readSamples(fragment, fd);
                let buffer = VideoLib.HLSPacketizer.packetize(fragment, sampleBuffers);
                // Now buffer contains MPEG-TS chunk
            }
        } catch (ex) {
            console.error('Error:', ex);
        } finally {
            fs.closeSync(fd);
            fs.closeSync(fdi);
        }
    });
});

Classes

MovieParser

A tool for parsing video files (MP4 or FLV).

const MovieParser = require('node-video-lib').MovieParser

Methods:

  • parse(source) - Parse video file
    • source <Integer>|<Buffer> - Source (File descriptor or Buffer)
    • Return: <Movie>

MP4Parser

A tool for parsing MP4 video files.

const MP4Parser = require('node-video-lib').MP4Parser

Methods:

  • parse(source) - Parse MP4 file
    • source <Integer>|<Buffer> - Source (File descriptor or Buffer)
    • Return: <Movie>
  • check(buffer) - Check MP4 header
    • buffer <Buffer> - File header (first 8 bytes)
    • Return: <boolean>

FLVParser

A tool for parsing FLV video files.

const FLVParser = require('node-video-lib').FLVParser

Methods:

  • parse(source) - Parse FLV file
    • source <Integer>|<Buffer> - Source (File descriptor or Buffer)
    • Return: <Movie>
  • check(buffer) - Check FLV header
    • buffer <Buffer> - File header (first 8 bytes)
    • Return: <boolean>

MP4Builder

A tool for building MP4 video files.

const MP4Builder = require('node-video-lib').MP4Builder

Methods:

  • build(movie, source, fd) - Build MP4 file
    • movie <Movie> - Movie
    • source <Integer>|<Buffer> - Source (File descriptor or Buffer)
    • fd <Integer> - File descriptor

HLSPacketizer

A tool for creating MPEG-TS chunks.

const HLSPacketizer = require('node-video-lib').HLSPacketizer

Methods:

  • packetize(fragment, sampleBuffers) - Create MPEG-TS chunk from movie fragment
    • fragment <Fragment> - Movie fragment
    • sampleBuffers <Array> - Array of buffers
    • Return: <Buffer>

FragmentListBuilder

A tool for splitting the movie into a list of fragments.

const FragmentListBuilder = require('node-video-lib').FragmentListBuilder

Methods:

  • build(movie, fragmentDuration) - Split the movie to a list of fragments with an appropriate duration

FragmentListIndexer

A tool to work with index files.

const FragmentListIndexer = require('node-video-lib').FragmentListIndexer

Methods:

  • index(fragmentList, fd) - Index fragment list
    • fragmentList <FragmentList> - Fragment list
    • fd <Integer> - File descriptor
  • read(fd) - Read fragment list from index

FragmentReader

A tool for reading samples data of the given movie fragment.

const FragmentReader = require('node-video-lib').FragmentReader

Methods:

  • readSamples(fragment, source) - Read samples data
    • fragment <Fragment> - Movie fragment
    • source <Integer>|<Buffer> - Source (File descriptor or Buffer)
    • Return: <Array> Array of buffers

Movie

A movie class

const Movie = require('node-video-lib').Movie

Properties:

  • duration <Integer> - Movie duration
  • timescale <Integer> - Movie timescale
  • tracks <Array> - List of movie tracks

Methods:

  • relativeDuration() - Movie duration in seconds
    • Return: <Number>
  • resolution() - Video resolution
    • Return: <String>
  • size() - Samples size
    • Return: <Integer>
  • addTrack(track) - Add a track to the tracks list
    • track <Track> - Track
  • videoTrack() - Get the first video track
    • Return: <VideoTrack>
  • audioTrack() - Get the first audio track
    • Return: <AudioTrack>
  • samples() - Get a list of movie samples ordered by relative timestamp
    • Return: <Array>
  • ensureDuration() - Calculate and set duration based on the track durations (only if duration is zero)
    • Return: <Number>

FragmentList

A list of movie fragments class.

const FragmentList = require('node-video-lib').FragmentList

Properties:

  • fragmentDuration <Integer> - Target fragment duration
  • duration <Integer> - Movie duration
  • timescale <Integer> - Movie timescale
  • video <Object> - Video info
    • timescale <Integer> - Video timescale
    • codec <String> - Codec string
    • extraData <Buffer> - Video codec information
    • size <Integer> - Video samples size
    • width <Integer> - Video width
    • height <Integer> - Video height
  • audio <Object> - Audio info
    • timescale <Integer> - Audio timescale
    • codec <String> - Codec string
    • extraData <Buffer> - Audio codec information
    • size <Integer> - Audio samples size

Methods:

  • relativeDuration() - Movie duration in seconds
    • Return: <Number>
  • count() - Fragments count
    • Return: <Integer>
  • size() - Samples size
    • Return: <Integer>
  • get(index) - Get fragment by index

Fragment

A movie fragment class

const Fragment = require('node-video-lib').Fragment

Properties:

  • timestamp <Integer> - Fragment timestamp
  • duration <Integer> - Fragment duration
  • timescale <Integer> - Fragment timescale
  • videoExtraData <Buffer> - Video codec information
  • audioExtraData <Buffer> - Audio codec information
  • samples <Array> - List of fragment samples

Methods:

  • relativeTimestamp() - Fragment timestamp in seconds
    • Return: <Number>
  • relativeDuration() - Fragment duration in seconds
    • Return: <Number>
  • hasVideo() - Fragment has a video track
    • Return: <Boolean>
  • hasAudio() - Fragment has an audio track
    • Return: <Boolean>

Track

A general track class

const Track = require('node-video-lib').Track

Properties:

  • duration <Integer> - Track duration
  • timescale <Integer> - Track timescale
  • codec <String> - Codec string
  • extraData <Buffer> - Codec information
  • samples <Array> - List of track samples

Methods:

  • relativeDuration() - Track duration in seconds
    • Return: <Number>
  • ensureDuration() - Calculate and set duration based on the sample durations (only if duration is zero)
    • Return: <Number>
  • size() - Samples size
    • Return: <Integer>

AudioTrack

An audio track class. Extends the general track class

const AudioTrack = require('node-video-lib').AudioTrack

Properties:

  • channels <Integer> - Number of audio channels
  • sampleRate <Integer> - Audio sample rate
  • sampleSize <Integer> - Audio sample size

VideoTrack

A video track class. Extends the general track class

const VideoTrack = require('node-video-lib').VideoTrack

Properties:

  • width <Integer> - Video width
  • height <Integer> - Video height

Methods:

  • resolution() - Video resolution
    • Return: <String>

Sample

A general video sample class

const Sample = require('node-video-lib').Sample

Properties:

  • timestamp <Integer> - Sample timestamp
  • timescale <Integer> - Sample timescale
  • size <Integer> - Sample size
  • offset <Integer> - Sample offset in the file

Methods:

  • relativeTimestamp() - Sample timestamp in seconds
    • Return: <Number>

AudioSample

An audio sample class. Extends the general sample class

const AudioSample = require('node-video-lib').AudioSample

VideoSample

A video sample class. Extends the general sample class

const VideoSample = require('node-video-lib').VideoSample

Properties:

  • compositionOffset <Integer> - Composition offset
  • keyframe <Boolean> - Keyframe flag
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].