CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  专题开发/技术/项目 >  多媒体/流媒体开发

有关MPEG-4编码器的使用

楼主pale(态度很重要)2002-12-11 12:27:30 在 专题开发/技术/项目 / 多媒体/流媒体开发 提问

是从以前的贴子上下的一个MPEG4编码器的源码mpeg4encsrc  
  里面的主要文件名称叫做encore,也提供了一个encore()出口函数  
  编译之后应该是生成一个*.dll文件  
  我现在不太清楚它到底是怎么来用这个编码器  
  看了encore()函数的参数,要求提供四个参数,最后两个是   param1,param2  
  这两个好象是需要外部给提供的  
  那到底应该怎么提供这两个参数呢?  
  哪位高手给讲解一下!  
  问题点数:50、回复次数:10Top

1 楼smallsmallbird(小鸟)回复于 2002-12-11 18:31:42 得分 3

把源码拿来,提供下载看看再说Top

2 楼pale(态度很重要)回复于 2002-12-12 12:31:39 得分 0

http://www.vckbase.com/code/listcode.asp?mclsid=7&sclsid=709  
   
  就是那个编码器源程序!  
  我现在自己给param1赋值,但里面有几个参数的意义不是很明白  
  所以无法加进去!Top

3 楼luoxiao10000(紫色火焰)回复于 2002-12-12 15:12:07 得分 30

下面是原来的前辈capboy留下的动动,看看对你有没有帮助?  
   
  capboy  
  /**************************************************************************  
    *  
    *             XVID   MPEG-4   VIDEO   CODEC   -   Example   for   encoding   and   decoding  
    *  
    *             This   program   is   free   software;   you   can   redistribute   it   and/or   modify  
    *             it   under   the   terms   of   the   GNU   General   Public   License   as   published   by  
    *             the   Free   Software   Foundation;   either   version   2   of   the   License,   or  
    *             (at   your   option)   any   later   version.  
    *  
    *             This   program   is   distributed   in   the   hope   that   it   will   be   useful,  
    *             but   WITHOUT   ANY   WARRANTY;   without   even   the   implied   warranty   of  
    *             MERCHANTABILITY   or   FITNESS   FOR   A   PARTICULAR   PURPOSE.     See   the  
    *             GNU   General   Public   License   for   more   details.  
    *  
    *             You   should   have   received   a   copy   of   the   GNU   General   Public   License  
    *             along   with   this   program;   if   not,   write   to   the   Free   Software  
    *             Foundation,   Inc.,   675   Mass   Ave,   Cambridge,   MA   02139,   USA.  
    *  
    *************************************************************************/  
   
  /************************************************************************  
    *                                          
    *     Test   routine   for   XviD   using   the   OpenDivX/Divx4-API                                              
    *     (C)   Christoph   Lampert,   2002/01/19                              
    *                                          
    *     A   sequence   of   YUV   pics   in   PGM   file   format   is   encoded   and   decoded                                            
    *                                        
    *     The   program   is   plain   C   and   needs   no   libraries   except   for   libxvidcore,    
    *     so   with   UN*X   you   simply   compile   by  
    *    
    *     gcc   -o   odivx_enc_dec   odivx_enc_dec.c   -lxvidcore    
    *  
    *     Run   without   parameters,   then   PGM   input   input   is   read   from   stdin.  
    *  
    *     PGM/xvid-output   is   saved,   if   corresponding   flags   are   set    
    *    
    *     input   data   can   be   generated   e.g.   out   of   MPEG2   with   mpeg2dec   -o   pgmpipe    
    *  
    ************************************************************************/  
   
  #include   <stdio.h>  
  #include   <malloc.h>  
   
  #include   "encore2.h"  
  #include   "decore.h" /*   these   come   with   XviD   */  
   
  #define   ARG_FRAMERATE   25  
  #define   ARG_BITRATE   900  
   
  int   QUALITY   =5;  
  int   QUANTI   =   0; //   used   for   fixed-quantizer   encoding    
   
  int   XDIM=0;  
  int   YDIM=0; //   will   be   set   when   reading   first   image  
  int   filenr   =   0;  
   
  int   save_m4v_flag   =   0; //   save   MPEG4-bytestream?  
  int   save_dec_flag   =   0; //   save   decompressed   bytestream?  
  char   filepath[256]   =   "."; //   path   where   to   save    
   
  void   *enchandle   =   NULL; //   enchandle   is   a   void*,   written   by   encore  
  const   long   dechandle   =   0x0815; //   dechandle   is   a   unique   constant!!!    
   
  /*********************************************************************/  
  /* Routines   for   file   input/output,   nothing   specific   to   XviD           */  
  /*********************************************************************/  
   
  int   read_pgmheader(FILE*   handle)  
  { int   bytes,xsize,ysize,depth;  
  char   dummy[2];  
   
  bytes   =   fread(dummy,1,2,handle);  
   
  if   (   (bytes   <   2)   ||   (dummy[0]   !=   'P')   ||   (dummy[1]   !=   '5'   ))  
        return   1;  
  fscanf(handle,"%d   %d   %d",&xsize,&ysize,&depth);    
  if   (   (xsize   >   1440)   ||   (ysize   >   2880   )   ||   (depth   !=   255)   )  
  {  
  fprintf(stderr,"%d   %d   %d\n",XDIM,YDIM,depth);  
        return   2;  
  }  
  if   (   (XDIM==0)   ||   (YDIM==0)   )  
  { XDIM=xsize;  
  YDIM=ysize;  
  }  
   
  return   0;  
  }  
   
  int   read_pgmdata(FILE*   handle,   unsigned   char   *image)  
  { int   i;  
  char   dummy;  
         
  unsigned   char*   buff1_ptr2   =   image   +   XDIM*YDIM;  
  unsigned   char*   buff1_ptr3   =   image   +   XDIM*YDIM   +   XDIM/2*YDIM/2;    
   
  fread(image,XDIM,YDIM,stdin);  
     
        for   (i=0;i<YDIM/2;i++)  
  {  
  fread(buff1_ptr2,XDIM/2,1,stdin);                      
  buff1_ptr2   +=   XDIM/2;  
  fread(buff1_ptr3,XDIM/2,1,stdin);              
  buff1_ptr3   +=   XDIM/2;  
  }  
  fread(&dummy,1,1,handle); //   should   be   EOF  
  return   0;  
  }  
   
   
  /*********************************************************************/  
  /*   Routines   for   encoding:   init   encoder,   frame   step,   release   encoder     */  
  /*********************************************************************/  
   
  #define   FRAMERATE_INCR   1001  
  int   enc_init()  
  {  
  int   status;  
  ENC_PARAM   enc_param;  
   
  enc_param.x_dim   =   XDIM;  
  enc_param.y_dim   =   YDIM;  
  enc_param.framerate   =   ARG_FRAMERATE; //   a   float  
  enc_param.bitrate   =   ARG_BITRATE*1000;  
   
  enc_param.rc_period   =   2000;  
  enc_param.rc_reaction_period   =   10;  
  enc_param.rc_reaction_ratio   =   20;  
   
  enc_param.max_quantizer   =   31;  
  enc_param.min_quantizer   =   1;  
   
  enc_param.quality   =   QUALITY;  
   
  enc_param.use_bidirect   =   0; //   use   bidirectional   coding  
  enc_param.deinterlace   =   0; //   fast   deinterlace  
  enc_param.obmc   =   0; //   flag   to   enable   overlapped   block   motion   compensation   mode  
   
  enc_param.max_key_interval   =   (int)ARG_FRAMERATE*10;  
  enc_param.handle   =   NULL; //will   be   filled   by   encore  
   
  status   =   encore(enchandle,   ENC_OPT_INIT,   &enc_param,   NULL);  
  enchandle   =   enc_param.handle;  
   
  // if   (status)          
  printf("Encore   INIT   return   %d,   handle=%lx\n",   status,   enchandle);  
   
  return   status;  
  }  
   
  int     enc_stop()  
  { int   status;  
   
  status   =   encore(enchandle,   ENC_OPT_RELEASE,   NULL,   NULL);  
  //       if   (status)    
  printf("Encore   RELEASE   return   %d\n",   status);  
   
                  return   status;  
  }  
   
  int     enc_main(unsigned   char*   image,   unsigned   char*   bitstream,   int   *streamlength)  
  { int   status;  
   
  ENC_FRAME   enc_frame;  
  ENC_RESULT   enc_result;  
   
  enc_frame.image   =   (void   *)   image;    
  enc_frame.bitstream   =   (void   *)   bitstream;  
  enc_frame.length   =   0; //   filled   by   encore  
  enc_frame.colorspace   =   ENC_CSP_YV12; //   input   is   YUV  
  enc_frame.mvs   =   NULL; //   unsupported  
   
  if   (QUANTI==0)  
  {  
  status   =   encore(enchandle,   ENC_OPT_ENCODE,   &enc_frame,   &enc_result);  
  }  
  else  
  { enc_frame.quant   =   QUANTI;  
  enc_frame.intra   =   -1; //   let   encoder   decide   if   frame   is   INTER/INTRA  
  status   =   encore(enchandle,   ENC_OPT_ENCODE_VBR,   &enc_frame,   &enc_result);  
  }  
   
  /*   ENC_OPT_ENCODE   is   used   to   encode   using   ratecontrol   alg.   and   bitrate   from   enc_init,    
        ENC_OPT_ENCODE_VBR   is   used   to   encode   with   fixed   quantizer   and   INTER/INTRA   mode    
  */  
   
  *streamlength   =   enc_frame.length;  
   
  return   status;  
  }  
   
  /*********************************************************************/  
  /*   Routines   for   decoding:   init   encoder,   frame   step,   release   encoder     */  
  /*********************************************************************/  
   
  int   dec_init()  
  {  
  int   status;  
   
  DEC_PARAM   dec_param;  
  DEC_SET   dec_set;  
   
  dec_param.x_dim   =   XDIM;  
  dec_param.y_dim   =   YDIM;  
  dec_param.output_format   =   DEC_RGB24; //       output   color   format,   ,   see   <decore.h>  
   
  dec_param.time_incr   =   20;  
   
  status   =   decore(dechandle,   DEC_OPT_INIT,   &dec_param,   NULL);  
  //             if   (status)    
  printf("Decore   INIT   return   %d\n",   status);  
   
  //   We   don't   do   any   postprocessing   here...    
   
  /* dec_set.postproc_level   =   0;  
  status   =   decore(dechandle,   DEC_OPT_SETPP,   &dec_set,   NULL);  
  if   (status)    
  printf("Decore   POSTPROC   %d   return   %d\n",   dec_set.postproc_level,   status);  
  */  
   
  return   status;  
  }    
   
  Top

4 楼luoxiao10000(紫色火焰)回复于 2002-12-12 15:12:30 得分 0

int   dec_main(unsigned   char   *m4v_buffer,   unsigned   char   *rgb_buffer,   int   m4v_size)  
  {  
  int   status;  
   
  static   DEC_FRAME   dec_frame;  
  static   DEC_FRAME_INFO   dec_frame_info;  
   
  dec_frame.length   =   m4v_size;  
  dec_frame.bitstream   =   m4v_buffer;  
  dec_frame.bmp   =   rgb_buffer;  
  dec_frame.render_flag   =   1; //   0   means:   skip   this   frame  
  dec_frame.stride   =   XDIM;  
   
  status   =   decore(dechandle,   DEC_OPT_FRAME,   &dec_frame,   &dec_frame_info);  
  if   (status)  
  printf("Decore   Frame   status   %d!\n",   status);  
   
  return   status;  
  }  
   
  int   dec_stop()  
  {  
  int   status;  
  status   =   decore(dechandle,   DEC_OPT_RELEASE,   NULL,   NULL);  
  // if   (status)    
  printf("Decore   RELEASE   return   %d\n",   status);  
  return   status;  
  }  
   
   
  /*********************************************************************/  
  /*                                                     Main   program                                                           */  
  /*********************************************************************/  
   
  int   main()  
  {  
      unsigned   char   *divx_buffer   =   NULL;  
      unsigned   char   *yuv_buffer   =   NULL;  
      unsigned   char   *rgb_buffer   =   NULL;  
   
      int   status;  
      int   frame_size;  
      int   m4v_size;  
       
      char   filename[256];  
       
      FILE   *filehandle;  
   
  /*   read   YUV   in   pgm   format   from   stdin   */  
      if   (read_pgmheader(stdin))  
          {  
              printf("Wrong   input   format,   I   want   YUV   encapsulated   in   PGM\n");  
              return   0;  
          }  
   
  /*   now   we   know   the   sizes,   so   allocate   memory   */  
      yuv_buffer   =   (unsigned   char   *)   malloc(XDIM*YDIM);  
      if   (!yuv_buffer)  
          goto   free_all_memory; //   goto   is   one   of   the   most   underestimated   instructions   in   C   !!!  
      divx_buffer   =   (unsigned   char   *)   malloc(XDIM*YDIM*2); //   this   should   really   be   enough!  
      if   (!divx_buffer)  
          goto   free_all_memory; //   actually,   every   program   should   contain   a   goto    
           
      YDIM   =   YDIM*2/3;   //   PGM   is   YUV   4:2:0   format,   so   height   is   *3/2   too   much  
           
      rgb_buffer   =   (unsigned   char   *)   malloc(XDIM*YDIM*4);  
      if   (!rgb_buffer)  
          goto   free_all_memory; //   the   more,   the   better!  
   
  /*********************************************************************/  
  /*                                       DIVX   PART     Start                                                     */  
  /*********************************************************************/  
   
      status   =   enc_init();  
  //               if   (status)          
      printf("Encore   INIT   return   %d,   handle=%lx\n",   status,   enchandle);  
   
      status   =   dec_init();  
  //             if   (status)    
      printf("Decore   INIT   return   %d\n",   status);  
   
   
  /*********************************************************************/  
  /*                                                   Main   loop                                                       */  
  /*********************************************************************/  
   
      do  
          {  
              status   =   read_pgmdata(stdin,   yuv_buffer); //   read   PGM   data   (YUV-format)  
              if   (status)  
  {  
      fprintf(stderr,   "PGM-Data-Error:   %d\n",   status); /*   this   should   not   happen   */  
      continue;  
  }  
   
  /*********************************************************************/  
  /*                               encode   and   decode   this   frame                                                 */  
  /*********************************************************************/  
   
  status   =   enc_main(yuv_buffer,   divx_buffer,   &m4v_size);  
   
  printf("Frame   %5d:   encore-ENCODE   status   %d,   m4v-stream   length=%7d   bytes\n",  
    filenr,   status,   m4v_size);  
   
              if   (save_m4v_flag)  
  {  
      sprintf(filename,   "%s/frame%05d.m4v",   filepath,   filenr);  
      filehandle   =   fopen(filename,   "wb");  
      fwrite(divx_buffer,   m4v_size,   1,   filehandle);  
      fclose(filehandle);  
  }  
   
              status   =   dec_main(divx_buffer,   rgb_buffer,   m4v_size);  
  if   (status)  
  printf("Frame   %5d:   decore   status   %d\n",status);  
               
              if   (save_dec_flag)  
  {  
  sprintf(filename,   "%s/dec%05d.ppm",   filepath,   filenr);  
                  filehandle=fopen(filename,"wb");  
  if   (filehandle)  
                  {  
                                  fprintf(filehandle,"P6\n"); //   rgb24   in   PPM   format  
              fprintf(filehandle,"%d   %d   255\n",XDIM,YDIM);  
              fwrite(rgb_buffer,XDIM,YDIM*3,filehandle);  
                                  fclose(filehandle);  
  }  
    }  
   
              filenr++;  
              status   =   read_pgmheader(stdin); //   if   it   was   the   last   PGM,   stop   after   it  
              if   (status)  
  {  
      fprintf(stderr,   "PGM-Header-Error:   %d\n",   status);   /*   normally,   just   end   of   file   */  
  }  
          }  
      while   (!status);  
   
   
  /*********************************************************************/  
  /*       DIVX   PART     Stop                                                 */  
  /*********************************************************************/  
   
   
  /*   Stop   XviD   */  
   
      dec_stop();  
  //               if   (status)          
  printf("Encore   RELEASE   return   %d\n",   status);  
   
      enc_stop();  
  //               if   (status)          
  printf("Decore   RELEASE   return   %d\n",   status);  
   
  free_all_memory:  
   
      if   (rgb_buffer)  
          free(rgb_buffer);  
      if   (divx_buffer)  
          free(divx_buffer);  
      if   (yuv_buffer)  
          free(yuv_buffer);  
   
      return   0;  
  }Top

5 楼luoxiao10000(紫色火焰)回复于 2002-12-12 15:18:38 得分 0

我也在看mpeg4的一些东西,愿意的话大家交流一下。  
      qq   87756188Top

6 楼gong_chen(尘)回复于 2003-02-07 15:05:15 得分 3

看看vfw   吧  
  那里有你想知道的关于param1   param2Top

7 楼nvideo(nvideo)回复于 2003-02-07 15:49:15 得分 3

看看www.xvid.org吧  
  什么都清楚了,国内很多mpeg4   encoder都是根据这个改的  
  Top

8 楼wd846(wd846)回复于 2003-02-08 11:48:10 得分 5

根据param1不同,param2的结构也不一样,一般是先初始化,如INIT之类的,param1如此类的结构:  
  typedef   struct  
  {  
  int   cpu_flags;       /**<   [in/out]  
      *  
      *   Filled   with   desired[in]   or   available[out]  
      *   cpu   instruction   sets.  
      */  
  int   api_version;   /**<   [out]  
      *  
      *   xvid_init   will   initialize   this   field   with  
      *   the   API_VERSION   used   in   this   XviD   core  
      *   library  
      */  
  int   core_build;     /**<   [out]  
      *   \todo   Unused.  
      */  
  }  
  然后是创建,此参数的结构又不一样,主要是根据第encore的第2个参数指定,应该有资料吧Top

9 楼duwenyong(啸海)回复于 2003-02-20 14:39:39 得分 3

你去看它提供的那个VFW代码就知道了Top

10 楼chenm001(CM)回复于 2003-02-20 16:17:34 得分 3

你到115fac.yeah.net可以下载VFW方面的源代码  
  到www.xvid.org下载源代码,里面examples/ex1是我的示例  
  有其它问题,可以到www.liumeiti.com的MPEG4论坛找我  
  这里我很少来了Top

相关问题

  • 有关微软的Windows Media 编码器问题
  • 我想在DirectShow中使用G.729压缩音频,是不是得自己写一个编码器?UP有分!
  • 我想在DirectShow中使用G.729压缩音频,是不是得自己写一个编码器?UP有分!
  • 请 问 哪里 有 avi,mpeg等 流 媒体 格式 的 文件 解码器 编码器 的 源 吗
  • 哪位搞过编码器?
  • 如何在Directshow程序中对MP3编码器的编码参数进行设置?使用那个接口啊?多谢了!!!
  • MediaPlay 编码器 的声音问题
  • 求一赫夫曼编码器程序!
  • 问问xvid编码器的用法?
  • 陆老师:我用mp3编码器压缩数据,怎样设置编码器的属性?

关键词

  • mpeg4
  • divx
  • mpeg
  • m4v
  • ydim
  • xdim
  • dec
  • pgm
  • dechandle
  • status

得分解答快速导航

  • 帖主:pale
  • smallsmallbird
  • luoxiao10000
  • gong_chen
  • nvideo
  • wd846
  • duwenyong
  • chenm001

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo