在初始化 AVAssetReader 时,我注意到大约 20% 的时间它无法开始阅读。下面是代码片段,它在代码停止 20% 的地方结束。 'startReading' 调用返回 NO。
有人知道为什么会这样吗?我在这里错过了什么吗?我还应该注意到这段代码经常被执行。它可能是大约 10 个视频,一个接一个地按顺序处理。因此,大约 2 或 3 个视频将无法处理,因为“startReading”调用将返回 NO。
NSError *error = nil;
NSURL *srcVideo = [NSURL fileURLWithPath:[video getVideoLocation]];
NSDictionary *opts =
[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:yes]
forKey:@"AVURLAssetPreferPreciseDurationAndTimingKey"];
AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:srcVideo options:opts];
// Get the video track but first check for existence of track
if( [[avAsset tracksWithMediaType:AVMediaTypeVideo] count] == 0 ) {
DLog(@"Error - no video tracks in asset");
return;
}
AVAssetTrack *videoTrack = [[avAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
// Set up the reading of the video track
AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:avAsset
error:&error];
NSDictionary *videoOptions =
[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
AVAssetReaderTrackOutput *assetReaderVideoOutput =
[[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack
outputSettings:videoOptions];
[reader addOutput:assetReaderVideoOutput];
if( ![reader startReading] ) {
DLog(@"Error - failed to start reading video");
DLog(@"Happens about 20% of time...");
return;
}
最佳答案
您可以请求时间在后台运行。 (已在 iOS8 上确认,也可能适用于更早的 iOS。)
为 UIBackgroundTaskIdentifier 添加一个属性。
@property (nonatomic) UIBackgroundTaskIdentifier bgIdentifier;
当您的应用进入后台时,开始后台任务。
self.bgIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^ {
NSLog(@"background task expired.");
[[UIApplication sharedApplication] endBackgroundTask:self.bgIdentifier];
self.bgIdentifier = UIBackgroundTaskInvalid;
}];
做一些工作。 (您的 Assets 阅读器现在应该在后台阅读)。
完成后结束任务,以便系统可以暂停您的应用。
[[UIApplication sharedApplication] endBackgroundTask:self.bgIdentifier];
self.bgIdentifier = UIBackgroundTaskInvalid;
请记住,使用此方法只会花几分钟的时间。
关于ios - 当应用程序在后台时,AVAssetReader 将无法正确初始化,因此无法开始阅读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17553624/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
在我的gem中,我需要yaml并且在我的本地计算机上运行良好。但是在将我的gem推送到rubygems.org之后,当我尝试使用我的gem时,我收到一条错误消息=>"uninitializedconstantPsych::Syck(NameError)"谁能帮我解决这个问题?附言RubyVersion=>ruby1.9.2,GemVersion=>1.6.2,Bundlerversion=>1.0.15 最佳答案 经过几个小时的研究,我发现=>“YAML使用未维护的Syck库,而Psych使用现代的LibYAML”因此,为了解决
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在Rails工作并有以下类(class):classPlayer当我运行时bundleexecrailsconsole然后尝试:a=Player.new("me",5.0,"UCLA")我回来了:=>#我不知道为什么Player对象不会在这里初始化。关于可能导致此问题的操作/解释的任何建议?谢谢,马里奥格 最佳答案 havenoideawhythePlayerobjectwouldn'tbeinitializedhere它没有初始化很简单,因为你还没有初始化它!您已经覆盖了ActiveRecord::Base初始化方法,但您没有调