所以我试图从我的 ftp 编写一些视频文件下载脚本并将它们发送到手刹进行编码。
我在保持 ftp 套接字打开时遇到了麻烦,但是由于 SO 用户的惊人响应已解决,但是:
现在手刹无法识别正在下载的文件。在我实现套接字解决方案之前,这个特定的文件编码良好,因此它与数据如何写入文件有关。
这是我的代码:
if ext in validExtensions:
print("Downloading new file: " + fil)
downloadFile(fil, newPath)
print("Download complete. Encoding: " + fil)
hb(newPath + f)
这里是downloadFile函数代码:
def downloadFile(filename, folder):
myhost = 'host'
myuser = 'user'
passw = 'pass'
#login
ftp = FTP(myhost,myuser,passw)
ftp.set_debuglevel(2)
sock = ftp.transfercmd('RETR ' + filename)
def background():
f = open(folder + filename, 'wb')
while True:
block = sock.recv(1024*1024)
if not block:
break
f.write(block)
sock.close()
f.close()
t = threading.Thread(target=background)
t.start()
while t.is_alive():
t.join(60)
ftp.voidcmd('NOOP')
ftp.quit()
这是handbrake.py:
def HandbrakeEncode(filepath):
import subprocess
import os
filename = os.path.basename(filepath)
file, ext = os.path.splitext(filename)
outputPath = "D:\\Converted Mp4\\" + file + ".mp4"
args = '-i ' + filepath + ' -o '+ outputPath
#Popen expects arguments borken up into chunks by spaces
cmd = ['C:\\Program Files\\Handbrake\\HandbrakeCLI.exe',
'-i', filepath,
'-o', outputPath,
'preset="AppleTV 2"']
p = subprocess.call(cmd)
#delete the original
os.remove(filepath)
这是我从 handrake 得到的输出
Download complete. Encoding: myvid.mp4
[20:52:39] hb_init: starting libhb thread
HandBrake 0.9.9 (2013052900) - MinGW x86_64 - http://handbrake.fr
4 CPUs detected
Opening D:\Downloads\AutoVid\myvid.mp4...
[20:52:39] hb_scan: path=D:\Downloads\Auto\myvid.m
p4, title_index=1
libbluray/bdnav/index_parse.c:162: indx_parse(): error opening D:\Downloads\Auto
\myvid.mp4/BDMV/index.bdmv
libbluray/bdnav/index_parse.c:162: indx_parse(): error opening D:\Downloads\Auto
\myvid.mp4/BDMV/BACKUP/index.bdmv
libbluray/bluray.c:1725: nav_get_title_list(D:\Downloads\Auto\myvid.mp4) failed (0000000001CD6900)
[20:52:39] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 4.1.3
libdvdread: Encrypted DVD support unavailable.
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdnav:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[20:52:39] dvd: not a dvd - trying as a stream/file instead
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000001CD73C0] moov atom not found
[20:52:39] hb_stream_open: open D:\Downloads\Auto\myvid.mp4 failed
[20:52:39] scan: unrecognized file type
[20:52:39] libhb: scan thread found 0 valid title(s)
No title found.
HandBrake has exited.
更新:好的,我更接近了,我已经确定原始传输正在以 BINARY 传输,而现在正在以 ASCII 传输。一旦我弄清楚如何将其设置回 BINARY 我们应该没问题