打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
FFmpeg 视频编码
系列博客:
http://blog.csdn.net/leixiaohua1020/article/category/1360795
=====================================================
最简单的基于FFmpeg的移动端例子系列文章列表:
最简单的基于FFmpeg的移动端例子:Android HelloWorld
最简单的基于FFmpeg的移动端例子:Android 视频解码器
最简单的基于FFmpeg的移动端例子:Android 视频解码器-单个库版
最简单的基于FFmpeg的移动端例子:Android 推流器
最简单的基于FFmpeg的移动端例子:Android 视频转码器
最简单的基于FFmpeg的移动端例子附件:Android 自带播放器
最简单的基于FFmpeg的移动端例子附件:SDL Android HelloWorld
最简单的基于FFmpeg的移动端例子:IOS HelloWorld
最简单的基于FFmpeg的移动端例子:IOS 视频解码器
最简单的基于FFmpeg的移动端例子:IOS 推流器
最简单的基于FFmpeg的移动端例子:IOS 视频转码器
最简单的基于FFmpeg的移动端例子附件:IOS自带播放器
最简单的基于FFmpeg的移动端例子:Windows Phone HelloWorld
=====================================================
前几篇文章记录的都是IOS下基于FFmpeg的多媒体程序。本文记录一个IOS下自带的视频播放器。相比于移植FFmpeg来说,IOS自带的多媒体框架播放视频要简单很多——只需要调用几个接口就可以了。
源代码
项目的源代码位于ViewController.m文件中,内容如下所示。
[objc] view plaincopy
/**
* 最简单的IOS视频播放器
* Simplest IOS Player
*
* 雷霄骅 Lei Xiaohua
* leixiaohua1020@126.com
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
* 本程序是IOS上最简单的视频播放器。
* This software is the simplest Video Player on IOS.
*
*/
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@property (nonatomic,strong) MPMoviePlayerController *moviePlayer;//视频播放控制器
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.moviePlayer play];
[self addNotification];
}
-(void)dealloc{
//移除所有通知监控
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(MPMoviePlayerController *)moviePlayer{
if (!_moviePlayer) {
NSString *urlStr=[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"resource.bundle/war3end.mp4"];
NSURL *url=[NSURL fileURLWithPath:urlStr];
_moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:url];
_moviePlayer.view.frame=self.view.bounds;
_moviePlayer.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_moviePlayer.view];
}
return _moviePlayer;
}
-(void)addNotification{
NSNotificationCenter *notificationCenter=[NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(mediaPlayerPlaybackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer];
[notificationCenter addObserver:self selector:@selector(mediaPlayerPlaybackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
}
-(void)mediaPlayerPlaybackStateChange:(NSNotification *)notification{
switch (self.moviePlayer.playbackState) {
case MPMoviePlaybackStatePlaying:
NSLog(@"正在播放...");
break;
case MPMoviePlaybackStatePaused:
NSLog(@"暂停播放.");
break;
case MPMoviePlaybackStateStopped:
NSLog(@"停止播放.");
break;
default:
NSLog(@"播放状态:%li",self.moviePlayer.playbackState);
break;
}
}
-(void)mediaPlayerPlaybackFinished:(NSNotification *)notification{
NSLog(@"播放完成.%li",self.moviePlayer.playbackState);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
[objc] view plaincopy
运行结果
App在手机上运行后的结果如下图所示。程序运行后,会自动播放resource.bundle中的war3end.mp4文件。
下载
simplest ffmpeg mobile
项目主页
Github:https://github.com/leixiaohua1020/simplest_ffmpeg_mobile
开源中国:https://git.oschina.net/leixiaohua1020/simplest_ffmpeg_mobile
SourceForge:https://sourceforge.net/projects/simplestffmpegmobile/
CSDN工程下载地址:http://download.csdn.net/detail/leixiaohua1020/8924391
本解决方案包含了使用FFmpeg在移动端处理多媒体的各种例子:
[Android]
simplest_android_player: 基于安卓接口的视频播放器
simplest_ffmpeg_android_helloworld: 安卓平台下基于FFmpeg的HelloWorld程序
simplest_ffmpeg_android_decoder: 安卓平台下最简单的基于FFmpeg的视频解码器
simplest_ffmpeg_android_decoder_onelib: 安卓平台下最简单的基于FFmpeg的视频解码器-单库版
simplest_ffmpeg_android_streamer: 安卓平台下最简单的基于FFmpeg的推流器
simplest_ffmpeg_android_transcoder: 安卓平台下移植的FFmpeg命令行工具
simplest_sdl_android_helloworld: 移植SDL到安卓平台的最简单程序
[IOS]
simplest_ios_player: 基于IOS接口的视频播放器
simplest_ffmpeg_ios_helloworld: IOS平台下基于FFmpeg的HelloWorld程序
simplest_ffmpeg_ios_decoder: IOS平台下最简单的基于FFmpeg的视频解码器
simplest_ffmpeg_ios_streamer: IOS平台下最简单的基于FFmpeg的推流器
simplest_ffmpeg_ios_transcoder: IOS平台下移植的ffmpeg.c命令行工具
simplest_sdl_ios_helloworld: 移植SDL到IOS平台的最简单程序
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
100行代码实现最简单的基于FFMPEG+SDL的视频播放器(SDL1.x)
最简单的基于FFmpeg的内存读写的例子
盘点那些堪称“神器”的手机APP,安卓和苹果都有,你用过几个?
Android和iOS操作系统区别的视频
android全格式多媒体播放器(三:基于ffmpeg架构) 提纲
检查安卓应用更新
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服