How to Use Ffmpeg on a Remote Machine via Ssh

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



Leave a reply



Submit