这是代码 -
import os
file = open("list.txt", "rw+")
text = file.readline()
print "ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 \""+text+".mp4\""
os.system("ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 \""+text+".mp4\"")
但输出是这样的:
ffmpeg -loop 1 -i image.jpg -i "some-file-path
" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 "some-file-path"
它应该在一行
并且ffmpeg会抛出一个文件不存在的错误!
答案 0 :(得分:5)
因为您的文件在行尾有一个换行符('\n'
),所以
所以text
是"some-file-path\n"
。
您应该将text = file.readline()
更改为text = file.readline().strip()
。
答案 1 :(得分:-2)
文本文件中的ALl行(当python至少读取它们时)以“\ n”结尾
简易解决方案
text = file.readline()[:-1]
这将修剪该行的最后一个字符“\ n”。 这样做时要小心,因为如果你想要回写一行,你需要在它上面添加一个“\ n”(当使用file.write(“something”)时)