0

I want to play a video from a pipe, and I try to use python-vlc.(I'm not prefer to use subprocess.Popen because I need to embedded the VLC window into pyqt)

I tried a simple code like this.

import os, time, vlc

r, w = os.pipe()

instance = vlc.Instance()
mediaplayer = instance.media_player_new()
mediaplayer.set_media(instance.media_new_fd(r))
mediaplayer.play()
time.sleep(5)

But got the following error message:

filesystem stream error: cannot open file \\3 (Bad file descriptor)
main input error: 您的输入无法被打开(Your input cannot be open)
main input error: VLC 无法打开 MRL「fd://3」。详情请检查日志。(VLC is unable to open the MRL fd://3, please check the log for detial)

I tried to switch the pipe to an opened fd, but nothing changed.

...
fd = os.open('test.mp4')
...
mediaplayer.set_media(instance.media_new_fd(fd))
...

I tried to use filename directly, then everything goes well.

mediaplayer.set_mrl('test.mp4')

I'm not sure what's wrong with my code. Thank you for your help!

I run the script on Win 10 x64, with python 3.8, VLC 3.0.11.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
PX.Liu
  • 171
  • 1
  • 7
  • If this were Linux, I'd ask what would happen if you used `mediaplayer.set_mrl(f'/dev/fd/{r}')`. – Charles Duffy Nov 05 '20 at 15:30
  • ...if it were Linux, I'd also encourage you to look in `/proc//fd` for the list of open files, to see if FD 3 was really inherited by the VLC command. I want to say that on Windows, you should be able to use Process Explorer for the same purpose. If the way `vlc.Instance` spawns the subprocess doesn't let it inherit file descriptors (other than the default stdin/stdout/stderr, if even those), that would explain the bug. – Charles Duffy Nov 05 '20 at 15:31
  • @CharlesDuffy Thank you very much. I try to run it in a ubuntu VM and hit another problem, vlc.Instance() returns None. I think they are not the same problems, and I'm keep trying. I'll replay if I fix it. Thanks again. – PX.Liu Nov 06 '20 at 20:44
  • 1
    Well, it seems that `media_new_fd` is not work on Windows. Finially, I found there is a command line argument `--drawable-hwnd` can display the vlc window in a hwnd. I walkthrough the problem with full command line `vlc - -I dummy --drawable-hwnd=` and use stdin as stream input. – PX.Liu Nov 08 '20 at 00:14
  • It sounds like you might be able to write up your solution -- if you want to do that, use the "Add an Answer" button; after it's been answered for a few days, you'll be able to accept the answer you added, and thus mark the question solved. – Charles Duffy Nov 08 '20 at 15:57

1 Answers1

0

It seems that media_new_fd is not work on Windows. Finially, I found there is a command line argument --drawable-hwnd can display the vlc window in a hwnd. I walkthrough the problem with full command line vlc - -I dummy --drawable-hwnd=<hwnd> and use stdin as stream input.

And this question Passing file-like objects to ctypes callbacks gives another solution.

PX.Liu
  • 171
  • 1
  • 7
  • I faced the MRL error on VLC app on windows. Smoe files played while others did not. The files were being retrived from a samba share mapped as a windows drive. I changed the folder name on the Samba to have a shorter path and it worked. Is VLC unable to handle long file paths? – Lord Loh. Jan 21 '22 at 01:03