V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
? Learn Python the Hard Way
Python Sites
? PyPI - Python Package Index
? http://diveintopython.org/toc/index.html
? Pocoo
值得关注的项目
? PyPy
? Celery
? Jinja2
? Read the Docs
? gevent
? pyenv
? virtualenv
? Stackless Python
? Beautiful Soup
? 结巴中文分词
? Green Unicorn
? Sentry
? Shovel
? Pyflakes
? pytest
Python 编程
? pep8 Checker
Styles
? PEP 8
? Google Python Style Guide
? Code Style from The Hitchhiker's Guide
Canglin
V2EX  ?  Python

想问问我这个 ffmpeg 方法该怎么办

  •  
  •   Canglin · 36 天前 · 1955 次点击
    这是一个创建于 36 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    是这样的,我想在 ffmpeg 输出的时候直接覆盖掉 output_file,在 ffmpeg.output 中也使用了 overwrite 参数但是运行的时候依旧要我手工在 ps 里面输入'y'才能继续执行,想问问各位大哥这个该怎么解决? 使用的包是 ffmpeg-python 内容如下:

    def ffmpeg_process(video_path, audio_path):
    
        video_stream = ffmpeg.input(video_path)
        audio_stream = ffmpeg.input(audio_path)
        output_path = os.path.join(
            OUTPUT_PATH,
            VIDEO_MAP['GROUP_TITLE'],
        )
        output_path = os.path.join(output_path, VIDEO_MAP['OUTPUT_FILE'])
    
        output_stream = ffmpeg.output(
            video_stream,
            audio_stream,
            output_path,
            vcodec='copy',
        )
    
        def count_none(Map):
            Nones = sum(values is None for values in Map.values())
            if Nones > 0:
                return False
            else:
                return True
    
        if count_none(VIDEO_MAP):
            Build.makedir(output_path)
            ffmpeg.run(output_stream)
    
    第 1 条附言  ·  36 天前
    已经解决了,解决办法分两步,第一步创建目录的时候需要赋权否则会出现权限不足的错误,然后使用 ffmpeg.run(output_stream, overwrite_output=True)语句即可
    8 条回复  ?  2024-03-24 10:57:05 +08:00
    wuruorocks
        1
    wuruorocks  
       36 天前
    ffmpeg 命令行有-y 参数,不知这个 python 包有没有对应的;实在不行就输出到临时文件,然后再 move
    formant
        2
    formant  
       36 天前 via Android
    vcodec='copy',
    '-y' # 添加这个参数试试?
    liyouran
        3
    liyouran  
       36 天前
    官方文档 https://ffmpeg.org/ffmpeg.html#Main-options 里有个-y 参数能直接覆盖,我直接用 subprocess 模块运行 ffmpeg
    Canglin
        4
    Canglin  
    OP
       36 天前
    @formant #2 不行,直接报错了
    Canglin
        5
    Canglin  
    OP
       36 天前
    @wuruorocks #1 是个简单粗暴的好办法
    chanssl
        6
    chanssl  
       36 天前
    文檔: https://kkroening.github.io/ffmpeg-python/# ,有個 overwrite_output 的參數。
    試試 ffmpeg.run(output_stream,overwrite_output=True)
    abccccabc
        7
    abccccabc  
       36 天前
    @liyouran 这个-y 参数不好用,在我 php 这里会报错。
    Canglin
        8
    Canglin  
    OP
       36 天前
    @chanssl #6 这个方法我刚试了一下,Error opening output files: Permission denied 提示这个错误
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5458 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:56 · PVG 15:56 · LAX 00:56 · JFK 03:56
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com