How to mix noise to "raw" file (AN4 database) - noise-reduction

I am doing a research in noise reduction. Could anyone tell me how to mix a noise file with an audio file? I am working with the AN4 database, so they are all in "raw" format.
Thanks in advance.

You can take a noise file noise.wav and then mix it to an4 file with sox:
sox -m -r 16000 -s -2 file.raw noise.wav file_noise.wav
You can run sox in a loop to mix noise into all files
You can also mix white noise with sox dither command.

Related

How to use sox to record audio from command line

I want to record audio with this code:
sox -d test.wav trim 0 20
but the problem is that it says: sox FAIL sox: Sorry, there is no default audio device configured
and if I try some other sox codes it gives me help of sox.
There is no other way to record audio(Or at least no other way to record audio from command line)?
SoX 14.4.2 for MS Windows has trouble identifying the default audio device. There are two possible solutions:
Replace -d with -t waveaudio 0. If you have multiple audio devices (e.g. a USB microphone next to the regular mic plug), then you may need to replace 0 with 1 or higher.
Uninstall SoX 14.4.2, install SoX 14.4.1 instead.
Source:
https://sourceforge.net/p/sox/mailman/sox-users/thread/98af0ce0-a4aa-a3a4-043c-9cad15c4f962%40telefonica.net/
https://sourceforge.net/p/sox/mailman/sox-users/thread/BAY182-W450E755095D5B204A047A5DDD90%40phx.gbl/

Batch script to convert, youtube-dl webm file to mp3 with ffmpeg

I'm using youtube-dl to extract the best possible audio quality from youtube videos. However the best quality audio usually turns out to be the webm format, which isn't useful. I would like to write a batch script that converts the webm file to an mp3 with ffmpeg. I've already tried using this guide on reddit to do it, but it doesn't seem to work. It appears to create an empty mp3 file that displays an error when i try to play it and the meta data is also completly blank.
Here is the batch script:
for %%a in ("Downloaded\*.*") do %CD%\ffmpeg\bin\ffmpeg.exe -i "%%a" -vn -ar 44100 -ac 2 -ab 192k -f mp3 "Converted\%%~na.mp3" pause
I'll also give an explanation of how the whole thing should work.
The idea is, is that you use youtube-dl to extract the best possible audio, then put that file into the Downloaded folder (see pic below) and then you run the mp3 script (which uses commands from ffmpeg) to convert the webm file in the Downloaded folder to a mp3 file, and place it in the Converted folder. The mp3 script is the code above. But it doesn't seem to work properly.
I'm not very familiar with batch scripting, nor with ffmpeg so any help would be appreicated.
Here is the picture to complement the explanation part.
youtube-dl already contains this functionality - just specify that you want mp3:
youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=BaW_jenozKc
Replace https://www.youtube.com/watch?v=BaW_jenozKc with your actual URL.
You can convert through this script:
for FILE in *.webm; do
echo -e "Processing video '\e[32m$FILE\e[0m'";
ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
done;
Save it into a .sh file and execute it. It will automatically convert all the .webm into .mp3
webm either uses vorbis or opus audio codec, both are far superior to mp3 in quality.
aac audio is available on youtube, which is somewhere between opus and vorbis in quality and is heavily supported by media players and gadgets.
quality wise, re-encoding lossy audio to another lossy audio is not recommended, especially if one of those autio formats is mp3.
i'd grab that aac if i were you.
as per this answer:
youtube-dl -f bestaudio[ext=m4a] --embed-thumbnail --add-metadata <Video-URL>
in my use case, .ogg was supported
ffmpeg -i "input.webm" -vn -c:a copy "output.ogg"
without reencoding: -c:a copy
.webm files indeed can contain vorbis audio, but it can also contain opus audio. Also an ogg file can contain both audio formats. One can transfer the audio without conversion to an .ogg file:
https://askubuntu.com/questions/1258842/how-to-save-the-audio-from-webm-to-ogg-without-transcoding-using-ffmpeg#1258910
If you added -f bestaudio option to the command
youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=BaW_jenozKc ,
it would first download the best audio from youtube, and then convert it to mp3 without needing an ffmpeg bash script.
In this case the command would be
youtube-dl -f bestaudio -x --audio-format mp3 https://www.youtube.com/watch?v=BaW_jenozKc
Hope this helps.

Using ghostscript in a Windows .bat file to convert multiple pdf files to png

I have many many pdf files in a directory that I need to convert from pdf to png. Currently, I am using the ImageMagick command:
magick mogrify -format png *.pdf
Because, there are so many files, I would like to use ghostscript directly because there are several sources that suggest that I could achieve a 75% reduction in processing time by doing this.
However, I am having trouble finding a clean dos command example to accomplish the same thing as the ImageMagick command above. I believe I need to execute the gswin64c.exe module but I am unsure how to do this to accomplish what I need to get done. Can someone provide me with a clean example of the ghostscript that accomplishes what I'm doing in ImageMagick?
After much digging, what I discovered was that ghostscript does not really have a wildcard that would allow reference to all files of a certain pattern (like ImageMagick does). To convert all files in a directory that are pdf's to png's, a dos script like the following could be used:
for %%x in (*) do gswin64c.exe -sDEVICE=png16m -dBATCH -dNOPAUSE -dQUIET -
SOutputFile="%%~nx.png" %%~nx.pdf
This can also be run from the command line by simply using single percentage signs (%) instead of the double percentage signs in the script above.
The terms are as follows:
gswin64c.exe: This is the dos command version of GhostScript. It should be used as opposed to gswin64.exe which will open a GhostScript window.
-sDEVICE=png16m This indicates the form of the output file. Is this case png.
-dBATCH -dNOPAUSE. These are GhostScript options and when employed will allow for continuous operation of the script (without them, the program will pause after each file converted).
-dQUIET - This suppresses notifications that display on stdout after each processed file.
SOutputFile="%%~nx.png" %%~nx.pdf This indicates the pattern for the input files and the output files. x is the loop variable. The % sign is used as a wild card. ~nx is a Dos convention which truncates the extension of an echoed file name.

Merge M4A files in Terminal

I have a couple of M4A (sound) files on a Mac that I want to combine into a single sound file. Can this be done with a Terminal command? Is there such a thing?
Yeah, ffmpeg doesn't work, contrary to what the internet echo chamber will tell you. At least not that way. It's incredible how many have to drool their wisdumb and waste everyone's time.
Here. Prove me wrong with a link, but this is what you want and this is the only place you'll see it. Tres simple.
ffmpeg -i file1.m4a -acodec copy file1.aac
ffmpeg -i file2.m4a -acodec copy file2.aac
cat file1.aac file2.aac >>filenew.aac
ffmpeg -i filenew.aac -acodec copy -bsf:a aac_adtstoasc filenew.m4a
I compiled my own ffmpeg for the extra libs, so I hope that that is one of the default ones. If not, it's definitely worth the hassle. I haven't been able to validate the above on a second system, but on my old Hardy Heron Ubuntu grunt system the joined file has all the right m4a meta data and tags and there is no change in audio quality.
FFMPEG can help you with this. Chekc out their How To Contatenate media files article.
github.com/mifi/lossless-cut is for audio/video editing using ffmpeg. Works fine for merging mp3/mp4/m4a with drag and drop.
sudo snap install losslesscut
Are you trying to have the audio playback one after another, or playback on top of one another at the same time?
Either way FFmpeg can do the trick. The way I read your question, you want them playing back at the same time... If that's the case, try:
ffmpeg -i [input1] -i [input2] -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map [a] -c:a libfdk_aac out.m4a
Note: this is going to compress the audio to AAC. It is one of the best audio encoders, so you won't really notice a difference, but if you need to maintain quality, you can always go uncompressed with pcm_s16le. However, I think you would then be better off going out to a .wav file.

Using only ffmpeg, is it possible to consume a source GIF image and output a video that is a set length > one loop through the input GIF?

Let's say I have an 8 frame animated GIF that is 2 seconds long. I would like to build a video file (codec not important at this point) that is 30 seconds long that consists of the source GIF repeating over and over.
Is it possible to do this using only ffmpeg? Answers that use convert or some other pre-processing utility do not count [The reason being that I would like to use this on PandaStream, which does not have that utility]. Let's also assume that shell scripts are out of the question as well, though it can be multiple ffmpeg commands.
Things I have tried that did not work (though maybe I did them wrong, I'm not terribly familiar with ffmpeg):
Using the -loop_input, -loop_output options present in the ffmpeg docs. Using both ffmpeg 1.2 and 2.0, I get a Unrecognized option 'loop_[input|output]' error message. I might be using this wrong though since the error is about not recognizing the option, though the docs say it is deprecated.
-loop option. Does not seem to do anything with GIF -> Video. I think this flag and the above flag are related to generating animated GIFs as the output.
Concat. Doing something like:
ffmpeg -i "concat:image.gif|image.gif|image1.gif|image2.gif|image3.gif|image4.gif" image-long.gif
Results in a 16 frame gif (so two gifs are concatenated) which is progress, though the output gif is of much lower quality.
I'm a bit at my wits end here (I have tried many other permutations of the above concepts), I'm at the point now of 'poking it with a stick', hopefully someone out there has done this!
Is it possible? Yes.
Looking at How to concatenate (join, merge) media files, we can take the gif and transcode to mpeg streams (you could copy the first one twice):
ffmpeg -i image.gif -f mpegts image1.ts
ffmpeg -i image.gif -f mpegts image2.ts
ffmpeg -i image.gif -f mpegts image3.ts
then concatenate them, outputting as a gif
ffmpeg -i "concat:image1.ts|image2.ts|image3.ts" -pix_fmt rgb24 output.gif
Starting with an mp4 or similar seems to give better results; replace the first step with
ffmpeg -i image.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts image1.ts
and repeat for the other copies.
I create multiple copies of the same because if I try to concat: the same file multiple times (concat:image1.ts|image1.ts|image1.ts) it doesn't work.
Enjoy

Resources