Quantcast
Channel: Buffer as input and output for fluent-ffmpeg - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Buffer as input and output for fluent-ffmpeg

$
0
0

The below looks like a lot but a it's primarily just output.

I'm trying to take in a buffer using multer (being send the request containing the video (.mov format) through Alamofire from an iPhone) as the input before a fluent-ffmpeg conversion, then I want it to output as a buffer, and then send the result to S3. I think I'm close, but I don't think fluent-ffmpeg can have a buffer passed in. This is deployed on heroku using this buildpack: https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.... How do I pass it in correctly?

const multer = require('multer')const upload = multer({ limits: { fieldSize: 100_000_000 } })app.post('/create', upload.single('video'), async function (request, response, next) {  let data = request.body  console.log(data) // prints [Object: null prototype] { param1: '' }  let bufferStream = new stream.PassThrough();  console.log(request.file.buffer) // prints '<Buffer 00 00 00 14 66 74 79 70 71 74 20 20 00 00 00 00 71 74 20 20 00 00 00 08 77 69 64 65 01 0e 28 55 6d 64 61 74 21 20 03 40 68 1c 21 4e ff 3c 59 96 7c 82 ... 17718642 more bytes>'  new ffmpeg({    source: stream.Readable.from(request.file.buffer, { objectMode: false })  })  // .format('mp4')  .on('error', function (err) {    console.log(Error: ${err})  })  .on('progress', function (progress) {    console.log("progress")  })  .on('end', function () {    console.log('Formatting finished!');    console.log("after");  })  .writeToStream(bufferStream);  // Read the passthrough stream  const buffers = [];  bufferStream.on('data', function (buf) {    buffers.push(buf);  });  bufferStream.on('end', function () {    const outputBuffer = Buffer.concat(buffers);  // use outputBuffer  });  console.log("Added.")  response.send("Success")});

The output is what you can see below (without .format('mp4')):

2022-09-03T13:12:24.194384+00:00 heroku[router]: at=info method=POST path="/createBusiness" host=sparrow-testing.herokuapp.com request_id=2774a4ec-e21e-4c2f-8086-460a4cba7d1d fwd="74.71.236.5" dyno=web.1 connect=0ms service=13157ms status=200 bytes=762 protocol=https2022-09-03T13:12:24.186257+00:00 app[web.1]: [Object: null prototype] { title: '' }2022-09-03T13:12:24.187296+00:00 app[web.1]: <Buffer 00 00 00 14 66 74 79 70 71 74 20 20 00 00 00 00 71 74 20 20 00 00 00 08 77 69 64 65 01 0e 28 55 6d 64 61 74 21 20 03 40 68 1c 21 4e ff 3c 59 96 7c 82 ... 17718642 more bytes>2022-09-03T13:12:24.189891+00:00 app[web.1]: Added.2022-09-03T13:12:24.891564+00:00 app[web.1]: Error: Error: ffmpeg exited with code 1: pipe:1: Invalid argument2022-09-03T13:12:24.891570+00:00 app[web.1]: 

This output is what you see with .format('mp4'):

2022-09-03T13:17:07.380415+00:00 app[web.1]: [Object: null prototype] { title: '' }2022-09-03T13:17:07.381335+00:00 app[web.1]: <Buffer 00 00 00 14 66 74 79 70 71 74 20 20 00 00 00 00 71 74 20 20 00 00 00 08 77 69 64 65 01 0e 28 55 6d 64 61 74 21 20 03 40 68 1c 21 4e ff 3c 59 96 7c 82 ... 17718642 more bytes>2022-09-03T13:17:07.384047+00:00 app[web.1]: Added.2022-09-03T13:17:07.388457+00:00 heroku[router]: at=info method=POST path="/createBusiness" host=sparrow-testing.herokuapp.com request_id=84e69ead-09b1-4668-8fc8-b9fc9d5f229d fwd="74.71.236.5" dyno=web.1 connect=0ms service=13079ms status=200 bytes=762 protocol=https2022-09-03T13:17:08.339746+00:00 app[web.1]: Error: Error: ffmpeg exited with code 1: Conversion failed!2022-09-03T13:17:08.339783+00:00 app[web.1]: 

My uploadFile function works correctly because I use it elsewhere--normally, I just pass in the request.file.buffer, but here it needs to be a buffer after the ffmpeg conversion

EDIT:

At Heiko's suggestion, I tried changing the multer initialization to

multer({ limits: { fieldSize: 100_000_000 }, dest: "uploads/" })

and the source I was passing in to ffmpeg to

new ffmpeg({  source: request.file.path // request.file.path seems to be a path of a Multer-generated file, I'd assume the one I'm sending to the server}).format('mp4')

but it still errored out to

Error: ffmpeg exited with code 1: Conversion failed!

when the request.file was:

{  fieldname: 'video',  originalname: 'video',  encoding: '7bit',  mimetype: 'clientMime',  destination: 'uploads/',  filename: '08d5d3bbdcf1ac29fb97800136a306e9',  path: 'uploads/08d5d3bbdcf1ac29fb97800136a306e9',  size: 1567480}

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images