Author Topic: How to encode to WMA  (Read 351 times)

kafffee

  • Posts: 248
How to encode to WMA
« on: 12 Sep '22 - 14:07 »
Hey there :-)

Instead of, for instance, encoding to mp3 like this:

Code: [Select]
RecordingEncoderHandle = BassEnc_Mp3.BASS_Encode_MP3_StartFile(MainModule.mixer, Nothing, BASSEncode.BASS_ENCODE_AUTOFREE, directory & filename)
I want to encode to wma. I could not find  a _StartFile method in basswma class.

Also, I want to stream as wma. How can this be done?

Chris

  • Posts: 2148
Re: How to encode to WMA
« Reply #1 on: 12 Sep '22 - 14:10 »
« Last Edit: 12 Sep '22 - 14:16 by Chris »

kafffee

  • Posts: 248
Re: How to encode to WMA
« Reply #2 on: 12 Sep '22 - 14:38 »
Hey Chris,

so now I got this:

Code: [Select]
RecordingEncoderHandle = BassWma.BASS_WMA_EncodeOpen(MainModule.mixer, 2,
BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128, Nothing, IntPtr.Zero)

Do I understand right, when I use the BASSWMAEncode.BASS_WMA_ENCODE_SOURCE flag, instead of the frequency I can put it to a source channel handler  (which would be MainModule.mixer)?
Because I get error #37 after this line of code... What am I doing wrong? Is it even possible to save this to a file?
« Last Edit: 12 Sep '22 - 15:19 by kafffee »

Chris

  • Posts: 2148
Re: How to encode to WMA
« Reply #3 on: 12 Sep '22 - 16:13 »
do you want to stream to your local PC , or to a windows Server ?

kafffee

  • Posts: 248
Re: How to encode to WMA
« Reply #4 on: 12 Sep '22 - 17:11 »
Whats the difference in between the two that you mentioned?

I want to save the stream to HD as this does:

Code: [Select]
RecordingEncoderHandle = BassEnc_Opus.BASS_Encode_OPUS_StartFile(MainModule.mixer, Nothing, BASSEncode.BASS_ENCODE_AUTOFREE, Path & Filename)
and I want to broadcast it to other users over www, just as

Code: [Select]
MainModule.StreamEncoderHandle = BassEnc_Mp3.BASS_Encode_MP3_Start(MainModule.mixer, Nothing, BASSEncode.BASS_ENCODE_LIMIT Or BASSEncode.BASS_ENCODE_AUTOFREE, Nothing, Nothing)
Portnumber = BassEnc.BASS_Encode_ServerInit(MainModule.StreamEncoderHandle, CStr(LayerViewModel.SettingsViewModel.Portnumber), 64000, 64000, BASSEncodeServer.BASS_ENCODE_SERVER_META, EnocdeClientProc, IntPtr.Zero)
does

Is this even doable?

Ian @ un4seen

  • Administrator
  • Posts: 25283
Re: How to encode to WMA
« Reply #5 on: 12 Sep '22 - 17:57 »
so now I got this:

Code: [Select]
RecordingEncoderHandle = BassWma.BASS_WMA_EncodeOpen(MainModule.mixer, 2,
BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128, Nothing, IntPtr.Zero)

Do I understand right, when I use the BASSWMAEncode.BASS_WMA_ENCODE_SOURCE flag, instead of the frequency I can put it to a source channel handler  (which would be MainModule.mixer)?
Because I get error #37 after this line of code... What am I doing wrong? Is it even possible to save this to a file?

Error code 37 (BASS_ERROR_NOTAVAIL) means that the requested bitrate isn't supported. Please note the bitrate is in bps rather then kbps, so you should use 128000 rather than 128 there.

You can use BASS_WMA_EncodeOpenFile to encode to a file.

and I want to broadcast it to other users over www, just as

Code: [Select]
MainModule.StreamEncoderHandle = BassEnc_Mp3.BASS_Encode_MP3_Start(MainModule.mixer, Nothing, BASSEncode.BASS_ENCODE_LIMIT Or BASSEncode.BASS_ENCODE_AUTOFREE, Nothing, Nothing)
Portnumber = BassEnc.BASS_Encode_ServerInit(MainModule.StreamEncoderHandle, CStr(LayerViewModel.SettingsViewModel.Portnumber), 64000, 64000, BASSEncodeServer.BASS_ENCODE_SERVER_META, EnocdeClientProc, IntPtr.Zero)
does

Is this even doable?

No, BASS_Encode_ServerInit doesn't support WMA. But BASSWMA has its own server function, BASS_WMA_EncodeOpenNetwork. Please see the documentation for details on that. You could also take a look at the WMALIVE.C example included in the BASSWMA package for a demonstration.

kafffee

  • Posts: 248
Re: How to encode to WMA
« Reply #6 on: 13 Sep '22 - 13:14 »
Ok I can record tracks as wma now, but when I try to play them in my application, I get this error when trying to display the remaining playback time:

Code: [Select]
Dim timespan As TimeSpan = TimeSpan.FromSeconds(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetPosition(stream)) - Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream)))
System.OverflowException: TimeSpan has overflown, because duration is too long (something like this, I translated this error message from German)

Do I have to use other methods while trying to get length and position of a playback channel when playing wma files?

And another issue:

When I try to stream my mix over the internet like this:

Code: [Select]
success = BassWma.BASS_WMA_EncodeOpenNetwork(MainModule.mixer, 2, BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128000, portnumber,  Listeners)
I get no error but I cannot play it with my VLC player, even though it should be supported...
« Last Edit: 13 Sep '22 - 14:03 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 25283
Re: How to encode to WMA
« Reply #7 on: 13 Sep '22 - 15:37 »
Code: [Select]
Dim timespan As TimeSpan = TimeSpan.FromSeconds(Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetPosition(stream)) - Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream)))
System.OverflowException: TimeSpan has overflown, because duration is too long (something like this, I translated this error message from German)

Do I have to use other methods while trying to get length and position of a playback channel when playing wma files?

No, you can use the normal BASS channel functions with WMA streams. To narrow down what the problem is, please check the BASS_ChannelGetLength return value. It might be that the file's header doesn't contain a duration, in which case that information won't be available until the end of playback/decoding.

When I try to stream my mix over the internet like this:

Code: [Select]
success = BassWma.BASS_WMA_EncodeOpenNetwork(MainModule.mixer, 2, BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128000, portnumber,  Listeners)
I get no error but I cannot play it with my VLC player, even though it should be supported...

Try using the MMS protocol instead of HTTP, eg. mms://<address>

kafffee

  • Posts: 248
Re: How to encode to WMA
« Reply #8 on: 13 Sep '22 - 15:51 »
Okay, with mms://, listening to the stream works out :-)
Is there any way to detect number of listeners?
Edit: ah I see, EncodeSetNotify :-)
The other problem:
I displayed ChannelGetLength, and in fact, it returns -1, but only for wma files... Is there any way to get the length without it having played first?
« Last Edit: 13 Sep '22 - 16:32 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 25283
Re: How to encode to WMA
« Reply #9 on: 13 Sep '22 - 17:15 »
The length should be available immediately if it's stored in the WMA file's header.

Were those WMA files created with BASS_WMA_EncodeOpenFile? If so, check that you're closing the encoder with BASS_WMA_EncodeClose or freeing the source channel (which will close the encoder automatically), so that the file is finalized properly.

kafffee

  • Posts: 248
Re: How to encode to WMA
« Reply #10 on: 14 Sep '22 - 09:50 »
Okay now it works properly :-)