Create a Foundation Command Line Tool in Xcode
Contents
Create a Foundation Command Line Tool in Xcode#
This topic describes the steps needed to configure an Objective-C++ console application in Xcode.
Create the Xcode project#
Create a new Command Line Tool project in Xcode. Name the project ‘SimpleConverter’, select ‘Foundation’ for type.
Rename
main.m
tomain.mm
.Select the ‘SimpleConverter’ project in Xcode, and then the ‘Build Settings’ tab:
Set the C++ Language Dialect to
C++11[-std=c++11]
Set the Build Products Path to
$(PROJECT_DIR)
Download the 64 bit version of AVBlocks for C++ (Mac). The file you need will have a name similar to
AVBlocks.1.14.0.Demo.dmg
except for the version number which may be different.Mount the dmg, copy the tgz archive and extract it in a location of your choice, then copy the
include
andlib
directories to the Xcode project directory.Add ‘AVBlocks.h’, ‘PrimoReference++.h’, and ‘PrimoUString.h’ to ‘SimpleConverter-Prefix.pch’:
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif
// the main AVBlocks header
#include "../include/AVBlocks.h"
// needed for C++11 features
#include "../include/PrimoReference++.h"
// needed for string conversion
#include "../include/PrimoUString.h"
In Xcode, select the ‘SimpleConverter’ target, and then the ‘Build Phases’ tab:
Expand the ‘Link Binary with Libraries’ section
Add the
libAVBlocks.dylib
from thelib
directory.
Restart Xcode!!! Otherwise it will not pick the new Build Products Path
Build the project ( ⌘B )
Copy the file
libAVBlocks.dylib
fromlib
toDebug
.Replace the contents of ‘main.mm’ with this code:
//
// main.mm
// SimpleConverter
//
// Copyright (c) 2014 Primo Software. All rights reserved.
//
using namespace primo;
using namespace primo::codecs;
using namespace primo::avblocks;
int main(int argc, const char * argv[])
{
@autoreleasepool {
Library::initialize();
auto inputFile = primo::ustring(L"AAP.m4v");
auto outputFile = primo::ustring(L"AAP.mp4");
auto inputInfo = primo::make_ref(Library::createMediaInfo());
inputInfo->setInputFile(inputFile.u16());
if (inputInfo->load()) {
auto inputSocket = primo::make_ref(Library::createMediaSocket(inputInfo.get()));
auto outputSocket = primo::make_ref(Library::createMediaSocket(Preset::iPad_H264_720p));
outputSocket->setFile(outputFile.u16());
auto transcoder = primo::make_ref(Library::createTranscoder());
transcoder->inputs()->add(inputSocket.get());
transcoder->outputs()->add(outputSocket.get());
if (transcoder->open()) {
transcoder->run();
transcoder->close();
}
}
Library::shutdown();
}
return 0;
}
Run the application#
Download the
AAP.m4v
HD movie from the Internet Archive and save it in theDebug
directory.Run the application in Xcode. Wait for the Transcoder to finish - it will take a few minutes. The converted file
AAP.mp4
will be in theDebug
directory.
Troubleshooting#
You may get “dyld: Library not loaded: @executable_path/libAVBlocks.dylib” or a similar message. To fix that, copy the file
libAVBlocks.dylib
fromlib
toDebug
.transcoder->open() may fail if there is already a file
AAP.mp4
in theDebug
directory. DeleteAAP.mp4
to solve that.