欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用VScode+QTdesigner写界面小程序-实现音频和视频的分离;

程序员文章站 2022-06-14 13:03:32
...

使用VScode+QTdesigner写界面小程序-实现音频和视频的分离;

使用python开发的一款小程序

使用anaconda下的文件 Qtdesigner.exe文件打开然后通过拖拽,把UI界面文件保存下来

然后用VScode打开;
安装 PYQT Integration 然后右键点击UI文件即可将其解析成为python代码进行修改;

大概的效果见下图

把文件拖到那个框框里面点击开始转换,就会在你视频的目录下面生成一个MP3文件(只能转换格式为mp4的视频)
使用VScode+QTdesigner写界面小程序-实现音频和视频的分离;

##界面文件Ui_mainw.py

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'c:\Users\cultivator\Desktop\audio_linger\mainw.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QPushButton, QMessageBox
import PyQt5.QtWidgets as qw
import sou
class Ui_audiolinger(object):
    def setupUi(self, audiolinger):
        audiolinger.setObjectName("audiolinger")
        audiolinger.resize(863, 453)
        audiolinger.setStyleSheet("#audiolinger{\n"
"background-image:url(C:/Users/cultivator/Desktop/audio_linger/main_image.jpg)\n"
"}")
        self.centralwidget = QtWidgets.QWidget(audiolinger)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(768, 780, 150, 46))
        self.pushButton.setObjectName("pushButton")
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(590, 200, 512, 512))
        self.textEdit.setStyleSheet("#textEdit{\n"
"background-image:url(C:/Users/cultivator/Desktop/audio_linger/1.jpg)\n"
"}")
        self.textEdit.setObjectName("textEdit")
        audiolinger.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(audiolinger)
        self.statusbar.setObjectName("statusbar")
        audiolinger.setStatusBar(self.statusbar)
        self.retranslateUi(audiolinger)
        QtCore.QMetaObject.connectSlotsByName(audiolinger)

    def retranslateUi(self, audiolinger):
        _translate = QtCore.QCoreApplication.translate
        audiolinger.setWindowTitle(_translate("audiolinger", "MainWindow"))
        self.pushButton.setText(_translate("audiolinger", "开始转换"))
    def solve(self):
        source_path=self.textEdit.toPlainText()   #搜先获取文件的原始路径
        #解析路径
        path=sou.exppath(source_path)
        if(path!=None and path.endswith(".mp4")):
            sou.explict(path)
        else:
            qw.QMessageBox.Critical(self,"错误","请检查文件格式是否为MP4!!")
            sys.exit(app.exec_())

if __name__ == "__main__":    
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_audiolinger()
    ui.setupUi(MainWindow)
    MainWindow.setWindowTitle("audio linger")
    MainWindow.setFixedSize(2*MainWindow.width(),2*MainWindow.height())
    MainWindow.show()
    ui.pushButton.clicked.connect(ui.solve)
    sys.exit(app.exec_())

后台文件sou.py

import time
from moviepy.editor import *
import PyQt5.QtWidgets as qw
#st = time.time()
def explict(video_path):
    audio_path = video_path.strip(".mp4")+".wav"
    video =VideoFileClip(video_path)
    audio =video.audio
    audio.write_audiofile(audio_path)
    qw.QMessageBox.Critical(self,"错误","请检查文件格式是否为MP4!!")
def exppath(source_path): #解析路径的函数
    str=source_path.strip("file:///")
    return str
#print("消耗时间:{}".format(time.time()-st))

相关标签: python