How do I use ffmpeg on a remote machine via ssh

2019-05-27 03:47发布

I have three computers on my LAN,

one running ubuntu,
one running openSuse
and my server running Archlinux.

I've only managed to get ffmpeg to work properly on my server.

I would like to write a script that would pretend to be an ffmpeg installation on the local machine, but would actually just be using the server's ffmpeg.

Example:

on the openSuse pc i would like to call:

ffmpeg -i file.avi out.flv

and then get the normal output as one would expect,
but I want it to use the ffmpeg on the archlinux.

any advice as to how I would get this to work.
( preferably in Ruby )

EDIT: I've extended this question to How do I display progress bars from a shell command over ssh

2条回答
太酷不给撩
2楼-- · 2019-05-27 04:06

Here are some options, easiest first:

  • Set up NFS on your LAN, remoted mount all disks on your server, then run an ssh command using the remote mounted names. The burden is on the user to use the strange names.

  • Set up NFS, but parse ffmpeg options to identify input and output files, then use something like the realname package (or a simple shell script) to convert the names first to absolute pathnames, then to the remote mounted names.

  • Don't use NFS, but parse ffmpeg options and use scp to copy the input files over and the output files back.

查看更多
别忘想泡老子
3楼-- · 2019-05-27 04:20

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*
查看更多
登录 后发表回答