Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python与Lame MP3转换器的等价物是什么?_Python_Audio - Fatal编程技术网

Python与Lame MP3转换器的等价物是什么?

Python与Lame MP3转换器的等价物是什么?,python,audio,Python,Audio,我需要在服务器端将mp3音频文件转换为64kbps 现在,我正在使用子流程调用lame,但我想知道是否有好的替代方案?关于这个主题,这里似乎有一个稍微陈旧的主题: 最后的结论是通过Python->C绑定创建到lame_enc.dll的自定义绑定 得出这一结论的原因是现有的绑定库(pymedia/pylame)没有得到维护 不幸的是,这家伙没有让它工作:) 也许您应该继续使用子流程。您可以利用这一选择,在稍高的级别抽象编码,并重用代码/策略来选择性地执行其他命令行编码工具(如ogg或shn工具)

我需要在服务器端将mp3音频文件转换为64kbps


现在,我正在使用
子流程
调用
lame
,但我想知道是否有好的替代方案?

关于这个主题,这里似乎有一个稍微陈旧的主题:

最后的结论是通过Python->C绑定创建到lame_enc.dll的自定义绑定

得出这一结论的原因是现有的绑定库(pymedia/pylame)没有得到维护

不幸的是,这家伙没有让它工作:)

也许您应该继续使用
子流程
。您可以利用这一选择,在稍高的级别抽象编码,并重用代码/策略来选择性地执行其他命令行编码工具(如ogg或shn工具)


我见过一些音频翻录工具采用这种策略。

如果您想使用LAME对MP3(而不是PyMedia)进行编码,您可以始终使用LAME编码器DLL(或者。如果您在Linux上)。您将使用的确切包装器代码将与LAME DLL版本相关联(不幸的是,其中有许多版本正在流行),因此我不能给您提供任何示例,但ctypes文档应该足够清楚地说明如何包装DLL。

警告:这里的程序员相对较新,我以前不需要转换音频文件

但是,如果我正确理解了服务器端的含义,您可能正在寻找一种管理大规模转换的好方法,而您对python解决方案的兴趣可能部分在于能够更好地管理资源使用或集成到处理链中。我有一个类似的问题/目标,我用Merlyn的推荐和芹菜的混合解决了这个问题。我不使用django芹菜,但如果这是一个基于django的项目,这可能也会吸引您。你可以在这里找到更多关于芹菜的信息:

根据您已经设置的内容,可能需要一点前期时间进行设置。为了充分利用您需要安装的rabbitmq/erlang的所有功能,但是如果您按照上面站点上的指南进行操作,现在就非常快了

下面是一个我如何使用芹菜子流程来解决类似问题的示例。与上面海报的建议类似,我使用subprocess调用ffmpeg,这与视频工具的效果一样好,也可能与音频工具的效果一样好。我在这里包含了一些不必要的内容,让您了解如何配置自己的一点

    #example of configuring an option, here I'm selecting how much I want to adjust bitrate
    #based on my input's format
    def generate_command_line_method(self):
        if self.bitrate:
            compression_dict =  {'.mp4':1.5, '.rm':1.5, '.avi': 1.2, 
                                '.mkv': 1.2, '.mpg': 1, '.mpeg':1}
            if self.ext.lower() in compression_dict.keys():
                compression_factor = compression_dict[self.ext.lower()]

        #Making a list to send to the command line through subprocess
        ffscript = ['ffmpeg',
                   '-i', self.fullpath,
                   '-b', str(self.bitrate * compression_factor),
                   '-qscale', '3', #quality factor, based on trial and error
                   '-g', '90', #iframe roughly per 3 seconds
                   '-intra',
                    outpath
                   ]
        return ffscript

        #The celery side of things, I'd have a celeryconfig.py file in the 
        #same directory as the script that points to the following function, so my task 
        #queue would know the specifics of the function I'll call through it.  You can
        #see example configs on the sites above, but it's basically just going to be
        #a tuple that says, here are the modules I want you to look in, celery, e.g.
        #CELERY_MODULES = ("exciting_asynchronous_module.py",).  This file then contains, 


        from celery.decorators import task
        from mymodule import myobject
        from subprocess import Popen

        @task(time_limit=600) #say, for example, 10 mins
        def run_ffscript(ffscript):
            some_result = Popen(ffscript).wait() 

            #Note: we'll wait because we don't want to compound
            #the asynchronous aspect (we don't want celery to launch the subprocess and think
            #it has finished.

        #Then I start up celery/rabbitmq, and got into my interactive shell (ipython shown):
        #I'll have some generator feeding these ffscripts command lines, then process them 
        #with something like:

        In[1]: for generated_ffscript in generator:
                  run_ffscript.delay(generated_ffscript)
让我知道这对你是否有用。我对回答这里的问题比较陌生,不确定我的尝试是否有用。祝你好运

我一直在使用它,它能够在不同的音频格式之间进行转换


我已经用它将.wav文件转换成mp3、.flac和.m4a。

好吧,有“丑陋的插件”Lammp3enc,还有Gstreamer(gst python 1.2,支持python 3.3)。我自己还没有试过走这条路,所以我真的没有资格推荐任何东西。。。坦白地说,在我看来,子流程解决方案要简单得多,如果不是“更干净”的话。

说真的,你试过谷歌吗?当我在google
PythonMP3
上搜索时,第一个目标是,它似乎正是你想要的。据说PythonPyMedia只适用于PythonPyMedia,它在Python2.4上消亡了。顺便说一句,当我在谷歌上搜索
使用蹩脚的mp3 python
时,这个问题首先出现了。我似乎找不到任何源代码示例,它们似乎都是命令行工具。我在我的github帐户/博客中添加了一个小代码示例
python音频工具
很棒,但不是你想要的-它使用
lame
来进行mp3编码。