aws/amazon-kinesis-video-streams-parser-library

How to use Stream Parser Library Java

Closed this issue · 10 comments

Help needed. I have added some metadata from producer side using kvs producer cpp. Now I want to retrieve the metadata using Stream Parserr Library. Documentation says that I need to use FragmentMetadataVistitor to retrieve. I am using IntelliJ but I dont know how to use. I checked src test files. I dont know how to start. Very new to Java. Can anyone tell how to retrieve metadata?

You have to use this kind of code : https://github.com/aws/amazon-kinesis-video-streams-parser-library/blob/master/src/main/java/com/amazonaws/kinesisvideo/parser/utilities/FrameRendererVisitor.java

And when you create your GetMediaWorker (using GetMediaWorker.create()), you can pass the FrameRenderedVIsitor to it, so it can proceed every frame (the last argument is a MKVElementVisitor)

@FlorianRuen Thank you so much. can I directly use FrameRendererVisitor.java or Do I have to create my own project and use these libraries?

Maybe you can use directly, on my side I've a full project to consume KVS frames, and I use FrameRendererVisitor to extract and save every frame on hard disk.

But for some imports, a library will be needed (like the AWS Java SDK) : https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-kinesisvideo

Closing assuming question is answered. Thank you @FlorianRuen .

You have to use this kind of code : https://github.com/aws/amazon-kinesis-video-streams-parser-library/blob/master/src/main/java/com/amazonaws/kinesisvideo/parser/utilities/FrameRendererVisitor.java

And when you create your GetMediaWorker (using GetMediaWorker.create()), you can pass the FrameRenderedVIsitor to it, so it can proceed every frame (the last argument is a MKVElementVisitor)

@FlorianRuen or @disa6302
Would you be willing to share a small snippet that exemplifies this process you are describing? Haven't done a lot of work with Java so not sure I fully understand the nuances behind the examples in the repo, being that some of them are a bit more complicated... I think a small short example of a Main App class or method would help me understand some of the gaps I have currently.

@Alex-Wenner-FHR ,

You can check this out: https://github.com/aws-samples/amazon-kinesis-video-streams-demos/blob/master/canary/consumer-java/src/main/java/com/amazon/kinesis/video/canary/consumer/ProducerSdkCanaryConsumer.java. All it does it consume frames. Hope this helps you get started

Thanks for the quick response. I will check this out and may follow up!

@disa6302 I am having trouble with this example. I understand what it is doing for the most part, I am just unable to see anything produced? I tried to add some logging statements as well but still not seeing them. What I see is as follows:

log4j:ERROR Could not instantiate class [com.amazonaws.services.lambda.runtime.log4j.LambdaAppender].
java.lang.ClassNotFoundException: com.amazonaws.services.lambda.runtime.log4j.LambdaAppender
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at org.apache.log4j.helpers.Loader.loadClass(Loader.java:190)
        at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:304)
        at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:123)
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:755)
        at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:738)
        at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:630)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:516)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:577)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:504)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:119)
        at org.slf4j.impl.Reload4jLoggerFactory.<init>(Reload4jLoggerFactory.java:67)
        at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
        at com.amazon.kinesis.video.canary.consumer.ProducerSdkCanaryConsumer.<clinit>(ProducerSdkCanaryConsumer.java:27)
log4j:ERROR Could not instantiate appender named "Lambda".
log4j:WARN No appenders could be found for logger (com.amazon.kinesis.video.canary.consumer.ProducerSdkCanaryConsumer).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.amazonaws.util.XpathUtils (file:/Users/alexw/.m2/repository/com/amazonaws/aws-java-sdk-core/1.11.742/aws-java-sdk-core-1.11.742.jar) to method com.sun.org.apache.xpath.internal.XPathContext.getDTMManager()
WARNING: Please consider reporting this to the maintainers of com.amazonaws.util.XpathUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

After this last warning log it appears to just hang... I have done all the things mentioned in the README and made sure that proper env vars are set.

Follow up - after adding this

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-lambda-java-log4j</artifactId>
    <version>1.0.0</version>
</dependency>

to the pom.xml seemed to fix this issue!

@disa6302 I think last question... in order to save these incoming frames, would they need to be H264 decoded prior? May save me some trouble and stumbling through it!