def writeFrame(self, frame): buf = ctypes.addressof(self._buffer) self._frame.pts = self._currentPts self._currentPts += 1 bytes = avcodec.avcodec_encode_video(self._codecCtx, buf, self._bufSize, self._frame) # print "pts", self._frame.pts print "bytes",bytes if bytes>0: self._pkt.data = ctypes.cast(self._buffer, ctypes.POINTER(ctypes.c_uint8)) self._pkt.size = bytes self._pkt.pts = self._frame.pts # if self._codecCtx.coded_frame.contents.key_frame: # self._pkt.flags |= cppdefs.PKT_FLAG_KEY avformat.av_interleaved_write_frame(self._formatCtx, self._pkt)
def writeFrame__dummy(self): # Create a packet struct and initialize it pkt = AVPacket() avcodec.av_init_packet(pkt) #pkt.stream_index = outputstream.index #big_picture.pts= ost->sync_opts; # Encode the frame bytes = avcodec.avcodec_encode_video(codecCtx, buf, bufsize, picture) if bytes>0: pkt.data = buf pkt.size = bytes # pkt.pts = ... if codecCtx.coded_frame.key_frame: pkt.flags |= PKT_FLAG_KEY avformat.av_interleaved_write_frame(formatCtx, pkt)