author | mickeyl <mickeyl> | 2003-04-21 00:36:04 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-21 00:36:04 (UTC) |
commit | 74b6398e9b2e8d206310b3d61e6db4f1fa5e51a6 (patch) (side-by-side diff) | |
tree | b9073d7b7deb36ff6572c9462fdcc047c1087cd0 | |
parent | 9163bfcc25b78477a75a153f2a75be30ad297c6a (diff) | |
download | opie-74b6398e9b2e8d206310b3d61e6db4f1fa5e51a6.zip opie-74b6398e9b2e8d206310b3d61e6db4f1fa5e51a6.tar.gz opie-74b6398e9b2e8d206310b3d61e6db4f1fa5e51a6.tar.bz2 |
Yahoo! Found the last three bugs in writing the avi stream. It now works :-D
-rw-r--r-- | noncore/multimedia/camera/avi.c | 3 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 10 |
2 files changed, 9 insertions, 4 deletions
diff --git a/noncore/multimedia/camera/avi.c b/noncore/multimedia/camera/avi.c index 0c757c9..77aba33 100644 --- a/noncore/multimedia/camera/avi.c +++ b/noncore/multimedia/camera/avi.c @@ -71,105 +71,106 @@ void avi_add(int fd, u8 *buf, int size) // overwrite JFIF type with AVI1 buf[6]='A'; buf[7]='V'; buf[8]='I'; buf[9]='1'; while( size%4 ) size++; // align 0 modulo 4*/ db.size = size; write( fd, &db, sizeof(db) ); write( fd, buf, size ); sizes[nframes] = size; nframes++; totalsize += size; // total frame size } // finish writing the AVI file - filling in the header void avi_end(int fd, int width, int height, int fps) { struct idx1_head idx = {"idx1", 16*nframes }; struct db_head db = {"00db", 0}; struct riff_head rh = { "RIFF", 0, "AVI "}; struct list_head lh1 = {"LIST", 0, "hdrl"}; struct avi_head ah; struct list_head lh2 = {"LIST", 0, "strl"}; struct stream_head sh; struct frame_head fh; struct list_head lh3 = {"LIST", 0, "odml" }; struct dmlh_head dh = {"dmlh", 4, nframes }; struct list_head lh4 = {"LIST", 0, "movi"}; int i; unsigned int offset = 4; printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps ); // write index write(fd, &idx, sizeof(idx)); for ( i = 0; i < nframes; i++ ) { write(fd, &db, 4 ); // only need the 00db fprint_quartet( fd, 18 ); // ??? fprint_quartet( fd, offset ); fprint_quartet( fd, sizes[i] ); - offset += sizes[i]; + offset += sizes[i] + 8; //+8 (for the additional header) } free( sizes ); bzero( &ah, sizeof(ah) ); strcpy(ah.avih, "avih"); ah.time = 1000000 / fps; ah.maxbytespersec = 1000000.0*(totalsize/nframes)/ah.time; + ah.nframes = nframes; ah.numstreams = 1; ah.flags = AVIF_HASINDEX; ah.width = width; ah.height = height; bzero(&sh, sizeof(sh)); strcpy(sh.strh, "strh"); strcpy(sh.vids, "vids"); strcpy(sh.codec, "MJPG"); sh.scale = ah.time; sh.rate = 1000000; sh.length = nframes; bzero(&fh, sizeof(fh)); strcpy(fh.strf, "strf"); fh.width = width; fh.height = height; fh.planes = 1; fh.bitcount = 24; strcpy(fh.codec,"MJPG"); fh.unpackedsize = 3*width*height; rh.size = sizeof(lh1)+sizeof(ah)+sizeof(lh2)+sizeof(sh)+ sizeof(fh)+sizeof(lh3)+sizeof(dh)+sizeof(lh4)+ nframes*sizeof(struct db_head)+ totalsize + sizeof(struct idx1_head)+ (16*nframes) +4; // FIXME:16 bytes per nframe // the '4' - what for??? lh1.size = 4+sizeof(ah)+sizeof(lh2)+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh); ah.size = sizeof(ah)-8; lh2.size = 4+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh); //4+sizeof(sh)+sizeof(fh); sh.size = sizeof(sh)-8; fh.size = sizeof(fh)-8; fh.size2 = fh.size; lh3.size = 4+sizeof(dh); lh4.size = 4+ nframes*sizeof(struct db_head)+ totalsize; lseek(fd, 0, SEEK_SET); write(fd, &rh, sizeof(rh)); write(fd, &lh1, sizeof(lh1)); write(fd, &ah, sizeof(ah)); write(fd, &lh2, sizeof(lh2)); write(fd, &sh, sizeof(sh)); write(fd, &fh, sizeof(fh)); write(fd, &lh3, sizeof(lh3)); write(fd, &dh, sizeof(dh)); write(fd, &lh4, sizeof(lh4)); } diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index e27a50e..7e60e16 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp @@ -451,101 +451,105 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o qApp->processEvents(); // open files int infd = ::open( (const char*) infile, O_RDONLY ); if ( infd == -1 ) { owarn << "couldn't open capture file: " << strerror(errno) << oendl; return; } int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); if ( outfd == -1 ) { owarn << "couldn't open output file: " << strerror(errno) << oendl; return; } int framesize = captureX*captureY*2; unsigned char* inbuffer = new unsigned char[ framesize ]; QImage image; avi_start( outfd, _videopics ); // write preambel // post process for ( int i = 0; i < _videopics; ++i ) { odebug << "processing frame " << i << oendl; // <gui> label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) ); bar->setProgress( i ); bar->repaint(); qApp->processEvents(); // </gui> int read = ::read( infd, inbuffer, framesize ); odebug << "read " << read << " bytes" << oendl; bufferToImage( captureX, captureY, inbuffer, &image ); QPixmap p; p.convertFromImage( image ); preview->setPixmap( p ); preview->repaint(); qApp->processEvents(); + #ifndef QT_NO_DEBUG + QString tmpfilename; + tmpfilename.sprintf( "/tmp/test/%04d.jpg", i ); + #else QString tmpfilename( "/tmp/tempfile" ); - //tmpfilename.sprintf( "/tmp/test/%d.jpg", i ); + #endif imageToFile( &image, tmpfilename, "JPEG", quality ); QFile framefile( tmpfilename ); if ( !framefile.open( IO_ReadOnly ) ) { oerr << "can't process file: %s" << strerror(errno) << oendl; return; // TODO: clean up temp ressources } int filesize = framefile.size(); odebug << "filesize for frame " << i << " = " << filesize << oendl; unsigned char* tempbuffer = new unsigned char[ filesize ]; framefile.readBlock( (char*) tempbuffer, filesize ); avi_add( outfd, tempbuffer, filesize ); delete tempbuffer; framefile.close(); } avi_end( outfd, captureX, captureY, _framerate ); fr->hide(); delete fr; updateCaption(); } void CameraMainWindow::updateCaption() { if ( !_capturing ) setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) ); else setCaption( "Opie-Camera: => CAPTURING <=" ); } #ifndef QT_NO_DEBUG void CameraMainWindow::doSomething() { captureX = 240; captureY = 320; - _videopics = 176; + _videopics = 50; _framerate = 5; - postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", + postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat", "/tmp/output.avi" ); } #endif |