📜 ⬆️ ⬇️

Stream video processing with lighttpd / nginx, Mplayer (Mencoder), Ruby, Flvtool2

As soon as there is a need for a video service on the website or portal, immediately the developers are faced with the question of converting the video files uploaded by users of the resource into a browser-friendly flash video format.

The study of this problem is reflected in the next article.

Steps for streaming video:
  1. Server for video with streaming module enabled
    There are two most common options for implementing a video processing platform:
    • lighthttpd
      It requires:
    • nginx
      It requires:
      • Install nginx .
      • Recompile nginx with the –with-http_flv_module option. In the new module http_flv_module, the first implemented streaming function in version 0.4.7 (there was an annoying error in the implementation of streaming, which is fixed http://blog.kovyrin.net/files/flv_fix.patch). There is no error in 0.4.8.
        # ./configure --with-http_flv_module ...SOME-OTHER-OPTS...
      • The next step is to activate streaming for flv files in nginx.conf:
        server {<br/> ...<br/> location ~ \.flv$ {<br/> flv;<br/> }<br/> ...<br/> }
      The nginx server for reviews is a more acceptable option.
      See also here .
  2. Convert video files to a format intended for transmission over the network as a Flash Video stream (flv)
    There are two most common options for converting:
    • using the ffmpeg module
      Read more here .
      However, this is not the most suitable tool for the task, as He organizes two-step video transcoding through intermediate formats understandable by ffmpeg.
    • using MPlayer / MEncoder
      For this you need:
      • Download the mplayer source package from the mplayer official site and compile them;
      • Minimize the set of disabled codecs at compile time.
        Example of transcoding with mencoder:
        mencoder The.Simpsons.18x05.avi \<br/> -o simpsons.flv -of lavf \<br/> -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc \<br/> -ofps 25 \<br/> -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 \<br/> -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames \<br/> -vf scale=320:240
        Documentation - see here . It is necessary to consider that a file of 170 MB will be recoded within 17-20 minutes. Those. it is necessary either to prohibit files of similar size, or to include the process in the background.
      Comment:
      Mplayer already has codecs for audio decoding. For Ffmpeg, you must install an additional Lame codec for audio decoding.
  3. Receiving video file metadata.
    Get the metadata is necessary in order to be able to scroll the video.
    This requires flvtool2 utility.
    It is written in Ruby. For flvtool2 to work, a version not lower than 1.8.4 is required - download .
    To install the flvtool2 package:
    gem install flvtool2-1.0.6.gem
    To update the meta information in the file:
    flvtool2 -UP simpsons.flv
    Comment:
    The source blog.kovyrin.net states that the current version of flvtool2 contains a small, but very unpleasant error, preventing the use of this software with files generated by mencoder. When you run flvtool2, you will get the following result:
    /usr/local/lib/site_ruby/1.8/flv/amf_string_buffer.rb:163: [BUG] Segmentation fault
    To solve this problem, open the file lib / flv / amf_string_buffer.rb in the flvtool2 source code and change line 163 to:
    write [(time.to_i * 1000.0)].pack('G')
    on:
    write [(time.to_f * 1000.0)].pack('G') However, the source webnext.ru does not indicate such an error - it may have been corrected in new versions of flvtool2.
  4. Creating a queue
    It must be borne in mind that video conversion is a fairly resource-intensive process. It must be run with low priority. Plus you need to create a queue of files waiting for conversion. The length of the queue must be calculated based on the configuration of each specific server.
  5. Flash player that understands stream-video
    FlowplayerJW FLV MEDIA PLAYER

')

Source: https://habr.com/ru/post/43506/


All Articles