在这篇博客中,我们将深入探讨一个使用Python和wxPython构建的音频/视频提取器应用程序。这个应用程序允许用户从视频文件中提取音频,或者从音频文件中截取特定时间段。让我们逐步分析这个程序的功能和实现。
C:\pythoncode\new\MP3towav.py
全部代码
import wx
import os
import subprocess
from datetime import datetime
import json
from moviepy.editor import VideoFileClip, AudioFileClip
class AudioVideoExtractor(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='Audio/Video Extractor')
self.panel = wx.Panel(self)
self.create_widgets()
self.load_settings()
def create_widgets(self):
# File selection
self.file_picker = wx.FilePickerCtrl(self.panel, message="Choose an audio or video file")
# Time range
self.start_time = wx.TextCtrl(self.panel, value="00:00:00")
self.end_time = wx.TextCtrl(self.panel, value="00:00:00")
# Output format
self.formats = ['mp3', 'wav', 'aac']
self.format_choice = wx.Choice(self.panel, choices=self.formats)
# Output directory
self.dir_picker = wx.DirPickerCtrl(self.panel, message="Choose output directory")
# Export button
self.export_btn = wx.Button(self.panel, label="Export")
self.export_btn.Bind(wx.EVT_BUTTON, self.on_export)
# Open button
self.open_btn = wx.Button(self.panel, label="Open in PotPlayer")
self.open_btn.Bind(wx.EVT_BUTTON, self.on_open)
# Layout
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(wx.StaticText(self.panel, label="Select Audio or Video File:"), 0, wx.ALL, 5)
sizer.Add(self.file_picker, 0, wx.EXPAND|wx.ALL, 5)
sizer.Add(wx.StaticText(self.panel, label="Start Time (HH:MM:SS):"), 0, wx.ALL, 5)
sizer.Add(self.start_time, 0, wx.EXPAND|wx.ALL, 5)
sizer.Add(wx.StaticText(self.panel, label="End Time (HH:MM:SS):"), 0, wx.ALL, 5)
sizer.Add(self.end_time, 0, wx.EXPAND|wx.ALL, 5)
sizer.Add(wx.StaticText(self.panel, label="Output Format:"), 0, wx.ALL, 5)
sizer.Add(self.format_choice, 0, wx.EXPAND|wx.ALL, 5)
sizer.Add(wx.StaticText(self.panel, label="Output Directory:"), 0, wx.ALL, 5)
sizer

最低0.47元/天 解锁文章
3630

被折叠的 条评论
为什么被折叠?



