Fix bug with files with multiple video or audio streams

This commit is contained in:
simon 2019-10-26 21:12:51 -04:00
parent f44e6336dc
commit c063d87232
2 changed files with 25 additions and 20 deletions

View File

@ -5,7 +5,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.5"; static const char *const Version = "1.0.6";
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",

View File

@ -151,6 +151,7 @@ void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
void parse_media(const char *filepath, document_t *doc) { void parse_media(const char *filepath, document_t *doc) {
int video_stream = -1; int video_stream = -1;
int audio_stream = -1;
AVFormatContext *pFormatCtx = avformat_alloc_context(); AVFormatContext *pFormatCtx = avformat_alloc_context();
if (pFormatCtx == NULL) { if (pFormatCtx == NULL) {
@ -169,15 +170,18 @@ void parse_media(const char *filepath, document_t *doc) {
AVStream *stream = pFormatCtx->streams[i]; AVStream *stream = pFormatCtx->streams[i];
if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
if (audio_stream == -1) {
meta_line_t *meta_audio = malloc(sizeof(meta_line_t)); meta_line_t *meta_audio = malloc(sizeof(meta_line_t));
meta_audio->key = MetaMediaAudioCodec; meta_audio->key = MetaMediaAudioCodec;
meta_audio->intval = stream->codecpar->codec_id; meta_audio->intval = stream->codecpar->codec_id;
APPEND_META(doc, meta_audio) APPEND_META(doc, meta_audio)
append_audio_meta(pFormatCtx, doc); append_audio_meta(pFormatCtx, doc);
audio_stream = i;
}
} else if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
if (video_stream == -1) {
meta_line_t *meta_vid = malloc(sizeof(meta_line_t)); meta_line_t *meta_vid = malloc(sizeof(meta_line_t));
meta_vid->key = MetaMediaVideoCodec; meta_vid->key = MetaMediaVideoCodec;
meta_vid->intval = stream->codecpar->codec_id; meta_vid->intval = stream->codecpar->codec_id;
@ -196,6 +200,7 @@ void parse_media(const char *filepath, document_t *doc) {
video_stream = i; video_stream = i;
} }
} }
}
if (video_stream != -1) { if (video_stream != -1) {
AVStream *stream = pFormatCtx->streams[video_stream]; AVStream *stream = pFormatCtx->streams[video_stream];