出现错误:pipe:: Invalid data found when processing input

来源:5-5 编写转换MIDI到MP3的方法

慕圣434229

2018-05-01

import os
  5 import subprocess
  6
  7
  8 def convertMidi2Mp3():
  9         #将神经网络生成的MIDI文件转成MP3文件
 10         input_file = "output.mid"
 11         output_file = "output.mp3"
 12 #python assert断言是声明其布尔值必须为真的判定,如果发生异常就说明表达示为假。可以理解assert断言语句为raise-if-not,用来测试表示式,其返回值为假,
    就会触发异常。
 13         assert os.path.exists(input_file)#存在就进行下一步操作
 14
 15         print('converting %s to MP#'% input_file)
 16
 17         #用 timidity 生成 MP3 文件
 18         command = 'timidity {} -0w -o -|ffmpeg -i - -acodec libmp3lame -ab 64k {}'.format(input_file,output_file)
 19         #运行command。该函数将一直等待到子进程运行结束,并返回进程的returncode。如果子进程不需要进行交互,就可以使用该函数来创建。
 20         subprocess.call(command,shell = True)
 21
 22         print('Converted.Generated file is %s' % output_file)
 23
 24 if __name__ == "__main__":
 25         convertMidi2Mp3()

写回答

2回答

慕的地591

2018-09-05

我也出现这个问题,这是截图:

//img.mukewang.com/szimg/5b8fba0700013f2712460648.jpg

0
2
xxu1999102
command='timidity {} -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 256k {}'.format(input_file, output_file) 改成这个,就可以了,我也遇到同样问题,从timidity Wiki上复制来的命令
2019-11-30
共2条回复

Oscar

2018-05-01

能否给错误信息截个图?谢谢

0
1
慕的地591
我也出现这个问题,截图在上面。
2018-09-05
共1条回复

基于Python玩转人工智能最火框架 TensorFlow应用实践

机器学习入门,打牢TensorFlow框架应用是关键!

2214 学习 · 688 问题

查看课程