Mercurial > mplayer.hg
comparison libmpcodecs/vd_ffmpeg.c @ 13190:8be7dbcea0be
AVC (fourcc avc1) in mp4 support
author | rtognimp |
---|---|
date | Sun, 29 Aug 2004 13:52:19 +0000 |
parents | 2af30a65a772 |
children | a83623b3b86a |
comparison
equal
deleted
inserted
replaced
13189:bd954530394b | 13190:8be7dbcea0be |
---|---|
70 int qp_stat[32]; | 70 int qp_stat[32]; |
71 double qp_sum; | 71 double qp_sum; |
72 double inv_qp_sum; | 72 double inv_qp_sum; |
73 int ip_count; | 73 int ip_count; |
74 int b_count; | 74 int b_count; |
75 // AVC data | |
76 int got_avcC; | |
77 int nal_length_size; | |
78 void *data_bak; | |
79 int len_bak; | |
75 } vd_ffmpeg_ctx; | 80 } vd_ffmpeg_ctx; |
76 | 81 |
77 //#ifdef FF_POSTPROCESS | 82 //#ifdef FF_POSTPROCESS |
78 //unsigned int lavc_pp=0; | 83 //unsigned int lavc_pp=0; |
79 //#endif | 84 //#endif |
337 avctx->extradata_size = *(int*)sh->ImageDesc; | 342 avctx->extradata_size = *(int*)sh->ImageDesc; |
338 avctx->extradata = malloc(avctx->extradata_size); | 343 avctx->extradata = malloc(avctx->extradata_size); |
339 memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); | 344 memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); |
340 } | 345 } |
341 | 346 |
347 if(sh->format == mmioFOURCC('a', 'v', 'c', '1')) { | |
348 ctx->got_avcC = 0; | |
349 } | |
350 | |
342 if(sh->bih) | 351 if(sh->bih) |
343 avctx->bits_per_sample= sh->bih->biBitCount; | 352 avctx->bits_per_sample= sh->bih->biBitCount; |
344 | 353 |
345 /* open it */ | 354 /* open it */ |
346 if (avcodec_open(avctx, lavc_codec) < 0) { | 355 if (avcodec_open(avctx, lavc_codec) < 0) { |
676 uint32_t timestamp; // timestamp from packet header | 685 uint32_t timestamp; // timestamp from packet header |
677 uint32_t len; // length of actual data | 686 uint32_t len; // length of actual data |
678 uint32_t chunktab; // offset to chunk offset array | 687 uint32_t chunktab; // offset to chunk offset array |
679 } dp_hdr_t; | 688 } dp_hdr_t; |
680 | 689 |
690 | |
691 /** | |
692 * Add sync to a nal and queue it in buffer, increasing buffer size as needed | |
693 * @param dest pointer to current buffer area | |
694 * @param destsize pointer to size of current dest area | |
695 * @param source pointer to source nal data (after length bytes) | |
696 * @param nal_len length of nal data | |
697 */ | |
698 unsigned char* avc1_addnal(unsigned char *dest, int *destsize, unsigned char* source, int nal_len) | |
699 { | |
700 unsigned char *temp; | |
701 int tempsize; | |
702 | |
703 tempsize = *destsize + nal_len + 4; | |
704 temp = malloc (tempsize); | |
705 if (dest) | |
706 memcpy (temp, dest, *destsize); | |
707 temp[*destsize] = 0; | |
708 temp[*destsize+1] = 0; | |
709 temp[*destsize+2] = 0; | |
710 temp[*destsize+3] = 1; | |
711 memcpy (temp + *destsize + 4, source, nal_len); | |
712 if (dest) | |
713 free(dest); | |
714 *destsize = tempsize; | |
715 | |
716 return temp; | |
717 } | |
718 | |
719 | |
681 // decode a frame | 720 // decode a frame |
682 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | 721 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ |
683 int got_picture=0; | 722 int got_picture=0; |
684 int ret; | 723 int ret; |
685 vd_ffmpeg_ctx *ctx = sh->context; | 724 vd_ffmpeg_ctx *ctx = sh->context; |
686 AVFrame *pic= ctx->pic; | 725 AVFrame *pic= ctx->pic; |
687 AVCodecContext *avctx = ctx->avctx; | 726 AVCodecContext *avctx = ctx->avctx; |
688 mp_image_t* mpi=NULL; | 727 mp_image_t* mpi=NULL; |
689 int dr1= ctx->do_dr1; | 728 int dr1= ctx->do_dr1; |
729 unsigned char *buf = NULL; | |
690 | 730 |
691 if(len<=0) return NULL; // skipped frame | 731 if(len<=0) return NULL; // skipped frame |
692 | 732 |
693 #if LIBAVCODEC_BUILD < 4707 | 733 #if LIBAVCODEC_BUILD < 4707 |
694 | 734 |
734 avctx->slice_offset[i]= ((uint32_t*)(data+hdr->chunktab))[2*i+1]; | 774 avctx->slice_offset[i]= ((uint32_t*)(data+hdr->chunktab))[2*i+1]; |
735 len=hdr->len; | 775 len=hdr->len; |
736 data+= sizeof(dp_hdr_t); | 776 data+= sizeof(dp_hdr_t); |
737 } | 777 } |
738 | 778 |
779 /* | |
780 * Convert avc1 nals to annexb nals (remove lenght, add sync) | |
781 * If first frame extract and process avcC (configuration data) | |
782 */ | |
783 if(sh->format == mmioFOURCC('a', 'v', 'c', '1')) { | |
784 int bufsize = 0; | |
785 int nalsize; | |
786 unsigned char *p = data; | |
787 int i; | |
788 int cnt, poffs; | |
789 | |
790 // Remember original values | |
791 ctx->data_bak = data; | |
792 ctx->len_bak = len; | |
793 | |
794 if (!ctx->got_avcC) { | |
795 // Parse some parts of avcC, just for fun :) | |
796 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC version: %d\n", *(p)); | |
797 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC profile: %d\n", *(p+1)); | |
798 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC profile compatibility: %d\n", *(p+2)); | |
799 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC level: %d\n", *(p+3)); | |
800 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC nal length size: %d\n", ctx->nal_length_size = ((*(p+4))&0x03)+1); | |
801 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC number of sequence param sets: %d\n", cnt = (*(p+5) & 0x1f)); | |
802 poffs = 6; | |
803 for (i = 0; i < cnt; i++) { | |
804 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC sps %d have length %d\n", i, nalsize = BE_16(p+poffs)); | |
805 buf = avc1_addnal(buf, &bufsize, p + poffs + 2, nalsize); | |
806 poffs += nalsize + 2; | |
807 } | |
808 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC number of picture param sets: %d\n", *(p+poffs)); | |
809 poffs++; | |
810 for (i = 0; i < cnt; i++) { | |
811 mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] avcC pps %d have length %d\n", i, nalsize = BE_16(p+poffs)); | |
812 buf = avc1_addnal(buf, &bufsize, p + poffs + 2, nalsize); | |
813 poffs += nalsize + 2; | |
814 } | |
815 p += poffs; | |
816 ctx->got_avcC = 1; | |
817 } | |
818 | |
819 while (p < (data + len)) { | |
820 nalsize = 0; | |
821 for(i = 0; i < ctx->nal_length_size; i++) | |
822 nalsize = (nalsize << 8) | (*p++); | |
823 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "[ffmpeg] avc1: nalsize = %d\n", nalsize); | |
824 buf = avc1_addnal(buf, &bufsize, p, nalsize); | |
825 p += nalsize; | |
826 len -= nalsize; | |
827 } | |
828 data = buf; | |
829 len = bufsize; | |
830 } | |
831 | |
739 ret = avcodec_decode_video(avctx, pic, | 832 ret = avcodec_decode_video(avctx, pic, |
740 &got_picture, data, len); | 833 &got_picture, data, len); |
834 | |
835 if(sh->format == mmioFOURCC('a', 'v', 'c', '1')) { | |
836 free(buf); | |
837 data = ctx->data_bak; | |
838 len = ctx->len_bak; | |
839 } | |
840 | |
741 dr1= ctx->do_dr1; | 841 dr1= ctx->do_dr1; |
742 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); | 842 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); |
743 //printf("repeat: %d\n", pic->repeat_pict); | 843 //printf("repeat: %d\n", pic->repeat_pict); |
744 //-- vstats generation | 844 //-- vstats generation |
745 #if LIBAVCODEC_BUILD >= 4643 | 845 #if LIBAVCODEC_BUILD >= 4643 |