9 comments

  • amelius 13 minutes ago
    > 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())
  • fireattack 1 hour ago
    > 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 )

  • Simon_O_Rourke 4 hours ago
    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.
  • alabhyajindal 13 hours ago
    I learned Python from your Udemy course of the same name. Congrats on the new edition of the book!
  • cortical_iv 9 hours ago
    I'm curious why you didn't end up including this material?
    • globalnode 6 hours ago
      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?
  • analog31 8 hours ago
    This is fantastic. I've gotten so much out of cv2 and Python, and just a perusal of the page suggests that there's lots more to learn.
  • bix6 12 hours ago
    One of my favorite programming books of all times. Cheers Al!
  • geophph 9 hours ago
    And a transit nerd supporter!
  • xbmcuser 7 hours ago
    I was never able to get my head around programing despite my interest over the years. But LLM and python scripts in the last 3-4 years have changed my life.
    • ymck 6 hours ago
      What thing have you found most interesting or impactful for you?