[Openal] OpenAl video audio ?

Orlay Garcia Ducunge oducunge at estudiantes.uci.cu
Fri Apr 18 21:19:44 PDT 2008


I need to play the sound of a video file .avi on Linux, using OpenAl, to read the file of video I use avifile-0.7.  
This code extracts the video audio and save it in mp3 format, I don't need save it, I just need to store it in an OpenAl buffer to reproduce it. What I can do ?


#include <avifile-0.7/avm_default.h>
#include <avifile-0.7/avifile.h>
#include <avifile-0.7/aviplay.h>
#include <avifile-0.7/avm_except.h>
#include <avifile-0.7/version.h>

#include <stdio.h>
#include <stdlib.h> // exit

#define __MODULE__ "extractor"

int main(int argc, char** argv)
{
    static const int buffer_size = 4000;
    static const char* outname = "./extractor.mp3";
    FILE* f = 0;
    avm::IReadFile* ac = 0;
    avm::IReadStream* as = 0;
    uint8_t* zz = 0;
    if (GetAvifileVersion() != AVIFILE_VERSION)
    {
	fprintf(stderr, "This binary was compiled for Avifile ver. %d "
		", but the library is ver. %d. Aborting.\n",
		AVIFILE_VERSION, GetAvifileVersion());
	return 0;
    }

    if (argc == 0)
    {
	fprintf(stderr, "Missing argument: filename\n");
	exit(0);
    }

    try
    {
	if (!(f = fopen(outname, "wb")))
	    throw FATAL("Can't open %s for writing", outname);
	if (!(ac = avm::CreateReadFile("data/Bleach.avi")))
	    throw FATAL("Can't read given file");
	if (!(as = ac->GetStream(0, avm::IStream::Audio)))
	    throw FATAL("Stream doesn't contain audio stream");

	zz = new uint8_t[buffer_size];
	while (!as->Eof())
	{
	    uint_t samp_read, bytes_read;
	    as->ReadDirect(zz, buffer_size, buffer_size, samp_read, bytes_read);

	    fwrite(zz, bytes_read, 1, f);
	}
    }
    catch (FatalError& error)
    {
	error.Print();
    }

    delete ac;
    delete zz;
    if (f)
	fclose(f);
}




More information about the Openal mailing list