python - 使用 python 的 subprocess.Popen 使用 ffmpeg 连接文件

标签 python ffmpeg subprocess

我正在尝试连接生成以下命令的视频:

ffmpeg -i /srv/proj/chunks/phrases/lq/ti.mp4 -y -c copy -bsf:v h264_mp4toannexb -f mpegts /tmp/ti.mp4 & ffmpeg -i /srv/proj/chunks/phrases/lq/luchshii.mp4 -y -c copy -bsf:v h264_mp4toannexb -f mpegts /tmp/luchshii.mp4 & ffmpeg -i /srv/proj/chunks/phrases/lq/novii.mp4 -y -c copy -bsf:v h264_mp4toannexb -f mpegts /tmp/novii.mp4 & ffmpeg -i /srv/proj/chunks/phrases/lq/drug.mp4 -y -c copy -bsf:v h264_mp4toannexb -f mpegts /tmp/drug.mp4 & ffmpeg -f mpegts -i "concat:/tmp/ti.mp4|/tmp/luchshii.mp4|/tmp/novii.mp4|/tmp/drug.mp4" -y -c copy -bsf:a aac_adtstoasc /srv/proj/concats/ty-luchshii-novyi-drug.lq.mp4

当我只是在终端中输入它时,这个命令非常有效,但是当我使用 subprocess.Popen 时,它卡在最后处理的 block 上,如 this

有什么问题?

PS :这就是我执行命令的方式:
def _execute(command_str, **kwargs):
    import subprocess
    import shlex

    command = shlex.split(command_str)

    try:
        pipe = subprocess.Popen(command, **kwargs)
        pipe.wait()
        stdout, stderr = pipe.communicate()
    except Exception:
        raise ConcatError('cannot concat files')

    return stdout

P.P.S : os.system()而不是 subprocess.Popen()成功了,但子进程的问题仍然存在。

最佳答案

删除 pipe.wait() , 只留下 .communicate()称呼。也可以查看pipe.returncode为 == 0 表示没有错误。

关于python - 使用 python 的 subprocess.Popen 使用 ffmpeg 连接文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27230483/

相关文章:

Python:比较不同深度的字典对的工具?

python - 使用 mongoengine 从字典中的列表中提取

c++ - 子进程卡住 popen().stdout.read

python - 当我从批处理文件和任务计划程序运行脚本时,子进程运行、check_output、Popen 返回空字符串

python - 增加 seaborn 中的刻度标签字体大小

ffmpeg - 将 H265 编码为 hvc1 编解码器

adobe - 对视频进行编码以用于 Adob​​e Live Streaming

ffmpeg - 管道管道线到 ffmpeg 标准输入

python - 从 python 脚本以 super 用户身份运行命令

python - 删除重复的序列名称 pandas