首页 > 解决方案 > 如何在 lambda python 中正确运行 ffmpeg 命令

问题描述

此代码在 lambda 中无法正常运行。我应该先从s3下载资源吗?然后在 ffmpeg 中调用它?或者直接s3调用是可能的?我得到的错误是

{“errorMessage”:“调用 HeadObject 操作时发生错误(404):未找到”,“errorType”:“ClientError”,
“stackTrace”:[“文件”/var/task/lambda_function.py”,第 18 行, 在 lambda_handler\n
s3_client.download_file('sourceff1-ffmpeg.s3.amazonaws.com', 'list.txt', '/tmp/list.txt')\n", "文件"/var/runtime/boto3/s3/inject.py ",第 171 行,在 download_file\n 中返回 transfer.download_file(\n"," 文件 "/var/runtime/boto3/s3/transfer.py",第 307 行,在 download_file\n future.result()\n" , " 文件 "/var/runtime/s3transfer/futures.py", 第 106 行, 结果\n 返回 self._coordinator.result()\n", " 文件 "/var/runtime/s3transfer/futures.py",第 265 行,结果\n 引发 self._exception\n"," 文件 "/var/runtime/s3transfer/tasks.py",第 255 行,在 _main\n self._submit(transfer_future=transfer_future, **kwargs)\ n","文件"/var/runtime/s3transfer/download.py",第 340 行,在 _submit\n 响应 = client.head_object(\n", " 文件 "/var/runtime/botocore/client.py", 第 386 行,在 _api_call\n 中返回 self._make_api_call(operation_name, kwargs)\n", "文件“/var/runtime/botocore/client.py”,第 705 行,在 _make_api_call\n raise error_class(parsed_response, operation_name)\n" ] }

import json
import os
import subprocess
import shlex
import boto3
import subprocess

S3_DESTINATION_BUCKET = "ugc-destination-bucket-ff1"

def lambda_handler(event, context):
    
    s3_client = boto3.client('s3')
    S3_DESTINATION_BUCKET = "ugc-destination-bucket-ff1"
    s3_destination_filename="output77.mp4"
    s3_client.download_file('sourceff1-ffmpeg.s3.amazonaws.com', 'list.txt', '/tmp/list.txt')
    s3_client.download_file('sourceff1-ffmpeg.s3.amazonaws.com', '2.mp4', '/tmp/2.mp4')
    s3_client.download_file("sourceff1-ffmpeg.s3.amazonaws.com", "list.txt", "/tmp/list.txt") 
    

    ffmpeg_cmd = "/opt/bin/ffmpeg -f concat -safe 0 -i sourceff1-ffmpeg.s3.amazonaws.com/list.txt -c copy /tmp/output.mp4"
    command1 = shlex.split(ffmpeg_cmd)
    
    

    return {
        'statusCode': 200,
        'body': json.dumps('Processing complete successfully')
    }

标签: pythonamazon-web-servicesaws-lambda

解决方案


推荐阅读