hook-gi.repository.Gst.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 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. We also need to resolve
  19. # 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, collect_glib_translations, get_gi_typelibs)
  24. binaries, datas, hiddenimports = get_gi_typelibs('Gst', '1.0')
  25. datas += collect_glib_share_files('gstreamer-1.0')
  26. hiddenimports += ["gi.repository.Gio"]
  27. def hook(hook_api):
  28. hook_datas = []
  29. lang_list = get_hook_config(hook_api, "gi", "languages")
  30. for prog in [
  31. '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. ]:
  37. hook_datas += collect_glib_translations(prog, lang_list)
  38. hook_api.add_datas(hook_datas)
  39. statement = """
  40. import os
  41. import gi
  42. gi.require_version('Gst', '1.0')
  43. from gi.repository import Gst
  44. Gst.init(None)
  45. reg = Gst.Registry.get()
  46. plug = reg.find_plugin('coreelements')
  47. path = plug.get_filename()
  48. print(os.path.dirname(path))
  49. """
  50. plugin_path = exec_statement(statement)
  51. # Use a pattern of libgst* as all GStreamer plugins that conform to GStreamer standards start with libgst, and we may
  52. # have mixed plugin extensions, e.g., .so and .dylib.
  53. for pattern in ['libgst*.dll', 'libgst*.dylib', 'libgst*.so']:
  54. pattern = os.path.join(plugin_path, pattern)
  55. binaries += [(f, os.path.join('gst_plugins')) for f in glob.glob(pattern)]