Add stream metadata tags. (#17)

This commit is contained in:
Alfred Gutierrez
2022-05-28 16:48:14 -07:00
committed by GitHub
parent ff36b01373
commit 48507f53a6
3 changed files with 90 additions and 24 deletions

View File

@@ -27,6 +27,11 @@ const std::string c_avutil_version() {
return AV_STRINGIFY(LIBAVUTIL_VERSION);
}
typedef struct Tag {
std::string key;
std::string value;
} Tag;
typedef struct Stream {
int id;
int start_time;
@@ -42,13 +47,9 @@ typedef struct Stream {
int channels;
int sample_rate;
int frame_size;
std::vector<Tag> tags;
} Stream;
typedef struct Tag {
std::string key;
std::string value;
} Tag;
typedef struct Chapter {
int id;
std::string time_base;
@@ -152,6 +153,17 @@ FileInfoResponse get_file_info(std::string filename) {
.sample_rate = (int)pLocalCodecParameters->sample_rate,
.frame_size = (int)pLocalCodecParameters->frame_size,
};
// Add tags to stream.
const AVDictionaryEntry *tag = NULL;
while ((tag = av_dict_get(pFormatContext->streams[i]->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
Tag t = {
.key = tag->key,
.value = tag->value,
};
stream.tags.push_back(t);
}
r.streams.push_back(stream);
free(fourcc);
}
@@ -322,6 +334,12 @@ EMSCRIPTEN_BINDINGS(constants) {
}
EMSCRIPTEN_BINDINGS(structs) {
emscripten::value_object<Tag>("Tag")
.field("key", &Tag::key)
.field("value", &Tag::value)
;
register_vector<Tag>("Tag");
emscripten::value_object<Stream>("Stream")
.field("id", &Stream::id)
.field("start_time", &Stream::start_time)
@@ -337,15 +355,10 @@ EMSCRIPTEN_BINDINGS(structs) {
.field("channels", &Stream::channels)
.field("sample_rate", &Stream::sample_rate)
.field("frame_size", &Stream::frame_size)
.field("tags", &Stream::tags)
;
register_vector<Stream>("Stream");
emscripten::value_object<Tag>("Tag")
.field("key", &Tag::key)
.field("value", &Tag::value)
;
register_vector<Tag>("Tag");
emscripten::value_object<Chapter>("Chapter")
.field("id", &Chapter::id)
.field("time_base", &Chapter::time_base)