主流的跨平台媒体库:
库名 | 简介 | 需要的能力 | 官网链接 |
---|---|---|---|
ffmpeg | FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多codec都是从头开发的。 | 了解视频编解码原理和流程、了解图像压缩技术、音频压缩技术等 | http://ffmpeg.org |
live555 | Live555实现了对多种音视频编码格式的音视频数据的流化、接收和处理等支持,包括MPEG、H.263+、DV、JPEG视频和多种音频编码。同时由于良好的设计,Live555非常容易扩展对其他格式的支持。 | 了解视频编解码原理和流程、了解图像压缩技术、音频压缩技术等 | http://www.live555.com |
MobileVLCKit | 鼎鼎大名的播放器VLC ,优秀的封装,源码中最核心的部分,被封装成了独立的库,基于ffmpeg ,live555 提供完整的媒体播放库,你只需要定制自己的界面,支持CocoaPods导入库,开发一个简单界面的播放器,你只需要几行代码,几乎覆盖所有媒体格式! | 你只需要定制好自己的界面,它的API看起来就是一个播放器 | http://www.videolan.org |
主流开源流媒体服务器:
- 流媒体解决方案 Live555 (C++)
- 流媒体平台框架 EasyDarwin (C++,国产精品)
- 实时流媒体播放服务器程序DarwinStreamingSrvr (C++)
- Flash流媒体服务器 Red5 (Java)
- 流媒体服务器 Open Streaming Server (Java)
- FMS流媒体服务器 (Adobe,收费的)
- Wowza流媒体服务器(Java)
- 开源流媒体平台FreeCast(Java)
- Ngix+RTMP插件
Live555:
官网:http://www.live555.com/,Live555的源代码:http://www.live555.com/liveMedia/public/
Live555是一个实现了RTSP协议的开源流媒体框架,Live555包含RTSP服务器端的实现以及RTSP客户端的实现。Live555可以将若干种格式的视频文件或者音频文件转换成视频流或者音频流在网络中通过RTSP协议分发传播,这便是流媒体服务器最核心的功能。经过Live555流化后的视频流或者音频流可以通过实现了标准RTSP协议的播放器(如VLC)来播放。Live555支持以下几种文件格式的流化:
- A MPEG Transport Stream file (with file name suffix ".ts")
- A Matroska or WebM file (with filename suffix ".mkv" or ".webm")
- An Ogg file (with filename suffix ".ogg", "ogv", or ".opus")
- A MPEG-1 or 2 Program Stream file (with file name suffix ".mpg")
- A MPEG-4 Video Elementary Stream file (with file name suffix ".m4e")
- A H.264 Video Elementary Stream file (with file name suffix ".264")
- A H.265 Video Elementary Stream file (with file name suffix ".265")
- A VOB video+audio file (with file name suffix ".vob")
- A DV video file (with file name suffix ".dv")
- A MPEG-1 or 2 (including layer III - i.e., 'MP3') audio file (with file name suffix ".mp3")
- A WAV (PCM) audio file (with file name suffix ".wav")
- An AMR audio file (with file name suffix ".amr")
- An AC-3 audio file (with file name suffix ".ac3")
- An AAC (ADTS format) audio file (with file name suffix ".aac")
****************************
开源视频播放器:https://github.com/Bilibili/ijkplayer(哔哩哔哩的)、https://github.com/kolyvan/kxmovie、VLC播放器(https://github.com/videolan/vlc)http://www.videolan.org/;
***ijkplayer:
ijkplayer需要环境:git和yasm;
下载Homebrew,然后再下载yasm,git是Mac自带的,不用下载。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew install yasm
打开终端cd到init-ios.sh文件的父目录执行./init-ios.sh,这一步需要等很长时间,
然后cd到ios文件夹执行./complie-ffmpeg.sh clean,
再执行./complie-ffmpeg.sh all,
再次运行IJKMediaDemo.xcodeproj就OK了。
如果上面的步骤不行,就需要使用到https,执行以下:
cd到最外层目录
./init-ios-openssl.sh
./init-ios.sh
cd ios文件夹
./compile-openssl.sh clean
./compile-ffmpeg.sh clean
./compile-openssl.sh all
./compile-ffmpeg.sh all
上面执行完成后,extra文件夹中会多出一些依赖库内容:
ios文件夹下也会生成一些文件:
如果过程中有这样的报错:说明不支持arm7,那么删除这个编译目标;其他的类似操作,根据自己 需要支持的编译平台,自己修改;
./libavutil/arm/asm.S:50:9: error: unknown directive
.arch armv7-a
^
解决:
打开ios目录下这个 compile-ffmpeg.sh 文件
第24行 改为: FF_ALL_ARCHS_IOS8_SDK="arm64 x86_64"
第120行 改为: if [ "$FF_TARGET" = "arm64" ]; then
第159行 改为: echo " compile-ffmpeg.sh arm64|x86_64"
选中IJKMediaPlayer工程,模拟器和真机分别deubeg和release编译,然后再products文件中找到IJKMediaPlayer.framework,右键show in finder 找到静态库;然后用下面的命令合并静态库;
lipo -create 真机版本编译后文件路径 模拟器版本编译后文件路径 -output 合成后路径
在使用的时候直接把静态库导入自己的工程,添加lybcrycto.a和libssl.a两个静态库(在上面编译后得到的lib文件中);还需要添加如下的库文件:
解决错误:
1、xxx does not contain bitcode:
xcode默认开启了bitcode,如果我们集成的库没有bitcode编译的包,则有可能出现报错。
解决方法:target-->build setting-->enable bitcode-->NO
2.运行时crash,提示:dyld: Library not loaded: @rpath xxx reason: image not found
出现这种错误,是因为在运行时没有找到framewok对应的包,如果运行到这个包时,就会崩溃。
解决方法:
手动添加framework到项目中:
参考:https://www.jianshu.com/p/3d03502c7daa、https://www.cnblogs.com/baitongtong/p/12745148.html
到此ijkplayer集成完成;
***kxmovie:
使用步骤:
1.利用FFmpeg-iOS-build-script库编译成ios静态库,得到如下图所示,把include和lib拖入新创建的项目中;参考我的另一篇文章https://blog.csdn.net/u011146511/article/details/108647012;
2.下载https://github.com/kolyvan/kxmovie;把kxmovie文件夹拖入新建的项目中; 需要添加三个库,如果ffmpeg导入的时候添加了,这里就不需要添加了;
libiconv.tbd
libbz2.tbd
libz.tbd
3.解决报错:
一、编译报错:'libavformat/avformat.h' file not found;
错误是由于文件路径不对,需要在Build Settings -> Header Search Paths 添加文件路径。"$(SRCROOT)/KxMovieExample/FFmpeg-iOS/include"这个用的是demo中的例子;
二、错误:
Undefined symbols for architecture armv7:
"_VTDecompressionSessionDecodeFrame", referenced from:
_videotoolbox_common_end_frame in libavcodec.a(videotoolbox.o)
"_VTDecompressionSessionWaitForAsynchronousFrames", referenced from:
_videotoolbox_common_end_frame in libavcodec.a(videotoolbox.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是因为缺少VideoToolbox.framework
库,添加这个库即可。
三、错误信息:
Use of undeclared identifier 'PIX_FMT_RGB24'; did you mean 'AV_PIX_FMT_RGB24'?
按照它的提示,点击fix将 'PIX_FMT_RGB24'改变成'AV_PIX_FMT_RGB24'即可,有两个地方。
四、错误提示:
Implicit declaration of function 'avpicture_deinterlace' is invalid in C99
直接把报错的地方注释掉; KxMovieDecoder.m 中从1398行处开始,注释掉以下代码:
avpicture_deinterlace((AVPicture*)_videoFrame,
// (AVPicture*)_videoFrame,
// _videoCodecCtx->pix_fmt,
// _videoCodecCtx->width,
// _videoCodecCtx->height);
五、报错:有几处关于UIImage的报错;
在KxMovieDecoder.h中添加#import <UIKit/UIKit.h>
到此kxmovie集成完成;
使用:
/*PATH播放的视频源
@"http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8",
@"http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8",
@"http://ivi.bupt.edu.cn/hls/cctv5phd.m3u8",
@"http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8",
*/
NSString *path;
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
// increase buffering for .wmv, it solves problem with delaying audio frames
if ([path.pathExtension isEqualToString:@"wmv"])
parameters[KxMovieParameterMinBufferedDuration] = @(5.0);
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
parameters[KxMovieParameterDisableDeinterlacing] = @(YES);
}
//创建播放器控制器
KxMovieViewController *vc = [KxMovieViewController movieViewControllerWithContentPath:path parameters:parameters];
//弹出播放器控制器
[self presentViewController:vc animated:YES completion:nil];
***VLC:源码:https://github.com/videolan/vlc、http://code.videolan.org/videolan/VLCKit.git
VLC 是一款强大的全平台播放器, 几乎支持所有的音频、视频格式文件播放, 官网地址:http://www.videolan.org/, 在iOS 中也可以集成 VLC 的 SDK 进行开发, 使用之前需要先去官网下载 SDK, 然后编译成 iOS 中使用的库文件才能使用, 这种集成方法在编译的过程中需要 VPN 翻墙进行联网编译, 如果网速不好或者不稳定, 很容易编译出错, 如果网速好, 可以按照 wiki 的说明去编译: https://wiki.videolan.org/iOSCompile。当然也可以直接去下载编译好的MobileVLCKit.framework,使用这个框架不需要再导入ffmpeg的静态库,里面已经包含了ffmpeg框架;
1.MobileVLCKit.framework导入到xcode中,下载地址:http://nightlies.videolan.org/build/iOS/ (所有编译好的版本http://nightlies.videolan.org/build/) 或者用cocoaPods导入
pod 'MobileVLCKit', '~> 3.0.1'
2.在Build Phases -> Linked Frameworks and Libraries 添加依赖库:
3.将使用框架的.m文件后缀改为.mm(随便一个类改成.m也可以,否则会报之std::*****类的错误),因为框架底层用到了C++代码;
到此集成完成;
简单使用:
#import <MobileVLCKit/MobileVLCKit.h>
@interface Nextvc ()<VLCMediaPlayerDelegate>
@property (strong, nonatomic) VLCMediaPlayer *player;
@end
-(void)playvideo{
//1.创建视频播放器
self.player = [[VLCMediaPlayer alloc] init];
//2.设置播放的view
self.player.drawable = self.view;
self.player.delegate = self;
//3.设置播放资源路径
//网络资源
// NSString *netpath= NSString *netpath=@"http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8";//@"http://ivi.bupt.edu.cn/hls/cctv5Phd.m3u8"
// NSURL *remoteUrl = [NSURL URLWithString:netpath];
// self.player.media = [VLCMedia mediaWithURL:remoteUrl];
//本地资源
NSString *localpath=[[NSBundle mainBundle]pathForResource:@"water" ofType:@"mp4"];
self.player.media=[VLCMedia mediaWithPath:localpath];
//4.开始播放
[self.player play];
}