LibVlc can't be used in Qt Frame in Python - python

So I'm trying to embed a few VLC media players into their separate QTFrames. Everything is done in python. However for some reason the official example doesn't want to work (found here)
My code looks like this:
for files in tutorialVideoFiles:
#frame = QFrame()
mediaplayer = vlcInstance.media_player_new() #create media player
media = vlcInstance.media_new(mainTutorialDirectory + "/" + self.tutorialName + "/" + files) #load video file
mediaplayer.set_media(media) #assign video file
media.parse()
self.mediaplayers.append(mediaplayer)
#mediaplayer.set_hwnd(frame.winId())
If I uncomment the lines, I get the following error:
"directdraw vout display error: Win32VoutCreateWindow RegisterClass FAILED (err=1410)"
I'm using Windows 64 bit and Python 3.6

Related

ImageMagick problem on Windows 10 with Windows 2 error code

I want to make a python script to create a video with moviepy but I have some problems with windows. I tried installing ImageMagick but can not find a convert.exe I do not know why it is. But I am already stuck.
my code:
import moviepy.editor as mp
import os
print("Start")
def create_vertical_video(image_file, music_file, quote):
# Open image and resize to 9:16 aspect ratio (vertical video)
if not os.path.isfile(image_file):
raise ValueError(f"{image_file} is not a valid file path")
image = mp.ImageClip(image_file).resize(height=1080)
# Open music file and set to fit the duration of the image
if not os.path.isfile(music_file):
raise ValueError(f"{music_file} is not a valid file path")
music = mp.AudioFileClip(music_file)
music = music.set_duration(image.duration)
# Split quote into multiple lines if necessary
MAX_CHARS_PER_LINE = 25
lines = []
current_line = ""
for word in quote.split():
if len(current_line) + len(word) <= MAX_CHARS_PER_LINE:
current_line += word + " "
else:
lines.append(current_line.strip())
current_line = word + " "
lines.append(current_line.strip())
# Create text clip for each line
text_clips = [mp.TextClip(line, fontsize=24, color='white', bg_color='black')
.set_pos('center').set_duration(image.duration)
for line in lines]
# Overlay text clips on image
text_overlay = mp.concatenate_videoclips(text_clips, method='compose')
final_clip = mp.CompositeVideoClip([image, text_overlay])
# Add music to final clip
final_clip = final_clip.set_audio(music)
# Save video
final_clip.write_videofile("vertical_video.mp4", fps=24)
create_vertical_video("nature.jpg","music.mp3","Don't be pushed around by the fears in your mind. Be led by the dreams in your heart.")
my error:
[WinError 2] The system cannot find the file specified.
.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect`
In ImageMagick v7, the convert.exe program is replaced by magick.exe.
So if your Python script is looking for convert.exe, you must click "Install legacy commands" when installing ImageMagick.

MoviePy Audio doesn't exist on iPhone

I have produced a video using MoviePy and the audio works perfectly fine on PC, but when I try watch it on iPhone it has no audio. I played the uploaded clip on my PC too so it's not the platform where the video is. Also got a friend to listen on iPhone and it also has no audio so not my device. Edit: also tried playing on samsung tablet (android) and it also plays the audio fine.
This is the outputted video files properties:
This is my code:
from moviepy.editor import ImageClip, AudioFileClip, VideoFileClip, CompositeVideoClip
clips = [] # list of clips to be composited
current_duration = 0 # how long the total clip is
bg = VideoFileClip("background.MOV", audio=False) # remove audio from the background
title_audio = AudioFileClip("audio/title.mp3") # title audio
title_clip = ImageClip("screenshots/post.png", duration=title_audio.duration).set_audio(title_audio) # image + audio
clips.append(title_clip.resize(width=bg.w).set_position("center")) # append the resized centred clip
current_duration += title_audio.duration # increase the duration
# loop through clips 1-5 doing the same thing
for comment in range(1, 6):
com_audio = AudioFileClip("audio/voice" + str(comment) + ".mp3")
com_clip = ImageClip("screenshots/comment" + str(comment) + ".png", duration=com_audio.duration).set_audio(com_audio)
clips.append(com_clip.set_start(current_duration).resize(width=bg.w).set_position("center")) # start at current end
current_duration += com_audio.duration
final = CompositeVideoClip([bg.subclip(0, current_duration)] + clips) # composite the clips on top of the background
final.write_videofile("test.mp4", fps=24) # output the file
Based on this, you produced a video file that's (probably) h264/mp3, which isn't a supported format for iPhone - your video file needs to be h264/aac to work on iPhones (and probably any Mac device via Quicktime).
This is also an open issue for moviepy: https://github.com/Zulko/moviepy/issues/1709
You can specify an audio_codec when writing your file to make this work:
final.write_videofile("test.mp4", fps=24, audio_codec='aac') # output the file

Errno 5 Input/output error when closing console

I have a video converter which is converting audio and video files. Everything works but if I close my terminal from my server the audio file convert doesnt work anymore. I use PyTube for converting and moviepy for converting the mp4 from pytube into mp3. (I think the problem has something to do with moviepy bc. before I didnt have it.)
This is my code for converting audio:
if format == "3":
yt = YouTube(videolink)
downloads = MEDIA_ROOT + "/videos/"
ys = yt.streams.filter(file_extension='mp4').first().download(downloads)
base, ext = os.path.splitext(ys)
basename = os.path.basename(base + uuid + '.mp3')
videoclip = VideoFileClip(ys)
audioclip = videoclip.audio
audioclip.write_audiofile(base + uuid + ".mp3")
audioclip.close()
videoclip.close()
maybe something with the os code is wrong.
But I cant figure out why it works if I leave the console open.
Im thankful for every help I get.
So I found the solution, for everyone who faces the same problem. You have to disable the console output in moviepy. You can do the with the logger parameter in the "write" function. Then the error should disappear.

AWS Lambda, Python, and Plotly: Generating SVG via plotly.offline.plot() doesn't seem to work

I'm trying to output SVG from AWS Lambda using plotly's plot() method. This works in a local environment but seems to fail in Lambda.
The block of code:
downloadRootFolder = "/tmp/" # Lambda's write directory is /tmp. Other directories will deny access
aFilename = "py_chart_" + uuid.uuid1().hex
plotly.offline.plot(chart,
output_type = "file",
filename = downloadRootFolder + aFilename + ".html", # /tmp/py_chart_UUID.html
image_filename = downloadRootFolder + aFilename, # /tmp/py_chart_UUID
image = "svg", image_width = w, # defined earlier
image_height = h)
myFilename = aFilename + ".svg"
svgText = "<svg>could not find the svg file!</svg>"
maxAttempts = 20
millisecsToWait = 250
print(os.listdir("/tmp/")) # output: ['py_chart_380ac7b4fcf411e9b6c0d273169078fd.html'] (no .svg file)
for c in range(0,maxAttempts):
if os.path.exists(downloadRootFolder + myFilename):
f = open(downloadRootFolder + myFilename,"r")
svgText = f.read()
f.close()
else:
time.sleep(millisecsToWait/1000)
print("look for saved svg file attempt # " + str(c))
return(svgText) # returns "could not find the svg file!"
My understanding of the above code, which I did not write, is that plotly generates SVG by first creating an html with executable JS, which then downloads the html as SVG. We try to open the html file to download SVG, but have to wait and retry several times in case it is taking time. (If you know a better way to do it, please let me know.)
On the print(os.listdir) line, you'll notice the html exists, but either A) The SVG is not being generated, or B) if it is generated, it is written by plotly to some weird directory.
Questions:
1) How do I control the directory plotly.offline.plot() writes SVG to?
2) Where is it attempting to write to on CentOS by default? It's possible it is trying and failing to write there due to Lambda permissions.
3) Is there a "downloads" folder on Lambda outside of /tmp/ that I could check?
4) Is there some other reason Lambda may be failing to export the SVG - for example, unable to open HTML files or unable to loaded embedded JS.
5) Where could I look to further debug this problem?
Appreciate any insight you may have here.
Have you tried plotly.io.write_image? Or something like fig.write_image("images/fig1.svg")
The Plotly docs describe Static Image Export here: https://plot.ly/python/v3/offline/
Basically, convert a figure into image bytes then write to a file.
import plotly.io as pio
static_image_bytes = pio.to_image(fig, format='png')
pio.write_image(fig, file='plotly_static_image.png', format='png')

Doing a download with easywebdav results in bad files

I have a small program I created to download image files form a FlashAir webdav enabled SD Card. This works fine with Powershell but trying a Python implementation.
I have it working where easywebdav can download the file but the resulting size is 22Kb which is wrong and windows does not recognize them as a valid file.
I have applied a basestring fix to the client.py for handling Python 3.x instead of 2.x found here How to overcome Python 3.4 NameError: name 'basestring' is not defined.
I'm on Python 3.5.1.
import easywebdav
urlFlashAir = 'http://flashair'
imgLocation = '/DCIM/101MSDCF'
destLocation = 'c:\\test3\\'
remoteDirName = ''
webDavConnection = easywebdav.connect('flashair', '', '')
lsOutput = webDavConnection.ls(imgLocation)
for i in lsOutput:
if i.size == 0:
remoteDirName = i.name
if i.size > 0:
filename = (i.name).replace(remoteDirName,'')
print(i.name)
print(remoteDirName)
print(filename)
webDavConnection.download(imgLocation, destLocation + filename)
I inspected the 22KB article with notepad++ and found that it was a web page for the flashair card. Upon investigation of the code and documentation I found I was not referencing the remote filename just the location. Once I fixed the code to append a forward slash and a filename. Now properly downloads the file.

Categories

Resources