ffmpeg转换为flash文件

时间:2011-02-02 18:22:40

标签: ruby-on-rails ffmpeg

用户上传视频后,我希望ffmpeg将其转换为.flv文件。这在我的开发中的本地主机上正常工作,但在我的VPS上没有生产。我在调试模式下运行的生产日志中没有错误。在我的本地计算机上进行开发时,看起来ffmpeg会在发出post请求之前转换文件。我认为这可能与问题有关。

    FFmpeg version git-740ad0d, Copyright (c) 2000-2011 the FFmpeg developers
    built on Jan 31 2011 12:04:56 with gcc 4.4.5
    configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc   
   --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-          

     libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-
     libx264 --enable-libxvid --enable-x11grab
     libavutil    50. 36. 0 / 50. 36. 0
     libavcore     0. 16. 1 /  0. 16. 1
     libavcodec   52.108. 0 / 52.108. 0
     libavformat  52. 94. 0 / 52. 94. 0
     libavdevice  52.  2. 3 / 52.  2. 3
     libavfilter   1. 74. 0 /  1. 74. 0
     libswscale    0. 12. 0 /  0. 12. 0
     libpostproc  51.  2. 0 / 51.  2. 0
     Input #0, avi, from '/path/public/system/assets/1/original 
    /215aa96bf54c591a8278bdc451c6d8b4.avi':
    Metadata:
    creation_time   : 2011-01-09 20:10:41
     encoder         : CanonMVI06
   Duration: 00:00:01.76, start: 0.000000, bitrate: 12810 kb/s
 Stream #0.0: Video: mjpeg, yuvj422p, 640x480, 30 tbr, 30 tbn, 30 tbc
 Stream #0.1: Audio: pcm_u8, 11024 Hz, 1 channels, u8, 88 kb/s
 Incompatible sample format 'u8' for codec 'libmp3lame', auto-selecting format 's16'
 [buffer @ 0xa058510] w:640 h:480 pixfmt:yuvj422p
 [scale @ 0xa0588f0] w:640 h:480 fmt:yuvj422p -> w:480 h:360 fmt:yuv420p      
 flags:0xa0000004
 Output #0, flv, to '/path/public/system/assets/1/original 
 /215aa96bf54c591a8278bdc451c6d8b4.avi.flv':
 Metadata:
creation_time   : 2011-01-09 20:10:41
encoder         : Lavf52.94.0
Stream #0.0: Video: flv, yuv420p, 480x360, q=2-31, 200 kb/s, 1k tbn, 25 tbc
Stream #0.1: Audio: libmp3lame, 22050 Hz, 1 channels, s16, 32 kb/s
 Stream mapping:
 Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
 Press [q] to stop encoding
Warning, using s16 intermediate sample format for resampling
frame=   37 fps=  0 q=8.0 size=     187kB time=1.48 bitrate=1035.4kbits/s dup=0  
frame=   44 fps=  0 q=8.0 Lsize=     197kB time=1.76 bitrate= 916.3kbits/s dup=0 
drop=9    
video:188kB audio:7kB global headers:0kB muxing overhead 1.093285%


Started POST "/uploads" for 127.0.0.1 at Mon Jan 31 12:10:45 -0800 2011
 Processing by UploadsController#create as HTML
 Parameters: {"commit"=>"Create Upload", "upload"=>{"name"=>"", "asset"=>#  
 <ActionDispatch::Http::UploadedFile:0xb6737e84 @content_type="video/x-msvideo",  
 @original_filename="MVI_0767.AVI", @headers="Content-Disposition: form-data;  
 name=\"upload[asset]\"; filename=\"MVI_0767.AVI\"\r\nContent-Type: video/x- 
 msvideo\r\n", @tempfile=#<File:/tmp/RackMultipart20110131-22703-mb6pnq-0>>},  
 "authenticity_token"=>"tnMScVhmgvnxFpmMVhL/jm13O4rBoVT5bQGSiYZXemk=", "utf8"=>"✓"}
  SQL (0.2ms)  BEGIN
  SQL (0.5ms)  SHOW TABLES
  SQL (1.2ms)  describe `uploads`
 AREL (0.4ms)  INSERT INTO `uploads` (`created_at`, `updated_at`, `asset_updated_at`,  
 `asset_file_size`, `name`, `asset_file_name`, `status`, `asset_content_type`) VALUES  
 ('2011-01-31 20:10:45', '2011-01-31 20:10:45', '2011-01-31 20:10:45', 2828934, '',  
  '215aa96bf54c591a8278bdc451c6d8b4.avi', 'pending', 'video/x-msvideo')
 [paperclip] Saving attachments.
 [paperclip] saving /path/public/system/assets/1/original 
 /215aa96bf54c591a8278bdc451c6d8b4.avi
  SQL (26.0ms)  COMMIT
  SQL (0.1ms)  BEGIN
  AREL (33.7ms)  UPDATE `uploads` SET `updated_at` = '2011-01-31 20:10:45', `status`  
  =  'converting' WHERE (`uploads`.`id` = 1)
  [paperclip] Saving attachments.
  SQL (36.8ms)  COMMIT
  Converting video...command:       ffmpeg -i /path/public/system 
  /assets/1/original/215aa96bf54c591a8278bdc451c6d8b4.avi  -ar 22050 -ab 32k -s  
  480x360 -vcodec flv -r 25 -qscale 8 -f flv -y /home/sean/applelocal/public/system
  /assets/1/original/215aa96bf54c591a8278bdc451c6d8b4.avi.flv
  SQL (0.2ms)  BEGIN
  AREL (1.2ms)  UPDATE `uploads` SET `updated_at` = '2011-01-31 20:10:46',  
  `asset_file_name` = '215aa96bf54c591a8278bdc451c6d8b4.avi.flv' WHERE  
   (`uploads`.`id`    = 1)
   [paperclip] Saving attachments.
   SQL (24.6ms)  COMMIT
   SQL (0.1ms)  BEGIN
   AREL (0.4ms)  UPDATE `uploads` SET `updated_at` = '2011-01-31 20:10:46',  
   `asset_content_type` = 'application/x-flash-video' WHERE (`uploads`.`id` = 1)
   [paperclip] Saving attachments.
   SQL (51.3ms)  COMMIT
   SQL (0.1ms)  BEGIN
   AREL (0.5ms)  UPDATE `uploads` SET `updated_at` = '2011-01-31 20:10:46', `status`  
   =     'converted' WHERE (`uploads`.`id` = 1)
   [paperclip] Saving attachments.
   SQL (51.3ms)  COMMIT
   Redirected to http://localhost:3000/uploads
   Completed 302 Found in 1349ms

我的生产日志显示了这个:

     Started POST "/uploads/fast_upload?X-Progress-
    ID=a96b4851f686ff28c8818e35962318bf" for 67.127.52.10 at Wed Feb 02 17:57:31 +0000 
    2011
    Processing by UploadsController#create as HTML
    Parameters: {"name"=>"", "upload"=>{"fast_asset"=>
     {"original_name"=>"MVI_0767.AVI", "content_type"=>"video/x-msvideo",  
    "filepath"=>"/path$
     [paperclip] file -b --mime-type '/path/shared/6/0000000026_1/MVI_0767.AVI'  
     2>/dev/null
     ^[[1m^[[35mSQL (0.2ms)^[[0m  BEGIN
     ^[[1m^[[36mSQL (0.4ms)^[[0m  ^[[1mSHOW TABLES^[[0m
     ^[[1m^[[35mSQL (0.5ms)^[[0m  describe `uploads`
     ^[[1m^[[36mAREL (0.3ms)^[[0m  ^[[1mINSERT INTO `uploads` (`asset_updated_at`,  
     `asset_content_type`, `name`, `status`, `updated_at`, `created_at`, `asset_f$
     [paperclip] Saving attachments.
     [paperclip] saving /path/public/system/assets/1/original
    /df58a41b86249bbcb6ec4bafde725a75.avi
      ^[[1m^[[35mSQL (1.3ms)^[[0m  COMMIT
      ^[[1m^[[36mSQL (0.1ms)^[[0m  ^[[1mBEGIN^[[0m
      ^[[1m^[[35mAREL (0.3ms)^[[0m  UPDATE `uploads` SET `status` = 'converting',  
      `updated_at` = '2011-02-02 17:57:31' WHERE (`uploads`.`id` = 1)
       [paperclip] Saving attachments.
       ^[[1m^[[36mSQL (0.3ms)^[[0m  ^[[1mCOMMIT^[[0m
        Converting video...command:       ffmpeg -i /path/public/system/assets 
       /1/original/df58a41b86249bbcb6ec4bafde725a75.a$
      ^[[1m^[[35mSQL (0.2ms)^[[0m  BEGIN
       ^[[1m^[[36mAREL (0.3ms)^[[0m  ^[[1mUPDATE `uploads` SET `status` = 'error',  
       `updated_at` = '2011-02-02 17:57:31' WHERE (`uploads`.`id` = 1)^[[0m
       [paperclip] Saving attachments.
       ^[[1m^[[35mSQL (0.3ms)^[[0m  COMMIT
     Redirected to http://url.org/uploads
     Completed 302 Found in 93ms

在我的控制器中创建方法我只是这样:

      if @upload.save
         @upload.convert

.convert运行ffmpeg转换

1 个答案:

答案 0 :(得分:0)

问题出在我的模型中的ffmpeg命令中,我忽略了在bin目录中包含ffmpeg的完整路径。这不是我本地主机上的问题,但需要与乘客一起运行,需要完整路径。