-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an experimental VideoSourceMetadata analyser.
Signed-off-by: Ralph Gasser <[email protected]>
- Loading branch information
1 parent
fd78174
commit 5991e5c
Showing
18 changed files
with
355 additions
and
139 deletions.
There are no files selected for viewing
78 changes: 0 additions & 78 deletions
78
...ngine-core/src/main/kotlin/org/vitrivr/engine/core/features/metadata/file/FileMetadata.kt
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
...c/main/kotlin/org/vitrivr/engine/core/features/metadata/source/file/FileSourceMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.vitrivr.engine.core.features.metadata.source.file | ||
|
||
import io.github.oshai.kotlinlogging.KLogger | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.vitrivr.engine.core.context.IndexContext | ||
import org.vitrivr.engine.core.context.QueryContext | ||
import org.vitrivr.engine.core.model.content.element.ContentElement | ||
import org.vitrivr.engine.core.model.descriptor.struct.metadata.source.FileSourceMetadataDescriptor | ||
import org.vitrivr.engine.core.model.metamodel.Analyser | ||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.retrieve.Retriever | ||
import java.util.* | ||
|
||
private val logger: KLogger = KotlinLogging.logger {} | ||
|
||
/** | ||
* Implementation of the [FileSourceMetadata] [Analyser], which derives metadata information from file-based retrievables | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.0.0 | ||
*/ | ||
class FileSourceMetadata : Analyser<ContentElement<*>, FileSourceMetadataDescriptor> { | ||
override val contentClasses = setOf(ContentElement::class) | ||
override val descriptorClass = FileSourceMetadataDescriptor::class | ||
|
||
/** | ||
* Generates a prototypical [FileSourceMetadataDescriptor] for this [FileSourceMetadata]. | ||
* | ||
* @return [FileSourceMetadataDescriptor] | ||
*/ | ||
override fun prototype() = FileSourceMetadataDescriptor(UUID.randomUUID(), UUID.randomUUID(), "", 0, true) | ||
|
||
/** | ||
* Generates and returns a new [FileSourceMetadataExtractor] for the provided [Schema.Field]. | ||
* | ||
* @param field The [Schema.Field] for which to create the [FileSourceMetadataExtractor]. | ||
* @param input The input [Operator] | ||
* @param context The [IndexContext] | ||
* @param persisting Whether the resulting [FileSourceMetadataDescriptor]s should be persisted. | ||
* | ||
* @return [FileSourceMetadataExtractor] | ||
*/ | ||
override fun newExtractor(field: Schema.Field<ContentElement<*>, FileSourceMetadataDescriptor>, input: Operator<Retrievable>, context: IndexContext, persisting: Boolean, parameters: Map<String, Any>): FileSourceMetadataExtractor { | ||
require(field.analyser == this) { "Field type is incompatible with analyser. This is a programmer's error!" } | ||
logger.debug { "Creating new FileMetadataExtractor for field '${field.fieldName}' with parameters $parameters." } | ||
return FileSourceMetadataExtractor(input, field, persisting) | ||
} | ||
|
||
/** | ||
* Generates and returns a new [FileSourceMetadataRetriever] for the provided [Schema.Field]. | ||
* | ||
* @param field The [Schema.Field] for which to create the [FileSourceMetadataRetriever]. | ||
* @param content The [List] of [ContentElement] to create [FileSourceMetadataRetriever] for. This is usually empty. | ||
* @param context The [QueryContext] | ||
* | ||
* @return [FileSourceMetadataRetriever] | ||
*/ | ||
override fun newRetrieverForContent(field: Schema.Field<ContentElement<*>, FileSourceMetadataDescriptor>, content: Collection<ContentElement<*>>, context: QueryContext): FileSourceMetadataRetriever { | ||
require(field.analyser == this) { "Field type is incompatible with analyser. This is a programmer's error!" } | ||
return FileSourceMetadataRetriever(field, context) | ||
} | ||
|
||
/** | ||
* Generates and returns a new [FileSourceMetadataRetriever] for the provided [Schema.Field]. | ||
* | ||
* @param field The [Schema.Field] for which to create the [FileSourceMetadataRetriever]. | ||
* @param descriptors The [List] of [FileSourceMetadataDescriptor] to create [FileSourceMetadataRetriever] for. This is usually empty. | ||
* @param context The [QueryContext] | ||
* | ||
* @return [FileSourceMetadataRetriever] | ||
*/ | ||
override fun newRetrieverForDescriptors( | ||
field: Schema.Field<ContentElement<*>, FileSourceMetadataDescriptor>, | ||
descriptors: Collection<FileSourceMetadataDescriptor>, | ||
context: QueryContext | ||
): Retriever<ContentElement<*>, FileSourceMetadataDescriptor> { | ||
require(field.analyser == this) { "Field type is incompatible with analyser. This is a programmer's error!" } | ||
return FileSourceMetadataRetriever(field, context) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...es/metadata/file/FileMetadataRetriever.kt → ...ource/file/FileSourceMetadataRetriever.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...main/kotlin/org/vitrivr/engine/core/features/metadata/source/video/VideoSourceMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.vitrivr.engine.core.features.metadata.source.video | ||
|
||
import org.vitrivr.engine.core.context.IndexContext | ||
import org.vitrivr.engine.core.context.QueryContext | ||
import org.vitrivr.engine.core.features.metadata.source.file.FileSourceMetadata | ||
import org.vitrivr.engine.core.features.metadata.source.file.FileSourceMetadataExtractor | ||
import org.vitrivr.engine.core.features.metadata.source.file.FileSourceMetadataRetriever | ||
import org.vitrivr.engine.core.model.content.element.ContentElement | ||
import org.vitrivr.engine.core.model.descriptor.struct.metadata.source.FileSourceMetadataDescriptor | ||
import org.vitrivr.engine.core.model.descriptor.struct.metadata.source.VideoSourceMetadataDescriptor | ||
import org.vitrivr.engine.core.model.metamodel.Analyser | ||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.retrieve.Retriever | ||
import java.util.* | ||
|
||
/** | ||
* Implementation of the [VideoSourceMetadata] [Analyser], which derives metadata information from [Retr] | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.0.0 | ||
*/ | ||
class VideoSourceMetadata : Analyser<ContentElement<*>, VideoSourceMetadataDescriptor> { | ||
override val contentClasses = setOf(ContentElement::class) | ||
override val descriptorClass = VideoSourceMetadataDescriptor::class | ||
|
||
/** | ||
* Generates a prototypical [FileSourceMetadataDescriptor] for this [FileSourceMetadata]. | ||
* | ||
* @return [FileSourceMetadataDescriptor] | ||
*/ | ||
override fun prototype() = VideoSourceMetadataDescriptor.PROTOTYPE | ||
|
||
/** | ||
* Generates and returns a new [FileSourceMetadataExtractor] for the provided [Schema.Field]. | ||
* | ||
* @param field The [Schema.Field] for which to create the [FileSourceMetadataExtractor]. | ||
* @param input The input [Operator] | ||
* @param context The [IndexContext] | ||
* @param persisting Whether the resulting [FileSourceMetadataDescriptor]s should be persisted. | ||
* | ||
* @return [FileSourceMetadataExtractor] | ||
*/ | ||
override fun newExtractor(field: Schema.Field<ContentElement<*>, VideoSourceMetadataDescriptor>, input: Operator<Retrievable>, context: IndexContext, persisting: Boolean, parameters: Map<String, Any>): VideoSourceMetadataExtractor { | ||
require(field.analyser == this) { "Field type is incompatible with analyser. This is a programmer's error!" } | ||
return VideoSourceMetadataExtractor(input, field, persisting) | ||
} | ||
|
||
/** | ||
* Generates and returns a new [FileSourceMetadataRetriever] for the provided [Schema.Field]. | ||
* | ||
* @param field The [Schema.Field] for which to create the [FileSourceMetadataRetriever]. | ||
* @param content The [List] of [ContentElement] to create [FileSourceMetadataRetriever] for. This is usually empty. | ||
* @param context The [QueryContext] | ||
* | ||
* @return [FileSourceMetadataRetriever] | ||
*/ | ||
override fun newRetrieverForContent(field: Schema.Field<ContentElement<*>, VideoSourceMetadataDescriptor>, content: Collection<ContentElement<*>>, context: QueryContext): VideoSourceMetadataRetriever { | ||
require(field.analyser == this) { "Field type is incompatible with analyser. This is a programmer's error!" } | ||
return VideoSourceMetadataRetriever(field, context) | ||
} | ||
|
||
/** | ||
* Generates and returns a new [FileSourceMetadataRetriever] for the provided [Schema.Field]. | ||
* | ||
* @param field The [Schema.Field] for which to create the [FileSourceMetadataRetriever]. | ||
* @param descriptors The [List] of [FileSourceMetadataDescriptor] to create [FileSourceMetadataRetriever] for. This is usually empty. | ||
* @param context The [QueryContext] | ||
* | ||
* @return [FileSourceMetadataRetriever] | ||
*/ | ||
override fun newRetrieverForDescriptors( | ||
field: Schema.Field<ContentElement<*>, VideoSourceMetadataDescriptor>, | ||
descriptors: Collection<VideoSourceMetadataDescriptor>, | ||
context: QueryContext | ||
): Retriever<ContentElement<*>, VideoSourceMetadataDescriptor> { | ||
require(field.analyser == this) { "Field type is incompatible with analyser. This is a programmer's error!" } | ||
return VideoSourceMetadataRetriever(field, context) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...in/org/vitrivr/engine/core/features/metadata/source/video/VideoSourceMetadataExtractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.vitrivr.engine.core.features.metadata.source.video | ||
|
||
import org.vitrivr.engine.core.features.AbstractExtractor | ||
import org.vitrivr.engine.core.features.metadata.source.file.FileSourceMetadataExtractor | ||
import org.vitrivr.engine.core.model.content.element.ContentElement | ||
import org.vitrivr.engine.core.model.descriptor.Descriptor | ||
import org.vitrivr.engine.core.model.descriptor.struct.metadata.source.VideoSourceMetadataDescriptor | ||
import org.vitrivr.engine.core.model.metamodel.Schema | ||
import org.vitrivr.engine.core.model.retrievable.Retrievable | ||
import org.vitrivr.engine.core.model.retrievable.decorators.RetrievableWithSource | ||
import org.vitrivr.engine.core.operators.Operator | ||
import org.vitrivr.engine.core.operators.ingest.Extractor | ||
import org.vitrivr.engine.core.source.MediaType | ||
import org.vitrivr.engine.core.source.file.FileSource | ||
import java.util.* | ||
|
||
/** | ||
* | ||
* @author Ralph Gasser | ||
* @version 1.0.0 | ||
*/ | ||
class VideoSourceMetadataExtractor( | ||
input: Operator<Retrievable>, | ||
field: Schema.Field<ContentElement<*>, VideoSourceMetadataDescriptor>, | ||
persisting: Boolean = true | ||
) : AbstractExtractor<ContentElement<*>, VideoSourceMetadataDescriptor>(input, field, persisting, bufferSize = 1) { | ||
/** | ||
* Internal method to check, if [Retrievable] matches this [Extractor] and should thus be processed. | ||
* | ||
* [FileSourceMetadataExtractor] implementation only works with [RetrievableWithSource] that contain a [FileSource]. | ||
* | ||
* @param retrievable The [Retrievable] to check. | ||
* @return True on match, false otherwise, | ||
*/ | ||
override fun matches(retrievable: Retrievable): Boolean = | ||
retrievable is RetrievableWithSource && retrievable.source.type == MediaType.VIDEO | ||
|
||
/** | ||
* Internal method to perform extraction on [Retrievable]. | ||
** | ||
* @param retrievable The [Retrievable] to process. | ||
* @return List of resulting [Descriptor]s. | ||
*/ | ||
override fun extract(retrievable: Retrievable): List<VideoSourceMetadataDescriptor> { | ||
check(retrievable is RetrievableWithSource) { "Incoming retrievable is not a retrievable with source. This is a programmer's error!" } | ||
check(retrievable.source.type == MediaType.VIDEO) { "Incoming retrievable is not a retrievable with video source. This is a programmer's error!" } | ||
return listOf( | ||
VideoSourceMetadataDescriptor( | ||
id = UUID.randomUUID(), | ||
retrievableId = retrievable.id, | ||
width = retrievable.source.width() ?: 0, | ||
height = retrievable.source.height() ?: 0, | ||
fps = retrievable.source.fps() ?: 0.0, | ||
channels = retrievable.source.channels() ?: 0, | ||
sampleRate = retrievable.source.sampleRate() ?: 0, | ||
sampleSize = retrievable.source.sampleSize() ?: 0, | ||
transient = !persisting | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.