MyAVILIB

所属分类:多媒体编程
开发工具:Visual C++
文件大小:44KB
下载次数:180
上传日期:2005-07-31 07:47:03
上 传 者riverzjs
说明:  一个自己写的AVI文件操作函数库,可以用它在其它非Windows操作系统中对AVI文件进行操作
(himself wrote an AVI file manipulation functions, you can use it in other non-Windows operating system to operate AVI file)

文件列表:
MyAVILIB (0, 2004-11-25)
MyAVILIB\anna.avi (11210, 2004-11-25)
MyAVILIB\AVILIB (0, 2004-11-25)
MyAVILIB\AVILIB\avilib.c (30293, 2004-11-25)
MyAVILIB\AVILIB\AVILIB.dsp (2887, 2004-11-24)
MyAVILIB\AVILIB\avilib.h (6012, 2004-11-25)
MyAVILIB\AVILIB\AVILIB.ncb (66560, 2004-11-24)
MyAVILIB\AVILIB\AVILIB.opt (59904, 2004-11-24)
MyAVILIB\AVILIB\AVILIB.plg (771, 2004-11-24)
MyAVILIB\AVITest.c (1426, 2004-11-25)
MyAVILIB\AVITest.dsp (4293, 2004-11-24)
MyAVILIB\AVITest.dsw (818, 2004-11-25)
MyAVILIB\AVITest.ncb (66560, 2004-11-25)
MyAVILIB\AVITest.opt (58880, 2004-11-25)
MyAVILIB\AVITest.plg (1279, 2004-11-25)
MyAVILIB\frame1.jpg (1099, 2003-06-19)
MyAVILIB\frame2.jpg (1184, 2003-06-19)
MyAVILIB\frame3.jpg (1309, 2003-06-19)
MyAVILIB\frame4.jpg (1774, 2003-06-19)
MyAVILIB\frame5.jpg (1816, 2003-06-19)
MyAVILIB\frame6.jpg (1826, 2003-06-19)

avilib: Reading and writing avi files ===================================== Copyright (C) 1999 Rainer Johanni avilib is a open source library for dealing with AVI files under Linux or other UNIX operating systems. It provides a framework for extracting or adding raw audio and single raw (=compressed) frames from/to AVI Files. It does not deal with any compression issues which have to be handled on a higher level by the user of avilib. AVI files may have several video and audiotracks. avilib writes only one video track and (optionally) one audio track and also extracts only the first video and audio track (but input files may contain more than one track, the others just being ingored). The interface to avilib is kept similar to the quicktime4linux interface (by Adam Williams) with the following important differences: - since only the first track of video and audio is considered, there is no track argument in any of the routines. - audio is generally considered as a byte stream and therefore all size arguments used in reading/writing audio are in bytes and not in samples. - as mentioned above, there are no routines dealing with compression issues. Compiling: ========== Since the library consists only of one c source file, I have not provided a Makefile or similar, just compile with cc -c avilib.c Portability: ============ AVI-Files use little endian numbers throughout the file, I have tried to read/write these numbers in a way which doesn't depent on endianness. This library should therefore also be useable on big endian machines. This feature is not so heavily tested, however. Usage: ====== Basics, opening, closing ------------------------ Include "avilib.h" in your source and declare a pointer: avi_t *avifile; Open the AVI file with: avifile = AVI_open_input_file("xxx.avi",1); or avifile = AVI_open_output_file("xxx.avi"); You may either only read from the input file (leaving it unchanged) or create a completly new AVI file. There is no editing or append mode available. Both routines will either return a pointer to avi_t or a zero pointer in the case of an error. For closing the file, use: int AVI_close(avi_t *AVI); Files you have written MUST be closed (the header is written at close time), else they will not be readable by any other software. Files opened for reading should be closed to free the file descriptor and some data (unless your program is finishing anyway). Error handling: --------------- Most routines (besides open/close) will return 0 or a usefull number if successfull and a -1 in the case of an error. If an error occured, the external variable AVI_errno is set. See avilib.h for the meaning of the error codes in AVI_errno. There is also a routine (which acts like perror) to output a description of the last error to stderr: AVI_print_error(char *str) Reading from an AVI file: ------------------------- After opening the file, you can obtain the parameters of the AVI with the following routines: long AVI_video_frames(avi_t *AVI); number of video frames in the file int AVI_video_width(avi_t *AVI); int AVI_video_height(avi_t *AVI); width and height of the video in pixels double AVI_frame_rate(avi_t *AVI); frame rate in frames per second, notice that this is a double value! char* AVI_video_compressor(avi_t *AVI); string describing the compressor int AVI_audio_channels(avi_t *AVI); number of audio channels, 1 for mono, 2 for stereo, 0 if no audio present int AVI_audio_bits(avi_t *AVI); audio bits, usually 8 or 16 int AVI_audio_format(avi_t *AVI); audio format, most common is 1 for raw PCM, look into avilib.h for others long AVI_audio_rate(avi_t *AVI); audio rate in samples/second long AVI_audio_bytes(avi_t *AVI); total number of audio bytes in the file In order to read the video frame by frame, use (frame numbers are starting from 0 !!!!!) long AVI_frame_size(avi_t *AVI, long frame); to get the size of frame with number "frame" long AVI_read_frame(avi_t *AVI, char *vidbuf); to read the next frame (frame posittion is advanced by 1 after the read) int AVI_seek_start(avi_t *AVI); int AVI_set_video_position(avi_t *AVI, long frame); to position in the AVI file (for reading the frames out of order) Read audio with int AVI_set_audio_position(avi_t *AVI, long byte); to position to an arbitrary byte position within the audio stream long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes); to actually read "bytes" number of audio bytes. the audio position is advanced by "bytes", so there is no need to reposition before every call when reading in order. Avoiding lengthy index searches: -------------------------------- When opening the AVI file, avilib looks if the file has an index attached and if this is not the case, it creates one by reading through the whole file. If you want to read through the file only once, creation of an index is not necessary in that case. You may use AVI_open_input_file with the second argument set to 0 and then use AVI_read_data for readin through the file. Look to the source for the arguments of AVI_read_data. Writing to an AVI file: ----------------------- After you have opened the file, use the following routines to set the properties of the AVI file: void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor); void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format); with: width, height width and height of the video in pixels fps frame rate in frames per second, notice that this is a double value! compressor string describing the compressor channels number of audio channels, 1 for mono, 2 for stereo, 0 if no audio present rate audio rate in samples/second bits audio bits, usually 8 or 16, 0 if no audio present format audio format, most common is 1 for raw PCM, look into avilib.h for others to write video frames or audio, use: int AVI_write_frame(avi_t *AVI, char *data, long bytes); int AVI_write_audio(avi_t *AVI, char *data, long bytes); there is also a feature to duplicate the index entry of the last frame without writing the data again to the file, this should used with care since I don't know if all AVI players can handle the resulting file (xanim can do it!): int AVI_dup_frame(avi_t *AVI); AVI files have a 2 GB limit (as has the Linux ext2 file system), avilib will return an error if you try to add more data to the file (and it cares that the file still can be correctly closed). If you want to check yourself how far you are away from that limit (for example to synchronize the amount of audio and video data) use: long AVI_bytes_remain(avi_t *AVI); example: #include #include "avilib.h" void main(int argc, char argv[]) { char VideoFmtYV12[4] = { 'Y','V','1','2' }; FILE* fpYUV; char input_yuv[352*288*3/2]; avi_t* pAviHandle; pAviHandle = AVI_open_output_file("anna.avi"); if(!pAviHandle) { printf("avi file open failed \n"); return -1; } AVI_set_video(pAviHandle, 352, 288, 25, VideoFmtYV12); fpYUV = fopen("test.yuv","rb"); strcpy(input_yuv, argv[1]); do { fread(input_yuv, 1, 352*288*3/2, fpYUV); AVI_write_frame(pAviHandle, input_yuv, 352*288*3/2); } fclose(fpYUV); AVI_close(pAviHandle); }

近期下载者

相关文件


收藏者