awslabs / aws-streamer

Video Processing for AWS
Apache License 2.0
44 stars 9 forks source link

Failed to make element sink of type kvssink #4

Closed Omar-Turkmani closed 3 years ago

Omar-Turkmani commented 3 years ago

Hi First, thank you for this great work

I was trying to stream from my laptop camera to KVS using following SDK code :

`import awstreamer

client = awstreamer.client()
client.start({
    "pipeline": {
        "source": "v4l2src",
        "videoconvert": "videoconvert",
        "source_filter": "capsfilter",
        "encoder": "x264enc",
        "encoder_filter": "capsfilter",
        "sink": "kvssink"
    },
    "source": {
        "device": "/dev/video0"
    },
    "source_filter": {
        "caps": "video/x-raw,framerate=10/1,format=I420"
    },
    "encoder": {
        "bframes": 0,
        "key-int-max": 40,
        "bitrate": 500
    },
    "encoder_filter": {
        "caps": "video/x-h264,stream-format=avc,alignment=au,profile=baseline"
    },
    "sink": {
        "name": "kvssink",
        "stream-name": "TestStream"
    },
    "debug": True
})`

Got this error " Failed to make element sink of type kvssink " I tried to show stream on autovideosink and it worked correctly

So, is there anything missing ? or any problem on my installation ? or still this sink is not supported yet ?

Thanks in advance

bpawlik commented 3 years ago

Hi Omar,

Error shows that kvssink plug-in was not found. Have you built it? You can do that with:

./build.sh -DBUILD_KVS=ON

Let me know if that helps.

Omar-Turkmani commented 3 years ago

Thanks for your response Yes I've built it Is there any way to test if it built correctly or not ?

bpawlik commented 3 years ago

Did you see any errors in the console during the build? Upon success, you should see KVS libraries in the build folder: build/awstreamer_py/gst_plugins/kvs. File extensions depend on the OS, but you should see libgstkvssink. and libKinesisVideoProducer. files there.

If the files are there, check if they can be loaded with gst-inspect-1.0: GST_PLUGIN_PATH=build/awstreamer_py/gst_plugins/kvs gst-inspect-1.0 kvssink

If files are missing then it means that KVS build didn't go well. Try cleaning the repo git clean -d -f -f -x and building again. For resolving KVS build errors, check this link: https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp

Omar-Turkmani commented 3 years ago

I'm really appreciate your time

I've checked all these steps, KVS libraries are existed and can be loaded. anyway I tried to set GST_PLUGIN_PATH environment variable to "build/awstreamer_py/gst_plugins/kvs" directory inside my code and it is working . but if I export it from terminal it didn't work.

I've already "amazon-kinesis-video-streams-producer-sdk-cpp" downloaded before, so is this effect ? and isn't it supposed that set_env_variables method is responsible to set this variable when using the client ? Also if I want to use sdk in greengrass lambda how I can embed it with lambda package ?

bpawlik commented 3 years ago

I've commented on this issue immediately from phone, but apparently the comment went nowhere, apologies for that!

I think I know what went wrong for you: apparently you are importing awstreamer from source dir and not from the build dir. Please take a look at examples/ folder after the build, you will see that each subfolder contains compiled awstreamer in it. E.g. take a look at examples/test_app/app.py - import awstreamer imports the library from the current directory and not from the source dir.

As for greengrass, you can just zip the folder content with awstreamer folder and your lambda. Please have a look at examples/greengrass for a full-blown example including CloudFormation template.

Let me know if that helps!

Omar-Turkmani commented 3 years ago

No worries, I got your point now I have the following error :

Traceback (most recent call last): File "streamer.py", line 3, in <module> client = awstreamer.client() File "/home/baseet/videoStreamer/awsStreamer/awstreamer/client.py", line 11, in client from .gst_pipeline.stream_client import StreamClient as Client File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/stream_client.py", line 22, in <module> from gi.repository import GObject, Gst, GLib File "/home/baseet/.local/lib/python3.7/site-packages/gi/importer.py", line 145, in load_module dynamic_module = load_overrides(introspection_module) File "/home/baseet/.local/lib/python3.7/site-packages/gi/overrides/__init__.py", line 118, in load_overrides override_mod = importlib.import_module(override_package_name) File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/usr/lib/python3/dist-packages/gi/overrides/Gst.py", line 569, in <module> from . import _gi_gst ImportError: cannot import name '_gi_gst' from 'gi.overrides' (/home/baseet/.local/lib/python3.7/site-packages/gi/overrides/__init__.py)

bpawlik commented 3 years ago

Never seen this error. Did you install OS packages mentioned in the README?

You might have some python versioning / packages issues according to this thread: https://stackoverflow.com/questions/59838238/importerror-cannot-import-name-gi-from-partially-initialized-module-gi-mo

bpawlik commented 3 years ago

What is the folder structure from which you execute the script? It should be something like this:

. ├── [your_script].py └── awstreamer ├── init.py ├── client.py ├── gst_configurer │   ├── README.md │   ├── init.py │   ├── configurer_client.py │   └── templates │   ├── init.py │   ├── index.html │   ├── new_config.json │   └── new_request.json ├── gst_metadata │   ├── init.py │   └── gst_objects_info_meta.py ├── gst_pipeline │   ├── init.py │   ├── appsrc_pipeline.py │   ├── cmd_pipeline.py │   ├── cv_pipeline.py │   ├── ds_pipeline.py │   ├── dvr_pipeline.py │   ├── pipeline_factory.py │   ├── stream_client.py │   ├── stream_config.py │   ├── stream_graph.py │   ├── stream_pipeline.py │   └── video_pipeline.py ├── gst_plugins │   ├── kvs │   │   ├── libKinesisVideoProducer.dylib │   │   └── libgstkvssink.so │   └── python │   ├── gaussian_blur.py │   ├── metadata_test.py │   ├── neodlr.py │   └── osd.py ├── gst_viewer │   ├── README.md │   ├── init.py │   ├── templates │   │   ├── init.py │   │   └── index.html │   └── viewer_client.py └── utils ├── init.py ├── aws.py ├── gst.py ├── gst_hacks.py ├── plugin.py └── video.py

Package should internally set the GST_PLUGIN_PATH to the kvs binaries. If you still get the error, first check that kvs plug-in is built correctly:

GST_PLUGIN_PATH=awstreamer/gst_plugins/kvs gst-inspect-1.0 kvssink

Then execute your script this way:

GST_PLUGIN_PATH=awstreamer/gst_plugins/kvs python3 your_script.py

bpawlik commented 3 years ago

This is exactly what I was talking about before, it looks like a source repository and not the output build. You can only use python scripts if you import from source dir, must import from build dir in order to have binaries in it.

Omar-Turkmani commented 3 years ago

Sorry it was an old project This is what the folder contain
Screenshot from 2021-04-29 15-34-14

regards of the second point : "I noticed that gstreamer-1.0 is installed on /usr/lib/x86_64-linux-gnu/ instead of /usr/lib/ , is this effect ?" and is this folder should contain kvs binaries ?

bpawlik commented 3 years ago

You would get this kind of warning if that was the case: "libgstreamer-1.0 not found! Please export LIB_GSTREAMER_PATH env var manually."

Otherwise it’s not the case here. You can set LIB_GSTREAMER_PATH if you want to be double sure.

bpawlik commented 3 years ago

And yes, content of the folder above looks very correct, meaning that KVS plug-in build went without errors. What's the output of GST_PLUGIN_PATH=awstreamer/gst_plugins/kvs gst-inspect-1.0 kvssink?

Omar-Turkmani commented 3 years ago

The output

`kvs gst-inspect-1.0 kvssink
Factory Details:
  Rank                     primary + 10 (266)
  Long-name                KVS Sink
  Klass                    Sink/Video/Network
  Description              GStreamer AWS KVS plugin
  Author                   AWS KVS <kinesis-video-support@amazon.com>

Plugin Details:
  Name                     kvssink
  Description              GStreamer AWS KVS plugin
  Filename                 awstreamer/gst_plugins/kvs/libgstkvssink.so
  Version                  1.0
  License                  Proprietary
  Source module            kvssinkpackage
  Binary package           GStreamer
  Origin URL               http://gstreamer.net/

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstKvsSink

Pad Templates:
  SINK template: 'video_%u'
    Availability: On request
    Capabilities:
      video/x-h264
          stream-format: avc
              alignment: au
                  width: [ 16, 2147483647 ]
                 height: [ 16, 2147483647 ]
      video/x-h265
              alignment: au
                  width: [ 16, 2147483647 ]
                 height: [ 16, 2147483647 ]

  SINK template: 'audio_%u'
    Availability: On request
    Capabilities:
      audio/mpeg
            mpegversion: { (int)2, (int)4 }
          stream-format: raw
               channels: [ 1, 2147483647 ]
                   rate: [ 1, 2147483647 ]
      audio/x-alaw
               channels: { (int)1, (int)2 }
                   rate: [ 8000, 192000 ]
      audio/x-mulaw
               channels: { (int)1, (int)2 }
                   rate: [ 8000, 192000 ]

Element has no clocking capabilities.
Element has no URI handling capabilities.

Pads:
  none

Element Properties:
  name                : The name of the object
                        flags: readable, writable
                        String. Default: "kvssink0"
  parent              : The parent of the object
                        flags: readable, writable
                        Object of type "GstObject"
  stream-name         : Name of the destination stream
                        flags: readable, writable
                        String. Default: "DEFAULT_STREAM"
  retention-period    : Length of time stream is preserved. Unit: hours
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 2 
  streaming-type      : Streaming type
                        flags: readable, writable
                        Enum "GstKvsSinkStreamingType" Default: 0, "realtime"
                           (0): realtime         - streaming type realtime
                           (1): near-realtime    - streaming type near realtime
                           (2): offline          - streaming type offline
  content-type        : content type
                        flags: readable, writable
                        String. Default: null
  max-latency         : Max Latency. Unit: seconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 60 
  fragment-duration   : Fragment Duration. Unit: miliseconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 2000 
  timecode-scale      : Timecode Scale. Unit: milliseconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 1 
  key-frame-fragmentation: If true, generate new fragment on each keyframe, otherwise generate new fragment on first keyframe after fragment-duration has passed.
                        flags: readable, writable
                        Boolean. Default: true
  frame-timecodes     : Do frame timecodes
                        flags: readable, writable
                        Boolean. Default: true
  absolute-fragment-times: Use absolute fragment time
                        flags: readable, writable
                        Boolean. Default: true
  fragment-acks       : Do fragment acks
                        flags: readable, writable
                        Boolean. Default: true
  restart-on-error    : Do restart on error
                        flags: readable, writable
                        Boolean. Default: true
  recalculate-metrics : Do recalculate metrics
                        flags: readable, writable
                        Boolean. Default: true
  framerate           : Framerate
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 25 
  avg-bandwidth-bps   : Average bandwidth bps
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 4194304 
  buffer-duration     : Buffer duration. Unit: seconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 120 
  replay-duration     : Replay duration. Unit: seconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 40 
  connection-staleness: Connection staleness. Unit: seconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 60 
  codec-id            : Codec ID
                        flags: readable, writable
                        String. Default: "V_MPEG4/ISO/AVC"
  track-name          : Track name
                        flags: readable, writable
                        String. Default: "kinesis_video"
  access-key          : AWS Access Key
                        flags: readable, writable
                        String. Default: "access_key"
  secret-key          : AWS Secret Key
                        flags: readable, writable
                        String. Default: "secret_key"
  aws-region          : AWS Region
                        flags: readable, writable
                        String. Default: "us-west-2"
  rotation-period     : Rotation Period. Unit: seconds
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 3600 
  log-config          : Log Configuration Path
                        flags: readable, writable
                        String. Default: "./kvs_log_configuration"
  storage-size        : Storage Size. Unit: MB
                        flags: readable, writable
                        Unsigned Integer. Range: 0 - 4294967295 Default: 128 
  credential-path     : Credential File Path
                        flags: readable, writable
                        String. Default: ".kvs/credential"
  iot-certificate     : Use aws iot certificate to obtain credentials
                        flags: readable, writable
                        Boxed pointer of type "GstStructure"
  stream-tags         : key-value pair that you can define and assign to each stream
                        flags: readable, writable
                        Boxed pointer of type "GstStructure"
  file-start-time     : Epoch time that the file starts in kinesis video stream. By default, current time is used. Unit: Seconds
                        flags: readable, writable
                        Unsigned Integer64. Range: 0 - 18446744073709551615 Default: 1619700565 
  disable-buffer-clipping: Set to true only if your src/mux elements produce GST_CLOCK_TIME_NONE for segment start times.  It is non-standard behavior to set this to true, only use if there are known issues with your src/mux segment start/stop times.
                        flags: readable, writable
                        Boolean. Default: false
`
bpawlik commented 3 years ago

Then execute your script this way:

GST_PLUGIN_PATH=awstreamer/gst_plugins/kvs python3 your_script.py

And what about this one?

Omar-Turkmani commented 3 years ago

Yes it is worked

Omar-Turkmani commented 3 years ago

But if I want to run it in greengrass lambda function how would I solve this problem ?

bpawlik commented 3 years ago

But if I want to run it in greengrass lambda function how would I solve this problem ?

You can specify env vars in greengrass lambda configuration, but honestly this shouldn't be needed.

For debugging purposes, could you post here the console output when you just run 'python3 your_script.py'?

Omar-Turkmani commented 3 years ago

here the output :

INFO:awstreamer.gst_pipeline.stream_client:GST_PLUGIN_PATH: awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/
INFO:awstreamer.gst_pipeline.stream_client:Gstreamer version: 1.14.5.0
INFO:awstreamer.gst_pipeline.stream_client:LIB_GSTREAMER_PATH: /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
INFO:awstreamer.gst_pipeline.stream_client:GST_PLUGIN_PATH: awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/
>>>>>>>>>>>>>>awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/
INFO:awstreamer.gst_pipeline.stream_client:{'callback': None,
 'debug': True,
 'enabled': True,
 'encoder': {'bframes': 0, 'bitrate': 500, 'key-int-max': 40},
 'encoder_filter': {'caps': 'video/x-h264,stream-format=avc,alignment=au,profile=baseline'},
 'env': None,
 'id': 'default_0',
 'info': None,
 'pipeline': {'encoder': 'x264enc',
              'encoder_filter': 'capsfilter',
              'sink': 'kvssink',
              'source': 'v4l2src',
              'source_filter': 'capsfilter',
              'videoconvert': 'videoconvert'},
 'sink': {'access-key': '***********************',
          'aws-region': 'us-west-2',
          'name': 'kvssink',
          'secret-key': '******************',
          'storage-size': 512,
          'stream-name': 'TestStream'},
 'source': {'device': '/dev/video0'},
 'source_filter': {'caps': 'video/x-raw,framerate=10/1,format=I420'},
 'timeout': None}
INFO:awstreamer.gst_pipeline.pipeline_factory:PipelineFactory: creating a pipeline from path: .stream_pipeline.StreamPipeline
INFO:awstreamer.gst_pipeline.pipeline_factory:python_version: 3.7.5
INFO:awstreamer.gst_pipeline.stream_pipeline:Initializing StreamPipeline for default_0..
INFO:awstreamer.gst_pipeline.stream_graph:Initializing StreamGraph...
INFO:awstreamer.gst_pipeline.stream_pipeline:source: v4l2src
INFO:awstreamer.gst_pipeline.stream_pipeline:videoconvert: videoconvert
INFO:awstreamer.gst_pipeline.stream_pipeline:source_filter: capsfilter
INFO:awstreamer.gst_pipeline.stream_pipeline:encoder: x264enc
INFO:awstreamer.gst_pipeline.stream_pipeline:encoder_filter: capsfilter
INFO:awstreamer.gst_pipeline.stream_pipeline:sink: kvssink
ERROR:awstreamer.gst_pipeline.stream_graph:Failed to make element sink of type kvssink
Traceback (most recent call last):
  File "streamer.py", line 41, in <module>
    "debug": True
  File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/stream_client.py", line 197, in start
    pipeline = self.add(config_or_filename)
  File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/stream_client.py", line 162, in add
    pipeline = PipelineFactory.createPipeline(pipeline_config)
  File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/pipeline_factory.py", line 47, in createPipeline
    return class_(config) or None
  File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/stream_pipeline.py", line 49, in __init__
    self.build(self.config)
  File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/stream_pipeline.py", line 77, in build
    self.graph.add(v, k)
  File "/home/baseet/videoStreamer/awsStreamer/awstreamer/gst_pipeline/stream_graph.py", line 43, in add
    raise Exception(msg)
Exception: Failed to make element sink of type kvssink
bpawlik commented 3 years ago

INFO:awstreamer.gst_pipeline.stream_client:GST_PLUGIN_PATH: awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/

awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/

These '>>>' characters above look weird, do you get them every time? GST_PLUGIN_PATH path should be just this way awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/. Maybe that's the problem.

Another thought, try to clean GStreamer cache: rm -rf ~/.cache/gstreamer-1.0/

Omar-Turkmani commented 3 years ago

I'm printing these characters on my code, and unfortunately cleaning cache didn't work also,

I have question if GST_PLUGIN_PATH should contain kvs binaries or not ? because if I copy them into gstreamer-1.0 folder its working without any change

bpawlik commented 3 years ago

Could you checkout bpawlik-kvs-path branch or just cherry pick this commit https://github.com/awslabs/aws-streamer/pull/5/commits/5f050371aec4021dd43d1583fe94ce04fb186d4c and let me know if that works for you? If so, then it means that for some reason gstreamer plugin manager in your system is not able to recursively search for plug-ins. I can then modify the codebase accoringly.

Omar-Turkmani commented 3 years ago

Its not working I don't know if that will help but if I set GST_PLUGIN_PATH from my code to the same set path from module awstreamer/gst_pipeline/../gst_plugins:awstreamer/gst_pipeline/../gst_plugins/kvs:/usr/lib/gstreamer-1.0/ or awstreamer/gst_pipeline/../gst_plugins:/usr/lib/gstreamer-1.0/ it worked regardless if I disable setting from module or not also exporting from terminal worked.

But I'm confused because I can print it's value from my code, so what is the different between setting it from my code and setting it from module?

bpawlik commented 3 years ago

But I'm confused because I can print it's value from my code, so what is the different between setting it from my code and setting it from module?

There is no difference as far as I know. If you could provide docker image with the code that you run then perhaps it would be easier for me to debug, otherwise it's just guessing on my part..

Nevertheless, I think setting GST_PLUGIN_PATH explicitly in your code or in terminal is a decent solution and can qualify to close this issue.

Omar-Turkmani commented 3 years ago

Okay Thank you for your time