Hello!

        I have two questions / problems with multiple audio streams
encoding with the avifile lib.  Please have a look at the small
example program to create a video and some audio streams.


Problem 1
=========

As long as I use only one audio stream (./mas 1) all seams ok, but
when I increase the number, a core is dumped (segmentation fault):

MP3EncodeR::Close()
MP3EncodeR::Close()
Segmentation fault (core dumped)

A 'bt' in gdb:

#0  0x40778508 in get_side_info () at mp3encoder.cpp:121
#1  0x407b0458 in __DTOR_END__ () from 
/usr/lib/avifile/libmp3lame_audioenc.so.0
#2  0x000023d0 in ?? () at /usr/include/stdlib.h:359
Cannot access memory at address 0x360


Problem 2
=========

It is not possible to use the "as->Stop()" method (see line 128).  If
this is used, the same core as described above occurs.


Question
========

Is there a bug in the program mas.cc or in the avifile lib?

(My environment: PIII 866 / 256M / avifile cvs current 07.08.2001 /
RedHat 7.1 / gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) /
XFree 4.1.0)


Best Regards

Andre

//
// Put a P6 PPM pic (without some comments in it; you may want to
// remove them with an editor) named "pic.ppm" in the current dir.
//
// Compile with
//  g++ `avifile-config --cflags --libs` -o mas mas.cc
//
// Note: Yes, I know that the pic is not displayed correctly --- I
// only want to have some video data!
//

#include <avifile.h>
#include <fourcc.h>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>

int main(int argc, char * argv[])
{
   if(argc==1)
   {
      std::cerr << "Usage: " << argv[0] << " audio_channels_cnt" 
                << std::endl;
      return 10;
   }
   int cnt_audio = atoi(argv[1]);

   // Create AVI File
   IAviWriteFile * avi_write_file
      = CreateSegmentedFile("movie.avi");

   // ***
   // *** VIDEO
   // ***

   // Read in the PPM Pic
   std::string p6, w, h, c;

   std::fstream f("pic.ppm", std::ios::in);
   f >> p6 >> w >> h >> c;

   char i;
   f.read(&i, 1);

   assert(p6=="P6");
   unsigned long pic_width = atoi(w.c_str());
   unsigned long pic_height = atoi(h.c_str());
   assert(c=="255");

   unsigned char * pic_data = new unsigned char[pic_width*pic_height*3];
   f.read(reinterpret_cast<char*>(pic_data), pic_width*pic_height*3);
   CImage ci(pic_data, pic_width, pic_height);

   f.close();

   // Add video "stream"
   BITMAPINFOHEADER bh;
   bh.biSize = sizeof(BITMAPINFOHEADER);
   bh.biWidth = pic_width;
   bh.biHeight = pic_height;
   bh.biPlanes =  1;
   bh.biBitCount = 24; // avs->bit_cnt;
   bh.biCompression = 0;
   bh.biSizeImage = pic_width * pic_height * 3;
   bh.biXPelsPerMeter = 0;
   bh.biYPelsPerMeter = 0;
   bh.biClrUsed = 0;
   bh.biClrImportant = 0;
   
   IAviVideoWriteStream  * vs 
      = avi_write_file->AddVideoStream(fccdiv3, &bh, 40000);

   vs->SetQuality(9000);
   vs->Start();

   // Add 25 * 10 pics for 10 second playtime
   for(int i=0; i<25*10; ++i)
      vs->AddFrame(&ci);

   vs->Stop();
   delete vs;

   // ***
   // *** AUDIO
   // ***

   for(int i=0; i<cnt_audio; ++i)
   {
      std::cout << "Creating Audio Channel " << i << std::endl;

      WAVEFORMATEX wvfe;

      wvfe.wFormatTag = 1;
      wvfe.nChannels = 2;
      wvfe.nSamplesPerSec = 44100;
      wvfe.nAvgBytesPerSec = 2*2*44100;
      wvfe.nBlockAlign = 4;
      wvfe.wBitsPerSample = 16;
      wvfe.cbSize = sizeof(wvfe);

      IAviAudioWriteStream * as 
         = avi_write_file->AddAudioStream(0x55, &wvfe, 16000);

      as->Start();

      for(int s=0; s<10; ++s)
      {
         unsigned char buf[44100*2*2]; // buf for one sec.

         for(int j=0; j<44100; ++j)
         {
            int val = static_cast<int>
               (cos(static_cast<double>(j) 
                    * static_cast<double>(i+1) / 50.0) * 32768.);

            int low = val % 256;
            int high = val / 256;

            buf[j*4+0] = buf[j*4+2] = low;
            buf[j*4+1] = buf[j*4+3] = high;
         }

         as->AddData(buf, 44100*2*2);
      }

#warning Why does this cores?
//      as->Stop();
  
      delete as;
      std::cout << "Finished Audio Channel " << i << std::endl;

   }

   return 0;
}

Reply via email to