fluent-ffmpeg / node-fluent-ffmpeg

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

Writing MP3 metadata doesn't work #1028

Open talhabalaj opened 4 years ago

talhabalaj commented 4 years ago

I'm using fluent-ffmpeg to write id3tags to an output. The issue arrives when the string has multiple spaces. The result is unstable sometimes it will work and add "Charlie Path" with quotes to metadata and others it will output the error in the observed results below. I tried running the command on terminal it just works fine. I'm convinced that it's a linux only issue by this.

Version information

Code to reproduce


 const metadata = [
      "-metadata",
      `title="Charlie Puth Girlfriend Official Audio"`,
      "-metadata",
      `artist="Charlie Puth"`,
      "-metadata",
      `album="Single"`,
    ];

 Ffmpeg()
      .input(videoStream)
      .inputFormat("m4a")
      .withAudioCodec("libmp3lame")
      .outputFormat("mp3")
      .outputOptions(metadata)
      .on("start", function (cmd) {
        console.log("Started " + cmd);
      })
      .on("error", function (err) {
        console.log("An error occurred: " + err.message);
      })
      .on("progress", (test) => console.log(test))
      .on("end", function () {
        console.log("Finished encoding");
      })
      .writeToStream(res, { end: true });

Expected results

When the command printed on start in used in terminal.

ffmpeg version 4.2.2-1ubuntu1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-3ubuntu1)
  configuration: --prefix=/usr --extra-version=1ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'KHAAB _ AKHIL _ PARMISH VERMA _ NEW PUNJABI SONG 2018 _ CROWN RECORDS -2eliQ_KR8yA.m4a':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.29.100
  Duration: 00:03:39.10, start: 0.000000, bitrate: 129 kb/s
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
File 'test.mp3' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'test.mp3':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    TALB            : Single
    TIT2            : Charlie Puth Girlfriend Official Audio
    TPE1            : Charlie Puth
    TSSE            : Lavf58.29.100
    Stream #0:0(eng): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      encoder         : Lavc58.54.100 libmp3lame
size=    3425kB time=00:03:39.11 bitrate= 128.0kbits/s speed=38.1x    
video:0kB audio:3424k

Observed results

When executed by fluent-ffmpeg.

An error occurred: ffmpeg exited with code 1: pipe:1: Invalid argument
talhabalaj commented 4 years ago

I solved the issue by this. It seems like when the length after split by " " is 2, it messes up.

string = `${string}${string.split(" ").length == 2 ? " " : ""}`;
uncvrd commented 10 months ago

I have no idea why but this will also fix your problem:

.outputOptions(...metadata)

The outputOptions has two overrides:

outputOptions(options: string[]): FfmpegCommand;
outputOptions(...options: string[]): FfmpegCommand;

Using the second option worked, but your workaround works if you use the first one...anyone know why?

talhabalaj commented 10 months ago

I have no idea why but this will also fix your problem:

.outputOptions(...metadata)

The outputOptions has two overrides:

outputOptions(options: string[]): FfmpegCommand;
outputOptions(...options: string[]): FfmpegCommand;

Using the second option worked, but your workaround works if you use the first one...anyone know why?

Basically they have a check if the argument has a single space between two args, they automatically split it, and that causes the issue. It's 3 years old, this is as much as I can remember.

uncvrd commented 10 months ago

yea no problem! Thanks for your explanation, leaving mine as an alternative if another dev happens across this :)