[Ffmpeg-devel] Re: ffmpeg-devel Digest, Vol 19, Issue 250

Paul paul.pham
Mon Oct 30 18:14:56 CET 2006


 Here is my code to encode audio from sound buffer(using directsound to
capture). The codecs i use is MP2. Can you show me where my wrong?
............................................................................
................
        .........
        if( FAILED( hr = g_pDSBCapture->GetCurrentPosition( &dwCapturePos,
&dwReadPos ) ) )
            return DXTRACE_ERR_MSGBOX( TEXT("GetCurrentPosition"), hr );

        lLockSize = dwReadPos - g_dwNextCaptureOffset;
        if( lLockSize < 0 )
            lLockSize += g_dwCaptureBufferSize;

        // Block align lock size so that we are always write on a boundary
        lLockSize -= (lLockSize % g_dwNotifySize);

        if( lLockSize == 0 )
            return S_FALSE;

        // Lock the capture buffer down
        if( FAILED( hr = g_pDSBCapture->Lock( g_dwNextCaptureOffset,
lLockSize,
                                          &pbCaptureData, &dwCaptureLength,
                                          &pbCaptureData2,
&dwCaptureLength2, 0L ) ) )
            return DXTRACE_ERR_MSGBOX( TEXT("Lock"), hr );

     out_size = avcodec_encode_audio(c, outputtemp, dwCaptureLength,
(short*)pbCaptureData);
     fwrite(outputtemp, 1, out_size, f);

    // Move the capture offset along
    g_dwNextCaptureOffset += dwCaptureLength;
    g_dwNextCaptureOffset %= g_dwCaptureBufferSize; // Circular buffer

    // Unlock the capture buffer
    g_pDSBCapture->Unlock( pbCaptureData,  dwCaptureLength,
                           pbCaptureData2, dwCaptureLength2 );
    ........
............................................................................
.........................................................................
    Codes above in RecordSound function. Before i create a thread, call
RecordSound in While loop and i have a Bool value to determine when the
thread will stop.
    With codes above, i donot know why i can not get the file recoding (file
f) with codec is MP2.
    I check codec by opening the output file with windows media player. This
tool said that the output has MPEG codec

Note:    i can write to file (wav format, PCM codec) if i insert this code :
    // Write the data into the wav file
     if( FAILED( hr = g_pWaveFile->Write( outbuf_size,
                                              (BYTE*)pbCaptureData,
                                              &dwDataWrote ) ) )
        return DXTRACE_ERR_MSGBOX( TEXT("Write"), hr );

Please help me if you can ,...

Thank you very much.

> Paul wrote:
> > Hi,
>
> Please dont top-post.
>
> Please use a specific subject line.
>
> Please dont quote an entire irrelevant digest.
>
> Please dont post on devel when it clearly belongs on -user.
>
>
> i have use these files, apiexample.c and output_example.c,
> > if i use the codes sample in encode audio sample then the output file is
> > work().
> > but now, i would like to use audio buffer that i captured from
Directsound
> > application, encode this buffer (PCM codec) to MP2 (MP2 codec) using
FFMPEG.
>
> You mean, the libs plus your code, or the command line? If the former,
> post minimal code reproducing your problem. If the latter, post command
> line and output messages.
>
> > I did check the output file
>
> How?
>
> > and see that it was encoded
>
>
> How did you see that?
>
> > but the data (what i
> > can hear) of the output file is not correct...
>
> How so?
>
> >
> > anyone can help me???
>
> Possibly, but you're making it hard for anyone to help you...
>
> >>
>
> Greetings,





More information about the ffmpeg-devel mailing list