我正在尝试使用AVFoundation将多个视频剪辑组合成一个.我可以使用下面的代码使用AVMutableComposition创建单个视频
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime startTime = kCMTimeZero;
/*videoClipPaths is a array of paths of the video clips recorded*/
//for loop to combine clips into a single video
for (NSInteger i=0; i < [videoClipPaths count]; i++) {
NSString *path = (NSString*)[videoClipPaths objectAtIndex:i];
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
[url release];
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetTrack *audioTrack = [[asset …Run Code Online (Sandbox Code Playgroud) 我正在学习c ++ 11,我对移动语义和右值引用有疑问.我的示例代码如下(C++ Shell URL是cpp.sh/8gt):
#include <iostream>
#include <vector>
void aaa(std::vector<int>&& a)
{
std::cout << "size of a before move: " << a.size() << std::endl;
std::vector<int> v;
v = a; /*std::move(a)*/
std::cout << "size of a after move: " << a.size() << std::endl;
}
int main ()
{
std::vector<int> foo (3,0);
aaa(std::move(foo));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
结果是:
Run Code Online (Sandbox Code Playgroud)size of a before move: 3 size of a after move: 3
这似乎性病::向量的线,则不会调用的移动赋值运算符v = a的功能aaa,否则a将有大小为0,而不是3.
但是,如果我改变 …
假设我有以下代码,这是我的问题的简化示例:
#include <string>
#include <iostream>
#include <memory>
class A{
public:
std::string name() { return "class A"; }
};
class B{
public:
B(){
m_a = std::make_shared<A>();
}
std::shared_ptr<A> get_a() { return m_a; }
private:
std::shared_ptr<A> m_a;
};
std::shared_ptr<A> foo()
{
B b;
return b.get_a();
}
int main()
{
auto a = foo();
auto name = a->name();
std::cout << name;
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我想知道这样做是否安全?作为B实例的"b"将在函数foo结束时释放.主函数中的"a"是B :: m_a的shared_ptr."b"发布后使用"a"是否安全?
提前谢谢了!
c++ ×2
c++11 ×2
avfoundation ×1
ios ×1
iphone ×1
objective-c ×1
shared-ptr ×1
stdvector ×1
video ×1