I am using FFMPEG to transcode a large file to a smaller file. Usually the files will have 2 audio channels (though not always). I am trying to center all audio channels.
I asked over at the ffmpeg-users for examples of how to do this: http://ffmpeg-users.933282.n4.nabble.com/Panning-audio-channels-example-td4417939.html
What I got from the replies is that FFMPEG has yet to implement audio filters. Somehow I should be able to set up a libav filter (?) to pan all channels center... something to the effect of:
pan="c0=0.5*FL+0.5*FR" though when I do this, I get the error: No such filter: 'pan'. Those guys are great but I can't figure this out by reading the docs.
I have not disabled filters, here is my build info
configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264 --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/opt/local/bin/gcc-apple-4.2 --arch=x86_64 --enable-yasm --enable-nonfree --enable-libfaac
Here is an example of one of my built command lines: ffmpeg -i inMovie.mov -acodec libfaac -ab 64k -vcodec libx264 -vpre medium -b 320k -pass 1 -s 374x210 -threads 0 outMov.mp4
I've got the rest of my FFMPEG command line working great... Essentially what I am looking for is to have left/right audio channels both have the same audio in the output file. If there is an easier way to do this (convert to 2 mixed mono channels?) I am all ears!!
Thank you for your help!
The audio filters have a different sintax on FFMPEG. You can pan audio channels without create a mixdown.
Using your example:
ffmpeg -f lavfi -i "amovie=inMovie.mov,pan=stereo: c0=c0+c1: c1=c0+c1" -i inMovie.mov -map 0:0 -map 1:0 -vcodec libx264 -vpre medium -b 320k -pass 1 -s 374x210 -threads 0 -acodec libfaac -ab 64k outMov.mp4
I don't have a command reference handy at the moment, but I would use FFMPEG to mixdown to mono, and then convert back to stereo. This should give you the results you need.
Related
I'm trying to encode 6 arbitrary mono audio streams into a single AAC 5.1 track in an mp4 container (here with test streams):
ffmpeg -f lavfi -i testsrc=duration=10:size=100x100:rate=30 -f lavfi -i aevalsrc="-2+random(0)" -filter_complex "[1:a][1:a][1:a][1:a][1:a][1:a]join=inputs=6:channel_layout=5.1:map=0.0-FL|1.0-FR|2.0-FC|3.0-LFE|4.0-BL|5.0-BR[a]" -map '0:v' -map "[a]" -c:a aac -channel_layout 5.1 -t 10 testlfe.mp4
5 of the channels replicate the input audio just fine (modulo encoding). However, the LFE channel is lowpassed. Extracting with:
ffmpeg -i testlfe.mp4 -filter_complex "channelsplit=channel_layout=5.1:channels=LFE[LFE]" -map '[LFE]' testlfe.wav
I get a lowpassed rumble, instead of the original full white noise
(from ffmpeg -i testlfe.wav -lavfi showspectrumpic=s=640x320 testlfe.png)
Is there a way to prevent the lowpass from happening?
I couldn't find any references whether that's inherent to the AAC 5.1 encoding, something that ffmpeg does, or inherent to the decoding process. (I did decode my same test files using something that uses Microsoft MediaFoundation and the LFE channel was still lowpassed).
Turns out, the AAC codec inherently limits the LFE bandwidth, so there's no way around it.
(thanks to kesh in the comments) Wikipedia's Advanced Audio Encoding article claims the upper limit is 120Hz which matches my spectrogram, but doesn't cite a source. The actual ISO/IEC 13818-7:2006(en) Standard costs a bunch of money to read as usual, but in the free glossary there is an entry:
low frequency enhancement ( LFE ) channel:
limited bandwidth channel for low frequency audio effects in a multichannel system
Encode with
ffmpeg -i 6channels.wav -filter "channelmap=0|1|2|3|4|5:6.0(front)" -c:a libfdk_aac -ac 6 -profile:a aac_he -vbr 1 -cutoff 18000 -movflags +faststart 6channels-vbr1-fdk.m4a
It can also be done with regular aac codec.
After several hours I have narrowed down the issue with the garbled audio to be the 2-seconds silence audio mp3 I am appending (I think I had produced it once with Wavelab)
However, I tried using ffmpeg according to a post to produce a similar 2 seconds audio but it too will corrupt/garble/chop voice in the final concatenation of audio files.
ffmpeg -f lavfi -i anullsrc=r=44100:cl=mono -t 2 -q:a 9 -acodec libmp3lame SILENCE_2sec.MP3
I typically will have several audio files to concatenate together but for simplicity I have able to narrow it to a couple of files simplifying to the following script. A simple Windows batch file you should be able to use and reproduce the issue at your end.
rem
rem
SET EXE="S:\_BINS\FFmpeg 4.2.1 20200112\bin\ffmpeg.exe"
SET ROOTPATH=.\
SET IN_FILE="%ROOTPATH%MyList.txt"
ECHO file '%ROOTPATH%HELLO.mp3' > MyList.txt
ECHO file 'SILENCE_2sec.MP3' >> MyList.txt
SET OPTIONS= -f concat -safe 0 -i %IN_FILE% -c copy -y
SET OUT_FILE="%ROOTPATH%CONCATENATED_AUDIO_2.MP3"
SET INFO_FILE="INFO.TXT"
%EXE% %OPTIONS% %OUT_FILE% 1> %INFO_FILE% 2>&1
ECHO ======================== >> %INFO_FILE%
ECHO IN_FILE=%IN_FILE% >> %INFO_FILE%
ECHO EXE=%EXE% >> %INFO_FILE%
ECHO OPTIONS=%OPTIONS% >> %INFO_FILE%
ECHO ======================== >> %INFO_FILE%
Here is the console info output from the ffmpeg, let me know if you need other output include ones from ffprobe
ffmpeg version git-2020-01-10-3d894db Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20191125
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 38.100 / 56. 38.100
libavcodec 58. 65.103 / 58. 65.103
libavformat 58. 35.101 / 58. 35.101
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 70.101 / 7. 70.101
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
[mp3 # 000000000036af80] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from '.\MyList.txt':
Duration: N/A, start: 0.000000, bitrate: 32 kb/s
Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Output #0, mp3, to '.\CONCATENATED_AUDIO_2.MP3':
Metadata:
TSSE : Lavf58.35.101
Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp3 # 0000000000372d00] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 17280 >= 17255
size= 11kB time=00:00:02.73 bitrate= 33.2kbits/s speed=2.73e+03x
video:0kB audio:11kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.137446%
========================
IN_FILE=".\MyList.txt"
EXE="S:\_BINS\FFmpeg 4.2.1 20200112\bin\ffmpeg.exe"
OPTIONS= -f concat -safe 0 -i ".\MyList.txt" -c copy -y
========================
I believe I am running FFmpeg 4.2.1, recently installed (20200112)
You may produce the HELLO.mp3 by saving the following link
https://translate.google.com.vn/translate_tts?en=UTF-8&q=Hello+&tl=en&client=tw-ob
FYI, I am still a novice of ffmpeg and using it more like a black box with the help I received in this very super forum.
Please be as explicit as you can with command line options on how I can fix this issue.
Thank you.
Additional Hints Debugging:
If I append more files after the silence audio it seems that the silence audio impacts (garbles, chops) the previous audio.
You may try the following for the list of audio files input.
ECHO file '%ROOTPATH%HELLO.mp3' > MyList.txt
ECHO file 'SILENCE_2sec.MP3' >> MyList.txt
ECHO file '%ROOTPATH%HELLO.mp3' >> MyList.txt
ECHO file '%ROOTPATH%HELLO.mp3' >> MyList.txt
I typically add one or more silence file to derive a post silence effect after the actual audio. That's my current logic. However if you have an alternative to appending a silence in the process of concatenating several audio files or appending x-seconds silence to an existing audio file. I can use that method as well from my coding.
Thank you.
The silent audio needs to match the parameters of the main audio:
Stream #0:0: Audio: mp3, 24000 Hz, mono, fltp, 32 kb/s
The parameters above are:
sample rate (24000 Hz)
channel layout (mono)
sample format (fltp)
bitrate (32 kb/s)
The important parameters are sample rate and channel layout. In the anullsrc filter you can set these with the r/sample_rate and cl/channel_layout options as shown in ffmpeg -h filter=anullsrc.
Example command:
ffmpeg -f lavfi -i anullsrc=r=24000:cl=mono -t 2 -b:a 32k -c:a libmp3lame SILENCE_2sec.MP3
Alright, I have my own compiled ffmpeg with --enable-lv2. This allows for 3rd-party plugins to work. The plugin I use is: https://github.com/lucianodato/speech-denoiser it's a plugin that wraps around this RNN noise reduction library: https://github.com/GregorR/rnnoise-models
The following commands work:
(1) ffmpeg -i input.mov -filter_complex '[0:a]lv2=plugin=https\\://github.com/lucianodato/speech-denoiser[audio]' -map "[audio]" output.wav
(2) ffmpeg -i input.mov -filter_complex '[0:v]copy[video]' -map "[video]" output.mov
But when I do the combination, that doesn't work.
ffmpeg -i input.mov -filter_complex '[0:a]lv2=plugin=https\\://github.com/lucianodato/speech-denoiser[audio];[0:v]copy[video]' -map "[audio]" -map "[video]" output.mov
I think the error is essentially this:
Channel layout change is not supported
Error while filtering: Not yet implemented in FFmpeg, patches welcome
Failed to inject frame into filter network: Not yet implemented in FFmpeg, patches welcome
Error while processing the decoded data for stream #0:0
My guess: this 3rd-party filter is not configure to work with any other output stream other than audio.
My question: can I somehow trick this 3rd-party plugin that it is outputting to an audio file, while still outputting everything to a video file?
Note: I know, I can simply split this up in 2 commands and be done with it, so I'm wondering if I can accomplish this via one ffmpeg command. How I would split it up in 2 commands is as follows:
ffmpeg -i out_cropped.mov -af 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' -vcodec copy out_cropped_denoised.wav
&&
ffmpeg -i out_cropped.mov -i out_cropped_denoised.wav -c:v copy -map 0:v:0 -map 1:a:0 out_cropped_denoised.mov
But I want to be able to put it all in one complex filter (ideally) or at least in one ffmpeg command.
Appendix: here is the full interaction
ffmpeg -i input.mov -filter_complex '[0:a]lv2=plugin=https\\://github.com/lucianodato/speech-denoiser[audio];[0:v]copy[video]' -map "[audio]" -map "[video]" output.mov
ffmpeg version N-95577-g68f623d644 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.8)
configuration: --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --enable-lv2 --samples=fate-suite/
libavutil 56. 35.101 / 56. 35.101
libavcodec 58. 60.100 / 58. 60.100
libavformat 58. 33.100 / 58. 33.100
libavdevice 58. 9.100 / 58. 9.100
libavfilter 7. 65.100 / 7. 65.100
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.29.100
Duration: 00:16:19.11, start: 0.000000, bitrate: 1341 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1080x960, 1262 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : Core Media Video
encoder : Lavc58.54.100 libx264
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
Metadata:
handler_name : Core Media Audio
File 'output.mov' already exists. Overwrite? [y/N] y
#ote: I typed yes and then this came.
Stream mapping:
Stream #0:0 (h264) -> copy
Stream #0:1 (aac) -> lv2
lv2 -> Stream #0:0 (aac)
copy -> Stream #0:1 (libx264)
Press [q] to stop, [?] for help
[out_0_0 # 0x7fa6811066c0] Channel layout change is not supported
Error while filtering: Not yet implemented in FFmpeg, patches welcome
Failed to inject frame into filter network: Not yet implemented in FFmpeg, patches welcome
Error while processing the decoded data for stream #0:0
I forgot to post an answer here, but I recompiled the ffmpeg project.
And then I could use this command ffmpeg -i out_cropped.mov -af 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' -vcodec copy out_cropped_denoised.wav
I remember that I wrote a compilation guide to myself as compiling it seemed a scary thing to do. And it was (just a little), but ultimately it was perfectly doable.
Here's the guide.
How to compile ffmpeg, lv2 and speech-denoiser for mac and denoise your audio files (and put it into videos) on a Mac!
Helpful guide for compiling ffmpeg on MacOS:
CompilationGuide/macOS – FFmpeg
Install depencencies
brew install automake fdk-aac git lame libass libtool libvorbis libvpx \
opus sdl shtool texi2html theora wget x264 x265 xvid nasm
Install lilv (dependency for lv2)
brew install lilv #because of ERROR: lilv-0 not found using pkg-config when doing ./configure right away
Configure ffmpeg
./configure --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass \
--enable-libfdk-aac --enable-libfreetype --enable-libmp3lame \
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid --enable-lv2 \
--samples=fate-suite/
Make & Install
make
sudo make install
Install speech denoiser dependencies + the project itself
brew update
brew cask uninstall oclint
brew install lv2 meson ninja pkg-config autoconf m4 libtool automake
#Download and install speech denoiser
git clone https://github.com/lucianodato/speech-denoiser.git
cd speech-denoiser
chmod +x install.sh && ./install.sh
Check fo see if install exists
lv2ls #You got this command from installing lilv
Output: https://github.com/lucianodato/speech-denoiser
(yep a URL)
Use your command!
#audio to denoised audio
ffmpeg -i out_cropped.mov -af 'lv2=plugin=https\\://github.com/lucianodato/speech-denoiser' -vcodec copy out_cropped_denoised.wav
#for if you want to put it with a video
&&
ffmpeg -i out_cropped.mov -i out_cropped_denoised.wav -c:v copy -map 0:v:0 -map 1:a:0 out_cropped_denoised.mov
I cannot find enough documentation on the alimiter filter.
https://ffmpeg.org/ffmpeg-filters.html#alimiter
I used -filter_complex alimiter=limit=0.5 and it applied to the file but it boosted the volume.
I thought it was supposed to hardlimit the volume down?
FFmpeg says through cmd limit range [0.0625 - 1]
ffmpeg -i audio.wav -y -acodec libmp3lame -b:a 320k -ar 44100 -ac 2 -joint_stereo 1 -filter_complex alimiter=limit=0.5 audio.mp3
Here's a look at the two files through Adobe Audition
Original
FFmpeg alimiter 0.5
I found the problem was here:
level
Auto level output signal. Default is enabled. This normalizes audio back to 0dB if enabled.
I tried chaining the filter like this using level=disabled
-filter_complex alimiter=level_in=1:level_out=1:limit=0.5:attack=7:release=100:level=disabled
It now hard limits without raising the volume.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
FYI: Fedora 8 running on Amazon EC2...
Having a difficult time with FFmpeg doing a (what should be pretty simple) conversion. I can get FFmpeg to encode an mp3 file from an m4a file using the following:
ffmpeg -i file1.m4a -acodec libmp3lame -ab 160k file2.mp3
However, I cannot get it to to convert an mp3 -> mp3, it responds with "Unknown Format" using the following:
ffmpeg -i file1.mp3 -acodec libmp3lame -ab 160k file2.mp3
I get the following command string:
FFmpeg version UNKNOWN, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/share/man --incdir=/usr/include/ffmpeg --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libfaad --enable-libfaac --enable-libgsm --enable-libxvid --enable-libx264 --enable-liba52 --enable-liba52bin --enable-pp --enable-shared --enable-pthreads --enable-gpl --disable-strip
libavutil version: 49.6.0
libavcodec version: 51.50.1
libavformat version: 52.7.0
libavdevice version: 52.0.0
built on Feb 14 2008 17:47:08, gcc: 4.1.2 20070925 (Red Hat 4.1.2-33)
file1.mp3: Unknown format
Any help would be hugely appreciated!
Edit for clarity:
The input file is in /ebs/queue/input.mp3 and the output is /ebs/converted/output.mp3
ffmpeg -i /file.mp3 -acodec libmp3lame -ab 160k /file.mp3
Is it meaning that the input file and the output file have the same name? Does this make any difference?
ffmpeg -i /file.mp3 -acodec libmp3lame -ab 160k /file.mp3
Your output file is your input file. ffmpeg is probably opening file.mp3 as wb and truncating the contents.
When it goes to read it, it gets nothing.
Next time post on Super User.
The problem seems to have solved itself, however for the life of me I can't figure out what I could have possibly done to solve the problem. FFMpeg is now converting mp3 -> mp3 successfully using the code above.