fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.97k stars 881 forks source link

Unable to convert .mov file to .mp4 #1185

Open mvciekzvbek opened 2 years ago

mvciekzvbek commented 2 years ago

Version information

Code to reproduce

  async convertVideo(readStream, filename: string): Promise<string> {
    const outputFilePath = `./${TMP_VIDEO_DIRECTORY}/${filename}.${DEFAULT_VIDEO_EXTENSION}`;
    const writeStream = fs.createWriteStream(outputFilePath);

    return new Promise((resolve, reject) => {
      ffmpeg(readStream)
        .addOutputOptions('-movflags +frag_keyframe+separate_moof+omit_tfhd_offset+empty_moov')
        .videoCodec('libx264')
        .format(DEFAULT_VIDEO_EXTENSION)
        .size(`${DEFAULT_VIDEO_WIDTH}x${DEFAULT_VIDEO_HEIGHT}`)
        .autopad()
        .on('error', (err, stdout, stderr) => {
          console.log('An error occurred: ' + err.message);
          console.log('ffmpeg output:\n' + stdout);
          console.log('ffmpeg stderr:\n' + stderr);
          reject(err);
        })
        .on('end', () => {
          console.log('Processing finished !');
          resolve(outputFilePath);
        })
        .pipe(writeStream)
    })
  }

where DEFAULT_VIDEO_EXTENSION is mp4.

Expected results

I've used example from here: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/examples/any-to-mp4-steam.js I guess it should convert video to .mp4 format successfully.

Observed results

Generally, I can't find the way to convert any of these .mov videos: https://drive.google.com/file/d/1p5X35MSj7AZc8NT1M42jb069r_u7zw1L/view?usp=sharing https://drive.google.com/file/d/1v6DsziJe9Ye1sjwnypzdNbX3N2gGyg_q/view?usp=sharing https://drive.google.com/file/d/1SWyF3nM-K8VPExPZhvK9j6oNEpIO8iFF/view?usp=sharing

ffmpeg output:

ffmpeg stderr:
ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.3.1 (Alpine 10.3.1_git20211027) 20211027
  configuration: --prefix=/usr --enable-avresample --enable-avfilter --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-libx265 --enable-libtheora --enable-libv4l2 --enable-libdav1d --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-libxcb --enable-libsrt --enable-libssh --enable-libvidstab --disable-stripping --disable-static --disable-librtmp --enable-libaom --enable-libopus --enable-libsoxr --enable-libwebp --enable-vaapi --enable-vdpau --enable-vulkan --disable-debug
  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
  libavresample   4.  0.  0 /  4.  0.  0
  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 @ 0x7fa14c528640] stream 0, offset 0x24: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa14c528640] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 640x360, 60 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     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf57.19.100
  Duration: 00:00:30.57, start: 0.000000, bitrate: N/A
  Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), none, 640x360, 60 kb/s, 30 fps, 30 tbr, 15360 tbn, 30720 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : FFMP
      encoder         : Lavc57.16.101 libx264
  Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 139 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa14c528640] stream 0, offset 0x24: 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

Attached code works properly for: mp4, flv, mkv, avi formats.

Video conversion is successful when using ffmpeg from cli with command: ffmpeg -i video.mov -vcodec h264 "asd.mp4"

radvansky-tomas commented 2 years ago

Same here

Douglaskav commented 1 year ago

In my case, the opposite is happening, I can make any changes to other types of video files (including .mov), but when the video I receive as input is a mp4, it returns the same error

Douglaskav commented 1 year ago

Hey guys, I managed to solve the problem in my code. The error was caused by the way I prepared the input for ffmpeg. I used these two lines of code to convert a bufferArray to a format that ffmpeg can read, but this transformation was causing the bug.

const videoStream = new stream.PassThrough();
videoStream.end(Buffer.from(bufferFile));

ffmpeg()
  .input(videoStream)
  .output("output.mp4")

To fix it, I am now passing the direct link of the file that I have on the web, for example, https://my-file-repository/file.mp4.

ffmpeg()
  .input("https://my-file-repository/file.mp4")
  .output("output.mp4")