static int decode_packet(Pointer<Integer> got_frame, int cached)
			throws IOException {
		int ret = 0;
		int decoded = pkt.get().size();
		got_frame.setInt(0);

		if (pkt.get().stream_index() == video_stream_idx.get()) {
			/* decode video frame */
			ret = avcodec_decode_video2(video_dec_ctx, frame, got_frame,
					pkt);
			if (ret < 0) {
				System.err.printf("Error decoding video frame\n");
				return ret;
			}

			if (got_frame.get() != 0) {
				if(first_frame) {
					first_frame = false;
					StructInfo.printAVFrame(frame.get());
				}
				System.out.printf("video_frame%s n:%d coded_n:%d pts:%s\n",
						cached != 0 ? "(cached)" : "", video_frame_count++,
						frame.get().coded_picture_number(), av_ts2timestr(
								frame.get().pts(), video_dec_ctx.get().time_base()));

				/*
				 * copy decoded frame to destination buffer: this is required
				 * since rawvideo expects non aligned data
				 */
				av_image_copy(video_dst_data, video_dst_linesize,
						frame.get().data(), frame.get().linesize(), video_dec_ctx.get().pix_fmt(),
						video_dec_ctx.get().width(), video_dec_ctx.get().height());

				/* write to rawvideo file */
				streamptr = video_dst_data.get();
				video_dst_file.write(streamptr.getBytes(video_dst_bufsize));
			}
		} else if (pkt.get().stream_index() == audio_stream_idx.get()) {
			/* decode audio frame */
			ret = avcodec_decode_audio4(audio_dec_ctx, frame, got_frame,
					pkt);
			if (ret < 0) {
				System.err.printf("Error decoding audio frame\n");
				return ret;
			}
			/*
			 * Some audio decoders decode only part of the packet, and have to
			 * be called again with the remainder of the packet data. Sample:
			 * fate-suite/lossless-audio/luckynight-partial.shn Also, some
			 * decoders might over-read the packet.
			 */
			decoded = Math.min(ret, pkt.get().size());

			if (got_frame.get() != 0) {
				int unpadded_linesize = frame.get().nb_samples()
						* av_get_bytes_per_sample(AVSampleFormat.fromValue(frame.get().format()));
				System.out.printf("audio_frame%s n:%d nb_samples:%d pts:%s\n",
						cached != 0 ? "(cached)" : "", audio_frame_count++,
						frame.get().nb_samples(), av_ts2timestr(frame.get().pts(),
								audio_dec_ctx.get().time_base()));

				/*
				 * Write the raw audio data samples of the first plane. This
				 * works fine for packed formats (e.g. AV_SAMPLE_FMT_S16).
				 * However, most audio decoders output planar audio, which uses
				 * a separate plane of audio samples for each channel (e.g.
				 * AV_SAMPLE_FMT_S16P). In other words, this code will write
				 * only the first audio channel in these cases. You should use
				 * libswresample or libavfilter to convert the frame to packed
				 * data.
				 */
				streamptr = frame.get().extended_data().get();
				audio_dst_file.write(streamptr.getBytes(unpadded_linesize));
			}
		}

		return decoded;
	}