Thanks for maintaining mp3lame-sys and mp3lame-encoder! I set up encoding recently but needed a bit of a hack to correctly write the Xing VBR tag at the start of the file:
// save the inner ptr before calling .build()
let lame_ptr = unsafe { builder.as_ptr() };
// ... encode and write chunks to a file ...
// ... flush and write to file ...
// finally, get and write the vbr tag
// call with 0 first to get the required buffer size
let tag_size = unsafe { mp3lame_encoder::ffi::lame_get_lametag_frame(lame_ptr, std::ptr::null_mut(), 0) };
if tag_size > 0 {
let mut tag_buf = vec![0u8; tag_size];
let written = unsafe { mp3lame_encoder::ffi::lame_get_lametag_frame(lame_ptr, tag_buf.as_mut_ptr(), tag_size) };
if written == tag_size {
output_file.seek(SeekFrom::Start(0)).unwrap();
output_file.write_all(&tag_buf).unwrap();
}
}
I'm not 100% sure this code is correct but it seems to work. There also might be additional logic required if using ID3 tags per lame.h but I haven't looked into that yet.
At least exposing lame_get_lametag_frame (without stashing the pointer) is probably enough & the crate user can handle writing it somewhere correctly. Also, the builder allows getting the inner pointer but the encoder does not. It might be nice to allow getting it from the encoder as well.
Thanks for maintaining
mp3lame-sysandmp3lame-encoder! I set up encoding recently but needed a bit of a hack to correctly write the Xing VBR tag at the start of the file:I'm not 100% sure this code is correct but it seems to work. There also might be additional logic required if using ID3 tags per lame.h but I haven't looked into that yet.
At least exposing
lame_get_lametag_frame(without stashing the pointer) is probably enough & the crate user can handle writing it somewhere correctly. Also, the builder allows getting the inner pointer but the encoder does not. It might be nice to allow getting it from the encoder as well.