Revision f838b30a

View differences:

chunker_streamer/chunker_streamer.c
23 23
struct outstream {
24 24
	struct output *output;
25 25
	ExternalChunk *chunk;
26
	AVCodecContext *pCodecCtxEnc;
26 27
};
27 28
struct outstream outstream[2];
28 29

  
......
532 533
	AVFrame *pFrame1 = NULL;
533 534

  
534 535
	AVFormatContext *pFormatCtx;
535
	AVCodecContext  *pCodecCtx = NULL ,*pCodecCtxEnc = NULL ,*aCodecCtxEnc = NULL ,*aCodecCtx = NULL;
536
	AVCodec         *pCodec = NULL ,*pCodecEnc = NULL ,*aCodec = NULL ,*aCodecEnc = NULL;
536
	AVCodecContext  *pCodecCtx = NULL ,*aCodecCtxEnc = NULL ,*aCodecCtx = NULL;
537
	AVCodec         *pCodec = NULL ,*aCodec = NULL ,*aCodecEnc = NULL;
537 538
	AVPacket         packet;
538 539

  
539 540
	//stuff needed to compute the right timestamps
......
720 721
	dest_width = (dest_width > 0) ? dest_width : pCodecCtx->width;
721 722
	dest_height = (dest_height > 0) ? dest_height : pCodecCtx->height;
722 723

  
723
	pCodecCtxEnc = openVideoEncoder(video_codec, video_bitrate, dest_width, dest_height, pCodecCtx->time_base, codec_options);
724
	if (!pCodecCtxEnc) {
724
	//create an empty first video chunk
725
	outstream[0].chunk = (ExternalChunk *)malloc(sizeof(ExternalChunk));
726
	if(!outstream[0].chunk) {
727
		fprintf(stderr, "INIT: Memory error alloc chunk!!!\n");
728
		return -1;
729
	}
730
	outstream[0].chunk->data = NULL;
731
	outstream[0].chunk->seq = 0;
732
	dcprintf(DEBUG_CHUNKER, "INIT: chunk video %d\n", outstream[0].chunk->seq);
733
	outstream[0].pCodecCtxEnc = NULL;
734

  
735
	outstream[1].chunk = (ExternalChunk *)malloc(sizeof(ExternalChunk));
736
	if(!outstream[1].chunk) {
737
		fprintf(stderr, "INIT: Memory error alloc chunk!!!\n");
738
		return -1;
739
	}
740
	outstream[1].chunk->data = NULL;
741
	outstream[1].chunk->seq = 0;
742
	dcprintf(DEBUG_CHUNKER, "INIT: chunk video %d\n", outstream[1].chunk->seq);
743
	outstream[1].pCodecCtxEnc = openVideoEncoder(video_codec, video_bitrate, dest_width, dest_height, pCodecCtx->time_base, codec_options);
744
	if (!outstream[1].pCodecCtxEnc) {
725 745
		return -1;
726 746
	}
727 747

  
728
	fprintf(stderr, "INIT: VIDEO timebase OUT:%d %d IN: %d %d\n", pCodecCtxEnc->time_base.num, pCodecCtxEnc->time_base.den, pCodecCtx->time_base.num, pCodecCtx->time_base.den);
748
	fprintf(stderr, "INIT: VIDEO timebase OUT:%d %d IN: %d %d\n", outstream[1].pCodecCtxEnc->time_base.num, outstream[1].pCodecCtxEnc->time_base.den, pCodecCtx->time_base.num, pCodecCtx->time_base.den);
729 749

  
730 750
	if(pCodec==NULL) {
731 751
		fprintf(stderr, "INIT: Unsupported IN VIDEO pcodec!\n");
......
798 818
		return -1;
799 819
	}
800 820

  
801
	//create an empty first video chunk
802
	outstream[0].chunk = (ExternalChunk *)malloc(sizeof(ExternalChunk));
803
	if(!outstream[0].chunk) {
804
		fprintf(stderr, "INIT: Memory error alloc chunk!!!\n");
805
		return -1;
806
	}
807
	outstream[0].chunk->data = NULL;
808
	outstream[0].chunk->seq = 0;
809
	dcprintf(DEBUG_CHUNKER, "INIT: chunk video %d\n", outstream[0].chunk->seq);
810
	outstream[1].chunk = (ExternalChunk *)malloc(sizeof(ExternalChunk));
811
	if(!outstream[1].chunk) {
812
		fprintf(stderr, "INIT: Memory error alloc chunk!!!\n");
813
		return -1;
814
	}
815
	outstream[1].chunk->data = NULL;
816
	outstream[1].chunk->seq = 0;
817
	dcprintf(DEBUG_CHUNKER, "INIT: chunk video %d\n", outstream[1].chunk->seq);
818 821
	//create empty first audio chunk
819 822

  
820 823
	chunkaudio = (ExternalChunk *)malloc(sizeof(ExternalChunk));
......
1021 1024
						addFrameToOutstream(&outstream[0], frame, video_outbuf);
1022 1025
					}
1023 1026
					if(true) {
1024
						video_frame_size = transcodeFrame(video_outbuf, video_outbuf_size, &target_pts, pFrame, pFormatCtx->streams[videoStream]->time_base, pCodecCtx, pCodecCtxEnc);
1027
						video_frame_size = transcodeFrame(video_outbuf, video_outbuf_size, &target_pts, pFrame, pFormatCtx->streams[videoStream]->time_base, pCodecCtx, outstream[1].pCodecCtxEnc);
1025 1028
						if (video_frame_size <= 0) {
1026 1029
							av_free_packet(&packet);
1027 1030
							contFrameVideo = STREAMER_MAX(contFrameVideo-1, 0);
1028 1031
							continue;
1029 1032
						}
1030 1033
						createFrame(frame, pts2ms(target_pts - ptsvideo1, pFormatCtx->streams[videoStream]->time_base), video_frame_size, 
1031
					            (unsigned char)pCodecCtxEnc->coded_frame->pict_type);
1034
					            (unsigned char)outstream[1].pCodecCtxEnc->coded_frame->pict_type);
1032 1035
						addFrameToOutstream(&outstream[1], frame, video_outbuf);
1033 1036
					}
1034 1037

  
......
1276 1279
	av_free(samples);
1277 1280
  
1278 1281
	// Close the codec
1279
	if (!vcopy) avcodec_close(pCodecCtx);
1280
	if (!vcopy) avcodec_close(pCodecCtxEnc);
1282
	avcodec_close(pCodecCtx);
1283
	avcodec_close(outstream[1].pCodecCtxEnc);
1281 1284

  
1282 1285
	if(audioStream!=-1) {
1283 1286
		avcodec_close(aCodecCtx);

Also available in: Unified diff