Ejemplo n.º 1
0
//Remove frames from the buffer and record it to a file
void processQueue(){
	if(rQueue.empty()){
		return;
	}
	boost::unique_lock<boost::mutex> lock(io_mutex2);

	printf("Size of the queue is: %i\n",rQueue.size());

	//Flip the image upside down
	for(int i = height - 1; i >= 0; i--){
//		printf("hey %i\n", i);
		//memcpy(frame.pixels + (height - i - 1)*width*4, queue.dequeFrame() + i*width*4, width*4);
		memcpy(frame.pixels + (height - i - 1)*width*4, rQueue.front() + i*width*4, width*4);
	}

	//free(rQueue.front());
	rQueue.pop();
	//lock.unlock();

	int frameSize;
	revError = Revel_EncodeFrame(encoderHandle, &frame, &frameSize);
	if (revError != REVEL_ERR_NONE)
	{
		printf("Revel Error while writing frame: %d\n", revError);
		exit(1);
	}
	printf("Frame %d of %d: %d bytes\n", numFrames+1, numFrames, frameSize);
	numFrames++;
//	io_mutex2.unlock();
}
Ejemplo n.º 2
0
HRESULT CAVIGenerator::AddFrame(BYTE *bmBits)
{

	if(released) return 0;
	DWORD newtime=timeGetTime();
	Revel_Error revError;
	;

	INT delta = (1000/m_dwRate)-(newtime-oldtime);
	if (delta>0) {
		Sleep(delta);
		return 0;

	}
	oldtime=newtime;

	    // Draw and encode each frame.
    Revel_VideoFrame frame;
    frame.width = m_bih.biWidth;
    frame.height = m_bih.biHeight;
    frame.bytesPerPixel = m_bih.biBitCount/8;
	if(frame.bytesPerPixel==1)
    frame.pixelFormat = REVEL_PF_PLANAR;  //REVEL_PF_BGRA;
	else
	frame.pixelFormat = REVEL_PF_BGRA;

	frame.pixels = new int[m_bih.biWidth*m_bih.biHeight];
	
	memcpy(frame.pixels, bmBits, m_bih.biSizeImage);
	
    int frameSize;
    revError = Revel_EncodeFrame(encoderHandle, &frame, &frameSize);
    if (revError != REVEL_ERR_NONE)
        {
	        printf("Revel Error while writing frame: %d\n", revError);
	      //  exit(1);
	    }
    
    delete [] (int*)frame.pixels;


	return revError != REVEL_ERR_NONE;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    const char *filename = "checkers.avi";
    int numFrames = 64;
	Revel_Error revError;

	// Make sure the encoder is valid
	if (!Revel_IsEncoderValid(encoderHandle))
	{
		return -1;
	}

    // Attempt to load some sound data, to encode into the output movie's
    // audio stream.
    bool hasAudio = false;
    char *audioBuffer = NULL;
	int audioBufferSize = 0;
    LoadAudio(&hasAudio, &audioBuffer, &audioBufferSize);
    if (!hasAudio)
    {
        printf("Warning: Failed to load audio test file: chimes.raw\n");
        printf("         The audio encoding tests will be skipped.\n");
    }

	// Initiate encoding
    revError = Revel_EncodeStart(encoderHandle, filename);
    if (revError != REVEL_ERR_NONE)
    {
	    printf("Revel Error while starting encoding: %d\n", revError);
	    exit(1);
    }

    // Draw and encode each frame.
    Revel_VideoFrame frame;
    frame.width = width;
    frame.height = height;
    frame.bytesPerPixel = 4;
    frame.pixelFormat = REVEL_PF_RGBA;
    frame.pixels = new int[width*height];
    memset(frame.pixels, 0, width*height*4);
    for(int i=0; i<numFrames; ++i)
    {
        DrawFrame(frame.width, frame.height, 0xFF000000 + 0x000004*i, i, i,
            (int*)frame.pixels);
        int frameSize = 0;
        revError = Revel_EncodeFrame(encoderHandle, &frame, &frameSize);
    	if (revError != REVEL_ERR_NONE)
        {
	        printf("Revel Error while writing frame: %d\n", revError);
	        exit(1);
	    }
        printf("Frame %d of %d: %d bytes\n", i+1, numFrames, frameSize);
    }

    // Encode the audio track.  NOTE that each call to Revel_EncodeAudio()
    // *appends* the new audio data onto the existing audio track.  There is
    // no synchronization between the audio and video tracks!  If you want
    // the audio to start on frame 60, you need to manually insert 60 frames
    // worth of silence at the beginning of your audio track!
    //
    // To demonstrate this, we'll encode the audio buffer twice. Note that
    // the two chimes play immediately when the movie starts, one after the
    // other, even though we're encoding them "after" all the video frames.
    int totalAudioBytes = 0;
    revError = Revel_EncodeAudio(encoderHandle, audioBuffer, audioBufferSize,
        &totalAudioBytes);
    revError = Revel_EncodeAudio(encoderHandle, audioBuffer, audioBufferSize,
        &totalAudioBytes);
    if (revError != REVEL_ERR_NONE)
    {
        printf("Revel Error while writing audio: %d\n", revError);
        exit(1);
    }
    printf("Encoded %d bytes of audio\n", totalAudioBytes);
    

    // Finalize encoding.  If this step is skipped, the output movie will be
    // unviewable!
    int totalSize = 0;
    revError = Revel_EncodeEnd(encoderHandle, &totalSize);
    if (revError != REVEL_ERR_NONE)
    {
	    printf("Revel Error while ending encoding: %d\n", revError);
	    exit(1);
    }
    printf("%s written: %dx%d, %d frames, %d bytes\n", filename, width, height,
        numFrames, totalSize);

    // Final cleanup.
    Revel_DestroyEncoder(encoderHandle);
    if (audioBuffer != NULL)
        delete [] audioBuffer;
    delete [] (int*)frame.pixels;
    return 0;
}