I'm still struggling in "G726 encoding part", Has anyone any input on this ?
thanks
Bhupendra Singh <[EMAIL PROTECTED]> wrote: Hi All,
This is my first email to this group. I recently came across with this group
after doing lot of search on coding/encoding issue.
My current requirement is to convert MS 16bits 8000Hz wav file to G726 codec
(32KADPCM) and vice versa (decoding).
I have got decoding part working using audio_decode_example() from
apiexample.c But I had to add 44 bytes wav header after decoding the file.
Now, Problem is with encoding part. audio_encode_example() si not helping much
as it's written for MP2 encoding.
I'm using following code and always get garbage converted file.
AVCodec *codec;
AVCodecContext *c= NULL;
int frame_size, i, j, out_size, outbuf_size;
short *samples,*inbuf_ptr;
float t, tincr;
uint8_t *outbuf;
char tempfilename[256] = "temp2.wav";
int size, len;
FILE *f, *outfile;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE] ;
printf("Starting remove header\n");
RemoveWavHeader(ifilename,tempfilename); // removing wave header
avcodec_init();
/* register all the codecs (you can also register only the codec
you wish to have smaller code */
avcodec_register_all();
/* find the ADPCM encoder */
codec = avcodec_find_encoder(CODEC_ID_ADPCM_G726);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
c= avcodec_alloc_context();
//c->codec_id = CODEC_ID_ADPCM_G726;
c->frame_size = 1;
c->codec_type = CODEC_TYPE_AUDIO;
/* put sample parameters */
c->bit_rate = 16000;
c->sample_rate = 8000;
c->channels = 1;
/* open it */
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
//---------------------------- my stuff
-----------------------------------------
outbuf = (uint8_t *)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
samples = (short *)malloc(INBUF_SIZE);
f = fopen(tempfilename, "rb");
if (!f) {
fprintf(stderr, "could not open %s\n", ifilename);
return 0;
}
outfile = fopen(ofilename, "wb");
if (!outfile) {
free(c);
return 0;
}
inbuf_ptr = samples;
for(;;) {
size = fread(samples, 1, INBUF_SIZE, f);
if (size == 0)
break;
inbuf_ptr = samples;
while (size > 0) {
out_size = avcodec_encode_audio(c, outbuf, size, inbuf_ptr);
if (out_size < 0) {
fprintf(stderr, "Error while decoding\n");
return 0;
}
if (out_size > 0) {
// if a frame has been decoded, output it
fwrite(outbuf, 1, out_size, outfile);
}
size -= out_size;
inbuf_ptr += out_size;
}
}
//----------------------------------------------------------------------------------------
fclose(f);
fclose(outfile);
free(outbuf);
free(samples);
avcodec_close(c);
av_free(c);
DeleteFile(tempfilename);
return 0;
}
I appreciate if anyone can take a look and guide me.
thank you very much.
---------------------------------
Never miss a thing. Make Yahoo your homepage.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user