Discussion:
[Libav-user] OPUS transcoding to AAC but 960 sample increase to 1024 with a nomalized blank data.
=?ks_c_5601-1987?B?sK2xuMO2?=
2018-10-26 08:34:43 UTC
Permalink
Im transcode voice comming from WebRTC through by RTP with h264 video.

received sound unit is 20msec OPUS stereo 48000 2channel sample per second

its good decoded to PCM32 FLTP type and good play.

after decode I encode to AAC 48000 stereo frame nb_samples is 960. but
encoding ffmpeg aac function

attach 64 samples every each decoded raw PCM samples. what should I do for
it to improving final aac product quality ?



now I found AAC Context be able to control cypher block size 1024 to 960.
some documents say aac encoder default block is 1024.



AACContext *ac = (AACContext*)aac_context->priv_data;

MPEG4AudioConfig *m4ac = &(ac->oc[0].m4ac);

m4ac->frame_length_short = 1;//1:960, 0:1024



is this right approching ? appriciate any kinds of oppinion of you guys!!
He Lei
2018-10-26 09:15:47 UTC
Permalink
Using “audio_fifo” to cache samples, When the samples number in fifo is enough to 1024, and then encode it.
The last, If the number of samples is less than 1024 in fifo, fill with mute


look at “doc/examples/transcode_aac.c”

LeiHec
***@hotmail.com<mailto:***@hotmail.com>



圚 2018幎10月26日䞋午4:34강구철 <***@skycom.ne.kr<mailto:***@skycom.ne.kr>> 写道

Im transcode voice comming from WebRTC through by RTP with h264 video.
received sound unit is 20msec OPUS stereo 48000 2channel sample per second
its good decoded to PCM32 FLTP type and good play.
after decode I encode to AAC 48000 stereo frame nb_samples is 960. but encoding ffmpeg aac function
attach 64 samples every each decoded raw PCM samples. what should I do for it to improving final aac product quality ?

now I found AAC Context be able to control cypher block size 1024 to 960. some documents say aac encoder default block is 1024.

AACContext *ac = (AACContext*)aac_context->priv_data;
MPEG4AudioConfig *m4ac = &(ac->oc[0].m4ac);
m4ac->frame_length_short = 1;//1:960, 0:1024

is this right approching ? appriciate any kinds of oppinion of you guys!!


_______________________________________________
Libav-user mailing list
Libav-***@ffmpeg.org<mailto:Libav-***@ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user
강구철
2018-10-29 04:52:44 UTC
Permalink
I already tried using av_fifo for make it size to 1024. but still encoding
api output 960 plus blank 68 samples(total 1024).



//AVCodecContext initialization

AVCodecContext *opus_context;

AVCodecContext *aac_context;



opus_context->channels = 1;

opus_context->channel_layout = AV_CH_LAYOUT_MONO;

opus_context->sample_rate = 48000;//SRATE;

opus_context->sample_fmt = AV_SAMPLE_FMT_FLTP;//4BYTE

opus_context->bit_rate = 48000;//BITRATE;



aac_context->channels = 1;

aac_context->channel_layout = AV_CH_LAYOUT_MONO;

aac_context->sample_rate = 48000;//SRATE;

aac_context->sample_fmt = AV_SAMPLE_FMT_FLTP;

//aac_context->sample_fmt = AV_SAMPLE_FMT_S32;

aac_context->bit_rate = 48000;//BITRATE;//64000

//aac_context->strict_std_compliance =
FF_COMPLIANCE_EXPERIMENTAL;



fifo = av_audio_fifo_alloc(aac_context->sample_fmt,
aac_context->channels, 1);



opus_codec = avcodec_find_decoder( AV_CODEC_ID_OPUS );

aac_codec = avcodec_find_encoder( AV_CODEC_ID_AAC );



//transcoder function for trans OPUS => ACC



tcode(AVPacket* src, AVPacket* dst){

opus_context->frame_size=960;//TESTTEST

decoded_frame->data[0] = (uint8_t*)av_malloc(4*1024);//TESTTEST

ret = avcodec_decode_audio4(opus_context, decoded_frame,
&data_present, src); // decoded_frame 960 sucess

}







//WAVE Generate for 68
samples------------------------------------------------------------

unsigned char _cbuf[100];

unsigned char *cbuf=NULL;

cbuf = _cbuf;

cbuf[0]=0xf2;

cbuf[1]=0xdb;

cbuf[2]=0x0;

cbuf[3]=0x3f;

decoded_frame->nb_samples = 1024;//change to 1024 for AAC encoding block



for(int i=960; i<1024 ; i++){

decoded_frame->data[0][i*4+0] = (uint8_t)cbuf[0]; //float

decoded_frame->data[0][i*4+1] = (uint8_t)cbuf[1]; //float

decoded_frame->data[0][i*4+2] = (uint8_t)cbuf[2]; //float

decoded_frame->data[0][i*4+3] = (uint8_t)cbuf[3]; //float

cbuf[2] += 2; //make saw type wav using range is 0~96

if(cbuf[2] >= 96)cbuf[2]=0;//mod reset to 0

}//END OF Generate 68 sample of last WAVE(PCM Float 4byte LittleEndian
type)---------------------------------------------------------



ret = avcodec_encode_audio2(aac_context, dst, decoded_frame,
&data_present);//AAC ENCODING Success 1024 sampes compressed but contain
last 68 samples blank.



this mail attached sample result aac before muxing and next figure show you
every 20msec data has 64 nomalized blank samples(marked red pen). thanks for
any recommand or inform.



<abc1.m4a AAC recorded webrtc sample open with audacity>





From: Libav-user [mailto:libav-user-***@ffmpeg.org] On Behalf Of He Lei
Sent: Friday, October 26, 2018 6:16 PM
To: This list is about using libavcodec, libavformat, libavutil, libavdevice
and libavfilter.
Subject: Re: [Libav-user] OPUS transcoding to AAC but 960 sample increase to
1024 with a nomalized blank data.



Using “audio_fifo” to cache samples, When the samples number in fifo is
enough to 1024, and then encode it.

The last, If the number of samples is less than 1024 in fifo, fill with
mute





look at “doc/examples/transcode_aac.c”



LeiHec

***@hotmail.com









圚 2018幎10月26日䞋午4:34강구철 <***@skycom.ne.kr> 写道



Im transcode voice comming from WebRTC through by RTP with h264 video.

received sound unit is 20msec OPUS stereo 48000 2channel sample per second

its good decoded to PCM32 FLTP type and good play.

after decode I encode to AAC 48000 stereo frame nb_samples is 960. but
encoding ffmpeg aac function

attach 64 samples every each decoded raw PCM samples. what should I do for
it to improving final aac product quality ?



now I found AAC Context be able to control cypher block size 1024 to 960.
some documents say aac encoder default block is 1024.



AACContext *ac = (AACContext*)aac_context->priv_data;

MPEG4AudioConfig *m4ac = &(ac->oc[0].m4ac);

m4ac->frame_length_short = 1;//1:960, 0:1024



is this right approching ? appriciate any kinds of oppinion of you guys!!
He Lei
2018-10-29 05:44:25 UTC
Permalink
Sorry, I didn't make myself clear.

============================
while(has_data){

get_960_samples();

av_audio_fifo_write(960);

while(avio_audio_fifo_size() >= 1024){

avio_fifo_read(1024);

encode(1024); //encode in hear or other

}
}

if(avio_audio_fifo_size() % 1024){

fill_mute(1024 - avio_audio_fifo_size()); //Only fill the mute at the last!

avio_fifo_read(1024);

encode(); //encode in hear or other
}
============================


LeiHe
***@hotmail.com<mailto:***@hotmail.com>



圚 2018幎10月29日䞋午12:52강구철 <***@skycom.ne.kr<mailto:***@skycom.ne.kr>> 写道

I already tried using av_fifo for make it size to 1024. but still encoding api output 960 plus blank 68 samples(total 1024).

//AVCodecContext initialization
AVCodecContext *opus_context;
AVCodecContext *aac_context;

opus_context->channels = 1;
opus_context->channel_layout = AV_CH_LAYOUT_MONO;
opus_context->sample_rate = 48000;//SRATE;
opus_context->sample_fmt = AV_SAMPLE_FMT_FLTP;//4BYTE
opus_context->bit_rate = 48000;//BITRATE;

aac_context->channels = 1;
aac_context->channel_layout = AV_CH_LAYOUT_MONO;
aac_context->sample_rate = 48000;//SRATE;
aac_context->sample_fmt = AV_SAMPLE_FMT_FLTP;
//aac_context->sample_fmt = AV_SAMPLE_FMT_S32;
aac_context->bit_rate = 48000;//BITRATE;//64000
//aac_context->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;

fifo = av_audio_fifo_alloc(aac_context->sample_fmt, aac_context->channels, 1);

opus_codec = avcodec_find_decoder( AV_CODEC_ID_OPUS );
aac_codec = avcodec_find_encoder( AV_CODEC_ID_AAC );

//transcoder function for trans OPUS => ACC

tcode(AVPacket* src, AVPacket* dst){
opus_context->frame_size=960;//TESTTEST
decoded_frame->data[0] = (uint8_t*)av_malloc(4*1024);//TESTTEST
ret = avcodec_decode_audio4(opus_context, decoded_frame, &data_present, src); // decoded_frame 960 sucess
}



//WAVE Generate for 68 samples------------------------------------------------------------
unsigned char _cbuf[100];
unsigned char *cbuf=NULL;
cbuf = _cbuf;
cbuf[0]=0xf2;
cbuf[1]=0xdb;
cbuf[2]=0x0;
cbuf[3]=0x3f;
decoded_frame->nb_samples = 1024;//change to 1024 for AAC encoding block

for(int i=960; i<1024 ; i++){
decoded_frame->data[0][i*4+0] = (uint8_t)cbuf[0]; //float
decoded_frame->data[0][i*4+1] = (uint8_t)cbuf[1]; //float
decoded_frame->data[0][i*4+2] = (uint8_t)cbuf[2]; //float
decoded_frame->data[0][i*4+3] = (uint8_t)cbuf[3]; //float
cbuf[2] += 2; //make saw type wav using range is 0~96
if(cbuf[2] >= 96)cbuf[2]=0;//mod reset to 0
}//END OF Generate 68 sample of last WAVE(PCM Float 4byte LittleEndian type)---------------------------------------------------------

ret = avcodec_encode_audio2(aac_context, dst, decoded_frame, &data_present);//AAC ENCODING Success 1024 sampes compressed but contain last 68 samples blank.

this mail attached sample result aac before muxing and next figure show you every 20msec data has 64 nomalized blank samples(marked red pen). thanks for any recommand or inform.

<abc1.m4a AAC recorded webrtc sample open with audacity>
<image001.png>

From: Libav-user [mailto:libav-user-***@ffmpeg.org] On Behalf Of He Lei
Sent: Friday, October 26, 2018 6:16 PM
To: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
Subject: Re: [Libav-user] OPUS transcoding to AAC but 960 sample increase to 1024 with a nomalized blank data.

Using “audio_fifo” to cache samples, When the samples number in fifo is enough to 1024, and then encode it.
The last, If the number of samples is less than 1024 in fifo, fill with mute


look at “doc/examples/transcode_aac.c”

LeiHec
***@hotmail.com<mailto:***@hotmail.com>




圚 2018幎10月26日䞋午4:34강구철 <***@skycom.ne.kr<mailto:***@skycom.ne.kr>> 写道

Im transcode voice comming from WebRTC through by RTP with h264 video.
received sound unit is 20msec OPUS stereo 48000 2channel sample per second
its good decoded to PCM32 FLTP type and good play.
after decode I encode to AAC 48000 stereo frame nb_samples is 960. but encoding ffmpeg aac function
attach 64 samples every each decoded raw PCM samples. what should I do for it to improving final aac product quality ?

now I found AAC Context be able to control cypher block size 1024 to 960. some documents say aac encoder default block is 1024.

AACContext *ac = (AACContext*)aac_context->priv_data;
MPEG4AudioConfig *m4ac = &(ac->oc[0].m4ac);
m4ac->frame_length_short = 1;//1:960, 0:1024

is this right approching ? appriciate any kinds of oppinion of you guys!!


_______________________________________________
Libav-user mailing list
Libav-***@ffmpeg.org<mailto:Libav-***@ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user

<abc1.m4a>_______________________________________________
Libav-user mailing list
Libav-***@ffmpeg.org<mailto:Libav-***@ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user
강구철
2018-11-01 00:41:22 UTC
Permalink
its working. at first framesize 960 but aac encode output 1024 PCM FLTP
samples. (self check by decode)

but now put 1024 block of fltp raw pcm and output encode aac(1024). fifo
well working!!

Thanks He Lei



From: Libav-user [mailto:libav-user-***@ffmpeg.org] On Behalf Of He Lei
Sent: Monday, October 29, 2018 2:44 PM
To: This list is about using libavcodec, libavformat, libavutil, libavdevice
and libavfilter.
Subject: Re: [Libav-user] OPUS transcoding to AAC but 960 sample increase to
1024 with a nomalized blank data.



Sorry, I didn't make myself clear.



============================

while(has_data){



get_960_samples();



av_audio_fifo_write(960);





while(avio_audio_fifo_size() >= 1024){





avio_fifo_read(1024);





encode(1024); //encode in hear or other





}

}





if(avio_audio_fifo_size() % 1024){



fill_mute(1024 - avio_audio_fifo_size()); //Only fill the mute at the
last!



avio_fifo_read(1024);



encode(); //encode in hear or other

}

============================





LeiHe

***@hotmail.com









圚 2018幎10月29日䞋午12:52강구철 <***@skycom.ne.kr> 写道



I already tried using av_fifo for make it size to 1024. but still encoding
api output 960 plus blank 68 samples(total 1024).



//AVCodecContext initialization

AVCodecContext *opus_context;

AVCodecContext *aac_context;



opus_context->channels = 1;

opus_context->channel_layout = AV_CH_LAYOUT_MONO;

opus_context->sample_rate = 48000;//SRATE;

opus_context->sample_fmt = AV_SAMPLE_FMT_FLTP;//4BYTE

opus_context->bit_rate = 48000;//BITRATE;



aac_context->channels = 1;

aac_context->channel_layout = AV_CH_LAYOUT_MONO;

aac_context->sample_rate = 48000;//SRATE;

aac_context->sample_fmt = AV_SAMPLE_FMT_FLTP;

//aac_context->sample_fmt = AV_SAMPLE_FMT_S32;

aac_context->bit_rate = 48000;//BITRATE;//64000

//aac_context->strict_std_compliance =
FF_COMPLIANCE_EXPERIMENTAL;



fifo = av_audio_fifo_alloc(aac_context->sample_fmt,
aac_context->channels, 1);



opus_codec = avcodec_find_decoder( AV_CODEC_ID_OPUS );

aac_codec = avcodec_find_encoder( AV_CODEC_ID_AAC );



//transcoder function for trans OPUS => ACC



tcode(AVPacket* src, AVPacket* dst){

opus_context->frame_size=960;//TESTTEST

decoded_frame->data[0] = (uint8_t*)av_malloc(4*1024);//TESTTEST

ret = avcodec_decode_audio4(opus_context, decoded_frame,
&data_present, src); // decoded_frame 960 sucess

}







//WAVE Generate for 68
samples------------------------------------------------------------

unsigned char _cbuf[100];

unsigned char *cbuf=NULL;

cbuf = _cbuf;

cbuf[0]=0xf2;

cbuf[1]=0xdb;

cbuf[2]=0x0;

cbuf[3]=0x3f;

decoded_frame->nb_samples = 1024;//change to 1024 for AAC encoding block



for(int i=960; i<1024 ; i++){

decoded_frame->data[0][i*4+0] = (uint8_t)cbuf[0]; //float

decoded_frame->data[0][i*4+1] = (uint8_t)cbuf[1]; //float

decoded_frame->data[0][i*4+2] = (uint8_t)cbuf[2]; //float

decoded_frame->data[0][i*4+3] = (uint8_t)cbuf[3]; //float

cbuf[2] += 2; //make saw type wav using range is 0~96

if(cbuf[2] >= 96)cbuf[2]=0;//mod reset to 0

}//END OF Generate 68 sample of last WAVE(PCM Float 4byte LittleEndian
type)---------------------------------------------------------



ret = avcodec_encode_audio2(aac_context, dst, decoded_frame,
&data_present);//AAC ENCODING Success 1024 sampes compressed but contain
last 68 samples blank.



this mail attached sample result aac before muxing and next figure show you
every 20msec data has 64 nomalized blank samples(marked red pen). thanks for
any recommand or inform.



<abc1.m4a AAC recorded webrtc sample open with audacity>

<image001.png>



From: Libav-user [mailto:libav-user-***@ffmpeg.org] On Behalf Of He Lei
Sent: Friday, October 26, 2018 6:16 PM
To: This list is about using libavcodec, libavformat, libavutil, libavdevice
and libavfilter.
Subject: Re: [Libav-user] OPUS transcoding to AAC but 960 sample increase to
1024 with a nomalized blank data.



Using “audio_fifo” to cache samples, When the samples number in fifo is
enough to 1024, and then encode it.

The last, If the number of samples is less than 1024 in fifo, fill with
mute





look at “doc/examples/transcode_aac.c”



LeiHec

<mailto:***@hotmail.com> ***@hotmail.com










圚 2018幎10月26日䞋午4:34강구철 < <mailto:***@skycom.ne.kr> ***@skycom.ne.kr>
写道



Im transcode voice comming from WebRTC through by RTP with h264 video.

received sound unit is 20msec OPUS stereo 48000 2channel sample per second

its good decoded to PCM32 FLTP type and good play.

after decode I encode to AAC 48000 stereo frame nb_samples is 960. but
encoding ffmpeg aac function

attach 64 samples every each decoded raw PCM samples. what should I do for
it to improving final aac product quality ?



now I found AAC Context be able to control cypher block size 1024 to 960.
some documents say aac encoder default block is 1024.



AACContext *ac = (AACContext*)aac_context->priv_data;

MPEG4AudioConfig *m4ac = &(ac->oc[0].m4ac);

m4ac->frame_length_short = 1;//1:960, 0:1024



is this right approching ? appriciate any kinds of oppinion of you guys!!





_______________________________________________
Libav-user mailing list
<mailto:Libav-***@ffmpeg.org> Libav-***@ffmpeg.org
<http://ffmpeg.org/mailman/listinfo/libav-user>
http://ffmpeg.org/mailman/listinfo/libav-user



<abc1.m4a>_______________________________________________
Libav-user mailing list
<mailto:Libav-***@ffmpeg.org> Libav-***@ffmpeg.org
<http://ffmpeg.org/mailman/listinfo/libav-user>
http://ffmpeg.org/mailman/listinfo/libav-user

Loading...