PHP + FFMPEG + S3.直接在S3存储桶之间对视频进行转码 [英] PHP + FFMPEG + S3. Transcode video directly between S3 buckets

查看:117
本文介绍了PHP + FFMPEG + S3.直接在S3存储桶之间对视频进行转码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

  1. S3 INPUT存储桶
  2. S3 OUTPUT存储桶
  3. PHP
  4. ffmpeg

是否可以直接从INPUT存储桶中读取文件→转码为另一种格式→保存到OUTPUT存储桶中.

Is it possible to read file directly from INPUT bucket → Transcode to another format → Save into OUTPUT bucket.

请让我知道手册,库,框架以及任何有助于理解其用法的内容.
至少也欢迎使用python实现.至少至少有一些其他语言也可以.

Please let me know manuals, libraries, frameworks, any stuff that helps to understand how to do it.
At least python realisations also welcome. At least at least some different language also OK.

输入文件的大小可能超过10Gb,因此不希望在RAM中写入整个文件.最好使用基于块的方式.

Input file size may be more than 10Gb so writing whole file in RAM is undesirable. Some chunk-based way is preferable.

输出格式主要是 .mp4 ,但是输入格式可能是视频或图像( jpg gif 等)

Output format is mostly .mp4, but input format may be ts video or image (jpg, gif, etc)

PHP-FFmpeg-video-streaming 看起来很适合我的任务,但仅适用于网络流格式.

Looks like PHP-FFmpeg-video-streaming fit to my task, but it can work only with web streaming formats.

推荐答案

好的,我自己回答:

aws s3 cp s3://bucketA/input.jpg - | ffmpeg -y -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -f jpeg_pipe -loop 1 -i - -c:v 'libx264' -r 29.97 -t 30 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1" -c:a aac -shortest -movflags frag_keyframe+empty_moov -f mp4 /dev/stdout | aws s3 cp - s3://bucketB/output.mp4

说明:

  1. 将输入文件流式传输到stdout

aws s3 cp s3://bucketA/input.jpg - 

  1. 从stdin读取输入流,然后再次将其流传输到stdout

ffmpeg ... -f jpeg_pipe ... -i - ... -movflags frag_keyframe+empty_moov ... /dev/stdout

详细信息:

2.1. -f jpeg_pipe 输入格式必须为 pipe 类型.ffmpeg可以自动检测类型,因此不需要参数
2.2. -i-从输入(管道)中读取
2.3. -movflags frag_keyframe + empty_moov 仍然不理解

      2.1. -f jpeg_pipe input format must be pipe type. ffmpeg can detect type automatically so that is no necessary parameter
      2.2. -i - read from input (pipe)
      2.3. -movflags frag_keyframe+empty_moov still don't understand what that means, but can't create mp4 without this parameter. If somebody knows, please edit this place.
      2.4. /dev/stdout write output to stdout

  1. stdin 流复制到输出存储桶
  1. Copy stdin stream to output bucket

aws s3 cp - s3://bucketB/output.mp4

但是!我不喜欢这种解决方案.这里对情况的控制较少,我们无法引发/捕获异常.

But! I don't like this solution. Here is less control on situation and we don't able to raise/catch Exceptions.

我想自己控制流.使用PHP SDK S3客户端看起来更聪明...因此,我仍然需要考虑.

I want to control stream by myself. Using PHP SDK S3 client looks smarter... So I still open for considerations.

这篇关于PHP + FFMPEG + S3.直接在S3存储桶之间对视频进行转码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆