【问题标题】:Ruby on Rails 4 Heroku App Crash while uploading large size videoRuby on Rails 4 Heroku 应用程序在上传大尺寸视频时崩溃
【发布时间】:2016-11-26 09:35:03
【问题描述】:

大型视频文件未在 heroku 上上传并引发应用程序崩溃错误
这是我的模型代码:

has_attached_file :video, :styles => {
  :medium => {
    :geometry => "640x480",
    :format => 'mp4',
    :convert_options => {
    :output => {
      :vcodec => 'libx264',
      :acodec => 'copy'
    }
  }
  },
  :thumb => {
    :geometry => "300x300#",
    :format => 'jpg',
    :time => 2,
    :auto_rotate => true
  }
}, :processors => [:transcoder]

validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/

这是我在heroku的日志

2016-07-22T13:15:13.616340+00:00 app[web.1]: Command :: file -b --mime '/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-1e90wvf.mp4'
2016-07-22T13:15:13.771935+00:00 app[web.1]: [AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.773078+00:00 app[web.1]: [AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.774121+00:00 app[web.1]: [AV] Found ["ffmpeg"], using: Ffmpeg
2016-07-22T13:15:13.774159+00:00 app[web.1]: [AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.775225+00:00 app[web.1]: [AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.776771+00:00 app[web.1]: [AV] Found ["ffmpeg"], using: Ffmpeg
2016-07-22T13:15:13.776807+00:00 app[web.1]: [AV] Running command: ffmpeg -i "/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt.mp4" 2>&1
2016-07-22T13:15:13.814982+00:00 app[web.1]: [paperclip] [transcoder] Transocding supported file /tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt.mp4
2016-07-22T13:15:13.815056+00:00 app[web.1]: [AV] Adding output parameter ["acodec", "aac"]
2016-07-22T13:15:13.815103+00:00 app[web.1]: [AV] Adding output parameter ["strict", "experimental"]
2016-07-22T13:15:13.815289+00:00 app[web.1]: [AV] Adding output parameter [:s, "640x480"]
2016-07-22T13:15:13.815379+00:00 app[web.1]: [AV] Running command: ffmpeg -i "/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt.mp4" -acodec aac -strict experimental -s 640x480 -y "/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt20160722-3-1pwdg2k.mp4"
2016-07-22T13:15:43.237749+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/courses/5/sections/7/lessons/11" host=xxxxx.herokuapp.com request_id=a1408ac7-c7c3-40f4-8365-86156d2d2314 fwd="43.255.56.1" dyno=web.1 connect=0ms service=188655ms status=503 bytes=0

【问题讨论】:

  • 如果您有 Stacktrace 和 heroku 日志中的异常消息,将会非常有帮助。
  • @SriVishnuTotakura 我已将我的日志信息粘贴到问题描述中

标签: ruby-on-rails-4 heroku amazon-s3 ffmpeg paperclip


【解决方案1】:

显然是Request Timeout。检查heroku's documentation 他们建议如何处理请求超时。

当 HTTP 请求响应用户的时间过长时,会发生请求超时。服务器或在这种情况下,处理请求的 heorku 路由器如果在设置的超时时间内没有响应,则会终止请求。

这可能是因为文件很大,上传或处理文件需要更多时间。我建议您直接从 Javascript 到 S3 执行此类上传,或者使用后台工作人员来执行这项工作。这意味着,您需要重新解决向用户提供上传功能的方式。

检查Heroku's post 从用户浏览器直接上传到 S3

【讨论】:

  • 您说的是直接将大文件上传到 S3。但我还需要使用 ffmpeg 转码器生成缩略图。 ffmpeg 呢?
  • 那么你必须先从浏览器直接上传到 S3。一旦保存到 S3,然后生成缩略图。如果这需要相当长的时间,请使用一些后台工作人员来获取最近保存的视频,在后台处理它们并使用一些回调向用户显示状态。
猜你喜欢
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多