FFmpeg Python命令在PM2环境下只运行一次

4

PM2作为一个web用户运行。使用sudo apt install ffmpeg在Ubuntu 16.04 LTS中本地安装了ffmpeg。Python版本是3.6。该软件使用ffmpeg-python@0.1.17

产生的应用程序没有错误。当ffmpeg代码第一次执行时,我们会看到输出,并且ffmpeg进程按预期完成任务。

所有后续请求都在下一次ffmpeg执行时停顿。没有输出。ffmpeg进程没有返回。没有错误。PM2进程不会出现错误。应用程序日志在ffmpeg命令上停留,就像它被挂起了。

根本原因是什么?非常感谢任何帮助。

此外,PM2在子进程(如ffmpeg)上停滞的原因是什么?

以下是代码:

class ImageHelper:

def __init__(self):
    pass

@classmethod
def create_thumb_from_video_ffmpeg(cls, input_video_file_path,
                                   output_image_path,
                                   scale_width,
                                   scale_height
                                   ):
    """
        This function is used to create the thumb image
        from a source video file.
        We are using a python wrapper/library for FFMPEG
    """
    try:
        if Functions.get_attribute_env('ENVIRONMENT') == 'prod':

            out, err = (
                ffmpeg
                    .input(input_video_file_path, ss="00:00:00.001")
                    .filter('scale', scale_width, scale_height)
                    .output(output_image_path, vframes=1, loglevel='quiet')
                    .overwrite_output()
                    .run(capture_stdout=True)
            )
            print("We only see this once!")
        else:
            out, err = (
                ffmpeg
                    .input(input_video_file_path, ss="00:00:00.001")
                    .filter('scale', scale_width, scale_height)
                    .output(output_image_path, vframes=1)
                    .overwrite_output()
                    .run(capture_stdout=True)
            )
            print("We only see this once!")

        if err:
            if Functions.get_attribute_env('ENVIRONMENT') != 'prod':
                print('ffmpeg video thumb', err)
            else:
                Functions.logger_function(str(err))
            raise Exception(err)
        else:
            return output_image_path

    except Exception as e:
        if Functions.get_attribute_env('ENVIRONMENT') != 'prod':
            print('in thumb exception', e)
        else:
            Functions.logger_function(str(e))
        raise Exception(e)

你在它挂起后检查了活动进程,看看你的 ffmpeg 命令是否在其中吗? - aergistal
你尝试过在再次启动之前停止ffmpeg进程完成任务吗? - mfdebian
您是否尝试过在未使用PM2的情况下启动应用程序并进行检查? - Mirodil
3个回答

2

检查在发出顺序请求时ffmpeg进程是否正在运行。如果是,则需要确保该进程在第一次完成后关闭,以便可以为顺序请求重新启动。


0

apachenginx生成的进程将有执行时间限制,并将自动终止。在这些情况下,您可能希望将脚本触发以在Web进程池之外运行,例如:

setsid /usr/bin/python3 my_script.py 

0

对于任何遇到子进程问题的人来说,这可能有所帮助...解决方案最终被归因于糟糕的.env实现。当我们重新创建了.env文件时,问题就消失了。我实际上向我的团队推荐使用Anaconda作为我们的Python环境,这解决了问题。:'D


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接