From 81776eb70dcad6748b8494ff13fbd048c60c1fae Mon Sep 17 00:00:00 2001 From: mickeyl Date: Fri, 18 Apr 2003 00:37:32 +0000 Subject: add jpeg2avi for postprocessing a series of jpeg frames into an avi --- (limited to 'noncore/multimedia/camera/jpegtoavi/jpegtoavi.c') diff --git a/noncore/multimedia/camera/jpegtoavi/jpegtoavi.c b/noncore/multimedia/camera/jpegtoavi/jpegtoavi.c new file mode 100644 index 0000000..10a2f81 --- a/dev/null +++ b/noncore/multimedia/camera/jpegtoavi/jpegtoavi.c @@ -0,0 +1,349 @@ +/* + + A simple converter of JPEGs to an AVI-MJPEG animation. + + USAGE: + 1. jpegtoavi {usec per img} {img width} {img height} + {img1 .. imgN} + (writes AVI file to stdout) + + 2. jpegtoavi -f {fps} {img width} {img height} + {img1 .. imgN} + (same as #1 but with period specified in terms of fps) + + 3. jpegtoavi -fsz {img1 .. imgN} + (writes sz in bytes of such an AVI file to stdout) +*/ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#include +#include "avifmt.h" +#include +#include +#include +#include +#include +#include "byteswap.h" +#include + + +/* + spc: indicating file sz in bytes, -1 on error +*/ +off_t file_sz(char *fn) +{ + struct stat s; + if(stat(fn,&s)==-1) + return -1; + return s.st_size; +} + + +/* + spc: returning sum of sizes of named JPEGs, -1 on error; + file sizes adjusted to multiple of 4-bytes + pos: szarray, if non-0, contains true sizes of files +*/ +off_t img_array_sz(char **img,int imgsz,DWORD *szarray) +{ + off_t tmp,ret=0; + int i=0; + for(;i=MAX_RIFF_SZ) { + fprintf(stderr,"RIFF would exceed 2 Gb limit\n"); + return -3; + } + jpg_sz=(long)jpg_sz_64; + riff_sz=(DWORD)riff_sz_64; + + /* printing RIFF size and quitting */ + if(img0==2) { + printf("%lu\n",(unsigned long)riff_sz+8UL); + return 0; + } + + /* printing AVI.. riff hdr */ + printf("RIFF"); + print_quartet(riff_sz); + printf("AVI "); + + /* list hdrl */ + hdrl.avih.us_per_frame=LILEND4(per_usec); + hdrl.avih.max_bytes_per_sec=LILEND4(1000000*(jpg_sz/frames) + /per_usec); + hdrl.avih.tot_frames=LILEND4(frames); + hdrl.avih.width=LILEND4(width); + hdrl.avih.height=LILEND4(height); + hdrl.strl.strh.scale=LILEND4(per_usec); + hdrl.strl.strh.rate=LILEND4(1000000); + hdrl.strl.strh.length=LILEND4(frames); + hdrl.strl.strf.width=LILEND4(width); + hdrl.strl.strf.height=LILEND4(height); + hdrl.strl.strf.image_sz=LILEND4(width*height*3); + hdrl.strl.list_odml.frames=LILEND4(frames); + fwrite(&hdrl,sizeof(hdrl),1,stdout); + + /* list movi */ + printf("LIST"); + print_quartet(jpg_sz+8*frames+4); + printf("movi"); + + if((offsets=(DWORD *)malloc(frames*sizeof(DWORD)))==0) { + fprintf(stderr,"malloc error"); + return -4; + } + + for(f=img0;f0) { + fwrite(buff,nbr,1,stdout); + nbw+=nbr; + } + if(remnant>0) { + fwrite(buff,remnant,1,stdout); + nbw+=remnant; + } + tnbw+=nbw; + close(fd); + } + if(tnbw!=jpg_sz) { + fprintf(stderr,"error writing images (wrote %ld bytes, expected %ld bytes)\n", + tnbw,jpg_sz); + free(offsets); + free(szarray); + return -8; + } + + // indices + printf("idx1"); + print_quartet(16*frames); + for(f=0;f