[vlc-devel] [PATCH] UTF-16 chapter titles
Donald Campbell
donaciano2000 at gmail.com
Sun Jul 3 19:10:18 CEST 2016
UTF-16 chapter titles fix
Movies with UTF-16 chapter track names end up showing as ??* where * is the first character of the title in UTF-8. Since each character is followed by a null the chapter titles get truncated to 3 bytes.
This patch detects UTF-16 titles and copies their data with memcpy instead of strndup, then turns it into a UTF-8 passing string.
Comments appreciated this is my first patch.
---
modules/demux/mp4/mp4.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 79c28a7..09012a2 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -1854,7 +1854,19 @@ static void LoadChapterApple( demux_t *p_demux, mp4_track_t *tk )
{
seekpoint_t *s = vlc_seekpoint_New();
- s->psz_name = strndup( &p_buffer[2], i_len );
+ if(*(&p_buffer[2])==(char)255 && *(&p_buffer[2]+1)==(char)254){ // UTF-16 BOM
+ s->psz_name = malloc(i_len);
+ memcpy(s->psz_name, &p_buffer[2], i_len); // including null bytes
+ unsigned int i;
+ for(i=0; i< i_len/2-1; i++){
+ char cval = s->psz_name[(i*2)+2]; // every other char, offset 2 bytes
+ s->psz_name[i]=cval;
+ }
+ s->psz_name[i]=0; // null terminate utf-8 string
+ } else { // non UTF-16 strings
+ s->psz_name = strndup( &p_buffer[2], i_len );
+ }
+
EnsureUTF8( s->psz_name );
s->i_time_offset = i_dts + __MAX( i_pts_delta, 0 );
--
2.7.4 (Apple Git-66)
More information about the vlc-devel
mailing list