Lost Chapter of Automate the Boring Stuff: Audio, Video, and Webcams in Python
(inventwithpython.com)205 points by AlSweigart a day ago
205 points by AlSweigart a day ago
I guess it depends on the context? For example panda3d supports openAL, FMOD and Miles.
Oh, thanks for pointing this out. This was an early unpublished draft. I later changed to `playsound3` which is a modern fork of `playsound`. I've updated the web page.
This author is an apologist for the slander of Tim Peters:
https://www.reddit.com/r/Python/comments/1f00qdo/no_vote_of_...
He cites Glyph Lefkowitz to support him, who now gives advice on lunch vs. dinner networking strategies at PyCons. Which should be taken seriously: Being in the right circles and talking is all that matters in the Python ecosystem.
> Playing a video file from your Python program is complicated.
You can use PySide6. Here is an example:
import sys
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout
from PySide6.QtMultimedia import QMediaPlayer, QAudioOutput
from PySide6.QtMultimediaWidgets import QVideoWidget
from PySide6.QtCore import QUrl
class VideoPlayer(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Video Player - video.mp4")
self.resize(800, 600)
# Layout
layout = QVBoxLayout()
self.setLayout(layout)
# Video widget
self.video_widget = QVideoWidget()
layout.addWidget(self.video_widget)
# Media player
self.media_player = QMediaPlayer(self)
self.audio_output = QAudioOutput(self)
self.media_player.setAudioOutput(self.audio_output)
self.media_player.setVideoOutput(self.video_widget)
# Load video file
self.media_player.setSource(QUrl.fromLocalFile("video.mp4"))
self.media_player.play()
if __name__ == "__main__":
app = QApplication(sys.argv)
player = VideoPlayer()
player.show()
sys.exit(app.exec())
I learned Python from your Udemy course of the same name. Congrats on the new edition of the book!
I know I've been saying this for years, but I seriously will get around to updating the videos in the Udemy course this year.
As others here have already said, thank you for your book, and for having it for free on your website. After years of thinking about leraning to program, I finally started with you book a couple of years ago. It is so much fun, and it's been super helpful on my day to day job.
Love it, that's where I direct all our new hires who want to pick up the basics of Python. I'll be reading this chapter myself this weekend too.
I'm curious why you didn't end up including this material?
Page count. Automate the Boring Stuff with Python is supposed to be a beginner book for people with no coding experience, but it's almost 600 pages. The biggest hurdle to coding isn't being "smart" enough, but rather getting over the intimidation factor.
The editor recommended we cut this chapter. It made me realize that even though I work with multimedia stuff all the time, this isn't really something most office workers do (at least, not at the scale where you'd want to write Python scripts).
A lot of teaching people to code is hiding details so you don't fire hose them with information they don't need yet. So many software nerds don't get this, and they're excited about all these cool advanced techniques without realizing that beginners don't need to know about recursion or operator overloading. (I completely skip OOP in the book.)
When I saw yt-dlp I thought "risky", wasn't there was a lot of complaining from YT back in the day about this programs predecessor?
Hello, this is Al. Ha ha, I'm always surprised when people spot my name in supporter credits. Here's a (very out of date) web page of other folks I support: https://alsweigart.com/patreon.html
> playsound
This library is unfortunately effectively abandoned -- it hasn’t received any updates in over four years, and its latest version doesn’t work at all: https://github.com/TaylorSMarks/playsound/issues/101
(A workaround exists: downgrading to version 1.2.2, but that comes with its own issues.)
The last time I experimented with audio in Python, I was surprised by how lacking its multimedia libraries are.
For example, when I needed to read audio files as data, I tried `SoundFile`, `librosa` (a wrapper around `SoundFile` or `audioread`), and `pydub`, and none of them was particularly satisfying or has seen much active development lately.
If you need to read various formats, pydub is probably your best bet (it does this by invoking ffmpeg under the hood). I was hoping for a more "native" solution, but oh well. Unfortunately, `pydub` is also unmaintained and has some serious performance issues (for example: https://github.com/jiaaro/pydub/issues/518 )