void AppendFLVPacket(const BYTE *lpData, UINT size, BYTE type, DWORD timestamp) { if (!bSentSEI && type == 9 && lpData[0] == 0x17 && lpData[1] == 0x1) { //send SEI with first keyframe packet UINT networkDataSize = fastHtonl(size+sei.size); UINT networkTimestamp = fastHtonl(timestamp); UINT streamID = 0; fileOut.OutputByte(type); fileOut.Serialize(((LPBYTE)(&networkDataSize))+1, 3); fileOut.Serialize(((LPBYTE)(&networkTimestamp))+1, 3); fileOut.Serialize(&networkTimestamp, 1); fileOut.Serialize(&streamID, 3); fileOut.Serialize(lpData, 5); fileOut.Serialize(sei.lpPacket, sei.size); fileOut.Serialize(lpData+5, size-5); fileOut.OutputDword(fastHtonl(size+sei.size+11)); bSentSEI = true; } else { UINT networkDataSize = fastHtonl(size); UINT networkTimestamp = fastHtonl(timestamp); UINT streamID = 0; fileOut.OutputByte(type); fileOut.Serialize(((LPBYTE)(&networkDataSize))+1, 3); fileOut.Serialize(((LPBYTE)(&networkTimestamp))+1, 3); fileOut.Serialize(&networkTimestamp, 1); fileOut.Serialize(&streamID, 3); fileOut.Serialize(lpData, size); fileOut.OutputDword(fastHtonl(size+11)); } lastTimeStamp = timestamp; }
bool Init(CTSTR lpFile) { strFile = lpFile; initialTimestamp = -1; if(!fileOut.Open(lpFile, XFILE_CREATEALWAYS, 1024*1024)) return false; fileOut.OutputByte('F'); fileOut.OutputByte('L'); fileOut.OutputByte('V'); fileOut.OutputByte(1); fileOut.OutputByte(5); //bit 0 = (hasAudio), bit 2 = (hasAudio) fileOut.OutputDword(DWORD_BE(9)); fileOut.OutputDword(0); metaDataPos = fileOut.GetPos(); char metaDataBuffer[2048]; char *enc = metaDataBuffer; char *pend = metaDataBuffer+sizeof(metaDataBuffer); enc = AMF_EncodeString(enc, pend, &av_onMetaData); char *endMetaData = App->EncMetaData(enc, pend, true); UINT metaDataSize = endMetaData-metaDataBuffer; AppendFLVPacket((LPBYTE)metaDataBuffer, metaDataSize, 18, 0); return true; }
bool Init(CTSTR lpFile) { strFile = lpFile; if(!fileOut.Open(lpFile, XFILE_CREATEALWAYS, 1024*1024)) return false; fileOut.OutputDword(DWORD_BE(0x20)); fileOut.OutputDword(DWORD_BE('ftyp')); fileOut.OutputDword(DWORD_BE('isom')); fileOut.OutputDword(DWORD_BE(0x200)); fileOut.OutputDword(DWORD_BE('isom')); fileOut.OutputDword(DWORD_BE('iso2')); fileOut.OutputDword(DWORD_BE('avc1')); fileOut.OutputDword(DWORD_BE('mp41')); fileOut.OutputDword(DWORD_BE(0x8)); fileOut.OutputDword(DWORD_BE('free')); mdatStart = fileOut.GetPos(); fileOut.OutputDword(DWORD_BE(0x1)); fileOut.OutputDword(DWORD_BE('mdat')); #ifdef USE_64BIT_MP4 fileOut.OutputQword(0); #endif bMP3 = scmp(App->GetAudioEncoder()->GetCodec(), TEXT("MP3")) == 0; audioFrameSize = App->GetAudioEncoder()->GetFrameSize(); bStreamOpened = true; return true; }