I change it to heap as the sound seems to be getting much better though i don't know the reason behind but yes , have to put in av_frame_free(&frame)