⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 write-avi.c

📁 xawtv绝版源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    strcpy(h->file,filename);    if (-1 == (h->fd = open(h->file,O_CREAT | O_RDWR | O_TRUNC, 0666))) {	fprintf(stderr,"open %s: %s\n",h->file,strerror(errno));	free(h);	return NULL;    }    /* general */    streams = 0;    rate = 0;    if (h->video.fmtid != VIDEO_NONE) {	streams++;	rate += pvideo->bytesperpixel * fps / 1000;	h->avi_hdr.avih.width       = AVI_SWAP4(h->video.width);	h->avi_hdr.avih.height      = AVI_SWAP4(h->video.height);    }    if (h->audio.fmtid != AUDIO_NONE) {	streams++;	rate += ng_afmt_to_channels[h->audio.fmtid] *	    ng_afmt_to_bits[h->audio.fmtid] *	    h->audio.rate / 8;    }    us_frame = (long long)1000000000/fps;    h->avi_hdr.avih.us_frame    = AVI_SWAP4(us_frame);    h->avi_hdr.avih.bps         = AVI_SWAP4(rate);    h->avi_hdr.avih.streams     = AVI_SWAP4(streams);    h->hdr_size += write(h->fd,&h->avi_hdr,sizeof(struct AVI_HDR));    /* video */    if (h->video.fmtid != VIDEO_NONE) {	for (i = 0; i < 4; i++) {	    h->avi_hdr_video.strh.handler[i]     = pvideo->handler[i];	    h->avi_hdr_video.strf.compression[i] = pvideo->compress[i];	}	frame_bytes = pvideo->bytesperpixel * h->video.width * h->video.height;	depth = ng_vfmt_to_depth[h->video.fmtid];	h->frame_hdr.size                = AVI_SWAP4(frame_bytes);	h->avi_hdr_video.strh.scale      = AVI_SWAP4(us_frame);	h->avi_hdr_video.strh.rate       = AVI_SWAP4(1000000);	h->avi_hdr_video.strf.size       = AVI_SWAP4(sizeof(avi_hdr_video.strf));	h->avi_hdr_video.strf.width      = AVI_SWAP4(h->video.width);	h->avi_hdr_video.strf.height     = AVI_SWAP4(h->video.height);	h->avi_hdr_video.strf.planes     = AVI_SWAP2(1);	h->avi_hdr_video.strf.bit_cnt    = AVI_SWAP2(depth ? depth : 24);	h->avi_hdr_video.strf.image_size = AVI_SWAP4(frame_bytes);	h->hdr_size += write(h->fd,&h->avi_hdr_video,sizeof(struct AVI_HDR_VIDEO));    }    /* audio */    if (h->audio.fmtid != AUDIO_NONE) {	h->avi_hdr_audio.strh.scale      =	    AVI_SWAP4(ng_afmt_to_channels[h->audio.fmtid] *		      ng_afmt_to_bits[h->audio.fmtid] / 8);	h->avi_hdr_audio.strh.rate       =	    AVI_SWAP4(ng_afmt_to_channels[h->audio.fmtid] *		      ng_afmt_to_bits[h->audio.fmtid] *		      h->audio.rate / 8);	h->avi_hdr_audio.strh.samplesize =	    AVI_SWAP4(ng_afmt_to_channels[h->audio.fmtid] *		      ng_afmt_to_bits[h->audio.fmtid] / 8);	h->avi_hdr_audio.strf.format     =	    AVI_SWAP2(WAVE_FORMAT_PCM);	h->avi_hdr_audio.strf.channels   =	    AVI_SWAP2(ng_afmt_to_channels[h->audio.fmtid]);	h->avi_hdr_audio.strf.rate       =	    AVI_SWAP4(h->audio.rate);	h->avi_hdr_audio.strf.av_bps     = 	    AVI_SWAP4(ng_afmt_to_channels[h->audio.fmtid] *		      ng_afmt_to_bits[h->audio.fmtid] *		      h->audio.rate / 8);	h->avi_hdr_audio.strf.blockalign =	    AVI_SWAP2(ng_afmt_to_channels[h->audio.fmtid] *		      ng_afmt_to_bits[h->audio.fmtid] / 8);	h->avi_hdr_audio.strf.size       =	    AVI_SWAP2(ng_afmt_to_bits[h->audio.fmtid]);	h->hdr_size += write(h->fd,&h->avi_hdr_audio,			     sizeof(struct AVI_HDR_AUDIO));    }    if (h->video.fmtid != VIDEO_NONE)	h->hdr_size += write(h->fd,&h->avi_hdr_odml,sizeof(struct AVI_HDR_ODML));    /* data */    if (-1 == write(h->fd,&h->avi_data,sizeof(struct AVI_DATA))) {	fprintf(stderr,"write %s: %s\n",h->file,strerror(errno));	free(h);	return NULL;    }    h->data_size  = 4; /* list type */    h->idx_index  = 0;    h->idx_offset = h->hdr_size + sizeof(struct AVI_DATA);    avi_write_header(h);    return h;}static intavi_video(void *handle, struct ng_video_buf *buf){    struct avi_handle *h = handle;    struct iovec *line;    int y,bpl,size=0;    size = (buf->size + 3) & ~3;    h->frame_hdr.size = AVI_SWAP4(size);    if (-1 == write(h->fd,&h->frame_hdr,sizeof(struct CHUNK_HDR))) {	fprintf(stderr,"write %s: %s\n",h->file,strerror(errno));	return -1;    }    switch (h->video.fmtid) {    case VIDEO_RGB15_LE:    case VIDEO_BGR24:	bpl = h->video.width * ng_vfmt_to_depth[h->video.fmtid] / 8;	for (line = h->vec, y = h->video.height-1;	     y >= 0; line++, y--) {	    line->iov_base = ((unsigned char*)buf->data) + y * bpl;	    line->iov_len  = bpl;	}	if (-1 == writev(h->fd,h->vec,h->video.height)) {	    fprintf(stderr,"writev %s: %s\n",h->file,strerror(errno));	    return -1;	}	break;    case VIDEO_MJPEG:    case VIDEO_JPEG:	if (-1 == write(h->fd,buf->data,size)) {	    fprintf(stderr,"write %s: %s\n",h->file,strerror(errno));	    return -1;	}	break;    }    h->frames_total += 1;    if (!h->bigfile) {	avi_addindex(h,h->frame_hdr.id,0x12,size);	h->data_size  += size + sizeof(struct CHUNK_HDR);	h->frames     += 1;    } else {	h->datax_size += size + sizeof(struct CHUNK_HDR);	h->framesx    += 1;    }    if ((h->bigfile ? h->datax_size : h->data_size) > LIMIT_OPENDML)	avi_bigfile(h,0);    return 0;}static intavi_audio(void *handle, struct ng_audio_buf *buf){    struct avi_handle *h = handle;    h->sound_hdr.size = AVI_SWAP4(buf->size);    if (-1 == write(h->fd,&h->sound_hdr,sizeof(struct CHUNK_HDR))) {	fprintf(stderr,"write %s: %s\n",h->file,strerror(errno));	return -1;    }    if (-1 == write(h->fd,buf->data,buf->size)) {	fprintf(stderr,"write %s: %s\n",h->file,strerror(errno));	return -1;    }    if (!h->bigfile) {	avi_addindex(h,h->sound_hdr.id,0x0,buf->size);	h->data_size  += buf->size + sizeof(struct CHUNK_HDR);	h->audio_size += buf->size;    } else {	h->datax_size += buf->size + sizeof(struct CHUNK_HDR);    }    return 0;}static intavi_close(void *handle){    struct avi_handle *h = handle;    /* write frame index */    if (h->video.fmtid != VIDEO_NONE) {	if (!h->bigfile) {	    avi_writeindex(h);	} else {	    avi_bigfile(h,1);	    h->idx_size = 0;	}    }    avi_write_header(h);    close(h->fd);    free(h->vec);    free(h);    return 0;}/* ----------------------------------------------------------------------- *//* data structures describing our capabilities                             */static struct avi_video_priv avi_rgb15 = {    bytesperpixel:  2,};static struct avi_video_priv avi_rgb24 = {    bytesperpixel:  3,};static struct avi_video_priv avi_mjpeg = {    handler:        {'M','J','P','G'},    compress:       {'M','J','P','G'},    bytesperpixel:  3,};static const struct ng_format_list avi_vformats[] = {    {	name:  "rgb15",	ext:   "avi",	fmtid: VIDEO_RGB15_LE,	priv:  &avi_rgb15,    },{	name:  "rgb24",	ext:   "avi",	fmtid: VIDEO_BGR24,	priv:  &avi_rgb24,    },{	name:  "mjpeg",	ext:   "avi",	fmtid: VIDEO_MJPEG,	priv:  &avi_mjpeg,    },{	name:  "jpeg",	ext:   "avi",	fmtid: VIDEO_JPEG,	priv:  &avi_mjpeg,    },{	/* EOF */    }};static const struct ng_format_list avi_aformats[] = {    {	name:  "mono8",	ext:   "avi",	fmtid: AUDIO_U8_MONO,    },{	name:  "mono16",	ext:   "avi",	fmtid: AUDIO_S16_LE_MONO,    },{	name:  "stereo",	ext:   "avi",	fmtid: AUDIO_S16_LE_STEREO,    },{	/* EOF */    }};struct ng_writer avi_writer = {    name:      "avi",    desc:      "Microsoft AVI (RIFF) format",    combined:  1,    video:     avi_vformats,    audio:     avi_aformats,    wr_open:   avi_open,    wr_video:  avi_video,    wr_audio:  avi_audio,    wr_close:  avi_close,};extern void ng_plugin_init(void);void ng_plugin_init(void){    ng_writer_register(NG_PLUGIN_MAGIC,__FILE__,&avi_writer);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -