2017-05-25 89 views
0

首先,我不是開發人員。我試圖將一部電影分成1分鐘剪輯usinf ffmpeg-split.py python script。我確信FFmpeg的已安裝嘗試一個簡單的命令和它的工作就像魔術:FFmpeg-split.py無法確定視頻長度

ffmpeg -i soccer.mp4 -ss 00:00:00 -codec copy -t 10 soccer1.mp4

一個新的視頻文件在同一文件夾中創建。

我在同一個目錄中保存的FFmpeg-split.py,更新Python路徑中,並且鍵入了以下命令:

python ffmpeg-split.py -f soccer.mp4 -s 10

我回來是:

can't determine video length

我相信它只是無法找到該文件。我切換視頻文件,甚至刪除它,並得到相同的消息。

任何想法?

+0

您是否正在運行Windows?如果是這樣,ffmpeg-split.py將不起作用---它使用(相當懶惰地)一些Windows上不存在的命令/功能 – DoctorSelar

回答

0

我第一次看到那個名字!?因爲我相信你能夠從命令行運行ffmpeg並執行基本的Python東西,所以我建議遵循我的示例,因爲它應該避免給定文件中的任何奇怪的directory.connection.stuff(我忽略了它)。 「當天早些時候,」讓我忽略的.py腳本和共享如下: 假設你從windows.command.line跑 ffmpeg -i soccer.mp4 ...stuff... soccer1.mp4 ... 倒不如寫 ffmpeg -t 10 -i "Z:\\full\\input\\path.mp4" -c copy "Z:\\full\\output\\path.mp4" 此說,運行ffmpeg-t = input.duration.seconds,-i = input.file.next, "fullinpath"引號引起空間等,-c = all.codecs,copy = atlantian.magic.trick, "fulloutpath"也是安全的,沒有別的!

"Piping" through python to windows works great for this: 

    import subprocess as subprocess 
    def pegRunner(cmd): #Takes a list of strings we'll pass to windows. 
     command = [x for x in cmd] # peg short for mpeg, shoulda used meg.gem.gepm.gipper.translyvania.otheroptions 
     result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 
     output, err = result.communicate() 
     print result.wait() 
     return "pegRannered" 
    ######### 
    # Find the duration from properties or something. If you need to do this 
    # often it's more complicated. Let's say you found 4mins33secs. 
    ############ 
    leng = 4*60+33 # time in seconds 
    last_dur = int(leng%60) #remaining time after the 4 one.min.vids 
    if last_dur == 0: num_vids = int(leng/60) 
    else: num_vids = int(leng/60)+1 
    for i in range(num_vids): 
     da_command = ['ffmpeg'] 
     da_command.append('-ss') 
     da_command.append(str(i*60)) 
     da_command.append('-t') 
     if i != num_vids: da_command.append('60') 
     else: da_command.append(str(last_dur)) 
     da_command.append('-i') 
     da_command.append('Z:\\full\\input\\path.mp4') #this format! 
     da_command.append('-c') 
     da_command.append('copy') 
     #optionally to overwrite!!!!   da_command.append('-y') 
     da_command.append('Z:\\full\\output\\path\\filename_'+str(i)+'.mp4') 
     print pegRunner(da_command) 
    print "Finished "+str(i)+" filez." 

這應該處理1.min件,從蟒蛇的ffmpeg提供一個很好的起點。