首先,我不是开发人员。我正试图将电影分成1分钟片段ffmpeg-split.py python script。我确保FFmpeg安装它尝试一个简单的命令,它像魔术一样工作:
ffmpeg -i soccer.mp4 -ss 00:00:00 -codec copy -t 10 soccer1.mp4
在同一文件夹中创建了一个新的视频文件。
我将FFmpeg-split.py保存在同一目录中,更新了python PATH并输入以下命令:
python ffmpeg-split.py -f soccer.mp4 -s 10
我得到的是:
can't determine video length
我相信它找不到文件。我切换了视频文件,甚至删除了它,并得到了相同的消息。
有什么想法吗?
答案 0 :(得分:0)
我第一次见到这个名字!?因为我相信你能够从命令行运行ffmpeg并执行基本的python内容我建议遵循我的例子,因为它应该避免给定文件中的任何奇怪的directory.connection.stuff(我忽略了)。 "那天早些时候":让我忽略.py脚本并分享如下:
假设你跑了
ffmpeg -i soccer.mp4 ...stuff... soccer1.mp4
来自windows.command.line ...
写作会更好
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的片段,并为python的ffmpeg提供一个良好的起点。