m4v文件播放程序

这是一个使用Xvid库和SDL多媒体框架解码并播放M4V文件的程序。程序首先初始化SDL,然后读取M4V文件到缓冲区,通过Xvid解码器进行解码,并将解码后的数据输出到屏幕或保存为PNM或TGA图像文件。程序还提供了参数选项,如使用汇编优化、设置调试级别、保存解码输出等。
摘要由CSDN通过智能技术生成

/*********************************************************************************************
              gcc -o mpeg4_player mpeg4_player.c `sdl-config --cflags --libs` -lxvidcore

*********************************************************************************************/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <SDL/SDL.h>
#include "xvid.h"

#define USE_PNM 1
#define USE_TGA 0

static int SHXDIM = 0;//display size
static int SHYDIM = 0;
static int XDIM = 352;//real size
static int YDIM = 288;
static int ARG_SAVEDECOUTPUT = 0;
static int ARG_SAVEMPEGSTREAM = 0;
static char *ARG_INPUTFILE = NULL;
static int CSP = XVID_CSP_I420;
static int BPP = 1;
static int FORMAT = USE_PNM;
static char filepath[256] = "./";
static void *dec_handle = NULL;
#define BUFFER_SIZE (2*1024*1024)
static const int display_buffer_bytes = 0;
static SDL_Surface *screen;
static SDL_Overlay *overlay;
static SDL_Rect rect;
static double msecond();
static int dec_init(int use_assembler, int debug_level);
static int dec_main(unsigned char *istream,
     unsigned char *ostream,
     int istream_size,
     xvid_dec_stats_t *xvid_dec_stats);
static int dec_stop();
static void usage();
static int write_image(char *prefix, unsigned char *image);
static int write_pnm(char *filename, unsigned char *image);
static int write_tga(char *filename, unsigned char *image);
const char * type2str(int type)
{
    if (type==XVID_TYPE_IVOP)
        return "I";
    if (type==XVID_TYPE_PVOP)
        return "P";
    if (type==XVID_TYPE_BVOP)
        return "B";
    return "S";
}

static void init_SDL()
{
    if (SDL_Init (SDL_INIT_VIDEO) < 0)
    {
        fprintf (stderr, "Couldn't initialize SDL: %s/n", SDL_GetError());
        exit (1);
    }
    atexit (SDL_Quit);
    screen = SDL_SetVideoMode (SHXDIM, SHYDIM, 0, SDL_HWSURFACE
                                          | SDL_DOUBLEBUF
                                          | SDL_ANYFORMAT
                                          | SDL_RESIZABLE);
    if (screen == NULL)
    {
        fprintf(stderr, "Couldn't set video mode: %s/n", SDL_GetError());
        exit(2);
    }
    if (0 == screen->flags & SDL_HWSURFACE)
    {
        fprintf(stderr,"Can't get hardware surface/n");
        exit(3);
    }
    SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);      
    overlay = SDL_CreateYUVOverlay(XDIM, YDIM, SDL_YV12_OVERLAY, screen);
    if (!overlay)
    {
        fprintf(stderr, "Couldn't create overlay: %s/n", SDL_GetError());
        exit(4);
    }   
    //show the overlay status
    printf("Created %dx%dx%d %s %s overlay/n",overlay->w,overlay->h,overlay->planes,
           overlay->hw_overlay?"hardware":"software",
           overlay->format==SDL_YV12_OVERLAY?"YV12":
           overlay->format==SDL_IYUV_OVERLAY?"IYUV":
           overlay->format==SDL_YUY2_OVERLAY?"YUY2":
           overlay->format==SDL_UYVY_OVERLAY?"UYVY":
           overlay->format==SDL_YVYU_OVERLAY?"YVYU":
           "Unknown");
    rect.x=0;
    rect.y=0;
    rect.w=SHXDIM;
    rect.h=SHYDIM;
}

int main(int argc, char *argv[])
{
 SDL_Event event;
 uint32_t lastftick;
 unsigned char *mp4_buffer = NULL;
 unsigned char *mp4_ptr    = NULL;
 unsigned char *out_buffer = NULL;
 int useful_bytes;
 xvid_dec_stats_t xvid_dec_stats;
 
 double totaldectime;
 
 long totalsize;
 int status;
 int fps = 25;
     int fpsdelay;
 int paused=0;
     int resized=0; 
 int use_assembler = 1;
 int debug_level = 0;
 
 char filename[256];
 
 FILE *in_file;
 int filenr;
 int i;

 for (i=1; i< argc; i++) {
 
  if (strcmp("-asm", argv[i]) == 0 ) {
   use_assembler = 1;
  } else if (strcmp("-debug", argv[i]) == 0 && i < argc - 1 ) {
   i++;
   if (sscanf(argv[i], "0x%x", &debug_level) != 1) {
    debug_level = atoi(argv[i]);
   }
  } else if (strcmp("-d", argv[i]) == 0) {
   ARG_SAVEDECOUTPUT = 1;
  } els

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值