【问题标题】:How to pipe output and log files to S3 using FFMPEG如何使用 FFMPEG 将输出和日志文件通过管道传输到 S3
【发布时间】:2019-10-26 06:50:16
【问题描述】:

我正在使用以下方法将我的 FFMPEG 输出直接从我的 EC2 保存到 S3:

ffmpeg -i ${input} -f mp4 -movflags frag_keyframe+faststart -hide_banner -y pipe:1 | aws s3 cp - s3://my-bucket/video/output.mp4
-

效果很好,但我想像这样添加我的ffmpeg.logprogress.log

ffmpeg -i ${input} -f mp4 -movflags frag_keyframe+faststart -hide_banner -y -progress progress.log pipe:1 | aws s3 cp - s3://my-bucket/video/output.mp4 &> ffmpeg.log
-

但添加日志会引发错误并将日志保存在我的 EC2 上。我敢肯定它甚至不接近我所需要的。我也尝试添加多个管道,但没有任何乐趣。

如何使用 ffmpeg 将我的日志文件与输出文件一起添加到 S3?

【问题讨论】:

  • 也许可以试试2> ffmpeg.log。在 ffmpeg 上尝试相同的操作,例如 ffmpeg -i ${input} -f mp4 -movflags frag_keyframe+faststart -hide_banner -y pipe:1 2> progress.log。无论哪种方式,除非您提供不同的路径,否则日志应该出现在您当前的工作目录中。
  • 您可以使用命名管道或仅重定向 StdOut 的子外壳来执行此操作,但为什么呢?将主要输出直接发送到 S3 的主要原因是避免在本地缓冲潜在的大文件。日志文件不应该那么大。
  • @Jason 我尝试了你的建议,但它保存在 EC2 实例而不是 S3 上。

标签: bash amazon-web-services amazon-s3 ffmpeg


【解决方案1】:

您的日志将转到当前工作目录。您需要单独上传这些。由于我们对日志感兴趣,我想你可能也想做一些错误检查。如果没有,只需删除 if [...]fi 之间的内容即可。

#!/bin/bash
# This will report an error from ffmpeg to $? in the pipeline.
set -o pipefail

ffmpeg -i ${input} -f mp4 -movflags frag_keyframe+faststart -hide_banner -y pipe:1 2> progress.log | \
aws s3 cp - s3://my-bucket/video/output.mp4 2> ffmpeg.log
if [ $? -ne 0 ]; then
    echo "Failed to build /upload output.mp4"
    # Do anything else on error here...
fi

aws s3 cp progress.log s3://my-bucket/video/progress.log
if [ $? -ne 0 ]; then
    echo "Failed to upload progress.log"
fi

aws s3 cp ffmpeg.log s3://my-bucket/video/ffmpeg.log
if [ $? -ne 0 ]; then
    echo "Failed to upload ffmpeg.log"
fi

您还可以将日志与{...} 合并为一个。像这样:

{
    ffmpeg -i ${input} -f mp4 -movflags frag_keyframe+faststart -hide_banner -y pipe:1 | \
    aws s3 cp - s3://my-bucket/video/output.mp4
} 2> ffmpeg.log

【讨论】:

  • 我会试一试。关于progress.log 需要注意的一点是,FFMPEG 每秒几次将数据附加到文件末尾。想了想,把它放在 S3 上可能连那个都行不通。
猜你喜欢
  • 1970-01-01
  • 2016-02-13
  • 2015-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-16
  • 2023-04-04
  • 2013-09-08
相关资源
最近更新 更多