AydinAdn/MediaToolkit

MP3 Bitrate

Closed this issue · 11 comments

I am using MediaToolkit to convert user uploaded audio to a standard format (MP3) which works well, however the output does not include constant bit-rate (CBR) so the duration of MP3 audio is inaccurate.

using (var engine = new Engine())
{
engine.Convert(new MediaFile { Filename = Server.MapPath(pathA) }, new MediaFile { Filename = Server.MapPath(pathB) });
}

I have converted media files to mp3 and the output is CBR for me. Could you provide more details or a sample?

Thanks for the quick reply.

I've uploaded 2 files to WeTransfer @ https://we.tl/t-ZFZ4OXWQF6

file-info

File info (using PotPlayer) images also attached.

The code I'm using to generate is exactly as above (webforms/C# projects + MediaToolKit v 1.1.0.1).

Users can initially upload any type of audio file (MP3, WMA etc) and MediaToolkit is great at converting any kind of audio we throw at it but the output needs to be CBR as the accurate duration of the audio file is critical to us (as it's used for exam assessment).

Greetings, I have identified the issue. Here is the solution.

Your input mp3 file does not have a common bitrate. As a result FFMPEG encodes it in VBR and not CBR because its not something like (128,192,320k etc). So in order to encode it to CBR you simply have to specify an audio bitrate in the options. Since your input file is very close to 128 I chose that.

I have included the code snippet as well.

var inputFile = new MediaFile { Filename = @"C:\_test\audio.mp3" };
var outputFile = new MediaFile { Filename = @"C:\_test\audio2.mp3" };



            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);
                var options = new ConversionOptions();
                options.AudioBitRate = 128;
                engine.Convert(inputFile, outputFile,options);
            }

Finally, here is the result.

image

Thank you again for the quick reply.

I now have the following issue, I'm now unable to see the method:

image

I can however see other methods (such as options.VideoBitRate).

No problem. Are you sure that you are
using MediaToolkit.Model;
using MediaToolkit.Options;

in the main class? Also are you using the latest version of this library?

Make sure that AudioBitRate int variable insdie ConversionOptions is public. I would suggest you downloaded a ZIP of the current repo and use that. It includes a solution file, so just create another C# file and put a static void Main() in there.

I've download the current repo and that seeems

No problem. Are you sure that you are
using MediaToolkit.Model;
using MediaToolkit.Options;

in the main class? Also are you using the latest version of this library?

Yes/Yes

Make sure that AudioBitRate int variable insdie ConversionOptions is public. I would suggest you downloaded a ZIP of the current repo and use that. It includes a solution file, so just create another C# file and put a static void Main() in there.

Still no access to the AudioBitRate variable - I even tried creating a new project. I downloaded the current repo and that works fine.

Should I compile/copy the DLL across to my project and use that?

Yeah AudioBitRate var is not present on any release. Its the result of a merged past commit.

Compile the project in Release mode as a class library and reference it to any other project and that's it

Will give that a go, many thanks.

Are there any plans to include it (AudioBitRate) in a future release?

No problem. Unfortunately that is not in my control as I am not the owner of this project neither have write access. I am here because of a university project. Also if you have some requested issues or bug fixes please feel free to mention them.

If your issue is resolved, do not forget to close it.

Thank you :)