利用python+ffmpeg合并B站视频及格式转换的实例代码
程序员文章站
2024-01-09 14:12:46
利用python+ffmpeg合并b站视频及格式转换 b站客户端下载的视频一般有两种格式:早期的多为blv格式(由flv格式转换而来,音视频轨道在同一文件下)。如今的多为m4s格式,音频轨视频轨分开...
利用python+ffmpeg合并b站视频及格式转换 b站客户端下载的视频一般有两种格式:早期的多为blv格式(由flv格式转换而来,音视频轨道在同一文件下)。
如今的多为m4s格式,音频轨视频轨分开 以下为利用ffmpeg简单对文件处理,使其转换为大多数播放器能正常播放的mp4格式 前提:已正常安装ffmpeg
import tkinter as tk from tkinter import filedialog import os import tkinter.messagebox from tkinter import ttk maingui=tk.tk() width = 400 height = 400 screenwidth = maingui.winfo_screenwidth() screenheight = maingui.winfo_screenheight() alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2) maingui.geometry(alignstr) maingui.title("转码系统") def browsedialog(): root = tk.tk() root.withdraw() return filedialog.askopenfilename() def browsedialogto(): path=browsedialog() var.set(path) def browsedialogto2(): path=browsedialog() var2.set(path) def browsedialogtof2(): path=browsedialog() varf2.set(path) def browsedialogtof3(): path=browsedialog() varf3.set(path) def browsedialogtof4(): path=browsedialog() varf4.set(path) tab = ttk.notebook(maingui) frame0 = tk.frame(tab) tab6 = tab.add(frame0, text = "m4s转mp4") frame1 = tk.frame(tab) tab1 = tab.add(frame1, text = "blv,flv转mp4") frame2 = tk.frame(tab) tab2 = tab.add(frame2, text = "提取音频") frame3 = tk.frame(tab) tab3 = tab.add(frame3, text = "音频截取") tab.pack(expand = true, fill = tk.both) #----------------------------------------------------------------------------------------------# l1=tk.label(frame0,text = "请选择视频文件",font=('arial', 15),width=100,height=2) l1.pack() var=tk.stringvar() var.set("") e1 = tk.entry(frame0,textvariable = var, show = none)#显示成明文形式 e1.pack() b1=tk.button(frame0, text='浏览', width=6, height=2, command=browsedialogto) b1.pack() l2=tk.label(frame0,text = "请选择音频文件",font=('arial', 15),width=100,height=2) l2.pack() var2=tk.stringvar() var2.set("") e2 = tk.entry(frame0,textvariable = var2, show = none)#显示成明文形式 e2.pack() b2=tk.button(frame0, text='浏览', width=6, height=2, command=browsedialogto2) b2.pack() l3=tk.label(frame0,text = "请输入新文件命名",font=('arial', 15),width=100,height=2) l3.pack() e3 = tk.entry(frame0, show = none)#显示成明文形式 e3.pack() def mycmd(path1,path2,name): ver=os.popen("ffmpeg -i "+path1+" -i "+path2+" -codec copy "+"c:\\users\\renboyu010214\\desktop\\outputfile\\"+name+".mp4") ver.close() def mycmdmain(): path1=e1.get() path2=e2.get() name=e3.get() mycmd(path1,path2,name) tkinter.messagebox.showinfo(title='success', message="转码成功!") b4=tk.button(frame0, text='确定', width=6, height=2, command=mycmdmain) b4.pack() #----------------------------------------------------------------------------------------------# lf2=tk.label(frame1,text = "请选择blv或flv文件",font=('arial', 15),width=100,height=2) lf2.pack() varf2=tk.stringvar() varf2.set("") ef2 = tk.entry(frame1,textvariable = varf2, show = none)#显示成明文形式 ef2.pack() bf2=tk.button(frame1, text='浏览', width=6, height=2, command=browsedialogtof2) bf2.pack() lf2_1=tk.label(frame1,text = "请输入新文件命名",font=('arial', 15),width=100,height=2) lf2_1.pack() ef2_1 = tk.entry(frame1, show = none)#显示成明文形式 ef2_1.pack() def mycmdmainf2(): path1=ef2.get() name=ef2_1.get() ver=os.popen("ffmpeg -i "+path1+" "+"c:\\users\\renboyu010214\\desktop\\outputfile\\"+name+".mp4") ver.close() tkinter.messagebox.showinfo(title='success', message="转码成功!") bf2=tk.button(frame1, text='确定', width=6, height=2, command=mycmdmainf2) bf2.pack() #----------------------------------------------------------------------------------------------# lf3=tk.label(frame2,text = "请选择视频文件",font=('arial', 15),width=100,height=2) lf3.pack() varf3=tk.stringvar() varf3.set("") ef3 = tk.entry(frame2,textvariable = varf3, show = none)#显示成明文形式 ef3.pack() bf3=tk.button(frame2, text='浏览', width=6, height=2, command=browsedialogtof3)###### bf3.pack() lf3_1=tk.label(frame2,text = "请输入新文件命名",font=('arial', 15),width=100,height=2) lf3_1.pack() ef3_1 = tk.entry(frame2, show = none)#显示成明文形式 ef3_1.pack() def mycmdmainf3(): path1=ef3.get() name=ef3_1.get() ver=os.popen("ffmpeg -i "+path1+" -acodec copy -vn "+"c:\\users\\renboyu010214\\desktop\\outputfile\\"+name+".aac") #ffmpeg -i f:\video\冠世一战.mp4 -acodec copy -vn f:\video\output.aac ver.close() tkinter.messagebox.showinfo(title='success', message="音频提取成功!") bf3=tk.button(frame2, text='确定', width=6, height=2, command=mycmdmainf3) bf3.pack() #----------------------------------------------------------------------------------------------# #----------------------------------------------------------------------------------------------# lf4=tk.label(frame3,text = "请选择音频/视频文件",font=('arial', 15),width=100,height=2) lf4.pack() varf4=tk.stringvar() varf4.set("") ef4 = tk.entry(frame3,textvariable = varf4, show = none)#显示成明文形式 ef4.pack() bf4=tk.button(frame3, text='浏览', width=6, height=2, command=browsedialogtof4)###### bf4.pack() lf4_1=tk.label(frame3,text = "请输入新文件命名(音频后缀.mp3 视频后缀.mp4)",font=('arial', 15),width=100,height=2) lf4_1.pack() ef4_1 = tk.entry(frame3, show = none)#显示成明文形式 ef4_1.pack() lf4_2=tk.label(frame3,text = "请输入开始时间(xx:xx:xx)",font=('arial', 15),width=100,height=2) lf4_2.pack() ef4_2 = tk.entry(frame3, show = none)#显示成明文形式 ef4_2.pack() lf4_3=tk.label(frame3,text = "请输入截取时间(xx:xx:xx)",font=('arial', 15),width=100,height=2) lf4_3.pack() ef4_3 = tk.entry(frame3, show = none)#显示成明文形式 ef4_3.pack() def mycmdmainf4(): path1=ef4.get() name=ef4_1.get() starttime=ef4_2.get() time=ef4_3.get() ver=os.popen("ffmpeg -ss "+starttime+" -t "+time+" -i "+path1+" -vcodec copy -acodec copy "+"c:\\users\\renboyu010214\\desktop\\outputfile\\"+name) #ffmpeg -ss 00:00:00 -t 00:00:05 -i input.mp4 -vcodec copy -acodec copy output.mp4 ver.close() tkinter.messagebox.showinfo(title='success', message="音频/视频截取成功!") bf4=tk.button(frame3, text='确定', width=6, height=2, command=mycmdmainf4) bf4.pack() #----------------------------------------------------------------------------------------------# maingui.mainloop()
到此这篇关于利用python+ffmpeg合并b站视频及格式转换的实例代码的文章就介绍到这了,更多相关python+ffmpeg合并b站视频及格式转换内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!