ffmpeg Python命令仅在PM2环境中运行一次

问题描述 投票:4回答:3

PM2作为web用户运行。 ffmpeg使用sudo apt install ffmpeg安装在Ubuntu 16.04 LTS本地。 Python版本是3.6。该软件使用[email protected]

产生的应用程序不会产生错误。当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)
python ffmpeg python-3.6 pm2
3个回答
2
投票

在发出顺序请求时检查ffmpeg进程是否正在运行。如果是,您可能希望确保在第一次完成后关闭进程,以便它可以再次为顺序请求启动。


0
投票

apachenginx产生的进程将限制它们执行的时间并自动被杀死。在这些情况下,您可能希望触发脚本在Web进程池外部运行,例如。就像是:

setsid /usr/bin/python3 my_script.py 

0
投票

对于有子进程问题的任何人来说,它的价值......解决方案最终归结为一个糟糕的.env实现。当我们最终重新创建.env时,问题就消失了。我实际上向我的团队建议我们使用Anaconda作为我们的Python env并且这样做了。 :“d

© www.soinside.com 2019 - 2024. All rights reserved.