python - ffmpeg Python 命令在 PM2 环境中只运行一次
问题描述
PM2 以web
用户身份运行。ffmpeg 使用sudo apt install 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
在发出顺序请求时检查进程是否正在运行。如果是,您可能需要确保进程在第一次完成后关闭,以便它可以再次启动顺序请求。
推荐阅读
- r - 将日期和时间从因子转换为R中的数字
- go - 如何使用 chromedp 修改 HTML 元素的属性
- python - Google Cloud Platform - 最终例外:b'[Errno 28] No space left on device') 用于下载
- javascript - 如何在点击时淡出图像
- string - 在 sqlite-jdbc 驱动(3.23 或 3.30)中,字符串过长时更新失败,无一例外。但是在命令行和navicat下就可以了
- angular - Angular Material 嵌套 Stepper 的标签位置被覆盖
- java - cmd突然关闭时如何确保Java程序创建的临时文件被删除
- c++ - C++ shared_ptr,如何从方法内创建的共享指针返回对对象的引用?
- python - python继承类函数
- c# - 如何将标签中的信息导入 C# 和 HTMLAgilityPack?