python ftplib handbrake无法识别的文件类型 [英] python ftplib handbrake unrecognized file type

查看:216
本文介绍了python ftplib handbrake无法识别的文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试编写一些从ftp下载的视频文件的脚本,然后将其发送到手刹进行编码.

So I am trying to script some video file downloads from my ftp and send them to handbrake for encoding.

我在保持ftp套接字打开方面遇到了麻烦,但是由于来自SO用户的惊人响应已解决,但是:

I was having trouble with keeping the ftp socket open, but due to an amazing response from a SO user that is solved but:

现在,手刹无法识别正在下载的文件.在实施套接字解决方案之前,这个特定的文件编码良好,因此与如何将数据写入文件有关.

Now the file that is getting downloaded is not recognized by handbrake. This particular file encoded fine before I implemented the socket solution so its something to do with how the data is being written to the file.

这是我的代码:

if ext in validExtensions:
        print("Downloading new file: " + fil)
        downloadFile(fil, newPath)
        print("Download complete. Encoding: " + fil)
        hb(newPath + f)

这是downloadFile函数代码:

here is downloadFile function code:

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:

here is 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)

这是我从握手获得的输出

and here is the output I get from 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,就可以了

UPDATE: Ok I'm closer, I have identified that the original transfer is transferring in BINARY and this is now TRANSFERRING in ASCII. Once I figure out how to set it back to BINARY we should be ok

推荐答案

对我来说,解决方案是在执行传输之前发送明确的"TYPE I"命令

The solution for me was to send an explicit "TYPE I" Command before performing the transfer

希望这对其他人有帮助 新代码:

hope this helps someone else new code:

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')

这篇关于python ftplib handbrake无法识别的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆