public static void saveRawFrame(System.IO.MemoryStream data, AvcCBox avcC, string f) {//throws IOException { Stream raw = new System.IO.FileStream(f, FileMode.OpenOrCreate); saveStreamParams(avcC, raw); data.CopyTo(raw); raw.Close(); }
public static AvcCBox parseAVCC(VideoSampleEntry vse) { Box lb = Box.findFirst(vse, /*Box.bclass,*/ "avcC"); if (lb is AvcCBox) { return((AvcCBox)lb); } else { AvcCBox avcC = new AvcCBox(); avcC.parse(((LeafBox)lb).getData().duplicate()); return(avcC); } }
public static void saveStreamParams(AvcCBox avcC, Stream raw) {//throws IOException { System.IO.MemoryStream bb = new System.IO.MemoryStream(1024); foreach (var byteByffer in avcC.getSpsList()) { raw.Write(new byte[] { 0, 0, 0, 1, 0x67 }, 0, 5); Utility.escapeNAL(byteByffer.duplicate(), bb); bb.flip(); raw.CopyTo(bb); bb.clear(); } foreach (var byteBuffer in avcC.getPpsList()) { raw.Write(new byte[] { 0, 0, 0, 1, 0x68 }, 0, 5); Utility.escapeNAL(byteBuffer.duplicate(), bb); bb.flip(); raw.CopyTo(bb); bb.clear(); } }
public static SampleEntry createMOVSampleEntry(List <System.IO.MemoryStream> spsList, List <System.IO.MemoryStream> ppsList) { SeqParameterSet sps = readSPS(StreamExtensions.duplicate(spsList[0])); AvcCBox avcC = new AvcCBox(sps.profile_idc, 0, sps.level_idc, spsList, ppsList); int codedWidth = (sps.pic_width_in_mbs_minus1 + 1) << 4; int codedHeight = getPicHeightInMbs(sps) << 4; int width = sps.frame_cropping_flag ? codedWidth - ((sps.frame_crop_right_offset + sps.frame_crop_left_offset) << sps.chroma_format_idc.compWidth[1]) : codedWidth; int height = sps.frame_cropping_flag ? codedHeight - ((sps.frame_crop_bottom_offset + sps.frame_crop_top_offset) << sps.chroma_format_idc.compHeight[1]) : codedHeight; Size size = new Size(width, height); SampleEntry se = videoSampleEntry("avc1", size, "JCodec"); se.Add(avcC); return(se); }
public static List <System.IO.MemoryStream> splitMOVPacket(System.IO.MemoryStream buf, AvcCBox avcC) { List <System.IO.MemoryStream> result = new List <System.IO.MemoryStream>(); int nls = avcC.getNalLengthSize(); System.IO.MemoryStream dup = buf.duplicate(); while (dup.remaining() >= nls) { int len = readLen(dup, nls); if (len == 0) { break; } result.Add(StreamExtensions.read(dup, len)); } return(result); }