PDA

View Full Version : piping netcat to mplayer



Shibby284
4th July 2015, 13:16
hello!
When I write this line of code in the cmd:
nc ip 5000 | mplayer -fps 60 -cache 1024 -
I get a stream video running in mplayer from my raspberry pi server.
I want to do the same from a Qt app.
this is what i wrote but doesn't work:

QProcess *process1;
QProcess *process2;

process1 = new QProcess(0);
process2 = new QProcess(0);

process1->setStandardOutputProcess(process2);

QStringList args1;
QStringList args2;

args1 += "89.139.168.89 5001";
args2 += "-fps 60 -cache 1024 -";

process1->start("C:\\Program Files (x86)\\MPlayer for Windows\\nc.exe",args1);
process2->start("C:\\Program Files (x86)\\MPlayer for Windows\\mplayer.exe",args2);

anyone can tell me what is wrong here please?
thanks.

anda_skoa
4th July 2015, 14:10
In your shell example, you pass 2 arguments to "nc" and 5 arguments to mplayer.
In your Qt code, you pass 1 argument to nc and 1 argument to mplayer.

Cheers,
_

Shibby284
4th July 2015, 16:20
thanks you for the reply.
i've changed it to:
QProcess *process1;
QProcess *process2;

process1 = new QProcess(0);
process2 = new QProcess(0);

process1->setStandardOutputProcess(process2);

QStringList args1;
QStringList args2;

args1 += "89.139.168.89";
args1 += "5001";

args2 += "-fps";
args2 += "60";
args2 += "-cache";
args2 += "1024";
args2 += "-";

process1->start("C:\\Program Files (x86)\\MPlayer for Windows\\nc.exe",args1);
process2->start("C:\\Program Files (x86)\\MPlayer for Windows\\mplayer.exe",args2);

but still nothing happens..when i run it from cmd it does work.
any ideas?
thanks.

anda_skoa
4th July 2015, 17:58
but still nothing happens..when i run it from cmd it does work.
any ideas?
thanks.

Do the processes start?
If not, have you checked them for errors?

Cheers,
_

Shibby284
4th July 2015, 20:51
Do the processes start?
If not, have you checked them for errors?

Cheers,
_

both processes are running according to process->state().
thanks.

jefftee
4th July 2015, 22:59
In your shell example, you're using port 5000 for nc but in your QProcess, you're using port 5001. Does the same shell command work with port 5001?

I've never done what you're trying before, but I wonder if you might have a timing issue where you start both QProcesses and the mplayer process may try to read from stdin and hit EOF because the nc process hasn't started completely and starting sending output to its stdout?

What if you started process1, then do a process1->waitForStarted(-1) before starting process2? Just a thought.

Shibby284
6th July 2015, 21:34
first of all thank you for your replies.
well now it works but with a strange bug. when starting the processes nothing happens, and after I close the Qt app(The UI window) the Mplayer jumps to the screen and the stream is visible. How can I make it jump during the time the app is running?
Another thing is I want it to appear in the app itself(Qwidget or Qmedia player). I did this to run a video from a file in the disk:
args2 += "-slave";
args2 += "-wid";
args2 += QString::number((int)ui->Mwidget->winId());
args2 += "C:\\Program Files (x86)\\MPlayer for Windows\\MVI_1343.avi";

process2->start("C:\\Program Files (x86)\\MPlayer for Windows\\mplayer.exe",args2);

and it ran inside the Qwidget in my app, though combining all arguments together doesn't work(I can't see the video stream in the Qwidget window).
thanks.

jefftee
7th July 2015, 05:40
First thing I'd check is that ui->Mwidget->winId() returns an integer value. You're forcing the compiler to return an int and the actual return type is a WId. The doc states that WId is a platform dependent value, which on Windows is an HWND. I don't do Windows, so HWND's could be valid integers, but you should confirm since you're forcing the compiler to convert the WId to an integer value.

Seems that issue may be unrelated to your other point about the mplayer window not "jumping". Can you post the actual code you're using when the mplayer window is not "jumping" as well as a screen shot that shows what you're talking about?

Shibby284
7th July 2015, 09:52
First thing I'd check is that ui->Mwidget->winId() returns an integer value. You're forcing the compiler to return an int and the actual return type is a WId. The doc states that WId is a platform dependent value, which on Windows is an HWND. I don't do Windows, so HWND's could be valid integers, but you should confirm since you're forcing the compiler to convert the WId to an integer value.

Seems that issue may be unrelated to your other point about the mplayer window not "jumping". Can you post the actual code you're using when the mplayer window is not "jumping" as well as a screen shot that shows what you're talking about?

ui->Mwidget->winId() returns an integer value, as i said it works with a video from the disk. anyway i'll change that to Wid.

this is the code:

void Dialog::on_pushButton_clicked()
{
QProcess *process1;
QProcess *process2;

process1 = new QProcess(0);
process2 = new QProcess(0);

process1->setStandardOutputProcess(process2);

QStringList args1;
QStringList args2;

args1 += "10.0.0.21";
args1 += "5001";

args2 += "-fps";
args2 += "60";
args2 += "-cache";
args2 += "1024";
args2 += "-";

process1->start("C:\\Program Files (x86)\\MPlayer for Windows\\nc.exe",args1);

process2->start("C:\\Program Files (x86)\\MPlayer for Windows\\mplayer.exe",args2);

}

thanks.