mirror of
				https://github.com/simon987/sist2.git
				synced 2025-11-04 01:36:51 +00:00 
			
		
		
		
	video metadata
This commit is contained in:
		
							parent
							
								
									784c3c9435
								
							
						
					
					
						commit
						f8f1a27180
					
				@ -116,10 +116,10 @@ if (WITH_SIST2)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    target_compile_options(sist2
 | 
					    target_compile_options(sist2
 | 
				
			||||||
            PRIVATE
 | 
					            PRIVATE
 | 
				
			||||||
            -O3
 | 
					#            -O3
 | 
				
			||||||
            #        -march=native
 | 
					            #        -march=native
 | 
				
			||||||
            -fno-stack-protector
 | 
					#            -fno-stack-protector
 | 
				
			||||||
            -fomit-frame-pointer
 | 
					#            -fomit-frame-pointer
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    TARGET_LINK_LIBRARIES(
 | 
					    TARGET_LINK_LIBRARIES(
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,7 @@
 | 
				
			|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
 | 
					#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char *const Version = "1.0.13";
 | 
					static const char *const Version = "1.0.14";
 | 
				
			||||||
static const char *const usage[] = {
 | 
					static const char *const usage[] = {
 | 
				
			||||||
        "sist2 scan [OPTION]... PATH",
 | 
					        "sist2 scan [OPTION]... PATH",
 | 
				
			||||||
        "sist2 index [OPTION]... INDEX",
 | 
					        "sist2 index [OPTION]... INDEX",
 | 
				
			||||||
 | 
				
			|||||||
@ -107,6 +107,15 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
 | 
				
			|||||||
    return frame;
 | 
					    return frame;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define APPEND_TAG_META(doc, tag, keyname) \
 | 
				
			||||||
 | 
					    text_buffer_t tex = text_buffer_create(4096); \
 | 
				
			||||||
 | 
					    text_buffer_append_string(&tex, tag->value); \
 | 
				
			||||||
 | 
					    meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
 | 
				
			||||||
 | 
					    meta_tag->key = keyname; \
 | 
				
			||||||
 | 
					    strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
 | 
				
			||||||
 | 
					    APPEND_META(doc, meta_tag) \
 | 
				
			||||||
 | 
					    text_buffer_destroy(&tex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
 | 
					void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    AVDictionaryEntry *tag = NULL;
 | 
					    AVDictionaryEntry *tag = NULL;
 | 
				
			||||||
@ -115,35 +124,40 @@ void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
 | 
				
			|||||||
        for (; *key; ++key) *key = (char) tolower(*key);
 | 
					        for (; *key; ++key) *key = (char) tolower(*key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (strcmp(tag->key, "artist") == 0) {
 | 
					        if (strcmp(tag->key, "artist") == 0) {
 | 
				
			||||||
            size_t len = strlen(tag->value);
 | 
					            APPEND_TAG_META(doc, tag, MetaArtist)
 | 
				
			||||||
            meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + len);
 | 
					 | 
				
			||||||
            meta_tag->key = MetaArtist;
 | 
					 | 
				
			||||||
            memcpy(meta_tag->strval, tag->value, len);
 | 
					 | 
				
			||||||
            APPEND_META(doc, meta_tag)
 | 
					 | 
				
			||||||
        } else if (strcmp(tag->key, "genre") == 0) {
 | 
					        } else if (strcmp(tag->key, "genre") == 0) {
 | 
				
			||||||
            size_t len = strlen(tag->value);
 | 
					            APPEND_TAG_META(doc, tag, MetaGenre)
 | 
				
			||||||
            meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + len);
 | 
					 | 
				
			||||||
            meta_tag->key = MetaGenre;
 | 
					 | 
				
			||||||
            memcpy(meta_tag->strval, tag->value, len);
 | 
					 | 
				
			||||||
            APPEND_META(doc, meta_tag)
 | 
					 | 
				
			||||||
        } else if (strcmp(tag->key, "title") == 0) {
 | 
					        } else if (strcmp(tag->key, "title") == 0) {
 | 
				
			||||||
            size_t len = strlen(tag->value);
 | 
					            APPEND_TAG_META(doc, tag, MetaTitle)
 | 
				
			||||||
            meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + len);
 | 
					 | 
				
			||||||
            meta_tag->key = MetaTitle;
 | 
					 | 
				
			||||||
            memcpy(meta_tag->strval, tag->value, len);
 | 
					 | 
				
			||||||
            APPEND_META(doc, meta_tag)
 | 
					 | 
				
			||||||
        } else if (strcmp(tag->key, "album_artist") == 0) {
 | 
					        } else if (strcmp(tag->key, "album_artist") == 0) {
 | 
				
			||||||
            size_t len = strlen(tag->value);
 | 
					            APPEND_TAG_META(doc, tag, MetaAlbumArtist)
 | 
				
			||||||
            meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + len);
 | 
					 | 
				
			||||||
            meta_tag->key = MetaAlbumArtist;
 | 
					 | 
				
			||||||
            memcpy(meta_tag->strval, tag->value, len);
 | 
					 | 
				
			||||||
            APPEND_META(doc, meta_tag)
 | 
					 | 
				
			||||||
        } else if (strcmp(tag->key, "album") == 0) {
 | 
					        } else if (strcmp(tag->key, "album") == 0) {
 | 
				
			||||||
            size_t len = strlen(tag->value);
 | 
					            APPEND_TAG_META(doc, tag, MetaAlbum)
 | 
				
			||||||
            meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + len);
 | 
					        }
 | 
				
			||||||
            meta_tag->key = MetaAlbum;
 | 
					    }
 | 
				
			||||||
            memcpy(meta_tag->strval, tag->value, len);
 | 
					}
 | 
				
			||||||
            APPEND_META(doc, meta_tag)
 | 
					
 | 
				
			||||||
 | 
					void append_video_meta(AVFormatContext *pFormatCtx, document_t *doc, int include_audio_tags) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
 | 
				
			||||||
 | 
					    meta_duration->key = MetaMediaDuration;
 | 
				
			||||||
 | 
					    meta_duration->longval = pFormatCtx->duration / AV_TIME_BASE;
 | 
				
			||||||
 | 
					    APPEND_META(doc, meta_duration)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
 | 
				
			||||||
 | 
					    meta_bitrate->key = MetaMediaBitrate;
 | 
				
			||||||
 | 
					    meta_bitrate->intval = pFormatCtx->bit_rate;
 | 
				
			||||||
 | 
					    APPEND_META(doc, meta_bitrate)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    AVDictionaryEntry *tag = NULL;
 | 
				
			||||||
 | 
					    while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
 | 
				
			||||||
 | 
					        char *key = tag->key;
 | 
				
			||||||
 | 
					        for (; *key; ++key) *key = (char) tolower(*key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (strcmp(tag->key, "title") == 0 && include_audio_tags) {
 | 
				
			||||||
 | 
					            APPEND_TAG_META(doc, tag, MetaTitle)
 | 
				
			||||||
 | 
					        } else if (strcmp(tag->key, "comment") == 0) {
 | 
				
			||||||
 | 
					            APPEND_TAG_META(doc, tag, MetaContent)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -207,15 +221,7 @@ void parse_media(const char *filepath, document_t *doc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (stream->nb_frames > 1) {
 | 
					        if (stream->nb_frames > 1) {
 | 
				
			||||||
            //This is a video (not a still image)
 | 
					            //This is a video (not a still image)
 | 
				
			||||||
            meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
 | 
					            append_video_meta(pFormatCtx, doc, audio_stream == -1);
 | 
				
			||||||
            meta_duration->key = MetaMediaDuration;
 | 
					 | 
				
			||||||
            meta_duration->longval = pFormatCtx->duration / AV_TIME_BASE;
 | 
					 | 
				
			||||||
            APPEND_META(doc, meta_duration)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
 | 
					 | 
				
			||||||
            meta_bitrate->key = MetaMediaBitrate;
 | 
					 | 
				
			||||||
            meta_bitrate->intval = pFormatCtx->bit_rate;
 | 
					 | 
				
			||||||
            APPEND_META(doc, meta_bitrate)
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (stream->codecpar->width <= 20 || stream->codecpar->height <= 20) {
 | 
					        if (stream->codecpar->width <= 20 || stream->codecpar->height <= 20) {
 | 
				
			||||||
 | 
				
			|||||||
@ -89,6 +89,14 @@ void text_buffer_terminate_string(text_buffer_t *buf) {
 | 
				
			|||||||
    dyn_buffer_write_char(&buf->dyn_buffer, '\0');
 | 
					    dyn_buffer_write_char(&buf->dyn_buffer, '\0');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int text_buffer_append_string(text_buffer_t *buf, char * str) {
 | 
				
			||||||
 | 
					    char * ptr = str;
 | 
				
			||||||
 | 
					    while (*ptr) {
 | 
				
			||||||
 | 
					        text_buffer_append_char(buf, *ptr++);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    text_buffer_terminate_string(buf);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int text_buffer_append_char(text_buffer_t *buf, int c) {
 | 
					int text_buffer_append_char(text_buffer_t *buf, int c) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (SHOULD_IGNORE_CHAR(c)) {
 | 
					    if (SHOULD_IGNORE_CHAR(c)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -56,6 +56,7 @@ text_buffer_t text_buffer_create(int max_size);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void text_buffer_terminate_string(text_buffer_t *buf);
 | 
					void text_buffer_terminate_string(text_buffer_t *buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int text_buffer_append_string(text_buffer_t *buf, char * str);
 | 
				
			||||||
int text_buffer_append_char(text_buffer_t *buf, int c);
 | 
					int text_buffer_append_char(text_buffer_t *buf, int c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void incremental_put(GHashTable *table, unsigned long inode_no, int mtime);
 | 
					void incremental_put(GHashTable *table, unsigned long inode_no, int mtime);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user