5

问候,

我试图找到一个免费的 .NET 库或一个命令行可执行文件,它可以让我将 M4A 文件转换为 MP3 或 WMA 文件。请帮忙 :)。

4

5 回答 5

4

找到了!

http://pieter.wigleven.com/it/archives/3

可能还有其他解决方案,但这对于我正在寻找的东西来说是黄金。

PS 我写了一个 .NET DLL来处理这个幕后。这是非常糟糕的代码,但它完成了工作。

于 2008-09-27T21:14:44.697 回答
1

如果您知道正确的工具,这很简单:

ffmpeg -i infile.m4a tmp.wav
lame tmp.wav outfile.mp3

这是一个批处理版本(抱歉,仅限 Linux/Mac):

#!/bin/bash

n=0
maxjobs=3

for i in *.m4a ; do
    ffmpeg -i "$i" "$TMP/${i%m4a}wav"
    (lame "$TMP/${i%m4a}wav" "${i%m4a}mp3" ; rm "$TMP/${i%m4a}wav") &

    # limit jobs
    if (( $(($((++n)) % $maxjobs)) == 0 )) ; then
        wait
    fi

done
于 2011-07-21T09:31:15.360 回答
1

对于 UWP

public class ConvertToMp3Manager
{
    public PrepareTranscodeResult PrepareTranscode = null;
    public MediaTranscoder TransCoder = null;
    public StorageFile SourceAudio { get; set; }
    public StorageFile DestinationAudio { get; set; }
    public AudioFormat AudioFormat { get; set; }
    public AudioEncodingQuality AudioQuality { get; set; }
    private MediaEncodingProfile profile = null;
    public  ConvertToMp3Manager(StorageFile sourceAudio, StorageFile destinationAudio, AudioFormat AudioType = AudioFormat.MP3, AudioEncodingQuality audioEncodingQuality = AudioEncodingQuality.High)
    {
        if (sourceAudio == null || destinationAudio == null)
            throw new ArgumentNullException("sourceAudio and destinationAudio cannot be null");
        switch (AudioType)
        {
            case AudioFormat.AAC:
            case AudioFormat.M4A:
                profile = MediaEncodingProfile.CreateM4a(audioEncodingQuality);
                break;
            case AudioFormat.MP3:
                profile = MediaEncodingProfile.CreateMp3(audioEncodingQuality);
                break;
            case AudioFormat.WMA:
                profile = MediaEncodingProfile.CreateWma(audioEncodingQuality);
                break;
        }
        this.SourceAudio = sourceAudio;
        this.DestinationAudio = destinationAudio;
        this.AudioFormat = AudioType;
        this.AudioQuality = audioEncodingQuality;
        this.TransCoder = new MediaTranscoder();
    }
    /// <summary>
    /// Return true if audio can be transcoded
    /// </summary>
    /// <returns></returns>
    public async Task<bool> ConvertAudioAsync()
    {
        PrepareTranscode = await this.TransCoder.PrepareFileTranscodeAsync(this.SourceAudio, this.DestinationAudio, profile);
        if (PrepareTranscode.CanTranscode)
        {
            var transcodeOp = PrepareTranscode.TranscodeAsync();
            return true;
        }
        else
            return false;
    }
    public static async Task<bool> ConvertAudioAsync(StorageFile sourceAudio, StorageFile destinationAudio, AudioFormat AudioType = AudioFormat.MP3, AudioEncodingQuality audioEncodingQuality = AudioEncodingQuality.High)
    {
        ConvertToMp3Manager convertToMp3Manager = new ConvertToMp3Manager(sourceAudio, destinationAudio, AudioType, audioEncodingQuality);
        var success = await convertToMp3Manager.ConvertAudioAsync();
        return success;
    }
}
public enum AudioFormat
{
    MP3,
    AAC,
    M4A,
    WMA
}
于 2018-01-04T08:07:57.467 回答
0

有趣的。
您提供的链接指向命令行实用程序。
如果您真的想以编程方式执行此操作,您可能会对我在Rarewares找到的 DLL 版本感兴趣。不确定 API 描述是否附带... :-)

于 2008-09-27T22:00:32.777 回答
0

如何将媒体文件转换为 WMA 文件

string fileName = @"e:\Down\test.wmv";
DsConvert.ToWma(fileName, fileName + ".wma", DsConvert.WmaProfile.Stereo128);
于 2014-04-09T17:00:53.783 回答