MP4文件分析-python-1


最近項目需要,想做個對mp4文件進行解析的工具。

雖然已經有很多開源/收費的分析工具,如eseye等,但還是想做個自己的;一方面學習學習python,使用python寫該工具(貌似沒看到有python做的),另一方面,也是方便定制維護,要自己想要的功能,測試不太需要的就不做進去了。

自己是個python菜鳥,對這個工具僅有個基本的思路:

1、可分析mp4文件,具體包括分辨率、幀率、碼率、碼率類型、I幀間隔、時間戳等。

2、python代碼編寫,有GUI,可以彈窗選mp4文件。

3、文本輸出mp4文件分析情況、單幀分析情況等。

暫時考慮到的大的方面僅這些吧。

 

簡單了解了一下,整個mp4文件分析還是要花較大精力和時間的,現在還在一邊看mp4文件格式,另一方面考慮可不可以借助已有的分析庫。

了解的不多,這個邊看邊學習考慮吧。先把基本環節配置起來。

1、python27,編譯環境eclipse

2、GUI看了下,常用的有Tkinter,還有PyQt

就用PyQt試試

1、安裝python27,比較簡單,eclipse直接使用解壓版的。

2、安裝pyQt4,有exe文件,也比較簡單。

3、看教程,寫個簡單的GUI,了解一下PyQt的方法

from:http://www.linuxidc.com/Linux/2012-06/63652p2.htm 

實現代碼如下:

  1. # -*- coding: utf-8 -*-   
  2. from PyQt4.QtGui import *  
  3. from PyQt4.QtCore import *  
  4. import sys  
  5.   
  6. QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))  
  7.   
  8. class StandardDialog(QDialog):  
  9.   
  10.     def __init__(self,parent=None):  
  11.         super(StandardDialog,self).__init__(parent)  
  12.           
  13.         self.setWindowTitle("Standard Dialog")  
  14.           
  15.         filePushButton=QPushButton(self.tr("文件對話框"))  
  16.         colorPushButton=QPushButton(self.tr("顏色對話框"))  
  17.         fontPushButton=QPushButton(self.tr("字體對話框"))  
  18.   
  19.         self.fileLineEdit=QLineEdit()  
  20.         self.colorFrame=QFrame()  
  21.         self.colorFrame.setFrameShape(QFrame.Box)  
  22.         self.colorFrame.setAutoFillBackground(True)  
  23.         self.fontLineEdit=QLineEdit("Hello World!")  
  24.   
  25.         layout=QGridLayout()  
  26.         layout.addWidget(filePushButton,0,0)  
  27.         layout.addWidget(self.fileLineEdit,0,1)  
  28.         layout.addWidget(colorPushButton,1,0)  
  29.         layout.addWidget(self.colorFrame,1,1)  
  30.         layout.addWidget(fontPushButton,2,0)  
  31.         layout.addWidget(self.fontLineEdit,2,1)  
  32.   
  33.         self.setLayout(layout)  
  34.   
  35.         self.connect(filePushButton,SIGNAL("clicked()"),self.openFile)  
  36.         self.connect(colorPushButton,SIGNAL("clicked()"),self.openColor)  
  37.         self.connect(fontPushButton,SIGNAL("clicked()"),self.openFont)  
  38.   
  39.     def openFile(self):  
  40.           
  41.         s=QFileDialog.getOpenFileName(self,"Open file dialog","/","Python files(*.py)")  
  42.         self.fileLineEdit.setText(str(s))  
  43.   
  44.     def openColor(self):  
  45.   
  46.         c=QColorDialog.getColor(Qt.blue)  
  47.         if c.isValid():  
  48.             self.colorFrame.setPalette(QPalette(c))  
  49.   
  50.     def openFont(self):  
  51.      
  52.         f,ok=QFontDialog.getFont()  
  53.         if ok:  
  54.             self.fontLineEdit.setFont(f)  
  55.   
  56. app=QApplication(sys.argv)  
  57. form=StandardDialog()  
  58. form.show()  
  59. app.exec_() 

運行成功,沒什么問題

4、GUI生成exe

上述代碼可以運行成功,但是如何生成exe文件呢。

百度了一下,常用py2exe和pyinstaller。

py2exe安裝了一下,生成后無法運行,提示需要安裝sip,安裝sip時,需要minGW,放棄之。。

pyinstaller安裝比較簡單,需要安裝pywin32,安裝成功后,python pyinstaller.py -w pyQ.py,在生成的dist文件夾中找到pyQ.exe,運行成功。

 

先記錄這些。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM