im trying to display a video on a pygame surface using the pyglet library to import, play and then convert the frames into an image. I managed to battle my way through installing avbin but now I'm hitting a type error with my code
def cutscene(window_surface, filename):
player = pyglet.media.Player()
source = pyglet.media.load(filename)
player.queue(source)
player.play()
pygame.display.flip()
while True:
window_surface.fill(0)
player.dispatch_events()
tex = player.get_texture()
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
window_surface.blit(img, (0,0))
pygame.display.flip()
when I run, i get the following error
Traceback (most recent call last):
File "dino_game.py", line 348, in <module>
main()
File "dino_game.py", line 45, in main
cutscene(window_surface, "Cutscenes/Cutscene1.mov")
File "dino_game.py", line 68, in cutscene
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
AttributeError: 'NoneType' object has no attribute 'get_image_data'
Nothing that I do seems to solve it
EDIT: So after testing both this file and the sample files provided by pyglet, it seems that I get this error no matter what filetype I use, could this be an installation error with pyglet or AVbin?
Gave up trying to use pyglet and swapped to VLC where I just have to pass the window ID for the game and it does the rest for me
VLC script: https://wiki.videolan.org/Python_bindings/
Related
I'm trying to build a music player using Python Tkinter, but I really facing issues while I set the song path it seems some errors.
Here is my code:
song = song_box.get(ACTIVE)
song = f'C:/Users/parve/PycharmProjects/gf/songs/{song}.ogg'
pygame.mixer.music.load(song)
pygame.mixer.music.play(loops=0)
Here is the error I face:
File "C:/Users/parve/PycharmProjects/gf/music.py", line 25, in play
pygame.mixer.music.load(song)
pygame.error: Failed loading libvorbisfile-3.dll: The specified module could not be found.
I am working on a python project to control vlc player - volume up/down, play/pause, rewind/forward and I have installed python2.7, vlc 3.0.8 32bit on windows 7. this is the code below which is to play the local mp4 file
import vlc
instance = vlc.Instance()
player = instance.media_player_new()
Media = instance.media_new('d:\1280.mp4')
Media.get_mrl()
player.set_media(Media)
player.play()
problem is the keywords - Instance and other functions are not getting highlighted except import and am getting the following error
Traceback (most recent call last):
File "C:\Python27\vlc3.py", line 4, in <module>
Media = instance.media_new('d:\1280.mp4')
File "C:\Python27\vlc.py", line 1916, in media_new
m._instance = self
AttributeError: 'NoneType' object has no attribute '_instance'
I am not able to understand please help me out
Use forward slashes instead of backward slashes.
Use:
Media = instance.media_new('d:/1280.mp4')
Instead of:
Media = instance.media_new('d:\1280.mp4')
I have used pygame a lot, but never used sound before. I have checked and the files are there by the right name, and I have used the right pathway, but I just get this error message:
Traceback (most recent call last):
File "C:\Users\Rajive\AppData\Local\Programs\Python\Python3.4.3\D C W.py", line 11, in module
door_opening = pygame.mixer.Sound('C:\Users\Rajive\Downloads\door_opening.m4a')
pygame.error: Unable to open file 'C:\Users\Rajive\Downloads\door_opening.m4a'
import random, time, pygame
time = time.clock()
pygame.init()
diff = 1
door_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\door_opening.m4a')
door_closing = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\door_closing.m4a')
closet_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\closet_opening.m4a')
closet_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\closet_closing.m4a')
window_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\window_opening.m4a')
window_opening = pygame.mixer.Sound('C:\\Users\\Rajive\\Downloads\\window_closing.m4a')
From pygame documentation:
The Sound can be loaded from an OGG audio file or from an uncompressed WAV.
Doesn't look like the .m4a codec is supported. Perhaps try converting your file first.
I am making a program that builds a thumbnail based on user input, and I am running into problems actually saving the image. I am used to C++ where you can simply save the image, it seems that python does not support this.
This is my code right now:
def combine(self):
img = Image.new("RGBA", (top.width,top.height+mid.height+mid.height),(255,255,255))
img.paste(top, (0,0))
img.paste(mid, (0,top.height))
img.paste(bot, (0,top.height+mid.height))
img.show()
img.save("Thumbnail.png", "PNG")
The error that shows up when I run it is :
Traceback (most recent call last):
File "TextToThumbnail.py", line 4, in <module>
class Thumbnail(object):
File "TextToThumbnail.py", line 461, in Thumbnail
img.save("Thumbnail.png", "PNG")
NameError: name 'img' is not defined
What is going on? Preferably I just want to be able to save the image locally, since this program will be running on multiple setups with different pathways to the program.
A program I'm trying to convert from python2 to python3 uses PIL the python image library.
I try to download a thumbnail from the web to display within a tkinter style gui. Here is, what I think, the offending line of code:
# grab the thumbnail jpg.
req = requests.get(video.thumb)
photo = ImageTk.PhotoImage(Image.open(StringIO(req.content)))
# now this is in PhotoImage format can be displayed by Tk.
plabel = tk.Label(tf, image=photo)
plabel.image = photo
plabel.grid(row=0, column=2)
The program stops and gives a TypeError, here is the backtrce:
Traceback (most recent call last): File "/home/kreator/.local/bin/url-launcher.py", line 281, in <module>
main()
File "/home/kreator/.local/bin/url-launcher.py", line 251, in main
runYoutubeDownloader()
File "/home/kreator/.local/bin/url-launcher.py", line 210, in runYoutubeDownloader
photo = ImageTk.PhotoImage(Image.open(StringIO(req.content)))
TypeError: initial_value must be str or None, not bytes
How do I satisfy python3's requirements here?
In this case you can see that the library you have imported doesn't support Python3. This isn't something you can fix from within your own code.
The lack of Python3 support is because PIL has been discontinued for quite some time now. There is a fork that's actively maintained that I would recommend you use instead: https://pillow.readthedocs.io/
You can download it from pypi.