Search code examples
ruby-on-railshtmlruby-on-rails-4videounicorn

Adding mp4 mime-type prevents streaming of video with Unicorn and Rails 4


I'm seeing some strange behaviour where an .mp4 video file (located in /assets/images/) streams perfectly well without anything registered in mime_types.rb. But, if I register the video/mp4 mime-type, the video will not stream.

mime_types.rb:

Mime::Type.register "video/mp4", :mp4

Safari displays the first picture of the video, but cannot stream the video. This is only an issue with Safari and only with Unicorn (not Webrick).

We need the mime-type registered, because we're responding to mp4 requests in other locations of the app.

Any ideas how to solve this?

  • Rails 4.1.3
  • Ruby 2.1.2
  • Unicorn 4.8.3

Video details from ffmpeg -I

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'background_video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2015-03-06 14:03:09
    encoder         : Lavf54.6.100
  Duration: 00:00:11.29, start: 0.000000, bitrate: 893 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1114x494, 903 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2015-03-06 14:03:09
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default)
    Metadata:
      creation_time   : 2015-03-06 14:03:09
      handler_name    : SoundHandler

Solution

  • Moving the videos files to the /public/ folder fixes the issue.