philipjscott / simple-thumbnail

A library that produces thumbnails from images, videos and URLs :mag_right:
https://www.npmjs.com/package/simple-thumbnail
MIT License
25 stars 14 forks source link

Stream handling of mp4 files leads to invalid data ffmpeg error #85

Open damnedOperator opened 2 years ago

damnedOperator commented 2 years ago

Describe the bug FFMpeg throws an error when using an MP4 input stream from Buffer and a Duplex output stream

node_modules/simple-thumbnail/index.js:101
        const err = new Error(`ffmpeg exited ${code}\nffmpeg stderr:\n\n${stderr}`)
                    ^

Error: ffmpeg exited 1
ffmpeg stderr:

ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.27)
  configuration: --prefix=/Volumes/tempdisk/sw --extra-cflags=-fno-stack-check --arch=arm64 --cc=/usr/bin/clang --enable-gpl --enable-libopus --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libvpx --enable-libass --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libsnappy --enable-libaom --enable-libvidstab --enable-version3 --pkg-config-flags=--static --disable-ffplay --enable-postproc --enable-nonfree --enable-neon --enable-runtime-cpudetect --disable-indev=qtkit --disable-indev=x11grab_xcb
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x12580b800] stream 1, offset 0x2c: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x12580b800] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 2720x1530, 40025 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
  Metadata:
    major_brand     : avc1
    minor_version   : 538182144
    compatible_brands: avc1isom
    creation_time   : 2021-08-11T19:30:51.000000Z
    location        : +49.1106+8.5664
    location-{    : +49.1106+8.5664
    comment         : DE=None,SN=1SFLH6C0AB01BM, Type=Normal, HQ=Normal, Mode=P
  Duration: 00:00:07.74, start: 0.000000, bitrate: N/A
  Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), none, 2720x1530, 40025 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 60k tbc (default)
    Metadata:
      creation_time   : 2021-08-11T19:30:51.000000Z
      handler_name    : ?DJI.AVC
      vendor_id       : [0][0][0][0]
      encoder         : AVC encoder
  Stream #0:1(eng): Data: none (priv / 0x76697270)
    Metadata:
      creation_time   : 2021-08-11T19:30:51.000000Z
      handler_name    : ?DJI.Meta
  Stream #0:2(eng): Subtitle: mov_text (text / 0x74786574), 2 kb/s (default)
    Metadata:
      creation_time   : 2021-08-11T19:30:51.000000Z
      handler_name    : ?DJI.Subtitle
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x12580b800] stream 0, offset 0x1a069: partial file
pipe:0: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Conversion failed!

To Reproduce Code snippet or repository link that reproduces the error:

const generateAndUploadThumbnail = (blockClient: BlockBlobClient, videoID: string) => {
    const thumbnailContainerClient = blobClient.getContainerClient("thumbnails");
    return new Promise(async (resolve) => {
        const bufferStream = Readable.from(await blockClient.downloadToBuffer(0)) //Leads to mp4 video buffer
        let thumbnailStream: Duplex = new Duplex()
        genThumbnail(bufferStream, thumbnailStream, "200x?", {
            path: path
        }).then( //Breaks here
            async () => {
                const thumbClient: BlockBlobClient = thumbnailContainerClient.getBlockBlobClient(videoID);
                await thumbClient.uploadStream(thumbnailStream);
            }
        )
    })
}

Expected behavior

Environment (please complete the following information):

ShlomitGilo1 commented 2 years ago

I have the same issue. Any solution?

aceodus commented 1 year ago

change output format to image2pipe in https://github.com/philipjscott/simple-thumbnail/blob/4f0745a212457ec83b48f8dfbe3e9705479eed42/index.js#L171 typeof output === 'string' ?"${output}": '-f image2pipe pipe:1',