LibSourcey是跨平台C++11模块和类的集合,为开发人员提供了一个快速开发基于p2p和媒体流应用程序的高性能网络的库。可以把它看作libuv与FFmpeg,OpenCV和WebRTC特性的高度结合,所有这些都具有stl(C++标准库)的易用性和可读性。
使用LibSourcey一个很好的出发点是PacketStream,它可用来创建用于管道,处理并输出任意数据分组的动态委托链。分层分组处理器和动态功能的方法使得它能够快速且容易地开发出复杂的数据处理应用程序。例如,下面的代码将介绍如何捕捉实时摄像头流,将其编码为H.264,并通过互联网实时广播它:
// Create a PacketStream to pass packets from the// input device captures => encoder => socketPacketStream stream;// Setup the encoder optionsav::EncoderOptions options;options.oformat = av::Format("MP4", "mp4", av::VideoCodec("H.264", "libx264", 400, 300, 25, 48000, 128000, "yuv420p"), av::AudioCodec("AAC", "libfdk_aac", 2, 44100, 64000, "s16"));// Create a device manager instance to enumerate system devicesav::DeviceManager devman;av::Device device;// Create and attach the default video captureav::VideoCapture::Ptr video;if (devman.getDefaultCamera(device)) { video.open(device.id, 640, 480, 30); video.getEncoderFormat(options.iformat); stream.attachSource(video, true);}// Create and attach the default audio captureav::AudioCapture::Ptr audio;if (devman.getDefaultMicrophone(device)) { audio.open(device.id, 2, 44100); audio.getEncoderFormat(options.iformat); stream.attachSource(audio, true);}// Create and attach the multiplex encoderav::MultiplexPacketEncoder::Ptr encoder(options);stream.attach(encoder);// Attach the output net::Socket instance (instantiated elsewhere)// to broadcast encoded packets over the networkstream.attach(socket);// Start the stream// This method call will start the device captures and begin// pumping encoded media into the output socketstream.start();
评论