ffmpeg Option not found `var_stream_map a:0 a:1` - node.js

I am using fluent ffmpeg with ffmpeg v4.1.3 for HLS mukti bitrate streaming but I m not able to use -var_stream_map config it says option, not found but running this command outside fluent-ffmpeg works fine
Here is my code
const stream = ffmpeg(filePath);
stream.outputOptions([
'-preset slow',
'-g 48',
'-map 0:0',
'-q:a:0 64k',
'-q:a:1 128k',
'-var_stream_map a:0 a:1',
'-hls_time 6',
'-f hls',
'-hls_list_size 0',
'-master_pl_name /tmp/master.m3u8',
"-hls_segment_filename /tmp/v%v/fileSequence%d.t",
"/tmp/v%v/prog_index.m3u8"
])
.output('./master.m3u8')
.on('progress', function(progress) {
console.log('Processing: ' + progress.percent + '% done')
})
Here is the output
ffmpeg version 4.1.3-tessus https://evermeet.cx/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.3)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Unrecognized option 'var_stream_map a:0 a:1'.
Error splitting the argument list: Option not found
Can someone tell me how can I pass it correctly?

I also face the same problem and solve that by putting the 'var_stream_map' in another outputOption().
stream.outputOptions([
'-preset slow',
'-g 48',
'-map 0:v', '-map 0:v',
'-map 0:a', '-map 0:a',
'-q:a:0 64k',
'-q:a:1 128k',
'-hls_time 6',
'-f hls',
'-hls_list_size 0',
'-master_pl_name /tmp/master.m3u8',
"-hls_segment_filename /tmp/v%v/fileSequence%d.t",
"/tmp/v%v/prog_index.m3u8"
])
.outputOption('-var_stream_map', 'v:0,a:0 v:1,a:1')
.output('./master.m3u8')
.on('progress', function(progress) {
console.log('Processing: ' + progress.percent + '% done')
})

On command line it is recommended put the var_stream_map value between quotation marks.
'-var_stream_map', '"a:0 a:1"'
Also the -map parameter adds only one stream (stream 0:0). If you want to have two audio streams you must also add the -map parameter two times:
-map 0:0 -map 0:0
Here the same input stream 0:0 is added two times for the output processing.

Related

Fluent-ffmpeg node js adding subtitles properly on mac but isn't working on ubuntu

I have the same version on both OS but still get different output.
Here is the output that I get on ubuntu for Bengali subtitles:
Ubuntu Output Subtitles
Here is the version and configuration for ubuntu 20:
`
ffmpeg version 5.1.2-0ubuntu1~20.04.sav1.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr --extra-version='0ubuntu1~20.04.sav1.1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-lcms2 --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-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --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-sndio --enable-pocketsphinx --enable-librsvg --enable-libdav1d --enable-libjxl --enable-librist --enable-libvmaf --enable-libzimg --enable-crystalhd --enable-libmfx --enable-libsvtav1 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
`
And here is the version and config for mac os:
ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers built with Apple clang version 14.0.0 (clang-1400.0.29.102) configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.1.2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon libavutil 57. 28.100 / 57. 28.100 libavcodec 59. 37.100 / 59. 37.100 libavformat 59. 27.100 / 59. 27.100 libavdevice 59. 7.100 / 59. 7.100 libavfilter 8. 44.100 / 8. 44.100 libswscale 6. 7.100 / 6. 7.100 libswresample 4. 7.100 / 4. 7.100 libpostproc 56. 6.100 / 56. 6.100
Also My code is simply this:
`
ffmpeg(fileName)
.videoCodec("libx264")
.audioCodec("libmp3lame")
.outputOptions(`-vf subtitles=${subtitlesPath}`)
.on("error", function (err) {
callback(true, err);
})
.save(outputBurnedVideo)
.on("end", async function () {
await callback(false, "done");
});
`
I have tried using the sub_charenc option but I wasn't able to get the proper result.

Audio problem when concatenating MP4 videos

I want to concatenate some mp4 videos but coundn't manage to solve the audio problems.
Here are sample videos, to be concatenated, in this order: 1, 2 and 3. A concat.txtis also supplied. 2.mp4 is a fragment of a larger video and was reencoded (not just cut).
None of my attempts worked. Most of them lead to gaps in the audio, some change the pitch of the voice. There's clearly a DTS issue I just don't know how to deal with.
Sometimes there are more than three videos to put together.
What I tried so far:
The most obvious: fmpeg -f concat -safe 0 -i concat.txt -c copy out.mp4. This complains a lot (non-monotonous DTS). Very poor result.
Re-encoding video and audio: ffmpeg -f concat -safe 0 -i concat.txt -c:v libx264 -c:a aac out.mp4. Same poor result in a time consuming task. Using copy to avoid re-encoding just audio or just video leads nowhere.
Running away from mp4: I converted all files to avi and to ts thinking that that could be an mp4 issue. Bad results with avi and slightly better results with ts. Nothing good, though.
I tried playing with -video_track_timescale. No success.
I actually don't care about re-encoding the video, since the original has not a great quality already. But the audio issue must be solved.
I also hope for a generic solution, since I have many videos to handle and I wish to use just a script. Adjusting parameters for every single case would be a burden.
Using ffmpeg version 4.3.3 and Debian 11.
$ ffmpeg -version
ffmpeg version 4.3.3-0+deb11u1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Edit
Here are the ffprobe results for each input file:
$ for i in [123].mp4; do echo; echo "------------ $i"; ffprobe $i; done
------------ 1.mp4
ffprobe version 4.3.3-0+deb11u1 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:09.00, start: 0.040000, bitrate: 8842 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 8669 kb/s, 25.11 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 167 kb/s (default)
Metadata:
handler_name : SoundHandler
------------ 2.mp4
ffprobe version 4.3.3-0+deb11u1 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:07:24.45, start: 0.000000, bitrate: 219 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 81 kb/s, 25 fps, 30 tbr, 115200 tbn, 50 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 10/11/2020.
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 10/11/2020.
------------ 3.mp4
ffprobe version 4.3.3-0+deb11u1 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)
configuration: --prefix=/usr --extra-version=0+deb11u1 --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-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --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-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --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-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.45.100
Duration: 00:00:18.58, start: 0.040000, bitrate: 314 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 213 kb/s, 25.05 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
Metadata:
handler_name : SoundHandler

ffmpeg --help, node child_process spawn trigger stderr

So I simply run ffmpeg --help using node.js, why is there stderr? I think it should be only stdout. Is it an issue of ffmpeg or node.js?
Code:
import path from 'path';
import {spawn} from 'child_process';
const childProcess = spawn(path.join(__dirname, 'ffmpeg'), ['--help']);
childProcess.stderr.setEncoding('utf-8');
childProcess.stderr.on('data', data => {
console.log('stderr:');
console.log(data);
});
Output:
stderr:
ffmpeg version 4.4-tessus https://evermeet.cx/ffmpeg/ Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
stderr:
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
Let me answer my own question: ffmpeg by default redirects normal output to stderr. It is strange but it is how it is designed

File (mp3) concatenation issues using FFmpeg

I want to concatenate some MP3 files using the FFmpeg concatenation protocol.
Here is a successful try:
$ ffmpeg -loglevel panic -i "concat:audio/it/ci.mp3|audio/it/èsse.mp3|audio/it/cu.mp3|audio/it/u.mp3|audio/it/tre.mp3|audio/it/zero.mp3|audio/it/cinque.mp3|audio/it/quattro.mp3|audio/it/tre.mp3|audio/it/otto.mp3|audio/it/tre.mp3" -c copy audio/it/CSQU3054383.mp3 -y
$ ll audio/it/CSQU3054383.mp3
-rw-rw-r-- 1 giorgio 26K Nov 9 16:16 audio/it/CSQU3054383.mp3
So far, all is OK!
BTW, all (Mp3) files have the same codecs, so MP3 FFmpeg concatenation protocol runs as expected!
Now, I want to insert a pause file audio/it/PAUSE_2.mp3, between each previous files:
$ ffmpeg -loglevel panic -i "concat:audio/it/ci.mp3|audio/it/PAUSE_2.mp3|audio/it/èsse.mp3|audio/it/PAUSE_2.mp3|audio/it/cu.mp3|audio/it/PAUSE_2.mp3|audio/it/u.mp3|audio/it/PAUSE_2.mp3|audio/it/tre.mp3|audio/it/PAUSE_2.mp3|audio/it/zero.mp3|audio/it/PAUSE_2.mp3|audio/it/cinque.mp3|audio/it/PAUSE_2.mp3|audio/it/quattro.mp3|audio/it/PAUSE_2.mp3|audio/it/tre.mp3|audio/it/PAUSE_2.mp3|audio/it/otto.mp3|audio/it/PAUSE_2.mp3|audio/it/tre.mp3" -c copy audio/it/CSQU3054383.mp3 -y
$
This command run apparently without any error, but the output file (audio/it/CSQU3054383.mp3) is not generated at all.
**Question 1 (minor):
Why doesn't FFmpeg report any error and doesn't generate the expected output?**
In fact, I already experienced that FFmpeg, in some circumstances, fails without saying why :(
I suspect the problem happens because the file audio/it/PAUSE_2.mp3 doesn't have a constant bit rate (CBR), as other files, e.g.:
$ mediainfo audio/it/ci.mp3
General
Complete name : audio/it/ci.mp3
Format : MPEG Audio
File size : 2.06 KiB
Duration : 528 ms
Overall bit rate mode : Constant
Overall bit rate : 32.0 kb/s
Audio
Format : MPEG Audio
Format version : Version 2
Format profile : Layer 3
Duration : 528 ms
Bit rate mode : Constant
Bit rate : 32.0 kb/s
Channel(s) : 1 channel
Sampling rate : 24.0 kHz
Frame rate : 41.667 FPS (576 SPF)
Compression mode : Lossy
Stream size : 2.06 KiB (100%)
$ ffprobe audio/it/ci.mp3
ffprobe version 3.4.8-0ubuntu0.2 Copyright (c) 2007-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[mp3 # 0x564491288080] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'audio/it/ci.mp3':
Duration: 00:00:00.53, start: 0.000000, bitrate: 32 kb/s
Stream #0:0: Audio: mp3, 24000 Hz, mono, s16p, 32 kb/s
Instead, the inserted pause file has a variable bit rate, as mediainfo states:
$ mediainfo audio/it/PAUSE_2.mp3
General
Complete name : audio/it/PAUSE_2.mp3
Format : MPEG Audio
File size : 8.29 KiB
Overall bit rate mode : Variable
Writing library : LAME3.100
Audio
Format : MPEG Audio
Format version : Version 2
Format profile : Layer 3
Bit rate mode : Variable
Channel(s) : 1 channel
Sampling rate : 24.0 kHz
Compression mode : Lossy
Stream size : 8.06 KiB (97%)
Writing library : LAME3.100
Here my Bash script I used to generate the pause:
$ cat com/pause
#!/bin/bash
# https://ffmpeg.org/ffmpeg-filters.html#toc-anullsrc
# https://ffmpeg.org/ffmpeg-utils.html#toc-Examples-1
if [ $# -eq 0 ]
then
echo
echo "create a pause, a silence audio file (MP3) of specified number of milliseconds"
echo
echo "usage: $0 <time duration (in seconds)> <directory path>"
echo
echo "example: $0 2"
echo "example: $0 0.5 tmp/"
echo
exit
fi
timeDuration=$1
directoryPath=$2
suffix=mp3
# https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
#https://trac.ffmpeg.org/wiki/Encode/MP3
bitrate=32k
samplingRate=24000
outputFile="${directoryPath}PAUSE_${timeDuration}.${suffix}"
#-b:a $bitrate -minrate $bitrate -maxrate $bitrate -bufsize $bitrate \
ffmpeg \
-f lavfi \
-i anullsrc=r=$samplingRate:cl=mono \
-t $timeDuration \
-b:a $bitrate -minrate $bitrate -maxrate $bitrate \
-codec:a libmp3lame \
$outputFile -y
echo
echo "created file: $outputFile"
echo
Unfortunately, the created file seems with a variable bit rate and not with a constant bit rate (CBR), as expected ( -b:a ... ):
$ com/pause 2
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, lavfi, from 'anullsrc=r=24000:cl=mono':
Duration: N/A, start: 0.000000, bitrate: 192 kb/s
Stream #0:0: Audio: pcm_u8, 24000 Hz, mono, u8, 192 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_u8 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'PAUSE_2.mp3':
Metadata:
TSSE : Lavf57.83.100
Stream #0:0: Audio: mp3 (libmp3lame), 24000 Hz, mono, s16p, 32 kb/s
Metadata:
encoder : Lavc57.107.100 libmp3lame
size= 8kB time=00:00:02.01 bitrate= 33.7kbits/s speed= 192x
video:0kB audio:8kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.870640%
created file: PAUSE_2.mp3
Question 2:
What's wrong in my Bash script (why doesn't it generate a CBR file?
How can I generate an silence pause file (silence of N milliseconds) with the exact settings of previous files?

How to get stdout from FFmpeg without format?

I need to get stdout of rtsp stream without formatting. May someone know how to do it?
This is what I get if try to ffmpeg manually from command line:
root#cl-som-imx6ul-sid: ffmpeg -rtsp_transport tcp -i rtsp://admin:pass#10.168.9.141/Streaming/channels/1/ -vcodec cpoy -acodec copy -
ffmpeg version 3.2.5-1~bpo8+1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --prefix=/usr --extra-version='1~bpo8+1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --disable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Input #0, rtsp, from
'rtsp://admin:pass#10.168.9.141/Streaming/channels/1/':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.240000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 640x480, 25 fps, 25.08 tbr, 90k tbn, 50 tbc
[NULL # 0x5683bc30] Unable to find a suitable output format for 'pipe:'
pipe:: Invalid argument
NodeJS code sample
this.stream = child_process.spawn("ffmpeg", ["-rtsp_transport", "tcp", "-i", this.url, '-acodec', 'copy', '-vcodec', 'copy', '-'], {
detached: false
});
this.inputStreamStarted = true;
this.stream.stdout.on('data', function(data) {
return self.emit('mpeg1data', data);
});
this.stream.stderr.on('data', function(data) {
return self.emit('ffmpegError', data);
});
When outputting a pipe you are required to manually instruct ffmpeg what output format you want to use. You can do this with the -f option. Example:
ffmpeg -rtsp_transport tcp -i rtsp://admin:pass#10.168.9.141/Streaming/channels/1/ -c copy -f mpegts -
This does not perform any re-encoding because -c copy is being used.

Resources