所以我试图编写一些来自我的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中的TRANSFERRING。一旦我弄清楚如何将其设置回BINARY,我们应该没问题
答案 0 :(得分:0)
我的解决方案是在执行转移之前发送一个明确的“TYPE I”命令
希望这有助于其他人 新代码:
ftp = FTP(myhost,myuser,passw)
ftp.sendcmd('TYPE I')
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()
t = threading.Thread(target=background)
t.start()
while t.is_alive():
t.join(60)
ftp.voidcmd('NOOP')