This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stream facetime camera (0) | |
ffmpeg -f avfoundation -framerate 30 -i "0" -video_size 1024x720 -vcodec libx264 -preset ultrafast -f flv "rtmp://127.0.0.1/live" | |
# framerate needs to be set before the "-i" (input) | |
# list available devices: | |
ffmpeg -f avfoundation -list_devices true -i "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// ObjC | |
@implementation NSUserDefaults(Tracking) | |
+ (void)load { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
Class class = [self class]; | |
SEL originalSelector = @selector(setObject:forKey:); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Accelerate | |
import AVFoundation | |
func reverse(fromUrl: URL) -> URL? { | |
do { | |
let input = try AVAudioFile(forReading: fromUrl) | |
let format = input.processingFormat | |
let frameCount = AVAudioFrameCount(input.length) | |
let outSettings = [AVNumberOfChannelsKey: format.channelCount, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import VideoToolbox | |
class H264Coder { | |
var session: VTCompressionSession? | |
var onFrame: ((CMSampleBuffer) -> Void)? | |
let outputCallback: VTCompressionOutputCallback = { refcon, sourceFrameRefCon, status, infoFlags, sampleBuffer in | |
guard let refcon = refcon, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import UIKit | |
class AVSampleBufferView: UIView { | |
var bufferLayer: AVSampleBufferDisplayLayer { | |
return layer as! AVSampleBufferDisplayLayer | |
} | |
override static var layerClass: AnyClass { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init(width: Int32, height: Int32) { | |
let status = VTCompressionSessionCreate(allocator: kCFAllocatorDefault, | |
width: width, | |
height: height, | |
codecType: kCMVideoCodecType_H264, | |
encoderSpecification: nil, | |
imageBufferAttributes: nil, | |
compressedDataAllocator: nil, | |
outputCallback: outputCallback, | |
refcon: Unmanaged.passUnretained(self).toOpaque(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import VideoToolbox | |
class H264Coder { | |
var session: VTCompressionSession? | |
let outputCallback: VTCompressionOutputCallback = { refcon, sourceFrameRefCon, status, infoFlags, sampleBuffer in | |
guard let refcon = refcon, | |
status == noErr, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import UIKit | |
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { | |
private let avManager = AVManager() | |
private let cameraView = AVSampleBufferView() | |
private let encodedView = AVSampleBufferView() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import UIKit | |
class ViewController: UIViewController { | |
private let cameraView = AVSampleBufferView() | |
private let encodedView = AVSampleBufferView() | |
private let decodedView = AVSampleBufferView() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import UIKit | |
class AVSampleBufferView: UIView { | |
var bufferLayer: AVSampleBufferDisplayLayer { | |
return layer as! AVSampleBufferDisplayLayer | |
} | |
override static var layerClass: AnyClass { |
NewerOlder