[vlc-commits] demux: mp4: add support for thum preview
Francois Cartegnie
git at videolan.org
Wed Dec 4 18:51:51 CET 2019
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Dec 2 12:01:55 2019 +0100| [651bb77c08025aeb2a8f97ae69ca14bd8fa28c70] | committer: Francois Cartegnie
demux: mp4: add support for thum preview
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=651bb77c08025aeb2a8f97ae69ca14bd8fa28c70
---
modules/demux/mp4/attachments.c | 63 +++++++++++++++++++++++++++++++++++++++++
modules/demux/mp4/libmp4.c | 2 ++
modules/demux/mp4/libmp4.h | 1 +
3 files changed, 66 insertions(+)
diff --git a/modules/demux/mp4/attachments.c b/modules/demux/mp4/attachments.c
index 6ff926e185..1c93a3aee8 100644
--- a/modules/demux/mp4/attachments.c
+++ b/modules/demux/mp4/attachments.c
@@ -93,6 +93,23 @@ static const MP4_Box_t * GetValidPnotMeta( const MP4_Box_t *p_pnot,
return NULL;
}
+static const MP4_Box_t * GetValidThumMeta( const MP4_Box_t *p_thum,
+ unsigned *pi_index,
+ const void **ctx )
+{
+ for( ; p_thum; p_thum = p_thum->p_next )
+ {
+ if( p_thum->i_type != ATOM_thum || p_thum == *ctx )
+ continue;
+ (*pi_index)++;
+ if ( !p_thum->data.p_binary )
+ continue;
+ *ctx = p_thum;
+ return p_thum;
+ }
+ return NULL;
+}
+
int MP4_GetCoverMetaURI( const MP4_Box_t *p_root,
const MP4_Box_t *p_metaroot,
const char *psz_metapath,
@@ -140,6 +157,26 @@ int MP4_GetCoverMetaURI( const MP4_Box_t *p_root,
}
}
+
+ const MP4_Box_t *p_thum;
+ if( !b_attachment_set && (p_thum = MP4_BoxGet( p_root, "thum" )) )
+ {
+ unsigned i_index = 0;
+ const void *ctx = NULL;
+ if( (p_thum = GetValidThumMeta( p_thum, &i_index, &ctx )) )
+ {
+ char *psz_attachment;
+ if ( -1 != asprintf( &psz_attachment,
+ "attachment://thum[%u]",
+ i_index - 1 ) )
+ {
+ vlc_meta_SetArtURL( p_meta, psz_attachment );
+ b_attachment_set = true;
+ free( psz_attachment );
+ }
+ }
+ }
+
if( !b_attachment_set )
return VLC_EGENERIC;
@@ -256,6 +293,32 @@ int MP4_GetAttachments( const MP4_Box_t *p_root, input_attachment_t ***ppp_attac
}
}
+
+ /* Then other thumbnails */
+ const MP4_Box_t *p_thum = MP4_BoxGet( p_root, "thum" );
+ if( p_thum )
+ {
+ unsigned i_index = 0;
+ const void *ctx = NULL;
+ while( (p_thum = GetValidThumMeta( p_thum, &i_index, &ctx )) )
+ {
+ char *psz_location;
+ if ( asprintf( &psz_location, "thum[%u]", i_index - 1 ) > -1 )
+ {
+ input_attachment_t *p_attach =
+ vlc_input_attachment_New(
+ psz_location,
+ NULL,
+ "Cover picture",
+ p_thum->data.p_binary->p_blob,
+ p_thum->data.p_binary->i_blob );
+ free( psz_location );
+ if( p_attach )
+ pp_attach[i_count++] = p_attach;
+ }
+ }
+ }
+
/* errors in adding attachments */
if ( i_count == 0 )
{
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 4b431977d4..cdb4cd7e3f 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -4883,6 +4883,8 @@ static const struct
{ ATOM_pnot, MP4_ReadBox_pnot, 0 },
{ ATOM_pict, MP4_ReadBox_Binary, 0 },
{ ATOM_PICT, MP4_ReadBox_Binary, 0 },
+ /* Other preview atoms */
+ { ATOM_thum, MP4_ReadBox_Binary, 0 },
/* Nothing to do with this box */
{ ATOM_mdat, MP4_ReadBoxSkip, 0 },
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 23c265fced..74a785693b 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -394,6 +394,7 @@ typedef int64_t stime_t;
#define ATOM_covr VLC_FOURCC( 'c', 'o', 'v', 'r' )
#define ATOM_flvr VLC_FOURCC( 'f', 'l', 'v', 'r' )
#define ATOM_rtng VLC_FOURCC( 'r', 't', 'n', 'g' )
+#define ATOM_thum VLC_FOURCC( 't', 'h', 'u', 'm' )
#define ATOM_tsel VLC_FOURCC( 't', 's', 'e', 'l' )
#define ATOM_xid_ VLC_FOURCC( 'x', 'i', 'd', ' ' )
#define ATOM_gshh VLC_FOURCC( 'g', 's', 'h', 'h' )
More information about the vlc-commits
mailing list