multiple chunk from .wav file with specific timeframe - node.js

I want to create multiple .mp4 files from .wav audio file for specific given time.
Input:
.wav audio file with length of 120 sec.
chunks timeframes are
start: 20s, end: 35sec
start: 45s, end: 105sec
...
Output:
Output would be two .mp4 audio file
Audio file with length of 15sec (20s - 35s)
Audio file with length of 20sec (45s - 105s)
...
I'm using ffmpeg lib for that, How can I do that?

Related

Combine audio files based on the timestamps in their filenames

I just received dozens of audio files that are recorded radio transmissions. Each transmission is its own file, and each file has its transmission time as part of its filename.
How can I programmatically combine the files into a single mp3 file, with each transmission starting at the correct time relative to the first?
Filename format:
PD_YYYY_MM_DD_HH_MM_SS.wav
Examples:
PD_2022_01_22_16_21_52.wav
PD_2022_01_22_16_21_55.wav
PD_2022_01_22_16_22_02.wav
PD_2022_01_22_16_22_05.wav
PD_2022_01_22_16_23_03.wav

Play RTMP streaming and also want to update the mp3 file without breaking stream while running stream in parallel

The thing which I am doing right now is that I am playing RTMP streaming on media server using ffmpeg command and also creating an audio file using google text to speech.
So I want to update mp3 file with silence if there is no content, so that it will keep will keep stream running.
I have tried 2 approaches:
By writing raw binary data to mp3 file but not working as it says content is not accurate.
Concatenate the audio content with the silence data and export file. In this scenario, I am able to update file but stream broken at the point while we are exporting file.
I have tried to write the audio file with binary data and also tried to concatenate audio content with silence and then export file but it break stream while we export the file.

How to join mp3 and wav files

Hi all,
I've a PHP application to manage audio files.
I've two input about audio files: file wav and file MP3
My application joins all files in to an unique mp3 file, and so I convert the wav file in mp3 file before to join them.
I'm using LAME.
File wav (conversion):
lame -m m -b 128 file.wav filewav.mp3
File mp3 (in mp3 - to create the mp3 file with same characteristics of wav conversion):
lame --mp3input -b 128 file.mp3 filemp3.mp3
The problem is: I can't join files if they are different format (filewav.mp3 and filemp3.mp3)!
Is it possible to join different files?
Thank you
Pasquale
This is more of a 'How do I approach this problem' type of question.
It's not too hard, you just need to add some logic to your script to first check and see if all files are of the same format. If they are not, then determine which ones need to be converted and run separate lame conversions on each file which isn't in your desired format. Like so:
lame -V2 input.wav output.mp3
Then, at the end of your code, join them all together with the same join statement you're using there.
lame --mp3input -b 128 file.mp3 filemp3.mp3

How to convert gapless m4a tracks into a gapless HLS stream

I have an album stored as a list of gapless m4a files, ripped from CD. I need to stream the album gaplessly over HTTP Live Streaming, and the user must be able to "jump in" at the start of any track. For now, my only client is AVPlayer on iOS.
I can segment the tracks individually using Apple's mediafilesegmenter tool. For each track, this produces one .m3u8 playlist file and several .aac segment files, each ~10 seconds in duration except for the last.
The m3u8 playlist for Track 1 looks like this:
#EXTM3U
#EXT-X-TARGETDURATION:11
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:10.001,
segment0.aac
#EXTINF:9.983,
segment1.aac
...
#EXTINF:3.231,
segment23.aac
#EXT-X-ENDLIST
I can combine these m3u8 playlist files into one master m3u8 file for the album:
#EXTM3U
#EXT-X-TARGETDURATION:11
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:10.001, // begin track 1
segment0.aac
#EXTINF:9.983,
segment1.aac
...
#EXTINF:3.231,
segment23.aac
#EXT-X-DISCONTINUITY
#EXTINF:10.001, // begin track 2
segment24.aac
#EXTINF:9.983,
segment25.aac
...
#EXTINF:6.845,
segment46.aac
#EXT-X-DISCONTINUITY
#EXTINF:10.001, // begin track 3
segment47.aac
#EXTINF:9.983,
segment48.aac
...
#EXTINF:8.012,
segment80.aac
#EXT-X-ENDLIST
It will play through the whole album, but it isn't gapless. Notice the DISCONTINUITY tag between each track (without it, the player hangs forever). This introduces a small gap between tracks, maybe 300 milliseconds.
How can I create segments that flow into each other with no discontinuity?
You can concatenate the AAC files before using the mediafilesegmenter tool on the combined AAC file.
The following ffmpeg command might generate the output file.
ffmpeg -i "concat:input1.aac|input2.aac|input3.aac" -c copy output.aac
It's possible you'll need to remux the aac files to mpeg2ts files before concatenation, and then remux the mpeg2ts file to AAC.

Convert from PCM to WAV. Is it Possible?

I have an application for iPAD.
This application records the voice of the microphone.
The audio formats of the item must be PCM, MP3 and WAV files. The MP3 file I get it starting from the original raw file and then convert using LAME.
Unfortunately I have not found any example that allows me to convert a PCM file to a WAV file.
I just noticed that if I put the file extension to WAV format, starting from the raw application saves without problems, so I think that there is no type conversion from PCM WAV files.
Correct?
PS: Sorry for my english ... I use Google Translate
WAV is some kind of a box. PCM is in the box. There are many container formats like MP4. MP4 can contain audio, video or both. It can also contain multiple video or audio streams. Or zip files. Zip files can contain text files. But zip files can also contain images, pdfs,... But you can't say "how can I convert a zip file to the text file inside the zip".
If you want to convert PCM data to a WAVE file you should not many problems because WAV files are quite simple files. Take a look at this:
(See also WAVE PCM soundfile format.)
You first need that header and after you can just append all your pcm data (see the data field).
Converting PCM to WAV isn't too hard. PCM and WAV both format contains raw PCM data, the only difference is their header(wav contains a header where pcm doesn't). So if you just add wav header then it will do the tricks. Just get the PCM data and add the wav header on top of the PCM data. To add wav header with PCM data, check this link.
I was working on a system where it accepts only wav files, but the one I was receiving from amazon Polly was pcm, so finally did this and got my issue resolved. Hope it helps someone. This is an example of nodejs.
// https://github.com/TooTallNate/node-wav
const FileWriter = require('wav').FileWriter
let audioStream = bufferToStream(res.AudioStream);
var outputFileStream = new FileWriter(`${outputFileFolder}/wav/${outputFileName}.wav`, {
sampleRate: 8000,
channels: 1
});
audioStream.pipe(outputFileStream);
function bufferToStream(binary) {
const readableInstanceStream = new Stream.Readable({
read() {
this.push(binary);
this.push(null);
}
});
return readableInstanceStream;
}

Resources