Revision b9477cd0

View differences:

chunker_streamer/chunker_streamer.c
45 45
bool timebank = false;
46 46
char *outside_world_url = NULL;
47 47

  
48
bool vcopy = false;
49

  
48 50
// Constant number of frames per chunk
49 51
int chunkFilledFramesStrategy(ExternalChunk *echunk, int chunkType)
50 52
{
......
337 339
	dest_height = (dest_height > 0) ? dest_height : pCodecCtx->height;
338 340

  
339 341
	//setup video output encoder
342
 if (strcmp(video_codec, "copy") == 0) {
343
	vcopy = true;
344
 } else {
340 345
	pCodecEnc = avcodec_find_encoder_by_name(video_codec);
341 346
	if (pCodecEnc) {
342 347
		fprintf(stderr, "INIT: Setting VIDEO codecID to: %d\n",pCodecEnc->id);
......
396 401
    default:
397 402
	fprintf(stderr, "INIT: Unsupported OUT VIDEO codec: %s!\n", video_codec);
398 403
  }
399

  
404
 
400 405
	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);
406
 }
401 407

  
402 408
	if(pCodec==NULL) {
403 409
		fprintf(stderr, "INIT: Unsupported IN VIDEO pcodec!\n");
404 410
		return -1; // Codec not found
405 411
	}
406
	if(pCodecEnc==NULL) {
412
	if(!vcopy && pCodecEnc==NULL) {
407 413
		fprintf(stderr, "INIT: Unsupported OUT VIDEO pcodecenc!\n");
408 414
		return -1; // Codec not found
409 415
	}
......
411 417
		fprintf(stderr, "INIT: could not open IN VIDEO codec\n");
412 418
		return -1; // Could not open codec
413 419
	}
414
	if(avcodec_open(pCodecCtxEnc, pCodecEnc)<0) {
420
	if(!vcopy && avcodec_open(pCodecCtxEnc, pCodecEnc)<0) {
415 421
		fprintf(stderr, "INIT: could not open OUT VIDEO codecEnc\n");
416 422
		return -1; // Could not open codec
417 423
	}
418

  
419 424
	if(audioStream!=-1) {
420 425
		//setup audio output encoder
421 426
		aCodecCtxEnc = avcodec_alloc_context();
......
628 633
					frame->number = ++contFrameVideo;
629 634

  
630 635
#ifdef VIDEO_DEINTERLACE
636
				if (!vcopy) {
631 637
					avpicture_deinterlace(
632 638
						(AVPicture*) pFrame,
633 639
						(const AVPicture*) pFrame,
634 640
						pCodecCtxEnc->pix_fmt,
635 641
						pCodecCtxEnc->width,
636 642
						pCodecCtxEnc->height);
643
				}
637 644
#endif
638 645

  
639 646
#ifdef DEBUG_VIDEO_FRAMES
......
665 672
					fprintf(stderr, "VIDEO: deltavideo : %d\n", (int)delta_video);
666 673
#endif
667 674

  
668
					if(pCodecCtx->height != pCodecCtxEnc->height || pCodecCtx->width != pCodecCtxEnc->width)
669
					{
675
					if(vcopy) {
676
						video_frame_size = packet.size;
677
						if (video_frame_size > video_outbuf_size) {
678
							fprintf(stderr, "VIDEO: error, outbuf too small, SKIPPING\n");;
679
							continue;
680
						} else {
681
							memcpy(video_outbuf, packet.data, video_frame_size);
682
						}
683
					} else if(pCodecCtx->height != pCodecCtxEnc->height || pCodecCtx->width != pCodecCtxEnc->width) {
670 684
//						static AVPicture pict;
671 685
						static struct SwsContext *img_convert_ctx = NULL;
672 686
						
......
691 705
					}
692 706

  
693 707
#ifdef DEBUG_VIDEO_FRAMES
694
					if(pCodecCtxEnc->coded_frame) {
708
					if(!vcopy && pCodecCtxEnc->coded_frame) {
695 709
						fprintf(stderr, "\n-------VIDEO FRAME intype %d%s -> outtype: %d%s\n",
696 710
							pFrame->pict_type, pFrame->key_frame ? " (key)" : "",
697 711
							pCodecCtxEnc->coded_frame->pict_type, pCodecCtxEnc->coded_frame->key_frame ? " (key)" : "");
......
761 775
					frame->timestamp.tv_usec = newTime%1000;
762 776
					frame->size = video_frame_size;
763 777
					/* pict_type maybe 1 (I), 2 (P), 3 (B), 5 (AUDIO)*/
764
					frame->type = (unsigned char)pCodecCtxEnc->coded_frame->pict_type;
778
					frame->type = vcopy ? pFrame->pict_type : (unsigned char)pCodecCtxEnc->coded_frame->pict_type;
765 779

  
766 780
#ifdef DEBUG_VIDEO_FRAMES
767
					fprintf(stderr, "VIDEO: original codec frame number %d vs. encoded %d vs. packed %d\n", pCodecCtx->frame_number, pCodecCtxEnc->frame_number, frame->number);
768
					fprintf(stderr, "VIDEO: duration %d timebase %d %d container timebase %d\n", (int)packet.duration, pCodecCtxEnc->time_base.den, pCodecCtxEnc->time_base.num, pCodecCtx->time_base.den);
781
					if (!vcopy) fprintf(stderr, "VIDEO: original codec frame number %d vs. encoded %d vs. packed %d\n", pCodecCtx->frame_number, pCodecCtxEnc->frame_number, frame->number);
782
					if (!vcopy) fprintf(stderr, "VIDEO: duration %d timebase %d %d container timebase %d\n", (int)packet.duration, pCodecCtxEnc->time_base.den, pCodecCtxEnc->time_base.num, pCodecCtx->time_base.den);
769 783
#endif
770 784

  
771 785
#ifdef YUV_RECORD_ENABLED
772
					if(ChunkerStreamerTestMode)
786
					if(!vcopy && ChunkerStreamerTestMode)
773 787
					{
774 788
						if(videotrace)
775 789
							fprintf(videotrace, "%d %d %d\n", frame->number, pFrame->pict_type, frame->size);
......
1095 1109
	av_free(samples);
1096 1110
  
1097 1111
	// Close the codec
1098
	avcodec_close(pCodecCtx);
1099
	avcodec_close(pCodecCtxEnc);
1112
	if (!vcopy) avcodec_close(pCodecCtx);
1113
	if (!vcopy) avcodec_close(pCodecCtxEnc);
1100 1114

  
1101 1115
	if(audioStream!=-1) {
1102 1116
		avcodec_close(aCodecCtx);

Also available in: Unified diff