2

I am trying to use delayed_job to process large videos and audio files in the background. For the most part everything works. The only time it runs into any hiccups is when larger files are uploaded (~>200MB)

app/models/userfile.rb

has_attached_file :userfile,
    path: ':dir_path/:style_:filename', 
    use_timestamp: false, styles: lambda { |a| UserfileStyles.get(a.instance)[:styles] }, 
    only_process: lambda { |a| UserfileStyles.get(a.instance)[:foreground] }, 
    source_file_options: { all: '-auto-orient' }
validates_attachment_content_type :userfile, content_type: /.*/ 
process_in_background :userfile, 
    url_with_processing: false, 
    only_process: lambda { |a| UserfileStyles.get(a.instance)[:background] } 

app/models/userfile_styles.rb

module UserfileStyles 
    def self.get userfile 
        if userfile.video? 
            { 
                styles: { 
                    screenshot: ['300x300', :jpg], 
                    thumbnail: { 
                        gemoetry: '100x100#', 
                        format: :jpg, 
                        convert_options: '-thumbnail 100%' 
                    }, 
                    preview: { 
                        format: 'mp4', 
                        convert_options: { 
                            output: { ss: '0', t: '10' } 
                        }, 
                        processors: [:transcoder] 
                    }, 
                    mp4: { 
                        format: 'mp4', 
                        convert_options: { 
                            output: { 
                                vcodec: 'libx264', 
                                vb: '1000k', 
                                'profile:v': 'baseline', 
                                vf: 'scale=-2:480', 
                                acodec: 'aac', 
                                ab: '128k', 
                                preset: 'slow', 
                                threads: 0, 
                                movflags: 'faststart', 
                            } 
                        }, 
                        processors: [:transcoder] 
                    } 
                }, 
                foreground: [:screenshot, :thumbnail], 
                background: [:preview, :mp4] 
            }
        end 
    end 
end

Example (the first file is being converted from the second file, and the third file is being converted from the fourth file):

v2@web1 ~/divshare-v2 $ ls -alh /tmp
-rw-------  1 v2   v2    70M Sep 10 00:01 2158940a8739e7219125179e0d1528c120160909-14061-8dqfx020160909-14061-egeyeq.mp4
-rw-------  1 v2   v2   515M Sep  9 23:57 2158940a8739e7219125179e0d1528c120160909-14061-8dqfx0.mp4
-rw-------  1 v2   v2   145M Sep  9 23:33 76ba144beb8a14b6cf542225ef885a7c20160909-12733-1ui03vo20160909-12733-y7ywn.mp4
-rw-------  1 v2   v2   604M Sep  9 23:27 76ba144beb8a14b6cf542225ef885a7c20160909-12733-1ui03vo.mp4

I have tried uploading a couple times and with different files. Always gets caught around the same point. However everything works perfectly when smaller videos (~100-200MB).

This is the command being ran:

v2@web1 ~/divshare-v2 $ ps ux | grep ffmpeg
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
v2       14588 26.4  2.9 849840 240524 ?       Sl   Sep09  12:00 ffmpeg -i /tmp/2158940a8739e7219125179e0d1528c120160909-14061-8dqfx0.mp4 -acodec aac -strict experimental -vcodec libx264 -vb 1000k -profile:v baseline -vf scale=-2:480 -acodec aac -ab 128k -preset slow -threads 0 -movflags faststart -y /tmp/2158940a8739e7219125179e0d1528c120160909-14061-8dqfx020160909-14061-egeyeq.mp4

Any sort of help debugging this would be awesome.

NOTE: I copied the above command and manually ran it so that I could see some logs from ffmpeg, and worked flawlessly.

Noah Passalacqua
  • 742
  • 1
  • 8
  • 24

0 Answers0