如何在 Rails 中处理后更新回形针视频位置

发布于 2024-12-10 03:45:39 字数 286 浏览 0 评论 0原文

我正在使用 Paperclip 来处理用户通过 ffmpeg 上传的视频。我想创建缩略图并将视频转换为我选择的标准格式。我有 ffmpeg 处理工作,但是,我似乎不知道如何在处理完成后更新记录。我使用了许多 Rails - paperclip - ffmpeg 参考资料,但没有看到有人转换视频,然后在 Rails 数据库中使用转换后的视频,因为它正在创建一个新视频,我需要能够更新记录在回形针处理器内,但是怎么做呢?

感谢

  • Rails 3
  • 使用带有回形针处理器和 ffmpeg 的

I'm using Paperclip for processing a user uploaded video with ffmpeg. I want to create a thumbnail image as well as convert the video to a standard format of my choosing. I have the ffmpeg processing working, however, I can't seem to figure out how to update the record after it has finished processing. I've used a number of rails - paperclip - ffmpeg references but haven't seen anyone converting the video and then using the converted video in the rails db, since it's creating a new video I will need to be able to update the record from within the paperclip processor, but how to do it??

Thanks

  • using Rails 3
  • using paperclip processor with ffmpeg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一页 2024-12-17 03:45:39

根据 Paperclip::Processor 的文档:

您只需实现一种方法即可正确成为 [of] 的子类
Paperclip::Processor]:#make...

所有#make需要返回的是File的实例(Tempfile是可以接受的)
其中包含处理结果。

所以你的处理器看起来像这样:

module Paperclip
  class MyProcessor
    # ...

    def make file, options = {}, attachment = nil
      in_filename = File.absolute_path file.path  # probably just a good idea

      out_filename = 'output_filename.mp4' # doesn't matter, maybe you use
                                           # Tempfile--just need to know
                                           # the path of ffmpeg's output file
      # run ffmpeg
      self.class.run 'ffmpeg',
        "-i #{in_filename}", /* more params..., */ out_filename

      File.open out_filename, 'r'  # then just return a File object pointing to
    end                            # the output file; Paperclip does the rest
  end
end

Per the documentation for Paperclip::Processor:

There is only one method you must implement to properly be a subclass [of
Paperclip::Processor]: #make...

All #make needs to return is an instance of File (Tempfile is acceptable)
which contains the results of the processing.

So your Processor would look something like this:

module Paperclip
  class MyProcessor
    # ...

    def make file, options = {}, attachment = nil
      in_filename = File.absolute_path file.path  # probably just a good idea

      out_filename = 'output_filename.mp4' # doesn't matter, maybe you use
                                           # Tempfile--just need to know
                                           # the path of ffmpeg's output file
      # run ffmpeg
      self.class.run 'ffmpeg',
        "-i #{in_filename}", /* more params..., */ out_filename

      File.open out_filename, 'r'  # then just return a File object pointing to
    end                            # the output file; Paperclip does the rest
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文