Results 1 to 9 of 9

Thread: piping netcat to mplayer

  1. #1
    Join Date
    Jul 2015
    Posts
    13
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default piping netcat to mplayer

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: piping netcat to mplayer

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Shibby284 (4th July 2015)

  4. #3
    Join Date
    Jul 2015
    Posts
    13
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: piping netcat to mplayer

    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: piping netcat to mplayer

    Quote Originally Posted by Shibby284 View Post
    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,
    _

  6. #5
    Join Date
    Jul 2015
    Posts
    13
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: piping netcat to mplayer

    Quote Originally Posted by anda_skoa View Post
    Do the processes start?
    If not, have you checked them for errors?

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

  7. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: piping netcat to mplayer

    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.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  8. The following user says thank you to jefftee for this useful post:

    Shibby284 (6th July 2015)

  9. #7
    Join Date
    Jul 2015
    Posts
    13
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: piping netcat to mplayer

    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.

  10. #8
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: piping netcat to mplayer

    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?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  11. The following user says thank you to jefftee for this useful post:

    Shibby284 (7th July 2015)

  12. #9
    Join Date
    Jul 2015
    Posts
    13
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: piping netcat to mplayer

    Quote Originally Posted by jefftee View Post
    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:n_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.

Similar Threads

  1. Embed Mplayer in QML
    By mastablasta in forum Qt Quick
    Replies: 7
    Last Post: 29th April 2015, 17:18
  2. [SOLVED] Piping to QProcess very slow performance
    By Phlucious in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2013, 17:45
  3. How to switch mplayer fullscreen?
    By kenchan in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2012, 12:30
  4. Integrating Mplayer inside Qt Tab
    By hitesh_sharma@satyam in forum Qt Programming
    Replies: 1
    Last Post: 20th April 2012, 13:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.