python - 使用 BytesIO 进入 python-ffmpeg 或其他

标签 python ffmpeg ffmpeg-python

你好我有以下poc要开发
给定两个 S3 路径,起点和终点,我需要从起点下载应用转换并上传到目标。
如果您知道的话,我们的想法是不使用临时本地文件夹并使用流数据作为另一个更好的选择。
为了做到这一点,我有以下代码:

import ffmpeg
import boto3
from io import BytesIO

origin = 'ah/a.mkv'
destination = 'av/a.mp4'

s3_client = boto3.client('s3')

f = BytesIO()
s3_client.download_fileobj('bucket', origin, f)

stream = ffmpeg.input(f)
stream = ffmpeg.output(stream, 'a.mp4', codec='copy')

(stream.run())
问题是
输入没有这个库看起来这个操作是不可能的。
https://kkroening.github.io/ffmpeg-python/

TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO


但是当另一个图书馆喜欢
https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming#opening-a-resource
我也不知道怎么转换。
那么你知道有什么方法吗?
谢谢

最佳答案

最后,图书馆与

s3_client = boto3.client('s3')

f = BytesIO()
s3_client.download_fileobj('bucket', 'path', f)

process = (
    ffmpeg
    .input('pipe:') \
    .output('aa.mp4') \
    .overwrite_output() \
    .run_async(pipe_stdin=True) \
)

process.communicate(input=f.getbuffer())
合作。

关于python - 使用 BytesIO 进入 python-ffmpeg 或其他,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72100457/

相关文章:

java - 如何读取进程 getInputstream?

python - 写入同一视频后,视频的 NumPy 数组从原始数组发生变化

ffmpeg - 如何使用 ffmpeg-python 制作此命令?

php - 从 php 页面执行时,ffmpeg 不会保存文件

video - 为什么 FFmpeg 打印 SAR 而不是 PAR?

python - FFmpegPCMaudio 在我的服务器上不起作用,但它在我的计算机上工作

python - 如何从嵌套列表中删除项目

python - Ansible - 在新终端窗口中启动 Python Flask 脚本

java - 在 Java 中显示列表与在 Python 中一样优雅

python - 通过python确认当前的电源计划