Ticket #598: patchpgs.diff

File patchpgs.diff, 3.9 KB (added by cehoyos, 5 years ago)
  • libavformat/Makefile

    diff --git a/libavformat/Makefile b/libavformat/Makefile
    index 0f35593..3a6434c 100644
    a b OBJS-$(CONFIG_PCM_U32LE_MUXER) += pcmenc.o rawenc.o 
    230230OBJS-$(CONFIG_PCM_U8_DEMUXER)            += pcmdec.o pcm.o rawdec.o 
    231231OBJS-$(CONFIG_PCM_U8_MUXER)              += pcmenc.o rawenc.o 
    232232OBJS-$(CONFIG_PMP_DEMUXER)               += pmpdec.o 
     233OBJS-$(CONFIG_PGS_DEMUXER)               += pgsdec.o 
    233234OBJS-$(CONFIG_PVA_DEMUXER)               += pva.o 
    234235OBJS-$(CONFIG_QCP_DEMUXER)               += qcp.o 
    235236OBJS-$(CONFIG_R3D_DEMUXER)               += r3d.o 
  • libavformat/allformats.c

    diff --git a/libavformat/allformats.c b/libavformat/allformats.c
    index cc9a902..5ddbc3e 100644
    a b void av_register_all(void) 
    184184    REGISTER_MUXDEMUX (PCM_U16BE, pcm_u16be); 
    185185    REGISTER_MUXDEMUX (PCM_U16LE, pcm_u16le); 
    186186    REGISTER_MUXDEMUX (PCM_U8,    pcm_u8); 
     187    REGISTER_DEMUXER  (PGS, pgs); 
    187188    REGISTER_DEMUXER  (PMP, pmp); 
    188189    REGISTER_MUXER    (PSP, psp); 
    189190    REGISTER_DEMUXER  (PVA, pva); 
  • new file libavformat/pgsdec.c

    diff --git a/libavformat/pgsdec.c b/libavformat/pgsdec.c
    new file mode 100644
    index 0000000..ed43f62
    - +  
     1/* 
     2 * probe function for PGS subtitles  
     3 * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at> 
     4 * Copyright (c) 2011 Carl Eugen Hoyos for FFmpeg 
     5 * 
     6 * This file is part of FFmpeg. 
     7 * 
     8 * FFmpeg is free software; you can redistribute it and/or 
     9 * modify it under the terms of the GNU Lesser General Public 
     10 * License as published by the Free Software Foundation; either 
     11 * version 2.1 of the License, or (at your option) any later version. 
     12 * 
     13 * FFmpeg is distributed in the hope that it will be useful, 
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     16 * Lesser General Public License for more details. 
     17 * 
     18 * You should have received a copy of the GNU Lesser General Public 
     19 * License along with FFmpeg; if not, write to the Free Software 
     20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
     21 */ 
     22 
     23#include "libavutil/intreadwrite.h" 
     24#include "avformat.h" 
     25 
     26static int pgs_subtitle_probe(AVProbeData *p) 
     27{ 
     28    int frames, max_frames = 0, first_frames = 0; 
     29    uint8_t *buf0 = p->buf; 
     30    uint8_t *buf, *buf2; 
     31    uint8_t *end = buf0 + p->buf_size - 3; 
     32 
     33    buf = buf0; 
     34 
     35    for(; buf < end; buf= buf2+1) { 
     36        buf2 = buf; 
     37 
     38        for(frames = 0; buf2 < end; frames++) { 
     39            uint16_t size = AV_RB16(buf2 + 1) + 3; 
     40            if (*buf2 != 0x80 && (*buf2 | 3) != 0x17 || 
     41                buf2 + size > end || 
     42                buf2[size] != 0x80 && (buf2[size] | 3) != 0x17) 
     43                break; 
     44            buf2 += size; 
     45        } 
     46        max_frames = FFMAX(max_frames, frames); 
     47        if(buf == buf0) 
     48            first_frames= frames; 
     49    } 
     50    if   (first_frames>=10) return AVPROBE_SCORE_MAX/2+1; 
     51    else if(max_frames>50)  return AVPROBE_SCORE_MAX/2; 
     52    else if(max_frames>=5)  return AVPROBE_SCORE_MAX/4; 
     53    else if(max_frames>=3)  return 1; 
     54    else                    return 0; 
     55} 
     56 
     57AVInputFormat ff_pgs_demuxer = { 
     58    .name           = "pgs", 
     59    .long_name      = NULL_IF_CONFIG_SMALL("raw PGS subtitles"), 
     60    .read_probe     = pgs_subtitle_probe, 
     61    .value = CODEC_ID_HDMV_PGS_SUBTITLE, 
     62}; 
  • libavformat/utils.c

    diff --git a/libavformat/utils.c b/libavformat/utils.c
    index 2cf42d3..70fab25 100644
    a b static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeDa 
    374374        { "m4v"      , CODEC_ID_MPEG4     , AVMEDIA_TYPE_VIDEO }, 
    375375        { "mp3"      , CODEC_ID_MP3       , AVMEDIA_TYPE_AUDIO }, 
    376376        { "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, 
     377        { "pgs"      , CODEC_ID_HDMV_PGS_SUBTITLE, AVMEDIA_TYPE_SUBTITLE }, 
    377378        { 0 } 
    378379    }; 
    379380    int score;