author | mickeyl <mickeyl> | 2003-04-21 00:36:04 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-21 00:36:04 (UTC) |
commit | 74b6398e9b2e8d206310b3d61e6db4f1fa5e51a6 (patch) (unidiff) | |
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 | |||
@@ -95,57 +95,58 @@ void avi_end(int fd, int width, int height, int fps) | |||
95 | struct riff_head rh = { "RIFF", 0, "AVI "}; | 95 | struct riff_head rh = { "RIFF", 0, "AVI "}; |
96 | struct list_head lh1 = {"LIST", 0, "hdrl"}; | 96 | struct list_head lh1 = {"LIST", 0, "hdrl"}; |
97 | struct avi_head ah; | 97 | struct avi_head ah; |
98 | struct list_head lh2 = {"LIST", 0, "strl"}; | 98 | struct list_head lh2 = {"LIST", 0, "strl"}; |
99 | struct stream_head sh; | 99 | struct stream_head sh; |
100 | struct frame_head fh; | 100 | struct frame_head fh; |
101 | struct list_head lh3 = {"LIST", 0, "odml" }; | 101 | struct list_head lh3 = {"LIST", 0, "odml" }; |
102 | struct dmlh_head dh = {"dmlh", 4, nframes }; | 102 | struct dmlh_head dh = {"dmlh", 4, nframes }; |
103 | struct list_head lh4 = {"LIST", 0, "movi"}; | 103 | struct list_head lh4 = {"LIST", 0, "movi"}; |
104 | int i; | 104 | int i; |
105 | unsigned int offset = 4; | 105 | unsigned int offset = 4; |
106 | 106 | ||
107 | printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps ); | 107 | printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps ); |
108 | 108 | ||
109 | // write index | 109 | // write index |
110 | 110 | ||
111 | write(fd, &idx, sizeof(idx)); | 111 | write(fd, &idx, sizeof(idx)); |
112 | 112 | ||
113 | for ( i = 0; i < nframes; i++ ) | 113 | for ( i = 0; i < nframes; i++ ) |
114 | { | 114 | { |
115 | write(fd, &db, 4 ); // only need the 00db | 115 | write(fd, &db, 4 ); // only need the 00db |
116 | fprint_quartet( fd, 18 ); // ??? | 116 | fprint_quartet( fd, 18 ); // ??? |
117 | fprint_quartet( fd, offset ); | 117 | fprint_quartet( fd, offset ); |
118 | fprint_quartet( fd, sizes[i] ); | 118 | fprint_quartet( fd, sizes[i] ); |
119 | offset += sizes[i]; | 119 | offset += sizes[i] + 8; //+8 (for the additional header) |
120 | } | 120 | } |
121 | 121 | ||
122 | free( sizes ); | 122 | free( sizes ); |
123 | 123 | ||
124 | bzero( &ah, sizeof(ah) ); | 124 | bzero( &ah, sizeof(ah) ); |
125 | strcpy(ah.avih, "avih"); | 125 | strcpy(ah.avih, "avih"); |
126 | ah.time = 1000000 / fps; | 126 | ah.time = 1000000 / fps; |
127 | ah.maxbytespersec = 1000000.0*(totalsize/nframes)/ah.time; | 127 | ah.maxbytespersec = 1000000.0*(totalsize/nframes)/ah.time; |
128 | ah.nframes = nframes; | ||
128 | ah.numstreams = 1; | 129 | ah.numstreams = 1; |
129 | ah.flags = AVIF_HASINDEX; | 130 | ah.flags = AVIF_HASINDEX; |
130 | ah.width = width; | 131 | ah.width = width; |
131 | ah.height = height; | 132 | ah.height = height; |
132 | 133 | ||
133 | bzero(&sh, sizeof(sh)); | 134 | bzero(&sh, sizeof(sh)); |
134 | strcpy(sh.strh, "strh"); | 135 | strcpy(sh.strh, "strh"); |
135 | strcpy(sh.vids, "vids"); | 136 | strcpy(sh.vids, "vids"); |
136 | strcpy(sh.codec, "MJPG"); | 137 | strcpy(sh.codec, "MJPG"); |
137 | sh.scale = ah.time; | 138 | sh.scale = ah.time; |
138 | sh.rate = 1000000; | 139 | sh.rate = 1000000; |
139 | sh.length = nframes; | 140 | sh.length = nframes; |
140 | 141 | ||
141 | bzero(&fh, sizeof(fh)); | 142 | bzero(&fh, sizeof(fh)); |
142 | strcpy(fh.strf, "strf"); | 143 | strcpy(fh.strf, "strf"); |
143 | fh.width = width; | 144 | fh.width = width; |
144 | fh.height = height; | 145 | fh.height = height; |
145 | fh.planes = 1; | 146 | fh.planes = 1; |
146 | fh.bitcount = 24; | 147 | fh.bitcount = 24; |
147 | strcpy(fh.codec,"MJPG"); | 148 | strcpy(fh.codec,"MJPG"); |
148 | fh.unpackedsize = 3*width*height; | 149 | fh.unpackedsize = 3*width*height; |
149 | 150 | ||
150 | rh.size = sizeof(lh1)+sizeof(ah)+sizeof(lh2)+sizeof(sh)+ | 151 | rh.size = sizeof(lh1)+sizeof(ah)+sizeof(lh2)+sizeof(sh)+ |
151 | sizeof(fh)+sizeof(lh3)+sizeof(dh)+sizeof(lh4)+ | 152 | sizeof(fh)+sizeof(lh3)+sizeof(dh)+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 | |||
@@ -475,77 +475,81 @@ void CameraMainWindow::postProcessVideo( const QString& infile, const QString& o | |||
475 | 475 | ||
476 | // post process | 476 | // post process |
477 | 477 | ||
478 | for ( int i = 0; i < _videopics; ++i ) | 478 | for ( int i = 0; i < _videopics; ++i ) |
479 | { | 479 | { |
480 | odebug << "processing frame " << i << oendl; | 480 | odebug << "processing frame " << i << oendl; |
481 | 481 | ||
482 | // <gui> | 482 | // <gui> |
483 | label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) ); | 483 | label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) ); |
484 | bar->setProgress( i ); | 484 | bar->setProgress( i ); |
485 | bar->repaint(); | 485 | bar->repaint(); |
486 | qApp->processEvents(); | 486 | qApp->processEvents(); |
487 | // </gui> | 487 | // </gui> |
488 | 488 | ||
489 | int read = ::read( infd, inbuffer, framesize ); | 489 | int read = ::read( infd, inbuffer, framesize ); |
490 | odebug << "read " << read << " bytes" << oendl; | 490 | odebug << "read " << read << " bytes" << oendl; |
491 | bufferToImage( captureX, captureY, inbuffer, &image ); | 491 | bufferToImage( captureX, captureY, inbuffer, &image ); |
492 | 492 | ||
493 | QPixmap p; | 493 | QPixmap p; |
494 | p.convertFromImage( image ); | 494 | p.convertFromImage( image ); |
495 | preview->setPixmap( p ); | 495 | preview->setPixmap( p ); |
496 | preview->repaint(); | 496 | preview->repaint(); |
497 | qApp->processEvents(); | 497 | qApp->processEvents(); |
498 | 498 | ||
499 | #ifndef QT_NO_DEBUG | ||
500 | QString tmpfilename; | ||
501 | tmpfilename.sprintf( "/tmp/test/%04d.jpg", i ); | ||
502 | #else | ||
499 | QString tmpfilename( "/tmp/tempfile" ); | 503 | QString tmpfilename( "/tmp/tempfile" ); |
500 | //tmpfilename.sprintf( "/tmp/test/%d.jpg", i ); | 504 | #endif |
501 | 505 | ||
502 | imageToFile( &image, tmpfilename, "JPEG", quality ); | 506 | imageToFile( &image, tmpfilename, "JPEG", quality ); |
503 | 507 | ||
504 | QFile framefile( tmpfilename ); | 508 | QFile framefile( tmpfilename ); |
505 | if ( !framefile.open( IO_ReadOnly ) ) | 509 | if ( !framefile.open( IO_ReadOnly ) ) |
506 | { | 510 | { |
507 | oerr << "can't process file: %s" << strerror(errno) << oendl; | 511 | oerr << "can't process file: %s" << strerror(errno) << oendl; |
508 | return; // TODO: clean up temp ressources | 512 | return; // TODO: clean up temp ressources |
509 | } | 513 | } |
510 | 514 | ||
511 | int filesize = framefile.size(); | 515 | int filesize = framefile.size(); |
512 | odebug << "filesize for frame " << i << " = " << filesize << oendl; | 516 | odebug << "filesize for frame " << i << " = " << filesize << oendl; |
513 | 517 | ||
514 | unsigned char* tempbuffer = new unsigned char[ filesize ]; | 518 | unsigned char* tempbuffer = new unsigned char[ filesize ]; |
515 | framefile.readBlock( (char*) tempbuffer, filesize ); | 519 | framefile.readBlock( (char*) tempbuffer, filesize ); |
516 | avi_add( outfd, tempbuffer, filesize ); | 520 | avi_add( outfd, tempbuffer, filesize ); |
517 | delete tempbuffer; | 521 | delete tempbuffer; |
518 | framefile.close(); | 522 | framefile.close(); |
519 | } | 523 | } |
520 | 524 | ||
521 | avi_end( outfd, captureX, captureY, _framerate ); | 525 | avi_end( outfd, captureX, captureY, _framerate ); |
522 | 526 | ||
523 | fr->hide(); | 527 | fr->hide(); |
524 | delete fr; | 528 | delete fr; |
525 | 529 | ||
526 | updateCaption(); | 530 | updateCaption(); |
527 | 531 | ||
528 | } | 532 | } |
529 | 533 | ||
530 | 534 | ||
531 | void CameraMainWindow::updateCaption() | 535 | void CameraMainWindow::updateCaption() |
532 | { | 536 | { |
533 | if ( !_capturing ) | 537 | if ( !_capturing ) |
534 | setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) ); | 538 | setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) ); |
535 | else | 539 | else |
536 | setCaption( "Opie-Camera: => CAPTURING <=" ); | 540 | setCaption( "Opie-Camera: => CAPTURING <=" ); |
537 | } | 541 | } |
538 | 542 | ||
539 | 543 | ||
540 | #ifndef QT_NO_DEBUG | 544 | #ifndef QT_NO_DEBUG |
541 | void CameraMainWindow::doSomething() | 545 | void CameraMainWindow::doSomething() |
542 | { | 546 | { |
543 | captureX = 240; | 547 | captureX = 240; |
544 | captureY = 320; | 548 | captureY = 320; |
545 | _videopics = 176; | 549 | _videopics = 50; |
546 | _framerate = 5; | 550 | _framerate = 5; |
547 | postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", | 551 | postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat", |
548 | "/tmp/output.avi" ); | 552 | "/tmp/output.avi" ); |
549 | } | 553 | } |
550 | #endif | 554 | #endif |
551 | 555 | ||