- 论坛徽章:
- 0
|
地址在此: http://bad-apple.no-ip.org
这是我自己架设的网站服务器,所以网速可能不尽人意。
我上传youku 后 ,会附加上 youku 地址 。。。
制作方法:
1,mplayer -vo jpeg bad_apple.flv
将bad apple 的视频一帧一帧的截取出来。
2,写一个shell脚本,然后执行。- #!/bin/bash
- pa="../tif/"
- for var in `ls | grep jpg`
- do
- convert -sample 120 `echo $var` `echo $pa$var|sed 's/...$/tif/'`
- done
复制代码 将所有的jpg图片 转成tif 图片,并且移动到 ../tif/ 目录中。
3,写一个程序,将tif图片转成纯 ansii 文件。(需要shell脚本配合执行)- #include <stdio.h>
- #include <stdlib.h>
- #include <tiffio.h>
- #include <string.h>
- int main (int argc,char *argv[])
- {
- TIFF *image;
- FILE *file;
- uint16 photo,bps,spp;
- uint32 width,height;
- char *buffer;
- tsize_t strip_size;
- unsigned long image_size,image_offset,res,count;
- int strip_max,strip_count,m=0,n=0,rgb=0,argv_len;
- char *new,*add="-ansii",ansi;
- argv_len=strlen(argv[1]);
- if((new=(char *)malloc(sizeof(char)*(argv_len+3)))==NULL)
- {
- perror("malloc failure\n");exit(1);
- }
- strncpy(new,argv[1],strlen(argv[1])-4);
- strcat(new,add);
- //printf("%s\n",new);
- if((file=fopen(new,"w"))==NULL)
- {
- perror("Creat File Failure\n");exit(1);
- }
- if((image=TIFFOpen(argv[1],"r"))==NULL)
- {
- perror("Can't open image\n");exit(1);
- }
- if(TIFFGetField(image,TIFFTAG_BITSPERSAMPLE,&bps)==0 ||
- TIFFGetField(image,TIFFTAG_SAMPLESPERPIXEL,&spp)==0 ||
- TIFFGetField(image,TIFFTAG_PHOTOMETRIC,&photo)==0
- )
- {
- perror("Unsupported file\n");exit(1);
- }
- TIFFGetField(image,TIFFTAG_IMAGEWIDTH,&width);
- TIFFGetField(image,TIFFTAG_IMAGELENGTH,&height);
- image_size=height*width*spp+1;
- strip_size=TIFFStripSize(image);
- strip_max=TIFFNumberOfStrips(image);
- image_offset=0;
- if((buffer=(char *)_TIFFmalloc(sizeof(unsigned long)*image_size))==NULL)
- {
- perror("Malloc failure\n");exit(1);
- }
- for(strip_count=0;strip_count<strip_max;strip_count++)
- {
- if((res=TIFFReadEncodedStrip(image,strip_count,buffer+image_offset,strip_size))==-1)
- {
- perror("Read Error\n");exit(1);
- }
- image_offset+=res;
- }
- for(count=0;count<image_size-1;count++)
- {
- ++m;
- rgb+=buffer[count];
- if(m==spp)
- {
- ++n;
- ansi=rgb>=0?'@':' ';
- fputc(ansi,file);
- fputc(ansi,file);
- if(n==width) {fputc('\n',file);n=0;}
- rgb=0;
- m=0;
- }
- }
- TIFFClose(image);
- _TIFFfree(buffer);
- fclose(file);
- free(new);
- exit(0);
- }
复制代码 因为我先研究的tiff图片,所以就先入为主了。不想再去研究jpeg png 等图片。如果我要是会jpeg png 编程的话 ,就可以省去第二步。
同样,将生成的 纯ansii文件 存在 ../ansii 中。
4, 写一个程序,来还原动画。原理很简单,就是不断的读入那些 ansii 文件,显示,然后清屏。。。就这样不断循环,保持和原视频同样的帧率。- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <curses.h>
- #include <time.h>
- #include <sys/time.h>
- void stop (int usec)
- {
- struct timeval tv;
- tv.tv_sec=0;
- tv.tv_usec=usec;
- select(0,NULL,NULL,NULL,&tv);
- }
- int main ()
- {
- int a[8]={0,0,0,0,0,0,0,0},n;
- char name[]={'.','/','a','n','s','i','i','/','a','a','a','a','a','a','a','a','-','a','n','s','i','i'};
- char *vul="0123456789",*buffer;
- FILE *souce_file;
- WINDOW *apple;
- initscr();noecho();curs_set(0);
- clear();
- if(COLS<240 || LINES<90)
- {
- mvprintw(LINES/2,COLS/2-24,"Your screen is NOT big enough.X=%d<240.Y=%d<90\n",COLS,LINES);
- refresh();sleep(3);endwin();exit(0);
- }
- if((apple=newwin(90,241,LINES/2-45,COLS/2-120))==NULL)
- {
- perror("Creat Window Failure\n");endwin();exit(1);
- }
- if((buffer=(char *)malloc(sizeof(char)*241*90))==NULL)
- {
- perror("Malloc Failure\n");delwin(apple);endwin();exit(1);
- }
- *(buffer+241*90-1)='\0';
- while(1)
- {
- wmove(apple,0,0);
- ++a[7];
- for(n=7;n>0;n--)
- {
- if(a[n]>9)
- {
- a[n]%=10;
- ++a[n-1];
- }
- if(a[n-1]<10) break;
- }
- for(n=0;n<8;n++)
- *(name+8+n)=*(vul+a[n]);
- if((souce_file=fopen(name,"r"))==NULL) break;
- for(n=0;n<241*90-1;n++)
- buffer[n]=fgetc(souce_file);
- fclose(souce_file);
- wprintw(apple,"%s",buffer);
- wrefresh(apple);
- stop(64000);
- }
- sleep(1);
- free(buffer);
- delwin(apple);
- endwin();
- exit(0);
- }
复制代码 完. |
|