/*
 * Class:     com_chris_yanlong_player
 * Method:    get_video_frame
 * Signature: (ILjava/lang/Double;)[B
 */
JNIEXPORT jbyteArray JNICALL Java_com_chris_yanlong_PlayerView_get_1video_1frame
  (JNIEnv *env, jobject obj, jint handle , jobject video_pts ,jobject byteBuffer ,jint back_play_mark){

	jbyte *directBuffer = (*env)->GetDirectBufferAddress(env, byteBuffer);

	media_handle_union_t * media_handle = (media_handle_union_t *) handle;

//	 __android_log_print(ANDROID_LOG_INFO,"chris_magic", "video packet.num = %d ,audio packet.num = %d" ,media_handle->video_queue.nb_packets
//			 	 ,media_handle->audio_queue.nb_packets);
	jclass c;
	jfieldID id;
	c = (*env)->FindClass(env ,"java/lang/Double");
	if (c == NULL)
	{
	   __android_log_print(ANDROID_LOG_INFO,"chris_magic", "jclass is null");
	  exit(NULL_POINT);
	   //return -1;
	}

	id = (*env)->GetFieldID( env ,c, "value", "D");
	if (id==NULL)
	{
	   __android_log_print(ANDROID_LOG_INFO,"chris_magic", "id is null");
//	   return -1;
	   exit(NULL_POINT);
	}
	double video_frame_pts = 0;
	get_video_frame((int)handle , &video_frame_pts ,directBuffer ,(int)back_play_mark);


	(*env)->SetDoubleField(env ,video_pts, id, video_frame_pts);

	return NULL;
}
Beispiel #2
0
/*
 * encode one video frame and send it to the muxer
 * return 1 when encoding is finished, 0 otherwise
 */
static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
{
    int ret;
    AVCodecContext *c;
    AVFrame *frame;
    int got_packet = 0;
    AVPacket pkt = { 0 };

    c = ost->enc;

    frame = get_video_frame(ost);

    av_init_packet(&pkt);

    /* encode the image */
    ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
    if (ret < 0) {
        fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret));
        exit(1);
    }

    if (got_packet) {
        ret = write_frame(oc, &c->time_base, ost->st, &pkt);
    } else {
        ret = 0;
    }

    if (ret < 0) {
        fprintf(stderr, "Error while writing video frame: %s\n", av_err2str(ret));
        exit(1);
    }

    return (frame || got_packet) ? 0 : 1;
}
Beispiel #3
0
BOOL CVideoLivRecord::write_video_frame(AVStream *st, void* pBuffer, LONG len)
{
	int got_packet = 0;
	AVFrame* frame = get_video_frame(st, pBuffer, len);
	if (!(m_pAVFormatContext->oformat->flags & AVFMT_RAWPICTURE)){
		AVPacket pkt = {0};
		av_init_packet(&pkt);
		AVCodecContext *avc = st->codec;

		int ret = avcodec_encode_video2(avc, &pkt, frame, &got_packet);
		if (ret < 0){
			log("[CVideoLivRecord::write_video_frame] -- avcodec_encode_video2() error");
			return FALSE;
		}
		if (got_packet){
			count++;
			/* rescale output packet timestamp values from codec to stream timebase */
			av_packet_rescale_ts(&pkt, st->codec->time_base, st->time_base);//这两个时间是不一样的,这里花了一下午时间找出问题来,汗!!!
			pkt.stream_index = st->index;
			ret = av_interleaved_write_frame(m_pAVFormatContext, &pkt);
		}
		if (ret < 0){
			log("[CVideoLivRecord::write_video_frame] -- error");
			return FALSE;
		}
	}
	return (frame || got_packet)? FALSE : TRUE;
}
Beispiel #4
0
/*
 * encode one video frame and send it to the muxer
 * return 1 when encoding is finished, 0 otherwise
 */
static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
{
    int ret;
    AVCodecContext *c;
    AVFrame *frame;
    int got_packet = 0;

    c = ost->st->codec;

    frame = get_video_frame(ost);

    if (oc->oformat->flags & AVFMT_RAWPICTURE) {
        /* a hack to avoid data copy with some raw video muxers */
        AVPacket pkt;
        av_init_packet(&pkt);

        if (!frame)
            return 1;

        pkt.flags        |= AV_PKT_FLAG_KEY;
        pkt.stream_index  = ost->st->index;
        pkt.data          = (uint8_t *)frame;
        pkt.size          = sizeof(AVPicture);

        pkt.pts = pkt.dts = frame->pts;
        av_packet_rescale_ts(&pkt, c->time_base, ost->st->time_base);

        ret = av_interleaved_write_frame(oc, &pkt);
    } else {
        AVPacket pkt = { 0 };
        av_init_packet(&pkt);

        /* encode the image */
        ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
        if (ret < 0) {
            fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret));
            exit(1);
        }

        if (got_packet) {
            ret = write_frame(oc, &c->time_base, ost->st, &pkt);
        } else {
            ret = 0;
        }
    }

    if (ret < 0) {
        fprintf(stderr, "Error while writing video frame: %s\n", av_err2str(ret));
        exit(1);
    }

    return (frame || got_packet) ? 0 : 1;
}
Beispiel #5
0
    int LibAVVideoWriter::Data::write_video_frame(const ImgBase *src, AVFormatContext *oc, OutputStream *ost)
    {
        int ret;
        AVCodecContext *c;
        AVFrame *frame;
        int got_packet = 0;

        c = ost->st->codec;

        frame = get_video_frame(src,ost);

        if (oc->oformat->flags & AVFMT_RAWPICTURE) {
            /* a hack to avoid data copy with some raw video muxers */
            AVPacket pkt;
            av_init_packet(&pkt);

            if (!frame)
                return 1;

            pkt.flags        |= AV_PKT_FLAG_KEY;
            pkt.stream_index  = ost->st->index;
            pkt.data          = (uint8_t *)frame;
            pkt.size          = sizeof(AVPicture);

            pkt.pts = pkt.dts = frame->pts;
#if LIBAVCODEC_VERSION_MAJOR > 54
            av_packet_rescale_ts(&pkt, c->time_base, ost->st->time_base);
#endif

            ret = av_interleaved_write_frame(oc, &pkt);
        } else {
            AVPacket pkt = { 0 };
            av_init_packet(&pkt);

            /* encode the image */
            ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
            if (ret < 0) throw ICLException("Error encoding a video frame");

            if (got_packet) {
#if LIBAVCODEC_VERSION_MAJOR > 54
                av_packet_rescale_ts(&pkt, c->time_base, ost->st->time_base);
#endif
                pkt.stream_index = ost->st->index;

                /* Write the compressed frame to the media file. */
                ret = av_interleaved_write_frame(oc, &pkt);
            }
        }
        if (ret != 0) throw ICLException("Error while writing video frame");
        return (frame || got_packet) ? 0 : 1;
    }
Beispiel #6
0
void movie_player::run_video()
{
    AVFrame *pFrame = av_frame_alloc();
    double dClockPts;
    int iError;

    while(!aborting)
    {
        av_frame_unref(pFrame);

#ifdef CORSIX_TH_MOVIE_USE_SEND_PACKET_API
        iError = get_frame(video_stream_index, pFrame);

        if (iError == AVERROR_EOF)
        {
            break;
        }
        else if (iError < 0)
        {
            std::cerr << "Unexpected error " << iError << " while decoding video packet" << std::endl;
            break;
        }
#else
        iError = get_video_frame(pFrame);
        if(iError < 0)
        {
            break;
        }
        else if(iError == 0)
        {
            continue;
        }
#endif

        dClockPts = get_presentation_time_for_frame(pFrame, video_stream_index);
        iError = movie_picture_buffer->write(pFrame, dClockPts);

        if(iError < 0)
        {
            break;
        }
    }

    avcodec_flush_buffers(video_codec_context);
    av_frame_free(&pFrame);
}
Beispiel #7
0
/*
 * encode one video frame and send it to the muxer
 * return 1 when encoding is finished, 0 otherwise
 */
static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
{
    int ret;
    AVCodecContext *c;
    AVFrame *frame;
    int got_packet = 0;

    c = ost->st->codec;

    frame = get_video_frame(ost);

    AVPacket pkt = { 0 };
    av_init_packet(&pkt);

    /* encode the image */
    ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
    if (ret < 0) {
        fprintf(stderr, "Error encoding a video frame\n");
        exit(1);
    }

    if (got_packet) {
        av_packet_rescale_ts(&pkt, c->time_base, ost->st->time_base);
        pkt.stream_index = ost->st->index;

        /* Write the compressed frame to the media file. */
        //ret = av_interleaved_write_frame(oc, &pkt);
        ret = av_write_frame(oc, &pkt);
    }

    if (ret != 0) {
        fprintf(stderr, "Error while writing video frame\n");
        exit(1);
    }

    return (frame || got_packet) ? 0 : 1;
}