A python .ap and .sc generator for enigma2 recordings
| fromstruct importpack, unpackimportioimportos.pathimportsysLEN=24064PACKET_SIZE =188    defWriteBufInternal(f, sc, tm):    f.write(pack('>QQ', sc, tm))defFrameGenerator(ts, packetoffset=0, maxlen=-1):    s =io.open(ts, 'rb', buffering=LEN)    buf =bytearray(PACKET_SIZE)    streamtype =-1    pid =-1    whilelen(s.peek())>=PACKET_SIZE: #Skip if not a whole packet left        whileord(s.peek()[0]) !=0x47: #Sync stream            s.read(1)            print("Skipped 1 byte")         filepos =s.tell()        ifmaxlen >=0andfilepos > maxlen: #Limit reading for debugging purposes            break                ifs.readinto(buf) !=PACKET_SIZE: #If not enough data quit            s.close()            break        ifnotbuf[3]&0x10: #Skip if there is no payload            continue        pos =buf[4] +5ifbuf[3]&0x20else4#Skip adaption field        ifpos > PACKET_SIZE: #Skip large adaption field            continue        tpid =((buf[1]&0x1F) << 8) | buf[2] #Read current packet pid        if(not(buf[pos] orbuf[pos+1] ornotbuf[pos+2]&0x01)            andbuf[pos+3]&0xf0==0xe0            andbuf[1]&0x040): #Find video pid            pid =tpid        elifpid>=0andpid !=tpid: #Wrong pid            continue        pts =-1        ifbuf[1]&0x40: #Pusi            ifbuf[pos] orbuf[pos+1] ornotbuf[pos+2]&0x01:                print("Broken startcode")                continue            ifbuf[pos+7]&0x80: #PTS present?                pts =((buf[pos+9]&0xE) << 29| (buf[pos+10]&0xFF) << 22|                       (buf[pos+11]&0xFE) << 14| (buf[pos+12]&0xFF) << 7|                       (buf[pos+13]&0xFE) >> 1)            pos =buf[pos+8] +9                whilepos < PACKET_SIZE -4:            ifnot(buf[pos] orbuf[pos+1] ornotbuf[pos+2]&0x01):                sc =buf[pos+3]                ifstreamtype < 0: #Stream type is unknown                    ifsc in[0x00, 0xb3, 0xb8]:                        streamtype =0                        print("Detected MPEG2 stream type")                    elifsc in[0x09]:                        streamtype =1                        print("Detected H264 stream type")                    else:                        pos +=1                        continue                                ifstreamtype ==0: #MPEG2                    ifsc in[0x00, 0xb3, 0xb8]: #Picture, sequence, group start code                        retpos =retpts =retdat =retpos2 =-1                        ifsc ==0xb3andpts >=0: #Sequence header                            retpos =filepos                            retpts =pts                        ifpos < PACKET_SIZE -6:                            retdat =sc | buf[pos+4] << 8| buf[pos+5] << 16                            ifpts >=0:                                retdat |=(pts << 31) | 0x1000000;                            retpos2 =filepos +pos                        yield(retpts, retpos, retdat, retpos2)                elifstreamtype ==1:                    ifsc ==0x09:                        retpos =retpts =retdat =retpos2 =-1                        retdat =sc | (buf[pos+4] << 8)                        ifpts >=0:                            retdat |=(pts << 31) | 0x1000000                        retpos2 =filepos +pos                        if(buf[pos+4]&0x60) ==0:                            ifpts >=0:                                retpos =filepos                                retpts =pts                        yield(retpts, retpos, retdat, retpos2)                                            pos +=1defProcessScAp(ts, maxlen=-1):    scf =open(ts+'.sc', 'wb')    apf =open(ts+'.ap', 'wb')    filesize =os.path.getsize(ts)    lastprogress =-1    for(pts, pos, dat, pos2) inFrameGenerator(ts, maxlen=maxlen):        curpos =max(pos, pos2)        ifcurpos >=0:            progress =curpos*100/filesize        ifprogress > lastprogress:            print("{0}%".format(progress))            lastprogress =progress        ifpts >=0andpos >=0:            WriteBufInternal(apf, pos,  pts)        ifdat >=0andpos2 >=0:            WriteBufInternal(scf, pos2, dat)    scf.close()    apf.close()-----------------------------------------------------------------------------------------------
maaf,,masih newbie masalah transcoder,,silahkan kunjungi http://serioustinker.blogspot.com/2013/01/a-python-ap-and-sc-generator-for.html 
untuk lebih mendalam.,,,thnks | 
Read more
 







 
 



