[英]How to open&save a video file in python?
I've just started to make a ubuntu application using PyGtk. 我刚刚开始使用PyGtk制作ubuntu应用程序。 My very first object is to open, convert and then save a video file. 我的第一个对象是打开,转换然后保存视频文件。 Ignoring convert phase, I'm going to implant open-save functions. 忽略转换阶段,我将植入开放保存功能。 But at the moment when I open a video file, and save it, I get non-video file with 11B size. 但是,当我打开视频文件并保存时,我得到的非视频文件的大小为11B。 I've just google this and found OpenCV for python. 我刚刚用谷歌搜索并找到了Python的OpenCV 。 But I'm not sure if it's the best way to do it. 但是我不确定这是否是最好的方法。 I also think I'm going to use ffmpeg libraries to do some manipulates on video files. 我还认为我将使用ffmpeg库对视频文件进行一些操作。 Is it what I want or there might be other built-in libraries? 是我想要的,还是可能有其他内置库?
By the way, here's my code to open and save the file : 顺便说一下,这是我的代码来打开和保存文件:
def on_openFile_clicked(self, widget):
filename=None
dialog = Gtk.FileChooserDialog("Please choose a file", self,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
response = dialog.run()
self.add_filters(dialog)
if response == Gtk.ResponseType.OK:
filename = dialog.get_filename()
elif response == Gtk.ResponseType.CANCEL:
print 'Cancel Clicked'
dialog.destroy()
print "File Choosen: ", filename
def add_filters(self, dialog):
filter_py = Gtk.FileFilter()
filter_py.set_name("Video Files")
filter_py.add_mime_type("video/mp4")
filter_py.add_mime_type("video/x-flv")
dialog.add_filter(filter_py)
filter_any = Gtk.FileFilter()
filter_any.set_name("Any files")
filter_any.add_pattern("*")
dialog.add_filter(filter_any)
def on_saveFile_clicked(self, widget):
filename=None
dialog = Gtk.FileChooserDialog("Please choose a file", self,
Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
response = dialog.run()
self.add_filters(dialog)
if response == Gtk.ResponseType.OK:
filename = dialog.get_filename()
elif response == Gtk.ResponseType.CANCEL:
print 'Cancel Clicked'
dialog.destroy()
if filename != None:
save_file=open(filename, 'w')
save_file.write("Sample Data")
save_file.close()
print "File Saved: ", filename
I think OpenCV is the best way ! 我认为OpenCV是最好的方法! because of its diverse and powerful functions for processing media ! 因为它具有处理媒体的强大功能! and also supports Windows
, Linux
, Mac OS
, iOS
and Android
. 并且还支持Windows
, Linux
, Mac OS
, iOS
和Android
。 OpenCV was designed for computational efficiency and with a strong focus on real-time applications. OpenCV旨在提高计算效率,并且非常关注实时应用程序。 Written in optimized C/C++, the library can take advantage of multi-core processing . 该库以优化的C / C ++语言编写,可以利用多核处理的优势。 you can find many Video Analysis functions in OpenCV ! 您可以在OpenCV中找到许多视频分析功能!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.