Sets up an MP3 encoder on a channel, writing the output to a file.

HENCODE BASS_Encode_MP3_StartFile(
    DWORD handle,
    char *options,
    DWORD flags,
    char *filename


handleThe channel handle... a HSTREAM, HMUSIC, or HRECORD.
optionsEncoder options... NULL = use defaults. The following LAME style options are supported: -b, -B, -v, -V, -q, -m, --abr, --preset, --alt-preset, -Y, --resample, -p, -t, --tt, --ta, --tl, --ty, --tc, --tn, --tg, --ti, --tv, --add-id3v2, --id3v1-only, --id3v2-only, --pad-id3v2, --pad-id3v2-size, --noreplaygain. Anything else that is included will be ignored. See the LAME documentation for details on the aforementioned options and defaults.
flagsA combination of these flags.
BASS_ENCODE_QUEUEQueue data to feed the encoder asynchronously. This prevents the data source (DSP system or BASS_Encode_Write call) getting blocked by the encoder, but if data is queud more quickly than the encoder can process it, that could result in lost data.
BASS_ENCODE_LIMITLimit the encoding rate to real-time speed, by introducing a delay when the rate is too high. With BASS 2.4.6 or above, this flag is ignored when the encoder is fed in a playback buffer update cycle (including BASS_Update and BASS_ChannelUpdate calls), to avoid possibly causing playback buffer underruns. Except for in those instances, this flag is applied automatically when the encoder is feeding a Shoutcast or Icecast server.
BASS_ENCODE_CAST_NOLIMITDon't limit the encoding rate to real-time speed when feeding a Shoutcast or Icecast server. This flag overrides the BASS_ENCODE_LIMIT flag.
BASS_ENCODE_PAUSEStart the encoder in a paused state.
BASS_ENCODE_AUTOFREEAutomatically free the encoder when the source channel is freed. If queuing is enabled, any remaining queued data will be sent to the encoder before it is freed.
BASS_UNICODEoptions and filename are in UTF-16 form. Otherwise options should be UTF-8 or ISO-8859-1 (or a mix of the two), and filename should be ANSI on Windows and UTF-8 on other platforms.
filenameOutput filename... NULL = no output file.

Return value

The encoder handle is returned if the encoder is successfully started, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_FORMATThe channel's sample format is not supported by the encoder.
BASS_ERROR_ILLPARAMoptions contains an invalid setting.
BASS_ERROR_FILEOPENA "--ti" option file could not be opened.
BASS_ERROR_FILEFORMA "--ti" option file has an invalid format. It needs to be JPEG, PNG, or GIF.
BASS_ERROR_CREATEThe file could not be created.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_NOTAVAILThis function is not available on platforms/architectures without an FPU.
BASS_ERROR_UNKNOWNSome other mystery problem!


BASS_Encode_StartUser is used internally to apply the encoder to the source channel, so the remarks in its documentation also apply to this function.

Each tag should be in either UTF-8 or ISO-8859-1 form (or UTF-16 when the BASS_UNICODE flag is used). ISO-8859-1 tags can be stored in ID3v1 and ID3v2 tag blocks. Unicode tags can only be stored in ID3v2 tag blocks. An ID3v2 tags block will be added automatically when required by the tags, otherwise only an ID3v1 tag block will added by default; this can be changed in options.


MP3 encoding involves extensive floating-point operations, so it is not supported on platforms/architectures that do not have an FPU, eg. older ARM platforms/architectures.

See also


BASS_Encode_IsActive, BASS_Encode_SetNotify, BASS_Encode_SetPaused, BASS_Encode_Stop, BASS_Encode_Write, BASS_CONFIG_ENCODE_PRIORITY