⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subtitle.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 3 页
字号:
                    return 0;                }                else                {                    if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )                    {                        memcpy( buffer_text + i_buffer_text,                                s,                                i_len );                        i_buffer_text += i_len;                        buffer_text[i_buffer_text] = '\n';                        i_buffer_text++;                    }                }            }        }    }}static int  ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle ){    demux_sys_t *p_sys = p_demux->p_sys;    text_t      *txt = &p_sys->txt;    /*     * h1:m1:s1.d1,h2:m2:s2.d2     * Line1[br]Line2     * Line3     * ...     * [empty line]     * ( works with subviewer and subviewer v2 )     */    char *s;    char buffer_text[ 10 * MAX_LINE];    int  i_buffer_text;    int64_t     i_start;    int64_t     i_stop;    p_subtitle->i_start = 0;    p_subtitle->i_stop  = 0;    p_subtitle->psz_text = NULL;    for( ;; )    {        int h1, m1, s1, d1, h2, m2, s2, d2;        if( ( s = TextGetLine( txt ) ) == NULL )        {            return( VLC_EGENERIC );        }        if( sscanf( s,                    "%d:%d:%d.%d,%d:%d:%d.%d",                    &h1, &m1, &s1, &d1,                    &h2, &m2, &s2, &d2 ) == 8 )        {            i_start = ( (int64_t)h1 * 3600*1000 +                        (int64_t)m1 * 60*1000 +                        (int64_t)s1 * 1000 +                        (int64_t)d1 ) * 1000;            i_stop  = ( (int64_t)h2 * 3600*1000 +                        (int64_t)m2 * 60*1000 +                        (int64_t)s2 * 1000 +                        (int64_t)d2 ) * 1000;            /* Now read text until an empty line */            for( i_buffer_text = 0;; )            {                int i_len, i;                if( ( s = TextGetLine( txt ) ) == NULL )                {                    return( VLC_EGENERIC );                }                i_len = strlen( s );                if( i_len <= 0 )                {                    /* empty line -> end of this subtitle */                    buffer_text[__MAX( i_buffer_text - 1, 0 )] = '\0';                    p_subtitle->i_start = i_start;                    p_subtitle->i_stop = i_stop;                    /* replace [br] by \n */                    for( i = 0; i < i_buffer_text - 3; i++ )                    {                        if( buffer_text[i] == '[' && buffer_text[i+1] == 'b' &&                            buffer_text[i+2] == 'r' && buffer_text[i+3] == ']' )                        {                            char *temp = buffer_text + i + 1;                            buffer_text[i] = '\n';                            memmove( temp, temp+3, strlen( temp ) -3 );                            temp[strlen( temp )-3] = '\0';                        }                    }                    p_subtitle->psz_text = strdup( buffer_text );                    return( 0 );                }                else                {                    if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )                    {                        memcpy( buffer_text + i_buffer_text,                                s,                                i_len );                        i_buffer_text += i_len;                        buffer_text[i_buffer_text] = '\n';                        i_buffer_text++;                    }                }            }        }    }}static int  ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle ){    demux_sys_t *p_sys = p_demux->p_sys;    text_t      *txt = &p_sys->txt;    char buffer_text[ 10 * MAX_LINE];    char buffer_text2[ 10 * MAX_LINE];    char *s;    int64_t     i_start;    int64_t     i_stop;    p_subtitle->i_start = 0;    p_subtitle->i_stop  = 0;    p_subtitle->psz_text = NULL;    for( ;; )    {        int h1, m1, s1, c1, h2, m2, s2, c2;        if( ( s = TextGetLine( txt ) ) == NULL )        {            return( VLC_EGENERIC );        }        p_subtitle->psz_text = malloc( strlen( s ) );        /* We expect (SSA2-4):         * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text         * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?         *         * SSA-1 is similar but only has 8 commas up untill the subtitle text. Probably the Effect field is no present, but not 100 % sure.         */        /* For ASS:         * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text         * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?         */        if( sscanf( s,                    "Dialogue: %[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",                    buffer_text2,                    &h1, &m1, &s1, &c1,                    &h2, &m2, &s2, &c2,                    buffer_text ) == 10 )        {            i_start = ( (int64_t)h1 * 3600*1000 +                        (int64_t)m1 * 60*1000 +                        (int64_t)s1 * 1000 +                        (int64_t)c1 * 10 ) * 1000;            i_stop  = ( (int64_t)h2 * 3600*1000 +                        (int64_t)m2 * 60*1000 +                        (int64_t)s2 * 1000 +                        (int64_t)c2 * 10 ) * 1000;            /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */            /* (Layer comes from ASS specs ... it's empty for SSA.) */            if( p_sys->i_type == SUB_TYPE_SSA1 )            {                sprintf( p_subtitle->psz_text,                         ",%s", strdup( buffer_text) ); /* SSA1 has only 8 commas before the text starts, not 9 */            }            else            {                sprintf( p_subtitle->psz_text,                         ",,%s", strdup( buffer_text) ); /* ReadOrder, Layer, %s(rest of fields) */            }            p_subtitle->i_start = i_start;            p_subtitle->i_stop = i_stop;            return 0;        }        else        {            /* All the other stuff we add to the header field */            if( p_sys->psz_header != NULL )            {                if( !( p_sys->psz_header = realloc( p_sys->psz_header,                          strlen( p_sys->psz_header ) + strlen( s ) + 2 ) ) )                {                    msg_Err( p_demux, "out of memory");                    return VLC_ENOMEM;                }                p_sys->psz_header = strcat( p_sys->psz_header, strdup( s ) );                p_sys->psz_header = strcat( p_sys->psz_header, "\n" );            }            else            {                if( !( p_sys->psz_header = malloc( strlen( s ) + 2 ) ) )                {                    msg_Err( p_demux, "out of memory");                    return VLC_ENOMEM;                }                p_sys->psz_header = strdup( s );                p_sys->psz_header = strcat( p_sys->psz_header, "\n" );            }        }    }}static int  ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle ){    demux_sys_t *p_sys = p_demux->p_sys;    text_t      *txt = &p_sys->txt;    /*     * each line:     *  h:m:s:Line1|Line2|Line3....     *  or     *  h:m:s Line1|Line2|Line3....     *     */    char *p;    char buffer_text[MAX_LINE + 1];    int64_t    i_start;    unsigned int i;    p_subtitle->i_start = 0;    p_subtitle->i_stop  = 0;    p_subtitle->psz_text = NULL;    for( ;; )    {        int h, m, s;        char c;        if( ( p = TextGetLine( txt ) ) == NULL )        {            return( VLC_EGENERIC );        }        i_start = 0;        memset( buffer_text, '\0', MAX_LINE );        if( sscanf( p, "%d:%d:%d%[ :]%[^\r\n]", &h, &m, &s, &c, buffer_text ) == 5 )        {            i_start = ( (int64_t)h * 3600*1000 +                        (int64_t)m * 60*1000 +                        (int64_t)s * 1000 ) * 1000;            break;        }    }    /* replace | by \n */    for( i = 0; i < strlen( buffer_text ); i++ )    {        if( buffer_text[i] == '|' )        {            buffer_text[i] = '\n';        }    }    p_subtitle->i_start = i_start;    p_subtitle->i_stop  = 0;    p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );    return( 0 );}static char *ParseSamiSearch( text_t *txt, char *psz_start, char *psz_str ){    if( psz_start )    {        if( strcasestr( psz_start, psz_str ) )        {            char *s = strcasestr( psz_start, psz_str );            s += strlen( psz_str );            return( s );        }    }    for( ;; )    {        char *p;        if( ( p = TextGetLine( txt ) ) == NULL )        {            return NULL;        }        if( strcasestr( p, psz_str ) )        {            char *s = strcasestr( p, psz_str );            s += strlen( psz_str );            return(  s);        }    }}static int  ParseSami( demux_t *p_demux, subtitle_t *p_subtitle ){    demux_sys_t *p_sys = p_demux->p_sys;    text_t      *txt = &p_sys->txt;    char *p;    int64_t i_start;    int  i_text;    char buffer_text[10*MAX_LINE + 1];    p_subtitle->i_start = 0;    p_subtitle->i_stop  = 0;    p_subtitle->psz_text = NULL;#define ADDC( c ) \    if( i_text < 10*MAX_LINE )      \    {                               \        buffer_text[i_text++] = c;  \        buffer_text[i_text] = '\0'; \    }    /* search "Start=" */    if( !( p = ParseSamiSearch( txt, NULL, "Start=" ) ) )    {        return VLC_EGENERIC;    }    /* get start value */    i_start = strtol( p, &p, 0 );    /* search <P */    if( !( p = ParseSamiSearch( txt, p, "<P" ) ) )    {        return VLC_EGENERIC;    }    /* search > */    if( !( p = ParseSamiSearch( txt, p, ">" ) ) )    {        return VLC_EGENERIC;    }    i_text = 0;    buffer_text[0] = '\0';    /* now get all txt until  a "Start=" line */    for( ;; )    {        if( *p )        {            if( *p == '<' )            {                if( !strncasecmp( p, "<br", 3 ) )                {                    ADDC( '\n' );                }                else if( strcasestr( p, "Start=" ) )                {                    TextPreviousLine( txt );                    break;                }                p = ParseSamiSearch( txt, p, ">" );            }            else if( !strncmp( p, "&nbsp;", 6 ) )            {                ADDC( ' ' );                p += 6;            }            else if( *p == '\t' )            {                ADDC( ' ' );                p++;            }            else            {                ADDC( *p );                p++;            }        }        else        {            p = TextGetLine( txt );        }        if( p == NULL )        {            break;        }    }    p_subtitle->i_start = i_start * 1000;    p_subtitle->i_stop  = 0;    p_subtitle->psz_text = strndup( buffer_text, 10*MAX_LINE );    return( VLC_SUCCESS );#undef ADDC}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -