How do I use ffmpeg on a remote machine via ssh
I don't have a lot of ruby-fu, but this seems to work!
Prerequisites,
sudo yum install rubygems
sudo gem install net-ssh net-sftp highline echoe
Code (with comments),
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/sftp'
require 'highline/import'
file = ARGV[ 0 ] # filename from command line
prod = file + "-new" # product filename (call it <file>-new)
rpath = "/tmp" # remote computer operating directory
rfile = "#{rpath}/#{file}" # remote filename
rprod = "#{rpath}/#{prod}" # remote product
cmd = "mv #{rfile} #{rprod}" # remote command, constructed
host = "-YOUR REMOTE HOST-"
user = "-YOUR REMOTE USERNAME-"
pass = ask("Password: ") { |q| q.echo = false } # password from stdin
Net::SSH.start(host, user, :password => pass) do |ssh|
ssh.sftp.connect do |sftp|
# upload local 'file' to remote 'rfile'
sftp.upload!(file, rfile)
# run remote command 'cmd' to produce 'rprod'
ssh.exec!(cmd)
# download remote 'rprod' to local 'prod'
sftp.download!(rprod, prod)
end
end
And then I can run this like so,
dylan@home ~/tmp/ruby) ls
bar remotefoo.rb*
dylan@home ~/tmp/ruby) ./remotefoo.rb bar
Password:
dylan@home ~/tmp/ruby) ls
bar bar-new remotefoo.rb*
ffmpeg HLS transcoding and chunks upload to remote server
I have created a bash script, which is installing NGINX, configuring it and limiting the access to a certain IP network on my Github page. You can check the solution at: Origin Server running on NGINX. The point is that as @mata said HTTP POST requires some kind of a handle which to process the POST requests and save them to the storage or you can use HTTP PUT, but in this case you need to explicitly allow it, because it is by default not allowed. My solution is actually allowing HTTP PUT only in one specific directory and it is also limiting the HTTP PUT method to only one IP. Make also sure to check my WIKI page for more detailed explanation.
Running PHP remotely via SSH
I figured it out.
From within my Laravel app I decided to try echo exec('whoami');
and see if that returned anything to the browser. It did, so I knew exec()
was working and I could trigger it via the SSH package.
Then I realized that my ffmpeg encoding command was suppressing output with 2>&1
. I removed that and finally saw what was going on: I was receiving a "file not found" error, which was weird because input.mpg
is in the same directory as index.php
.
This has worked on three other servers, but not on this one created with Forge.
So I added the full path to the input file and voilà! It works!
exec("ffmpeg -i /home/forge/mydomainname.com/public/test/input.mpg -c:v libx264 -preset faster -crf 22 -c:a aac -strict experimental -movflags +faststart -vf scale=360:-1 /home/forge/mydomainname.com/public/test/output.mp4 1> /home/forge/mydomainname.com/public/test/output.txt ");
ffmpeg: using the returned data in php
ffmpeg
sends that information on standard error, and not to standard output which is what shell_exec()
captures.
You need to add: 2>&1
at the end of your command:
$out = shell_exec('/path/to/ffmpeg -i Sleep\ Away.mp3 2>&1');
Related Topics
How to Daemonize Rails Rake Task on Elastic Beanstalk Start Up
Installing Rails with Gem, Error Loading Command: Install Undefined Method 'Invoke_With_Build_Args'
Unwanted Form Parameters Being Appended to Pagination Links
Undefined Method When Accessing Hash Element
Ruby: How to Load .Rb File in The Local Context
Ruby: Controlling Printing in Scientific Notation
How Does One Downgrade Jekyll to Work with Github Pages
Rbenv and Bundler: "Bad Interpreter: No Such File or Directory"
Calling a Class Method Within a Class
Ruby Gem Installation Error After Osx Yosemite and Xcode 6 Installation
Best Way to Use HTML5 Data Attributes with Rails Content_Tag Helper
Change The Ruby Process Name in Top
What Are These Numbers in Goto Anything of Sublime Text 2
Checking If Activerecord Find Returns a Result
How Do Enumerators Work in Ruby 1.9.1
Rails 3. How to Explicitly Round a Number to Two Decimal Places in The Model