Linux pcm to wav

How to convert pcm files to wav in Linux

Over the weekend I had to make a recording on my Android phone. I used the app Virtual Recorder thinking I’d be able to just share the file afterwards but Virtual Recorder creates pcm files not typical mp3 files. I sent the file over to my Linux laptop, running Linux mint, to convert it.

Initially I had some trouble getting the conversion to work. Here are the steps I took.

Open a terminal window and navigate to the where the pcm file is. If you don’t know how to do this use the GUI file explorer to navigate to the directory where the pcm file is and then right click on white space and click on the option to open a terminal window. The terminal will open already set to run against the directory the pcm file is located in.

If you try to run any of the commands below and you don’t have ffmpeg installed you will be notified ffmpeg needs to be installed and it will give you the command to type in and run to install it.

If you want to convert a Virtual Recorder file specially you can use this terminal command below changing the file names to what you need.

ffmpeg -f s16le -ar 11250 -ac 2 -i YouInputFileName.pcm -ar 44100 -ac 2 YouOutputFileName.wav

Converting pcm files created by other applications may have varying results due to the sample rate of the source file. For example if you replace 11250 with 22500 as in the command below your output file pitch and speed will be increased. So you may need to play around with sample rates to get the output right.

ffmpeg -f s16le -ar 22500 -ac 2 -i YouInputFileName.pcm -ar 44100 -ac 2 YouOutputFileName.wav

Источник

How to convert pcm files to wav in Linux

Over the weekend I had to make a recording on my Android phone. I used the app Virtual Recorder thinking I’d be able to just share the file afterwards but Virtual Recorder creates pcm files not typical mp3 files. I sent the file over to my Linux laptop, running Linux mint, to convert it.

Initially I had some trouble getting the conversion to work. Here are the steps I took.

Open a terminal window and navigate to the where the pcm file is. If you don’t know how to do this use the GUI file explorer to navigate to the directory where the pcm file is and then right click on white space and click on the option to open a terminal window. The terminal will open already set to run against the directory the pcm file is located in.

Читайте также:  Linux mail to smtp server

If you try to run any of the commands below and you don’t have ffmpeg installed you will be notified ffmpeg needs to be installed and it will give you the command to type in and run to install it.

If you want to convert a Virtual Recorder file specially you can use this terminal command below changing the file names to what you need.

ffmpeg -f s16le -ar 11250 -ac 2 -i YouInputFileName.pcm -ar 44100 -ac 2 YouOutputFileName.wav

Converting pcm files created by other applications may have varying results due to the sample rate of the source file. For example if you replace 11250 with 22500 as in the command below your output file pitch and speed will be increased. So you may need to play around with sample rates to get the output right.

ffmpeg -f s16le -ar 22500 -ac 2 -i YouInputFileName.pcm -ar 44100 -ac 2 YouOutputFileName.wav

Источник

How to convert raw PCM data to a valid WAV file with ffmpeg?

Where pipe:0 is the raw PCM data of the left channel of this file. Here is the output wav. The output seems to be semi valid. It won’t play in Quicktime or iTunes. When attempting to add it to an Ableton project, I get «output.wav could not be read. It may be corrupt or not licensed.» However, it does play fine if I simply drag the output wav in Chrome. The ffprobe output confirms some sort of problem with the file. For this command: ffprobe -loglevel verbose /Users/maximedupre/Desktop/Dropbox/Programming/api/gg.wav

ffprobe version 3.4.2 Copyright (c) 2007-2018 the FFmpeg developers built with Apple LLVM version 9.0.0 (clang-900.0.39.2) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma 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 [wav @ 0x7f81e3004a00] Ignoring maximum wav data size, file may be invalid [wav @ 0x7f81e3004a00] parser not found for codec pcm_s16le, packets or times may be invalid. [wav @ 0x7f81e3004a00] Estimating duration from bitrate, this may be inaccurate Input #0, wav, from '/Users/maximedupre/Desktop/Dropbox/Programming/api/gg.wav': Metadata: encoder : Lavf58.20.100 Duration: 00:06:12.01, bitrate: 705 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s 

Источник

Читайте также:  Run linux using virtualbox

Can ffmpeg convert audio from raw PCM to WAV?

The wav container just adds a simple header to the raw PCM data. The header includes the format, sample rate, and number of channels. Since the raw PCM data does not include this information, you will need to specify it on the command line. Options are specified before the file they apply to, so options before the input file may be used to specify the format of the input file, and options after the input file and before the output file may be used to specify the desired format of the output file. If you want the same bits/sample, sample rate, and number of channels in the output file then you don’t need any output options in this case; the wav container format is already indicated by the file extension.

Example to convert raw PCM to WAV:

ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav 
  • -f s16le … signed 16-bit little endian samples
  • -ar 44.1k … sample rate 44.1kHz
  • -ac 2 … 2 channels (stereo)
  • -i file.pcm … input file
  • file.wav … output file

@bos, I guess @mustafa.yavuz was asking the reverse(WAV to PCM). Then nothing special, simply ffmpeg -i file.wav file.pcm will do since all information needed to do the conversion is in the header of the wav file.

I tripped on the -f parameter. Tried to use one value from ffmpeg -sample_fmts. The right values are as on barney’s answer.

Be careful with RAW data format

-f u8 is unsigned 8 bit, s16 is signed just in case there are others

 $ ffmpeg -formats | grep PCM DE alaw PCM A-law DE f32be PCM 32-bit floating-point big-endian DE f32le PCM 32-bit floating-point little-endian DE f64be PCM 64-bit floating-point big-endian DE f64le PCM 64-bit floating-point little-endian DE mulaw PCM mu-law DE s16be PCM signed 16-bit big-endian DE s16le PCM signed 16-bit little-endian DE s24be PCM signed 24-bit big-endian DE s24le PCM signed 24-bit little-endian DE s32be PCM signed 32-bit big-endian DE s32le PCM signed 32-bit little-endian DE s8 PCM signed 8-bit DE u16be PCM unsigned 16-bit big-endian DE u16le PCM unsigned 16-bit little-endian DE u24be PCM unsigned 24-bit big-endian DE u24le PCM unsigned 24-bit little-endian DE u32be PCM unsigned 32-bit big-endian DE u32le PCM unsigned 32-bit little-endian DE u8 PCM unsigned 8-bit 

Источник

Converting RAW audio data to WAV with scripting

I have a large number of .RAW audio files (unsigned 8-bit PCM with no-endianness) which I want to convert to .WAV files. What command-line tool (windows or linux) can I use to convert these quickly?

Читайте также:  Linux узнать размеры файлов

7 Answers 7

I was pointed to SoX by a friend, which did the trick. The syntax used was sox -r 44100 -e unsigned -b 8 -c 1

SoX is fantastic. It’s a command line tool so it’s very straightforward to script, though the number of options can be a bit overwhelming at first.

I found sox to be incredibly fast and reliable. I use it for a dictation solution I put together with Asterisk. If you are using sox though, be aware that you should be aware of what the source encoding is. I found this to be my initial hangup with the project I did

For my implementation I use this:

sox -t auto -w -s -r 8000 -c 1

audioconvert is pretty standard (I think)

mencoder isn’t available by standard in totally-free linux distributions, but can convert to about anything

MPlayer should be able to convert your audio;

$ mplayer \ -quiet \ -vo null \ -vc dummy \ -af volume=0,resample=44100:0:1 \ -ao pcm:waveheader:file="file.wav" "file.raw" 

It’s available in most linux distributions package managers.

If you have a file name.txt which contains all the raw audio file names, then with python you can convert a batch of raw files to batch of wav.

from subprocess import call file = "name.txt" with open(file,'rU') as f: for name in f: name = name[:len(name)-4] name1 = './'+name+'raw' #input name2 = './'+name+'wav' #output call(["sox","-r","48000", "-t", "sw", "-e", "signed", "-c", "1", "-b", "16", name1, name2]) 

sample rate 48K,mono channel, precision 16 bit.

small but deadly typo, you’re missing a «.» before ‘raw’ and ‘wav’. Also be careful as sometimes files have extension «.RAW» (I’m specifically talking about the Radio Music SD card) and AFAIK the arguments of sox are case sensitive

 var Lame = require("node-lame").Lame; const decoder = new Lame(< output: "./new.wav", raw: true, bitwidth:16, sfreq:48, mode: "m" >).setFile("./a.pcm"); decoder.decode().then(() => < console.log("decoded successfully."); >).catch(error => < console.log("Error: "+error); >); 
sox -r 48000 -t sw -e signed -c 1 -b 16 a.pcm new.wav 

Let’s use Sox, it’s available pretty much everywhere.

sudo apt update && sudo apt install sox -y 

I tend to use 16k SR, 16-bit precision with encoding 16-bit Signed Integer PCM so will use those defaults. My files are .raw but could also be .pcm etc.

# assume you're in the directory with the raw wavs - we'll make a new wavs directory to put the converted ones mkdir -p wavs # 1-liner for f in *.raw; do sox -r 16000 -e signed -b 16 -c 1 "$f" wavs/"$.wav"; done 

To check that the wav files have their header, use soxi:

rob@tp:~/wavs$ soxi test.wav Input File : 'test.wav' Channels : 1 Sample Rate : 16000 Precision : 16-bit Duration : 00:00:12.62 = 201984 samples ~ 946.8 CDDA sectors File Size : 404k Bit Rate : 256k 

Источник

Оцените статью
Adblock
detector