00001 /* 00002 * RAW MPEG video demuxer 00003 * Copyright (c) 2002-2003 Fabrice Bellard 00004 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * FFmpeg is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with FFmpeg; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include "avformat.h" 00024 #include "rawdec.h" 00025 00026 #define SEQ_START_CODE 0x000001b3 00027 #define GOP_START_CODE 0x000001b8 00028 #define PICTURE_START_CODE 0x00000100 00029 #define SLICE_START_CODE 0x00000101 00030 #define PACK_START_CODE 0x000001ba 00031 #define VIDEO_ID 0x000001e0 00032 #define AUDIO_ID 0x000001c0 00033 00034 static int mpegvideo_probe(AVProbeData *p) 00035 { 00036 uint32_t code= -1; 00037 int pic=0, seq=0, slice=0, pspack=0, pes=0; 00038 int i; 00039 00040 for(i=0; i<p->buf_size; i++){ 00041 code = (code<<8) + p->buf[i]; 00042 if ((code & 0xffffff00) == 0x100) { 00043 switch(code){ 00044 case SEQ_START_CODE: seq++; break; 00045 case PICTURE_START_CODE: pic++; break; 00046 case SLICE_START_CODE: slice++; break; 00047 case PACK_START_CODE: pspack++; break; 00048 } 00049 if ((code & 0x1f0) == VIDEO_ID) pes++; 00050 else if((code & 0x1e0) == AUDIO_ID) pes++; 00051 } 00052 } 00053 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes) 00054 return pic>1 ? AVPROBE_SCORE_MAX/2+1 : AVPROBE_SCORE_MAX/4; // +1 for .mpg 00055 return 0; 00056 } 00057 00058 FF_DEF_RAWVIDEO_DEMUXER(mpegvideo, "raw MPEG video", mpegvideo_probe, NULL, CODEC_ID_MPEG1VIDEO)