Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to pipe image stream? #45

Closed
hbar-digital opened this issue Dec 6, 2017 · 4 comments
Closed

Possible to pipe image stream? #45

hbar-digital opened this issue Dec 6, 2017 · 4 comments

Comments

@hbar-digital
Copy link

I'm trying to do something like the following:

cat *.jpg | ffmpeg -f image2pipe -i - video.mp4

Is there some way to do something similar with ffmpeg.js?

I was looking into recording with canvas.captureStream, however, I want to ensure all frames get recorded (no skipping) and ideally as fast as I can generate the frames.

@iamrototo
Copy link

What I am doing right now is:

  • Every 30ms, store the canvas image in memory
  • send this image directly with MEMFS as explained in the README

Please see this code in this issues to help you:
#20 (comment)

@hbar-digital
Copy link
Author

Thanks for your response. I took a look at the code and here's my attempt at simply generating a video from an array of jpgs (ultimate goal being streaming the jpgs).

const ffmpeg = require('ffmpeg.js/ffmpeg-mp4.js');
const svg2img = require('svg2img');
const leftPad = require('left-pad');
const fs = require('fs');

let promises = [];

for(let i = 0; i < 30; i++) {
  let svg =
  `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="512" height="512" viewBox="0 0 512 512">
    <rect width="512" height="512" style="fill:rgb(200,200,255)" />
    <text x="100" y="100" font-size="35">Frame ${i}</text>
  </svg>`;

  promises.push(new Promise(resolve => svg2img(svg, (err, buff) => resolve(buff))));
}

Promise.all(promises)
  .then(blobs => {
    // blobs.forEach((d, i) => fs.writeFile(`tmp/image-${leftPad(i, 3, '0')}.jpg`, d))

    let result = ffmpeg({
      MEMFS: blobs.map((data, i) => ({ name: `frame-${leftPad(i, 3, '0')}.jpg`, data })),
      arguments: ["-i", "frame-%03d.jpg", "-c:v", "libx264", "-pix_fmt", "yuv420p", "out.mp4"],
      stdin: () => {},
    });

    console.log(result.MEMFS[0].data); // empty
  });

I get an empty result as well as the following output. Am I doing something wrong? The jpg data should be correct as writing them to files seems to work as intended. Any help is appreciated!

ffmpeg version n3.1.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with emcc (Emscripten gcc/clang-like replacement) 1.36.7 ()
  configuration: --cc=emcc --enable-cross-compile --target-os=none --arch=x86 --disable-runtime-cpudetect --disable-asm --disable-fast-unaligned --disable-pthreads --disable-w32threads --disable-os2threads --disable-debug --disable-stripping --disable-all --enable-ffmpeg --enable-avcodec --enable-avformat --enable-avutil --enable-swresample --enable-swscale --enable-avfilter --disable-network --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --enable-decoder=vp8 --enable-decoder=vp9 --enable-decoder=theora --enable-decoder=mpeg2video --enable-decoder=mpeg4 --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=png --enable-decoder=mjpeg --enable-decoder=vorbis --enable-decoder=opus --enable-decoder=mp3 --enable-decoder=ac3 --enable-decoder=aac --enable-decoder=ass --enable-decoder=ssa --enable-decoder=srt --enable-decoder=webvtt --enable-demuxer=matroska --enable-demuxer=ogg --enable-demuxer=avi --enable-demuxer=mov --enable-demuxer=flv --enable-demuxer=mpegps --enable-demuxer=image2 --enable-demuxer=mp3 --enable-demuxer=concat --enable-protocol=file --enable-filter=aresample --enable-filter=scale --enable-filter=crop --enable-filter=overlay --disable-bzlib --disable-iconv --disable-libxcb --disable-lzma --disable-sdl --disable-securetransport --disable-xlib --disable-zlib --enable-encoder=libx264 --enable-encoder=libmp3lame --enable-encoder=aac --enable-muxer=mp4 --enable-muxer=mp3 --enable-muxer=null --enable-gpl --enable-libmp3lame --enable-libx264 --extra-cflags=-I../lame/dist/include --extra-ldflags=-L../lame/dist/lib
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
[mjpeg @ 0x80a630] Warning: not compiled with thread support, using thread emulation
[mjpeg @ 0x80a630] bits 107 is invalid
[mjpeg @ 0x80a630] bits 71 is invalid
[mjpeg @ 0x80a630] No JPEG data found in image
    Last message repeated 1 times
[mjpeg @ 0x80a630] bits 137 is invalid
[mjpeg @ 0x80a630] bits 0 is invalid
[mjpeg @ 0x80a630] JPEG-LS support not enabled.
[mjpeg @ 0x80a630] No JPEG data found in image
    Last message repeated 1 times
[mjpeg @ 0x80a630] JPEG-LS support not enabled.
[mjpeg @ 0x80a630] No JPEG data found in image
    Last message repeated 1 times
[mjpeg @ 0x80a630] JPEG-LS support not enabled.
    Last message repeated 1 times
[mjpeg @ 0x80a630] No JPEG data found in image
[mjpeg @ 0x80a630] bits 62 is invalid
[mjpeg @ 0x80a630] No JPEG data found in image
[mjpeg @ 0x80a630] [IMGUTILS @ 0x309948] Picture size 56504x56161 is invalid
[mjpeg @ 0x80a630] No JPEG data found in image
[mjpeg @ 0x80a630] JPEG-LS support not enabled.
[mjpeg @ 0x80a630] bits 155 is invalid
[mjpeg @ 0x80a630] No JPEG data found in image
[mjpeg @ 0x80a630] bits 251 is invalid
[mjpeg @ 0x80a630] bits 242 is invalid
[mjpeg @ 0x80a630] bits 0 is invalid
[mjpeg @ 0x80a630] No JPEG data found in image
[mjpeg @ 0x80a630] bits 110 is invalid
[mjpeg @ 0x80a630] Changing bps from 6 to 7
[mjpeg @ 0x80a630] [IMGUTILS @ 0x309948] Picture size 48788x48673 is invalid
[mjpeg @ 0x80a630] No JPEG data found in image
[mjpeg @ 0x80a630] Changing bps from 7 to 11
[mjpeg @ 0x80a630] [IMGUTILS @ 0x309948] Picture size 26301x54195 is invalid
[image2 @ 0x809290] decoding for stream 0 failed
[image2 @ 0x809290] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown)): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, image2, from 'frame-%03d.jpg':
  Duration: 00:00:01.20, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, none(bt470bg/unknown/unknown), 25 fps, 25 tbr, 25 tbn, 25 tbc
[buffer @ 0x824010] Unable to parse option value "0x0" as image size
[buffer @ 0x824010] Unable to parse option value "-1" as pixel format
[buffer @ 0x824010] Unable to parse option value "0x0" as image size
[buffer @ 0x824010] Error setting option video_size to value 0x0.
[graph 0 input from stream 0:0 @ 0x824360] Error applying options to the filter.
Error opening filters!
Uint8Array [  ]

@CodeFetch
Copy link

Yes, that looks wrong to me. MEMFS can't parse Blobs, but only ArrayBuffers.
Either create a file reader from the Blob first or use WORKERFS:

mounts: [{
		type: "WORKERFS",
		mountpoint: "/test",
		opts: {
			blobs: [{
					name: "example.mp4",
					data: **blob**
				}]
			}
		}],

@Kagami
Copy link
Owner

Kagami commented Apr 19, 2020

@CodeFetch is right, thanks.

@Kagami Kagami closed this as completed Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants