ruby-av / paperclip-av-transcoder

Audio/Video Transcoder for Paperclip using FFMPEG/Avconv
MIT License
136 stars 83 forks source link

How to make it choose ffmpeg over avconv? #17

Closed dt1973 closed 9 years ago

dt1973 commented 9 years ago

How to make paperclip-av-transcoder choose ffmpeg over avconv if both are found?

http://runnable.com/VR3jBtJKSwh21EKs/paperclip-av-transcoder

Started POST "/default/topics" for ::ffff at 2015-04-05 14:05:33 +0000                                                                      
Processing by Forem::TopicsController#create as HTML                                                                                                    
  Parameters: {"utf8"=>"�~\~S", "authenticity_token"=>"+6Ma4fmBeexCEFsP9z8b5Af5vJQKarMssAxFdIHMHGEkRcP09T/zgmlVAM4Trb2iHWkHVFGFrHBqO3E8GGAzJw==", "topic
"=>{"subject"=>"sfgfgsfg", "posts_attributes"=>{"0"=>{"text"=>"sfhsg", "photos_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x
00000004502798 @tempfile=#<File:/tmp/RackMultipart20150405-50-183sbay.gif>, @original_filename="test.gif", @content_type="image/gif", @headers="Content-
Disposition: form-data; name=\"topic[posts_attributes][0][photos_attributes][0][attachment]\"; filename=\"test.gif\"\r\nContent-Type: image/gif\r\n">}}}
}}, "commit"=>"Create Topic", "forum_id"=>"default"}                                                                                                    
  ^[[1m^[[35mUser Load (0.3ms)^[[0m  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]              
  ^[[1m^[[36mForem::Forum Load (0.2ms)^[[0m  ^[[1mSELECT  "forem_forums".* FROM "forem_forums" WHERE "forem_forums"."slug" = ?  ORDER BY "forem_forums".
"position" ASC LIMIT 1^[[0m  [["slug", "default"]]                                                                                                      
  ^[[1m^[[35mForem::Category Load (0.1ms)^[[0m  SELECT  "forem_categories".* FROM "forem_categories" WHERE "forem_categories"."id" = ? LIMIT 1  [["id", 
1]]                                                                                                                                                     
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-oihgom.gif'                                                                 
[AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi                                                        
[AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi                                                         
[AV] Found ["avconv", "ffmpeg"], using: Avconv                                                                                                          
[AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi                                                        
[AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi                                                         
[AV] Found ["avconv", "ffmpeg"], using: Avconv                                                                                                          
[AV] Running command: avconv -i "/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid.gif" 2>&1                                                     
[paperclip] [transcoder] Transocding supported file /tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid.gif                                        
[AV] Adding output parameter ["acodec", "aac"]                                                                                                          
[AV] Adding output parameter ["strict", "experimental"]                                                                                                 
[AV] Running command: avconv -loglevel quiet -i "/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid.gif" -acodec aac -strict experimental -y "/tmp
/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid20150405-50-nyp8zp.mp4"                                                                             
[paperclip] [transcoder] Successfully transcoded 098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid to #<File:0x000000046bf298>                        
[paperclip] [qtfaststart] :source :dest                                                                                                                 
Command :: qtfaststart '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid20150405-50-nyp8zp.mp4' '/tmp/098f6bcd4621d373cade4e832627b4f620150405-5
0-1lz9oid20150405-50-nyp8zp20150405-50-1cczssi.mp4' 
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid20150405-50-nyp8zp20150405-50-1cczssi.mp4'                           
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid.gif[0]' 2>/dev/null                   
Command :: identify -format %m '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid.gif[0]'                                                        
Command :: convert '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid.gif' -coalesce -auto-orient -resize "x70" -crop "70x70+27+0" +repage -layer
s "optimize" '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid20150405-50-19tfyp0'                                                              
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1lz9oid20150405-50-19tfyp0'                                                 
  ^[[1m^[[36m (0.2ms)^[[0m  ^[[1mbegin transaction^[[0m                                                                                                 
  ^[[1m^[[35mForem::Topic Exists (0.4ms)^[[0m  SELECT  1 AS one FROM "forem_topics" WHERE ("forem_topics"."id" IS NOT NULL) AND "forem_topics"."slug" = 
? LIMIT 1  [["slug", "sfgfgsfg"]]                                                                                                                       
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-50-1kui4uq.gif'                                                                
  ^[[1m^[[36mSQL (0.7ms)^[[0m  ^[[1mINSERT INTO "forem_topics" ("subject", "forum_id", "user_id", "slug", "created_at", "updated_at") VALUES (?, ?, ?, ?
, ?, ?)^[[0m  [["subject", "sfgfgsfg"], ["forum_id", 1], ["user_id", 1], ["slug", "sfgfgsfg"], ["created_at", "2015-04-05 14:05:38.824979"], ["updated_a
t", "2015-04-05 14:05:38.824979"]]                                                                                                                      
  ^[[1m^[[35mSQL (0.2ms)^[[0m  INSERT INTO "forem_posts" ("text", "user_id", "topic_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)  [["text", "
sfhsg"], ["user_id", 1], ["topic_id", 9], ["created_at", "2015-04-05 14:05:38.828987"], ["updated_at", "2015-04-05 14:05:38.828987"]]                   
  ^[[1m^[[36mForem::Topic Load (0.2ms)^[[0m  ^[[1mSELECT  "forem_topics".* FROM "forem_topics" WHERE "forem_topics"."id" = ? LIMIT 1^[[0m  [["id", 9]]  
  ^[[1m^[[35mSQL (281.1ms)^[[0m  UPDATE "forem_topics" SET "last_post_at" = '2015-04-05 14:05:38.828987' WHERE "forem_topics"."id" = ?  [["id", 9]]     
  ^[[1m^[[36mForem::Subscription Load (0.4ms)^[[0m  ^[[1mSELECT  "forem_subscriptions".* FROM "forem_subscriptions" WHERE "forem_subscriptions"."topic_i
d" = ?  ORDER BY "forem_subscriptions"."id" ASC LIMIT 1000^[[0m  [["topic_id", 9]]

As one would expect, this was never a problem with paperclip-ffmpeg:

http://runnable.com/VSFEpaY88OsqHGa0/paperclip-reverted-to-ffmpeg

Started POST "/default/topics" for ::ffff at 2015-04-05 14:16:37 +0000                                                                      
Processing by Forem::TopicsController#create as HTML                                                                                                    
  Parameters: {"utf8"=>"�~\~S", "authenticity_token"=>"ZLQT2hWb+VtRpso+IWo/iAv2bf6x2Fcgp/bV9F8bwQdouiumXUXMNbtJrrdpkGkW1AMByf8R1bxiZVLA7BiUOQ==", "topic
"=>{"subject"=>"shfhfhf", "posts_attributes"=>{"0"=>{"text"=>"asdasdasd", "photos_attributes"=>{"0"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile
:0x00000005ba0a40 @tempfile=#<File:/tmp/RackMultipart20150405-60-1au05n3.gif>, @original_filename="test.gif", @content_type="image/gif", @headers="Conte
nt-Disposition: form-data; name=\"topic[posts_attributes][0][photos_attributes][0][attachment]\"; filename=\"test.gif\"\r\nContent-Type: image/gif\r\n">
}}}}}, "commit"=>"Create Topic", "forum_id"=>"default"}                                                                                                 
  ^[[1m^[[35mUser Load (0.3ms)^[[0m  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]              
  ^[[1m^[[36mForem::Forum Load (0.2ms)^[[0m  ^[[1mSELECT  "forem_forums".* FROM "forem_forums" WHERE "forem_forums"."slug" = ?  ORDER BY "forem_forums".
"position" ASC LIMIT 1^[[0m  [["slug", "default"]]                                                                                                      
  ^[[1m^[[35mForem::Category Load (0.2ms)^[[0m  SELECT  "forem_categories".* FROM "forem_categories" WHERE "forem_categories"."id" = ? LIMIT 1  [["id", 
1]]                                                                                                                                                     
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-1d84keo.gif'                                                                
[paperclip] [ffmpeg] ffprobe "/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw04.gif" 2>&1                                                         
[paperclip] [ffmpeg] Command Success                                                                                                                    
[paperclip] [ffmpeg] Making...                                                                                                                          
[paperclip] [ffmpeg] Building Destination File: '098f6bcd4621d373cade4e832627b4f620150405-60-akyw04' + 'mp4'                                            
[paperclip] [ffmpeg] Destination File Built                                                                                                             
[paperclip] [ffmpeg] Adding Geometry                                                                                                                    
[paperclip] [ffmpeg] Adding Format                                                                                                                      
[paperclip] [ffmpeg] Adding Source                                                                                                                      
[paperclip] [ffmpeg] Building Parameters                                                                                                                
[paperclip] [ffmpeg] -i :source -acodec aac -strict experimental -y :dest                                                                               
Command :: ffmpeg -i '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw04.gif' -acodec aac -strict experimental -y '/tmp/098f6bcd4621d373cade4e83262
7b4f620150405-60-akyw0420150405-60-nx0j61.mp4'                                                                                                          
[paperclip] [qtfaststart] :source :dest                                                                                                                 
Command :: qt-faststart '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw0420150405-60-nx0j61.mp4' '/tmp/098f6bcd4621d373cade4e832627b4f620150405-6
0-akyw0420150405-60-nx0j6120150405-60-jbc80d.mp4'                                                                                                       
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw0420150405-60-nx0j6120150405-60-jbc80d.mp4'                             
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw04.gif[0]' 2>/dev/null                    
Command :: identify -format %m '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw04.gif[0]'                                                         
Command :: convert '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw04.gif' -coalesce -auto-orient -resize "x70" -crop "70x70+27+0" +repage -layers
 "optimize" '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw0420150405-60-1benqrt'                                                                
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-akyw0420150405-60-1benqrt'                                                  
  ^[[1m^[[36m (0.2ms)^[[0m  ^[[1mbegin transaction^[[0m                                                                                                 
  ^[[1m^[[35mForem::Topic Exists (0.5ms)^[[0m  SELECT  1 AS one FROM "forem_topics" WHERE ("forem_topics"."id" IS NOT NULL) AND "forem_topics"."slug" = 
? LIMIT 1  [["slug", "shfhfhf"]]                                                                                                                        
Command :: file -b --mime '/tmp/098f6bcd4621d373cade4e832627b4f620150405-60-kdq57l.gif'                                                                 
  ^[[1m^[[36mSQL (1.0ms)^[[0m  ^[[1mINSERT INTO "forem_topics" ("subject", "forum_id", "user_id", "slug", "created_at", "updated_at") VALUES (?, ?, ?, ?
, ?, ?)^[[0m  [["subject", "shfhfhf"], ["forum_id", 1], ["user_id", 1], ["slug", "shfhfhf"], ["created_at", "2015-04-05 14:16:42.081114"], ["updated_at"
, "2015-04-05 14:16:42.081114"]]                                                                                                                        
  ^[[1m^[[35mSQL (0.4ms)^[[0m  INSERT INTO "forem_posts" ("text", "user_id", "topic_id", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)  [["text", "
asdasdasd"], ["user_id", 1], ["topic_id", 9], ["created_at", "2015-04-05 14:16:42.085832"], ["updated_at", "2015-04-05 14:16:42.085832"]]               
  ^[[1m^[[36mForem::Topic Load (0.1ms)^[[0m  ^[[1mSELECT  "forem_topics".* FROM "forem_topics" WHERE "forem_topics"."id" = ? LIMIT 1^[[0m  [["id", 9]]  
  ^[[1m^[[35mSQL (49.7ms)^[[0m  UPDATE "forem_topics" SET "last_post_at" = '2015-04-05 14:16:42.085832' WHERE "forem_topics"."id" = ?  [["id", 9]]      
  ^[[1m^[[36mForem::Subscription Load (0.2ms)^[[0m  ^[[1mSELECT  "forem_subscriptions".* FROM "forem_subscriptions" WHERE "forem_subscriptions"."topic_i
d" = ?  ORDER BY "forem_subscriptions"."id" ASC LIMIT 1000^[[0m  [["topic_id", 9]]
owahab commented 9 years ago

I think that's quite an edge case. You have both avconv and ffmpeg installed but you want to choose ffmpeg. Wouldn't uninstalling avconv be an option?

dt1973 commented 9 years ago

I never installed it myself so it must be some sorta dependency.

dt1973 commented 9 years ago

You're right, this is an edge case. That Runnable test case uses Ubuntu, and as with everything else in Ubuntu, installing ffmpeg is way harder than it has to be. And, somehow, it mysteriously manages to install avconv as well:

https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

Naturally, this is not a problem on OpenBSD where I actually host my app so I'm just going to close this one.

Thank you for your support.

dt1973 commented 9 years ago

@owahab how does paperclip-av-transcoder look for avconv? I removed /usr/bin/avconv as well as /usr/share/avconv but it still insists on using avconv:

http://runnable.com/VR3jBtJKSwh21EKs/paperclip-av-transcoder

attenzione commented 9 years ago

i don't know why (strange decision), but av gem tests for avprobe instead of avconv, so you need to remove avprobe and you can leave avconv as is in the system

dt1973 commented 9 years ago

Indeed you're right. Thank you @attenzione!

dt1973 commented 9 years ago

@owahab maybe you could make it look for avconv instead of avprobe?