On my node.js server I want to convert a wav file to apple lossless .m4a
Using fluent-ffmpeg, I got this so far:
const transcoder = ffmpeg(fs.createReadStream(`${__dirname}/convertTest.wav`));
transcoder
.withAudioCodec('alac')
.addOutput(fs.createWriteStream(`${__dirname}/test2.m4a`))
.run()
;
But it throws me the following error:
Error: ffmpeg exited with code 1: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Conversion failed!
I read that mp4 container needs a seekable file an therefore doesn't work with streams. So this actually works:
const transcoder = ffmpeg(`${__dirname}/convertTest.wav`);
transcoder
.withAudioCodec('alac')
.save(`${__dirname}/test2.m4a`)
.run()
;
Since I have all files as streams and not physical files, I am looking for way to somehow abstract this away to make it work with streams. Is this possible with fluent-ffmpeg?
The alac codec and .m4a format is non optional, so I need it to work with those formats.
Turns out that the ALAC codec does not support streams because the file head has to be read at different times. So I had to use it without streams.
Related
Is it possible to set the audio codec via -filter_complex in FFMPEG?
My Google-fu is weak and I haven't had good hits so far.
I'm working on a fork of a (possibly abandoned) project, and this is currently the -filter_complex argument:
[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.0[audout0]
How do I set the audio codec here?
I've tried:
[0:a]aformat=sample_fmts=fltp:sample_rates=44100:acodec=pcm_s16le:channel_layouts=stereo,volume=1.0[audout0]
by adding: acodec=pcm_s16le
But this results in: Option 'acodec' not found
I'm trying to accomplish is adding a default audio codec for a .wav output, because the system complains that there's no default audio codec chosen for a wav output, because I get this error message with my project when I try to output to .wav:
Automatic encoder selection failed for output stream #0:0. Default encoder for format wav (codec none) is probably disabled. Please choose an encoder manually.
Error selecting an encoder for stream 0:0
Thanks!
[mp2 # 0x555556aea340] Header missing
Error submitting the packet to the decoder
This above error is getting and i am unable to find out the reason.
I am decoding mp3 audio file using FFMPEG decode_audio.cpp pgm for which link is:
https://www.ffmpeg.org/doxygen/4.1/decode_audio_8c-example.html
I want to decode file into .wav file.
if anyone can answer this it would be helpful for everyone whoever in future doing audio decoding part.
codec = avcodec_find_decoder(AV_CODEC_ID_MP2);
if (!codec) {
fprintf(stderr, "Codec not found\n");
exit(1);
}
This is for the MP2 audio codec to decode the audio. You need to customize the code for mp3.
I'm trying to convert DVD iso files to mp4 using HandbrakeCLI. I use the following line in a batch file:
D:\HandBrakeCLI.exe -i "D:\input.iso" -o "D:\output.mp4" --no-markers --width "720" --height "480" --preset "HQ 480p30 Surround" --encoder "mpeg2" --audio-lang-list "eng"
When I do this, I must then extract the audio from the file, using the following line:
D:\eac3to\eac3to.exe "D:\output.mp4" "D:\output.wavs" -down16
However, when I attempt to extract the audio, I get the error message
The format of the source file could not be detected.
Is there anything wrong with my former line of code that's causing the mp4 to get screwed up?
Minor side question: I'm also trying to get handbrake to remove subtitles and also only keep English audio, do you know what code could be used for that? I started a bit there with the --audio-lang-list "eng" but I'm now sure what to do from there.
Thanks a lot in advance!
You need to use a valid audio format. .wavs is not valid. You have to use an available audio codec to output to the below for --aencoder. The default output audio for MP4 is .aac
av_aac
copy:aac
ac3
copy:ac3
eac3
copy:eac3
copy:truehd
copy:dts
copy:dtshd
mp3
copy:mp3
vorbis
flac16
flac24
copy:flac
opus
copy
Defaults for audio
av_mp4 = av_aac
av_mkv = mp3
You need to pass none for no subtitles
-s none
And define only eng track like you were doing
--audio-lang-list eng
Check out the Handbrake CLI Documentation for the command line code:
https://handbrake.fr/docs/en/latest/cli/cli-guide.html
You can also try using a different program once you extract the audio. A program like XMediaRecode. It can also remux audio and video and convert other audio formats to wav
https://www.videohelp.com/software/XMedia-Recode
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;
}
Im trying to extract each frame from a rtsp mp4 stream, and convert that into a jpeg/gif using ffmpeg. I'm getting the sdp header from 000001b0.....000001b5, and adding that into an byte array then capturing a frame starting from 000001b6 and appending it to the byte array.
When I flush it to a file (.mpg) and use ffmpeg it throws errors and not converting.
my header looks like 000001B008000001B58913000001000000012000C488BA98514043C1463F and after this I'm appending a frame (starting from 000001b6).
I did something similar with FFMPEG, and it seems that the frame data you get from FFMPEG already contains the frame header, which is all you need to transcode the data. Please make sure that you decode the mp4 data to a raw format (RGB24 for instance), then encode it to the pixelformat the JPEG/GIF encoder expects (probably a YUV format) using libswscale, before passing the data to the encoder.
Depending on the Codec you may not have to add anything or you may have to add a lot..
This is referred to as de-packetization and MPEG4-ES has no packetization model... H264 has many depending on the profile.
Check out the RFC..
Either 3016 or 3640 should help you.
https://www.rfc-editor.org/rfc/rfc3640
https://www.rfc-editor.org/rfc/rfc3016