 Foundation I think I'm gonna make the work for the country guys really really hard Because when I'm nervous I walk around all over the place So if you see me walking around to the restroom drinking some coffee going around to the restroom drinking more coffee That's the way I call myself Which I also call that That level to deep kind of thing situation and that ends either me My head exploding my bladder exploding or me giving a presentation So here I am So this is the company I work for we do mostly Web apps and iOS apps for other people. So when I heard Mark that he's open sourcing all his project. I was like, you know, right on let me do this I go ahead and tell all my clients, you know, I'm open sourcing everything I work And they are like you must be in San Francisco, man That's not gonna fly so what I did in my company was now I'm doing mostly cells So the apps I'm working on I mostly also open source So this is my Twitter account. Please just tweet me batch me No idea what I'm doing So let's talk about AV foundation, but first let's talk about money So, yeah, I wrote this small jam. It's just to make enough purchases That was my first jam in the room motion world Easy API, you know, you just pass it in your product ID You have three lambdas and you can see there that I put a lot of time designing the API So, yeah, that's a hello, you can do that. I also have another small jam called motion social And motion social basically allows you to tweet something really fast to your followers uses the Apple social Framework, so you can go to my github account and see that So let's talk about AV foundation, right? Really, I think that framework is really really awesome, but a lot of people are scared about it You know, it has a lot of moving parts, so I'm gonna explain you how to use that basically like on three steps You know how to display how to record and how to compose movies So first let's just jump back into my world Because when I'm not writing code, this is what I'm doing, right? I'm kite-surfing there in Mexico So after each kite board session, I have like 200 300 of these videos, right? And I basically gotta just like cut the interesting parts, which this is kind of one of them I'm gonna do a trick here Let's wait for it. Yeah So this is called a ham plan, so I do the trick there it is now I'm really happy you can see me You know victory and now I'm gonna try to stop the cam there, you know That didn't work Well, yeah, I do that a lot, you know, and I really like it and what I also like is I get to meet You know a lot of people, you know that are not like me, you know, like architects or lawyers or bankers A lot of people And what I really like about AB Foundation is like it gave me superpowers, you know Now after I do my kite trips I use AB foundations to create videos for my friends and instead of spending, you know, 20 minutes editing a video on Keynote about final code or after effects I can use This is what I think about a foundation Superpowers is really nice. And I also love this this guy. I think he's a guy He's called Dane Vengerho and he makes this and I just love his art So AB Foundation, right? It allows to capture to play back and to edit Video and audio. So it's all about video. It's all about audio, right? It's all and huge, you know, it's a lot of moving parts Ios 4 and OS X 10.7 so a few years already there and it's all and huge and In both work, it's almost identical, you know, in iOS or on OS X It's the same basically what it changes are the capturing devices or the constant, but it's the same concept so It's all about the screen the camera and the microphone and I'm here. I'm gonna show you my first app. I Feel like doing It's kind of like the hello world of Ruby motion or a sex up So this is the one that I did Here I'm recording this video. You can see this is something that we do regularly, you know, software developer. Oh, yeah It's going to be bad, you know, that's typical when you're working So yeah, this guy is recording the screen. You can see it here Okay, there it is my app. So you can see it's really simple. Abby has two buttons Basically, the start the stop and then you have automatically a blow set to the web, you know So that's kind of like my user interface. It has a top bottom a star bottom and he records the video So this is basically the ruby. I wanted to write, you know, this is what I wrote in my update And you can see here you can basically I just want to start a recording a stop a recording and then I want to have that file So this is more or less how it's gonna look in the code You can see on top the start the stop and then we're gonna talk about the whole AV foundation thing It's gonna be on these three methods, right first We're gonna set set up the video then we're gonna set up the audio And then we're gonna set up the recording So let's jump into that. But before we do let me just present you, you know, the first three AV foundation classes we're gonna be seeing so the AV capture session is kind of like a State object, you know, it's gonna hold our state Then the input This can be your screen. It can be your front facing camera your back facing camera and it can also be your microphone so you basically Initialize some inputs, then you pass those inputs to the session and we're off to erase it This is how it looks You can see there were creating a session AV capture session. Then we're having we're telling me We're initializing also a screen input basically a AV capture screen input That's gonna start recording basically or screen, you know what we see on the computer and then we say, you know a session Can we add this input? We can we basically just add so that's pretty much it for setting up the video We can also customize these two things are kind of nice, you know, we can say if we want to capture the clip so it displays You know in highlights where you're clicking and well the preset is just all about the quality and the size of the file So this is how we set up the audio for it. It's basically gonna like the same part of time, you know, we just Get our device and we add that device to the session So this session object is basically holding all the states and we add inputs to that session object In this class again, we just need to see how the set of recording Method so that method we just we're going to introduce another class of AV foundation, which is a big capture movie file output and It's just a class that we saw, you know, everything that is on the session dump it to this So this is how we look We kind of like initialize again that a big capture movie file output We set the delegate to sell there are a lot of delicate methods And then we add that output to the session and then the star method is just Telling that Movie file output that you need to start recording and to stop it. We just said stop recording on that AV capture file output. So Going back, you know, these are only the let's say three classes actually because on this device It can be many devices, right? So we have to this is basically kind of like the flow We're gonna see through all the framework, you know, we have a session object We have some devices that we're capturing data from and then we have an output, you know, that's so that's basically the whole idea behind AB foundation So this is how it looks, you know, this is the screen recording As I said, you know Really simple you just press start stop and then you'll get a URL out of it And I have that on the app store and it really amazes me that a lot of people from Asia you know and What I get from that is like we need to localize or I've been writing everything in English, but if I had localization, I guess more people will use So I think that's a big one So if you want to download that app You just go to this URL you can download it. It's free. It's I have all the code on github also, you know It's an open source app So this graph is I got it from Apple. This is just where AV foundation lies It's above the core audio, core video, core animation, core media But it's below the UI layer, you know, it's below UI kit that you can actually use I was actually using all of these from the common line, you know, just from my terminal I don't like that much GUI programming, you know So when not to use AV foundation if we just want to capture audio and video, you know, we can use What Apple provides or the wrappers bubble wrap, you know, we can take a picture everything from there But if you want to use if you want to compose videos if you want to detail over captured You know, if you want to inspect media properties, you can use AV foundation so let's see a An example of the class groups we can have, you know, the capture classes we already saw some of them like AV session AV capture file movie output for playback we have An AV player and that player allows to customize Everything we need, you know, so we can create a custom player using the AV player and let me just show you an example It's more artwork from them. I love it. Okay, so AV player. This is a Small diagram of how it works. So you will have your UI view You can use any of them, then you will initialize a player You will also initialize a AV player layer and then you will insert that layer into this UI view That's kind of throw off a lot of people, you know, because we're used to just meeting with you You know when we start on these frameworks, but here you're adding the AV player layer To the CA layer, not to the view. So let me show you how that looks, you know We'll have a UI view, you know, any view we can use Tico, we can use whatever we want for that So we initialize the AV player, we pass it a URL And that URL has to be a AV player asset, right? And then we initialize the player layer and we insert that layer into the sub-layer of the view and that's the simplest example I can come up with by just playing a video on using AV foundation So again, AV player with these The two new classes that we actually need to see the AV player, the AV player layer And we need to remember that the layer will be inserted into the sub-layer And I'm imagining this is because of optimization, right? Basically, plugging into a low-level part of it So let me also show you this, another video of me guiding because this is really what I needed AV foundation for You will see there, you know, it's a lot of different videos that I just teach together It's really simple editing. So instead of me learning how to do it in final cut, I Just wanted to have a tool that I can pass in a few videos. I'll do a small transition I put an audio layer there and teach all the videos together So this is pretty much what I wanted to do So this is what I got after a kiteboarding session. You can see like 300 videos So a lot of my work is actually cutting the videos into the interesting part because most videos are like three or four minutes and It is only like 20 second action, right? So I need to cut the videos and teach them together and And create one movie out of it So this is more or less the API that I wanted to have, you know And you can see this code and it's kind of simple, you know I just want to have Create an object that if you want to cut a video and that's pretty much it And well, you know, this code is kind of like somebody being a 12 year old, right? You have no problems your father's cook for you your mother You don't have any worries. So this is what I wanted to arrive at so before We we delve into that code. We gotta know about Chormilia time in time because every everything related to time on a B foundation. We got to use this kind of C strong Not an object actually so It's part of the core media So we need to but basically that's the end time what it does is this right? We have a value over a time scale. So the value here, you know, it's let's say 10 and 1 and it gives us this object So this is a really important to work with time So let me just show you how it looks, you know, exporting and cutting some videos, you know And it's kind of like the same Idea, right? We have a AB URL asset that asset can be locally can also be a stream. It can be on the net It can be anywhere Then we have a AB mutable composition and that composition. We have an export session Right, so the export session is the one that is gonna be holding all that state and the AB mutable composition It's an update that it's gonna Contain or order to cut the the moving into certain parts. So this is how we look on the code, you know Let's see the interesting part it's Yeah, we have a AB mutable composition Then we also have a duration and this is where the Cm time comes in and we also have a A result on the bottom right and that result we're basically saying, you know, you know this composition create a Coded in this time. That's what the Cm time range make those We give it a start time. So that's gonna be the start of the movie We tell it how long it's gonna be and then we pass in the asset. This is how it looks Right into a file. So we have the export session We initialize it with the composition asset and then we give it a URL, you know, to And then we also pass it We gotta say what type of files we want at the end of this, you know, it can be It can be many of them, but I guess, you know mp4 mp3 it can be, you know, any media file type So to recap, I just want to say that When I see this video, all of these videos that I showed some of them are Done through the tools I'm building, you know, and this is what I really like about AV foundation, you know, that it allowed me to not create an app for somebody else or Or make an iPhone app that somebody else wanted, you know, it allowed me to basically have superpowers with my friends because My friends are like, yeah, we're all kind borders, but you're the computer guy I had to step up basically, you know No, it's kind of funny, you know, because where they're traveling in Mexico and a police stop You know, they're doing the regular thing, you know, asking for your ID, asking where you work, and I'm explaining, you know I do iOS apps and all my clients have around the world and I do computers And the guy was so confused that a friend of mine is like, yeah, he just made computers, you know And the guy understood that, so yeah, that's what I do for my friends, you know, I make computers But yeah, besides from computers, I'm also Right now I'm kind of homeless because today I left my keys, my apartment keys inside the house Yeah, this was a house that a friend lent me, you know So now I don't have a house But the worst part is that when I was getting outside of the house, my wife asked me, do you have the keys? And I said, yes, yes, and then she closed the door and then, no, I don't have the keys So I have two problems now, you know, I gotta get the keys of my house and I gotta explain my wife Why I'm not paying attention when she talks So Any superpowers AV Foundation give me gonna go away So now we'll see really to recap, you know, if we want to record something on AV Foundation We gotta just know like three classes kind of thing, the AV capture session, the device, we add the device to the session And then we have an output and that's pretty much it For displaying or playback an asset What it what it really is is just initializing the AV player Also the AV player layer, which is kind of like a CA layer type of thing. And then we just insert that sublayer there And to compose or edit movies, we just need to know basically three classes, right? The AV URL asset, the AV mutable composition and the export session So AV URL assets are any kind of asset, you know, any videos, any Movies, MP3, anything you want. And what is really cool about the AV asset is They can also be a stream of data, so they cannot They don't need to be finite Basically, you know, it can be just a stream of data. That's kind of cool. And the mutable composition, we tell it, you know Mutable composition, get this asset I want it from second one to second fifteen and that's pretty much it. And then to export that, we'll just say, you know AV asset export session. This is my AV mutable composition and here we go So that's all I have for you guys. Thank you very much