2
我已經寫了這段代碼,所以當我輸入一些信息時,它會創建一個代碼讓我可以直播到抽搐。這是代碼:爲什麼我得到這個錯誤
import time
ip = input("Please enter the local IP address: ")
port = input("Please enter the port number: ")
resolution = input("Please enter the resolution: ")
valid_classes = ["ultrafast", "fast", "medium", "slow"]
while True:
print('What preset would you like? Choose from ultrafast, fast, medium and slow: ')
preset1 = input()
if preset1 not in valid_classes:
print("Please Enter A Valid Preset All In Lower Case")
time.sleep(1)
else:
fps = input("How many FPS would you like: ")
valid_service = ["youtube", "twitch"]
while True:
print('What service would you like to stream to? Please choose from youtube or twitch: ')
service = input()
if service not in valid_service:
print("Please Enter A Valid Service All In Lower Case")
time.sleep(1)
else:
key = input("Please enter your stream key: ")
if service == "twitch":
fortwitch = ("rtmp://live.justin.tv/app/")+key+("")
print("ffmpeg -f mpegts -i 'udp://")+ip+(":")+port+("?fifo_size=1000000&buffer_size=10000000&overrun_nonfatal=1' -vcodec libx264 -s ")+resolution+(" -g:v 40 -qscale:v 2 -threads 4 -preset ")+preset1+(" -b:v 1136k -minrate 1300k -maxrate 1300k -bufsize 8000k -r ")+fps+(" -acodec libmp3lame -ar 44100 -b:a 64k -f flv ")+fortwitch+("")
else:
print ("ok")
當我運行代碼,我得到了以下錯誤消息:
Traceback (most recent call last):
File "/Users/kiancross/Desktop/LIVESTREAM/livestreamoptions.py", line 25, in <module>
print("ffmpeg -f mpegts -i 'udp://")+ip+(":")+port+("? fifo_size=1000000&buffer_size=10000000&overrun_nonfatal=1' -vcodec libx264 -s ")+resolution+(" -g:v 40 -qscale:v 2 -threads 4 -preset ")+preset1+(" -b:v 1136k -minrate 1300k -maxrate 1300k -bufsize 8000k -r ")+fps+(" -acodec libmp3lame -ar 44100 -b:a 64k -f flv ")+fortwitch+("")
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
我不知道我做得更多。有關我在代碼中所做的更多信息,請參閱:http://marctv.de/blog/tutorial-hd-pvr-twitch-mac-os-ffmpeg/
此外,我如何使它在終端創建的代碼自動運行在終端中(我在Mac上)。
編輯
當我運行你的新代碼我做對了嗎?
import time
ip = input("Please enter the local IP address: ")
port = input("Please enter the port number: ")
resolution = input("Please enter the resolution: ")
valid_classes = ["ultrafast", "fast", "medium", "slow"]
while True:
print('What preset would you like? Choose from ultrafast, fast, medium and slow: ')
preset1 = input()
if preset1 not in valid_classes:
print("Please Enter A Valid Preset All In Lower Case")
time.sleep(1)
else:
fps = input("How many FPS would you like: ")
valid_service = ["youtube", "twitch"]
while True:
print('What service would you like to stream to? Please choose from youtube or twitch: ')
service = input()
if service not in valid_service:
print("Please Enter A Valid Service All In Lower Case")
time.sleep(1)
else:
key = input("Please enter your stream key: ")
if service == "twitch":
fortwitch = ("rtmp://live.justin.tv/app/")+key+("")
args = [
'ffmpeg', '-f', 'mpegts', '-i',
'udp://{}:{}?fifo_size=1000000&buffer_size=10000000&overrun_nonfatal=1'.format(ip, port),
'-vcodec', 'libx264', '-s', resolution, '-g:v', '40', '-qscale:v', '2',
'-threads', '4', '-preset', preset1, '-b:v', '1136k', '-minrate', '1300k',
'-maxrate', '1300k', '-bufsize', '8000k', '-r', fps, '-acodec', 'libmp3lame',
'-ar', '44100', '-b:a', '64k', '-f', 'flv', fortwitch]
subprocess.call(args)
當我運行它只是循環回到你想要流到什麼樣的服務。當它在終端它只是說
Traceback (most recent call last):
File "./livestreamoptions.py", line 8, in <module>
preset1 = input()
File "<string>", line 1, in <module>