简体   繁体   English

pydub mp3 导出有最大长度吗?

[英]Is there a maximal length for pydub mp3 exports?

When I try to export long audio segments to mp3, I get an error OSError: [Errno 22] Invalid argument .当我尝试将长音频段导出到 mp3 时,出现错误OSError: [Errno 22] Invalid argument The maximal acceptable duration seems to be somewhere between 202 and 205 minutes.可接受的最长持续时间似乎在 202 到 205 分钟之间。 The error and the code are below.错误和代码如下。

Is there any way to be able to export mp3s longer than 205 minutes?有什么办法可以导出超过 205 分钟的 mp3 吗?

compilation_audio.export(mp3_path, format = "mp3")   
File "/usr/local/lib/python3.6/site-packages/pydub/audio_segment.py", line 612, 
 in export wave_data.writeframesraw(self._data)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 422, 
 in writeframesraw self._file.write(data)   
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tempfile.py", line 483,
 in func_wrapper return func(*args, **kwargs) 
OSError: [Errno 22] Invalid argument

This is the code.这是代码。 I have used "Fur Elise" from here as the initial mp3 file.我使用这里的“Fur Elise”作为初始 mp3 文件。

202 minutes segment ("Fur Elise" repeated 69 times) saves ok, 205 minutes segment ("Fur Elise" repeated 70 times) export fails. 202 分钟片段(“Fur Elise”重复 69 次)保存正常,205 分钟片段(“Fur Elise”重复 70 次)导出失败。

import os, pydub
audio_name = os.path.expanduser('~/Downloads/Fur Elise.mp3') # just under 3 min long
audio = pydub.AudioSegment.from_mp3(audio_name)
for compilation_audio in (audio * 69, audio * 70):
    length_music = len(compilation_audio) / 60000.0
    print("compilation_audio duration (min): " + str((length_music)))
    mp3_path = os.path.expanduser('~/Downloads/compilation' + str(int(length_music)) + '.mp3')
    compilation_audio.export(mp3_path, format = "mp3")

If there is an attempt to save a 1000+ min long mp3 (Fur Elise * 370), there is another error message:如果尝试保存 1000+ 分钟长的 mp3 (Fur Elise * 370),则会出现另一条错误消息:

    compilation_audio.export(mp3_path, format = "mp3")
  File "/usr/local/lib/python3.6/site-packages/pydub/audio_segment.py", line 612, in export
    wave_data.writeframesraw(self._data)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 416, in writeframesraw
    self._ensure_header_written(len(data))
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 457, in _ensure_header_written
    self._write_header(datasize)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 474, in _write_header
    self._sampwidth * 8, b'data'))
struct.error: 'L' format requires 0 <= number <= 4294967295
Exception ignored in: <bound method Wave_write.__del__ of <wave.Wave_write object at 0x1177e7cf8>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 316, in __del__
    self.close()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 434, in close
    self._ensure_header_written(0)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 457, in _ensure_header_written
    self._write_header(datasize)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 474, in _write_header
    self._sampwidth * 8, b'data'))
struct.error: 'L' format requires 0 <= number <= 4294967295

I think this may be a bug in Python!我认为这可能是 Python 中的一个错误!

There's a related issue with no solution in the pydub repo . pydub repo 中一个没有解决方案的相关问题

We ran into this problem as well.我们也遇到了这个问题。

There was this issue in PyTorch with a similar stack trace. PyTorch 中存在此问题,并具有类似的堆栈跟踪。 They identified the problem being with lseek() .他们发现问题出在lseek() I didn't understand the fix, but I was able to find this issue in the Python bug tracker which does not appear to have been resolved.我不明白该修复程序,但我能够在 Python 错误跟踪器中找到此问题,该问题似乎尚未解决。 The problem appears to be with a signed integer wrapping around, making seeking in a file larger than 2^63 under certain circumstances impossible.问题似乎是有符号整数环绕,使得在某些情况下不可能在大于 2^63 的文件中查找。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM