Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PCM to MP3 Audio Compression

505 views
Skip to first unread message

Cleaver

unread,
Dec 9, 2004, 11:05:57 AM12/9/04
to

Cleaver

unread,
Dec 9, 2004, 11:12:57 AM12/9/04
to
I'm trying to create a video editor that deletes commercials from tv
programs and compresses the audio and video. I want to compress the audio
from PCM-44100,2channel,16bit to MP3-44100,2channel,16bit. I've been
trying for about two or three weeks with no luck. Can anyone give me some
information or source code on how to do this? Any help will be
appreciated...

Phil Taylor

unread,
Dec 9, 2004, 2:35:28 PM12/9/04
to
doesnt LAME do this? main.c appears to allow PCM input files and encodes to
MP3.

it also appears to come with an ACM wrapper.

"Cleaver" <brucec...@netzero.com> wrote in message
news:852da4ccd71368a8...@localhost.talkaboutsoftware.com...

Alessandro Angeli [MVP::DigitalMedia]

unread,
Dec 9, 2004, 4:28:40 PM12/9/04
to
Cleaver wrote:

You can use the MP3 ACM codec that comes with Windows (but I
think it can not encode at more than 56Kbps/24KHz) or you
can use the free LAME ACM codec or the free LAME DLL. The
following shows how to use the Windows' ACM codec (the LAME
ACM codec is named L"lameacm.acm") and it assumes the codec
is in the system's path (usually a codec is installed in
%WinDir%\System32, which is in the system's path by
default). The LAME DLL API is documented in the LAME
distribution.

OpenDriver(L"l3codeca.acm")
GetDriverModuleHandle()
GetProcAddress("DriverProc")
acmDriverAdd(ACM_DRIVERADDF_LOCAL|ACM_DRIVERADDF_FUNCTION)
acmDriverOpen()

acmStreamOpen()
acmStreamSize(ACM_STREAMSIZEF_SOURCE)
acmStreamSize(ACM_STREAMSIZEF_DESTINATION)
acmStreamPrepareHeader()
acmStreamConvert()
acmStreamUnprepareHeader()
acmStreamClose()

acmDriverClose()
acmDriverRemove()
CloseDriver()

The destination format must be (for MPE3, 44100Hz, 128Kbps,
stereo):

#include <mmreg.h>

MPEGLAYER3WAVEFORMAT.wfx.wFormatTag
= WAVE_FORMAT_MPEGLAYER3;
MPEGLAYER3WAVEFORMAT.wfx.nChannels
= 2;
MPEGLAYER3WAVEFORMAT.wfx.nSamplesPerSec
= 44100;
MPEGLAYER3WAVEFORMAT.wfx.nAvgBytesPerSec
= 16000;
MPEGLAYER3WAVEFORMAT.wfx.nBlockAlign
= 1;
MPEGLAYER3WAVEFORMAT.wfx.wBitsPerSample
= 0;
MPEGLAYER3WAVEFORMAT.wfx.cbSize
= MPEGLAYER3_WFX_EXTRA_BYTES;
MPEGLAYER3WAVEFORMAT.wID
= MPEGLAYER3_ID_MPEG;
MPEGLAYER3WAVEFORMAT.fdwFlags
= MPEGLAYER3_FLAG_PADDING_OFF;
MPEGLAYER3WAVEFORMAT.nBlockSize
= 417;
MPEGLAYER3WAVEFORMAT.nFramesPerBlock
= 1;
MPEGLAYER3WAVEFORMAT.nCodecDelay
= 1393;

nBlockSize is the actual MP3 frame_size * nFramesPerBlock.
The frame_size can be calculated from nSamplesPerSec and
nAvgBytesPerSec using the MP3 header tables and a simple
expression.

nAvgBytesPerSec is bitrate_in_Kbps * 1000 / 8.

nCodecDelay is a "magic" value used by the l3codeca.acm
codec while LAME uses 0.

The best way to fill your MPEGLAYER3WAVEFORMAT is to use

acmFormatEnum(ACM_FORMATENUMF_WFORMATTAG)

with

MPEGLAYER3WAVEFORMAT l3wfx = {
{ WAVE_FORMAT_MPEGLAYER3, },
};
ACMFORMATDETAILS afd = {
sizeof(ACMFORMATDETAILS),
0,
WAVE_FORMAT_MPEGLAYER3,
NOTHING,
(LPWAVEFORMATEX)&l3wfx,
sizeof(l3wfx),
};

and match the first ACMFORMATDETAILS that contains a
MPEGLAYER3WAVEFORMAT matching yoir sample rate, bit rate and
channel count.


--

// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net


0 new messages