0.3.2 • Published 2 months ago

yuv-rx v0.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

yuv-rx

JavaScript library for reading videos as Rx Observables of decoded frames

Example usage: reading a frame at 0:42, converting to RGB, and encoding it as a base64 encoded PNG image with sharp

import {Observable, from, take, map, concatMap} from 'rxjs';
import {toRGBInterleaved, YuvParser} from 'yuv-rx';
const sharp = require('sharp');

const yuvParser = new YuvParser({
    ffmpeg: '/usr/local/bin/ffmpeg', // optional path, defaults to 'ffmpeg'
    verbose: true
});
yuvParser.read('input.mp4', {
    videoStream: 1,  // select second video stream of input file
    seekSeconds: 42, // skip 42 seconds without decoding
    vframes: 1       // only decode 1 frame
}).pipe(
    take(1),
    map(toRGBInterleaved),
    concatMap(frame => {
        return from(sharp(frame.colorPlanes.rgb.data, {
            raw: {
                width: frame.header.width,
                height: frame.header.height,
                channels: 3,
                premultiplied: false
            }
        }).png().toBuffer().then(b => b.toString('base64')));
    })
).subscribe({
    next: base64frame => console.log(base64frame)
});

Example of usage with custom ffmpeg command line options to find frames with difference at pixel (42,42)

import {Observable, from, take, map, concatMap} from 'rxjs';

const yuvParser = new YuvParser({
    ffmpeg: '/usr/local/bin/ffmpeg', // optional path, defaults to 'ffmpeg'
    verbose: false
});

yuvParser.readCustom([
    '-i',
    'input1.mp4',
    '-i',
    'input2.mp4',
    '-filter_complex',
    '[0:v]format=gray[2];[1:v]format=gray[3];[2][3]blend=all_mode=difference[d];[d]format=yuv420p[v]',
    '-map',
    '[v]',
]).pipe(
    filter(diffFrame => diffFrame.colorPlanes.y.data[42*diffFrame.header.width + 42] > 10),
    map(diffFrame => diffFrame.header.fn),
    toArray()
).subscribe({
    next: frameNumbers => console.log(`Frames with difference at pixel (42,42): ${frameNumbers}`)
});

© VideoGorillas LLC 2022

0.3.2

2 months ago

0.3.1

2 months ago

0.3.0

3 months ago

0.2.0

3 months ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.16

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago