小编Son*_*ong的帖子

如何使用AVFoundation组合具有不同方向的视频剪辑

我正在尝试使用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)

iphone video objective-c avfoundation ios

29
推荐指数
1
解决办法
2万
查看次数

为什么需要std :: move来调用std :: vector的move assign运算符

我正在学习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)

结果是:

size of a before move: 3  
size of a after move: 3
Run Code Online (Sandbox Code Playgroud)

这似乎性病::向量的线,则不会调用的移动赋值运算符v = a的功能aaa,否则a将有大小为0,而不是3.
但是,如果我改变 …

c++ stdvector rvalue-reference move-semantics c++11

6
推荐指数
2
解决办法
1665
查看次数

返回一个shared_ptr的成员变量是否安全

假设我有以下代码,这是我的问题的简化示例:

#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++ shared-ptr c++11

2
推荐指数
1
解决办法
638
查看次数