Comments (15)
Try typing one of the following lines:
python vlc.py -v
or if vlc.py
was pip
-installed:
python -m vlc -v
from python-vlc.
vlc.py was pip installed, here's the output:
vlc.py: 3.0.18121 (Wed Nov 16 12:04:29 2022 3.0.18)
libVLC: 3.0.18 Vetinari (0x3001200)
plugins: C:\Program Files\VideoLAN\VLC
Python: 3.10.2 (64bit) Windows 10
from python-vlc.
So, at least on Windows 10 vlc.py
should work. Try running a video like
python -m vlc <video_file_name>
Then type ? to see more single-key options. After that, try the same 2 lines on Linux and that should provide some clue what's wrong.
from python-vlc.
I've not tried getting anything running on linux just yet. That'll (probably) be running on a raspberry pi on headless mode, or at least my laptop that has arch on it
Here's a screenshot that I took while the video was playing - I was trying to get it to recognise some input, but that didn't appeart to happen
Here's a screenshot that I took when the video ended. The issue of not recognising input is still there, so I'm unable to close the vlc player directly, but can close it by closing the terminal
from python-vlc.
The VLC.App must be installed and must be working properly on its own. Only then, python-vlc vlc.py
can work … as long as vlc.py
can find the libvlc.dll
or -.so
library included in the VLC.App.
from python-vlc.
VLC is installed and working fine:
from python-vlc.
This is Windows, isn't it? What about Linux and Raspberry? Does the plain VLC.App run on those?
Btw, the errors and not being able to quit are a vlc.py
issue on Windows. Try using the tkvlc.py example with Python 3.11.2 on Windows. Download that from the python-vlc web site and use the command line:
python tkvlc.py <video_file_name>
One final comment, make sure to use the 64-bit VLC.App with vlc.py
in 64-bit Python. Or use the 32-bit version of both.
from python-vlc.
I'll go try the other stuff with python 3.11.2 and see what happens
from python-vlc.
Still getting the same error in the initial script I had the issue in
Using the following:
Python 3.11.2 (64 bit)
python-vlc 3.0.18121 (from pip install)
VLC Application 3.0.18 64 bit
I'm also still developing the script so I'm just concerned with getting it working on Windows for the moment, I'll deal with linux when I've actually got something I can test
I can try it on linux if you think that'll help, though
from python-vlc.
A NameError
usually means undefined object. In the script core.py
there a line somewhere like this one
import vlc
or maybe -just a guess-
from main import vlc
In any case, first get the script to work on one platform (Windows or Linux) before moving to the other and then yet an other.
from python-vlc.
Currently I have the following in core.py
:
os.add_dll_directory(r"C:\\Program Files\\VideoLAN\\VLC")
# Some other code
try:
logging.info(msg="Importing libraries...")
# TODO: Add other needed libraries here
import yt_dlp
import vlc
except ImportError:
# Log which libraries failed to import
logging.error(msg="Failed to import libraries: " + str(sys.exc_info()[1]))
# Some other code
def play_song(self, url):
# Get the source url
source_url = self.get_video(url)
# Create the vlc instance
vlc_instance = vlc.Instance()
vlc_player = vlc_instance.media_player_new()
# Create the media
media = vlc_instance.media_new(source_url)
# Set the media
vlc_player.set_media(media)
# Play the media
vlc_player.play()
def test():
c = core()
c.play_song("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
if __name__ == '__main__':
test()
And then the output of that is just:
2023-03-25 00:04:04,310 Importing libraries...
Traceback (most recent call last):
File "G:\!Programming\Python\HKMB2\py\core.py", line 126, in <module>
test()
File "G:\!Programming\Python\HKMB2\py\core.py", line 123, in test
c.play_song("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
File "G:\!Programming\Python\HKMB2\py\core.py", line 109, in play_song
vlc_instance = vlc.Instance()
^^^
NameError: name 'vlc' is not defined
So it's definetly importing the module, but when I go to create the instance it says it's not defined
from python-vlc.
It is hard to tell, since several pieces are missing.
It seems play_song
is a method of some class. Where does it get vlc
from?
In any case, this is not a VLC or vlc.py
issue. Sorry.
from python-vlc.
Ok, so that works.
Full code for reference:
# Stanrdard library imports
import os
import logging
# Third party imports
import yt_dlp
import vlc
# Options for the ytdl object
ytdl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
'source_address': '0.0.0.0' # bind to all IPv4 addresses
}
# Create the YTDL object
ytdl = yt_dlp.YoutubeDL(ytdl_opts)
# Logging options
LOG_TO_FILE = False
LOG_FILE_NAME = "bot.log"
# Delete the log file if it exists
if os.path.isfile(path=LOG_FILE_NAME):
os.remove(path=LOG_FILE_NAME)
# Set up logging
if LOG_TO_FILE:
log_handler = logging.basicConfig(format='%(asctime)s %(message)s', filename=LOG_FILE_NAME, encoding='utf-8', level=logging.INFO)
else:
log_handler = logging.basicConfig(format='%(asctime)s %(message)s', encoding='utf-8', level=logging.INFO)
# Get the source url from the video url
def get_video(url):
info = ytdl.extract_info(url, download=False)
formats = info['formats']
# Get the best audio format
for f in formats:
if f.get('acodec') == 'opus':
best_audio_format = f
break
# If we didn't find an opus format, just use the first one
if not best_audio_format:
best_audio_format = formats[0]
# Get the source url
source_url = best_audio_format['url']
# Return the source url
return source_url
# Play the song
def play_song(url):
# Get the source url
source_url = get_video(url)
# Create the vlc instance
vlc_instance = vlc.Instance()
vlc_player = vlc_instance.media_player_new()
# Create the media
media = vlc_instance.media_new(source_url)
# Set the media
vlc_player.set_media(media)
# Play the media
vlc_player.play()
# Test here for now
if __name__ == '__main__':
play_song("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
from python-vlc.
Great.
from python-vlc.
I guess the solution then is to just try moving the imports around and hope lol
from python-vlc.
Related Issues (20)
- How to disable logs? HOT 1
- New playback of another video file in PyQT5 using VLC
- Media player causes memory leak
- Wrapper for struct libvlc_event_t is Error HOT 1
- MediaListEndReached event is never triggered
- python-vlc about wasapi generic error: cannot activate client (error 0x88890004)
- Qt Video Frame opacity
- Integrating the vlc window in Qt with Wayland HOT 2
- Render to custom OpenGL texture HOT 3
- no more functionnal with the daily vlc
- disable the option audio "time-stretching audio" HOT 1
- Add type hints HOT 1
- Discord invite is expired
- 360 video interaction with mouse
- SyntaxWarning: invalid escape sequence HOT 2
- Using the argument 'vout=mmal_xsplitter' on vlc.Instance does not seem te have any effect
- Not every logs are triggering the callback given to "log_set" HOT 1
- The function get_time() fails to provide an acurrate time HOT 1
- how to draw button over vlc video in pyqt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-vlc.