问题
I have:
- S3 INPUT bucket
- S3 OUTPUT bucket
- PHP
- ffmpeg
Is it possible to read file directly from INPUT bucket → Transcode to another format → Save into OUTPUT bucket.
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.
Input file size may be more than 10Gb so writing whole file in RAM is undesirable. Some chunk-based way is preferable.
Output format is mostly .mp4
, but input format may be ts video or image (jpg
, gif
, etc)
Looks like PHP-FFmpeg-video-streaming fit to my task, but it can work only with web streaming formats.
回答1:
Okay, answering by myself:
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
Explanation:
- Stream input file into stdout
aws s3 cp s3://bucketA/input.jpg -
- Read input stream from stdin and stream it into stdout again
ffmpeg ... -f jpeg_pipe ... -i - ... -movflags frag_keyframe+empty_moov ... /dev/stdout
details:
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
- 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.
I want to control stream by myself. Using PHP SDK S3 client looks smarter... So I still open for considerations.
来源:https://stackoverflow.com/questions/64889909/php-ffmpeg-s3-transcode-video-directly-between-s3-buckets