I can't seem to make any headway with ffmpeg and sound.

I've been at it for quite some time now and I have downloaded half the internet looking for a working example.

I am using a downloaded program falled 'fister' which is probably quite well known.

I have put code into it so that it will read the file, then compress and decompress the sound and play it.

I should be getting my own voice back but I get nothing.

Here is the code.

I can send the whole fister project if anyone could like to have a look at it.

Again, thanks in advance for any help received.

Peadar


void CPipe::ReadSoundDataFromFile(CBuffer* buffer)
{
    char ErrLine[501];

    int j,k,ret, got_output, len2, cnt;
    uint8_t *       out[]   = { audio_buf };

    if(m_pFile)
    {
        if(!m_pFile->Read(buffer))
        {
            OnEndOfPlayingFile();
            delete m_pFile;
        }
    }

    ChineseFrameBuff = (uint8_t *)buffer->ptr.c;

    av_init_packet(&ChinesePacket);
    ChinesePacket.data = NULL;
    ChinesePacket.size = 0;

    ret = avcodec_encode_audio2(ChineseCodecCtx, &ChinesePacket, ChineseFrame, &got_output);
    if (ret < 0)
    {
        sprintf(ErrLine, "Error encoding audio frame");
        AfxMessageBox(ErrLine);
        exit(1);
    }

    if (got_output)
    {
        int got_frame=0;
    //    avcodec_get_frame_defaults(Mp3Frame);    // doesn't seem to do aything

        int len = avcodec_decode_audio4(Mp3CodecContext, Mp3Frame, &got_frame, &ChinesePacket);

        if (len < 0 || got_frame == 0)
        {
            sprintf(ErrLine, "Error while decoding");
            AfxMessageBox(ErrLine);
            exit(1);
        }
        if(m_pSwrCtx == NULL)
        {
            m_pSwrCtx = swr_alloc_set_opts(NULL
                            , AV_CH_LAYOUT_STEREO
                            , AV_SAMPLE_FMT_S16
                            , Mp3CodecContext->sample_rate
                            , av_get_default_channel_layout(Mp3Frame->channels)
                            , (AVSampleFormat)Mp3Frame->format
                            , Mp3Frame->sample_rate
                            , 0
                            , NULL
                            );
            swr_init(m_pSwrCtx);
        }

        len2 = swr_convert(m_pSwrCtx
                            , out
                            , AVCODEC_MAX_AUDIO_FRAME_SIZE * 4
                            , (const uint8_t **)Mp3Frame->extended_data
                            , Mp3Frame->nb_samples
                            );

        // make sure the buffer is cleared out.

        for(int count=0; count<2000; count++)
        {
            buffer->ptr.c[count] = '*';
        }

        strcpy(buffer->ptr.c,  (char *)audio_buf);
    }
}






---
This email has been checked for viruses by AVG.
http://www.avg.com

_______________________________________________
ffmpeg-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to