hook-gi.repository.Gst.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. """
  12. Import hook for Gst(GStreamer) http://gstreamer.freedesktop.org/ introspected through
  13. PyGobject https://wiki.gnome.org/PyGObject via the GObject Introspection middleware
  14. layer https://wiki.gnome.org/Projects/GObjectIntrospection
  15. Tested with GStreamer 1.4.5, gst-python 1.4.0, PyGObject 3.16.2, and GObject Introspection 1.44.0 on Mac OS X 10.10 and
  16. GStreamer 1.4.5, gst-python 1.4.0, PyGObject 3.14.0, and GObject Introspection 1.42 on Windows 7
  17. """
  18. # GStreamer contains a lot of plugins. We need to collect them and bundle them wih the exe file.
  19. # We also need to resolve binary dependencies of these GStreamer plugins.
  20. import glob
  21. import os
  22. from PyInstaller.utils.hooks import exec_statement, get_hook_config
  23. from PyInstaller.utils.hooks.gi import collect_glib_share_files, \
  24. collect_glib_translations, get_gi_typelibs
  25. binaries, datas, hiddenimports = get_gi_typelibs('Gst', '1.0')
  26. datas += collect_glib_share_files('gstreamer-1.0')
  27. hiddenimports += ["gi.repository.Gio"]
  28. def hook(hook_api):
  29. hook_datas = []
  30. lang_list = get_hook_config(hook_api, "gi", "languages")
  31. for prog in ['gst-plugins-bad-1.0',
  32. 'gst-plugins-base-1.0',
  33. 'gst-plugins-good-1.0',
  34. 'gst-plugins-ugly-1.0',
  35. 'gstreamer-1.0']:
  36. hook_datas += collect_glib_translations(prog, lang_list)
  37. hook_api.add_datas(hook_datas)
  38. statement = """
  39. import os
  40. import gi
  41. gi.require_version('Gst', '1.0')
  42. from gi.repository import Gst
  43. Gst.init(None)
  44. reg = Gst.Registry.get()
  45. plug = reg.find_plugin('coreelements')
  46. path = plug.get_filename()
  47. print(os.path.dirname(path))
  48. """
  49. plugin_path = exec_statement(statement)
  50. # Use a pattern of libgst* since all GStreamer plugins that conform to GStreamer standards start with libgst
  51. # and we may have mixed plugin extensions, e.g., .so and .dylib.
  52. for pattern in ['libgst*.dll', 'libgst*.dylib', 'libgst*.so']:
  53. pattern = os.path.join(plugin_path, pattern)
  54. binaries += [(f, os.path.join('gst_plugins')) for f in glob.glob(pattern)]