python - FFmpeg-split.py 无法确定视频长度

标签 python video ffmpeg

首先,我不是开发人员。我正在尝试使用 ffmpeg-split.py python script 将电影分成 1 分钟的剪辑.我确保安装了 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
我相信它只是找不到文件。我切换了视频文件,甚至删除了它并收到了相同的消息。

有任何想法吗?

最佳答案

我第一次看到这个名字!?因为我相信您能够从命令行运行 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 =输入.持续时间.秒,-i =input.file.next,
"fullinpath"引号引起空格等,-c =所有.编解码器,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 提供一个良好的起点。

关于python - FFmpeg-split.py 无法确定视频长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44181252/

相关文章:

python - Matplotlib 按 Y 值绘制散点图颜色

涉及字节文字的 python 3.4 条件返回 false 而不是 true

html - 一次仅播放一个视频 HTML5

FFmpeg/FFplay directshow 和 blackmagic

apache 服务器中的 Python Cgi 脚本

python - 使用 scipy 对单个函数的多个输出进行曲线拟合

ios - 如何通过绝对路径从 iPhone 上的视频文件读取流

facebook - CakePHP 1.3:视频插件

for-loop - 如何在另一个命令之后在批处理脚本中删除 FOR 循环中的文件?

ffmpeg - 如何在FFMpeg中连接两个或多个具有相同宽度和不同高度的视频并保持相同的纵横比?