Permalink
Browse files

Add show-ppms (Mac)

  • Loading branch information...
1 parent c3319b6 commit 6ee3013671a97db38524710d075e476797b78b58 @andrewschaaf andrewschaaf committed Feb 1, 2014
View
@@ -1 +1,2 @@
build
+xcuserdata
View
@@ -8,10 +8,23 @@
`PPM-list` → `hash64(RGB frame pixels)-list`, e.g. for "trust-but-verify" frame accuracy for extracting clips.
cat foo.mp4 | \
- ffmpeg -loglevel warning -i - -f image2pipe -c ppm - \
+ ffmpeg -loglevel warning -i - -f image2pipe -c ppm - | \
hash-frames > foo.mp4.hashes
The current hash function is [cityhash](https://en.wikipedia.org/wiki/CityHash) (64-bit).
+### show-ppms (Mac)
+
+ cd mac-show-ppms && \
+ xcodebuild && \
+ cat foo.mp4 | \
+ ffmpeg -loglevel warning -i - -f image2pipe -c ppm - | \
+ ./build/Release/show-ppms.app/Contents/MacOS/show-ppms
+
+The current implementation plays frames as quickly as it can, which is approximately the right speed for my use case.
+
+TODO: improve performance, take `--fps=` argument.
+
+
### License: TBD

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,5 @@
+#import <Cocoa/Cocoa.h>
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+
+@end
@@ -0,0 +1,66 @@
+#import "AppDelegate.h"
+#import "PixelsView.h"
+#import <RSImg.h>
+#import <RSUtil.h>
+
+@interface AppDelegate () {
+ FILE *_file;
+ uint8_t *_frameData;
+ uint32_t _frameDataSize;
+ uint32_t _width;
+ uint32_t _height;
+ uint32_t _headerSize;
+}
+@property (strong) NSWindow *window;
+@property (strong) PixelsView *pixelsView;
+@end
+
+@implementation AppDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+ _file = stdin;
+ [self readFirstFrame];
+ [self createUI];
+ [NSTimer scheduledTimerWithTimeInterval:0
+ target:self
+ selector:@selector(next)
+ userInfo:nil
+ repeats:YES];
+}
+
+- (void)next {
+ if (fread(_frameData, _frameDataSize, 1, _file) != 1) {
+ exit(0);
+ }
+ self.pixelsView.needsDisplay = YES;
+}
+
+- (void)readFirstFrame {
+ if (!RSImgFreadPPMP6Header(_file, &_width, &_height, &_headerSize)) {
+ RSFatalError("couldn't read first frame");
+ }
+ uint32_t rgbPixelsSize = _width * _height * 3;
+ _frameDataSize = _headerSize + rgbPixelsSize;
+ _frameData = RSMallocOrDie(_frameDataSize);
+ uint8_t *rgbPixels = &(_frameData[_headerSize]);
+ RSFReadOrDie(rgbPixels, rgbPixelsSize, _file);
+}
+
+- (void)createUI {
+ NSScreen *screen = [NSScreen mainScreen];
+ self.window = [[NSWindow alloc] initWithContentRect:CGRectMake(0, screen.frame.size.height, _width, _height)
+ styleMask:NSTitledWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO
+ screen:screen];
+ NSView *contentView = self.window.contentView;
+ self.pixelsView = [[PixelsView alloc] initWithFrame:contentView.bounds
+ width:_width
+ height:_height
+ headerSize:_headerSize
+ frameData:_frameData];
+ [contentView addSubview:self.pixelsView];
+ [self.window makeKeyAndOrderFront:nil];
+}
+
+@end

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,58 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
@@ -0,0 +1,11 @@
+#import <Cocoa/Cocoa.h>
+
+@interface PixelsView : NSView
+
+- (id)initWithFrame:(NSRect)frame
+ width:(uint32_t)width
+ height:(uint32_t)height
+ headerSize:(uint32_t)headerSize
+ frameData:(uint8_t *)frameData;
+
+@end
@@ -0,0 +1,55 @@
+#import "PixelsView.h"
+#import <RSUtil.h>
+
+@interface PixelsView() {
+ CGColorSpaceRef _colorSpace;
+ CGDataProviderRef _provider;
+ uint32_t _width;
+ uint32_t _height;
+ uint32_t _headerSize;
+ uint8_t *_frameData;
+}
+@end
+
+@implementation PixelsView
+
+- (id)initWithFrame:(NSRect)frame
+ width:(uint32_t)width
+ height:(uint32_t)height
+ headerSize:(uint32_t)headerSize
+ frameData:(uint8_t *)frameData
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ _colorSpace = CGColorSpaceCreateDeviceRGB();
+ _width = width;
+ _height = height;
+ _headerSize = headerSize;
+ _frameData = frameData;
+ }
+ return self;
+}
+
+- (void)drawRect:(NSRect)dirtyRect {
+ if (!_provider) {
+ uint8_t *pixels = &(_frameData[_headerSize]);
+ _provider = CGDataProviderCreateWithData(nil, pixels, _width * _height, nil);
+ }
+ CGContextRef c = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+ size_t bitsPerComponent = 8;
+ size_t bitsPerPixel = 24;
+ size_t bytesPerRow = _width * 3;
+ CGImageRef image = CGImageCreate(
+ _width, _height,
+ bitsPerComponent, bitsPerPixel, bytesPerRow,
+ _colorSpace,
+ kCGBitmapByteOrderDefault,
+ _provider,
+ nil,
+ NO,
+ kCGRenderingIntentDefault);
+ CGContextDrawImage(c, self.bounds, image);
+ CGImageRelease(image);
+}
+
+@end
@@ -0,0 +1,5 @@
+{\rtf1\ansi\ansicpg1252\cocoartf1265
+{\fonttbl}
+{\colortbl;\red255\green255\blue255;}
+\vieww9600\viewh8400\viewkind0
+}
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
@@ -0,0 +1,5 @@
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, const char * argv[]) {
+ return NSApplicationMain(argc, argv);
+}
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.example.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
@@ -0,0 +1,9 @@
+//
+// Prefix header
+//
+// The contents of this file are implicitly included at the beginning of every source file.
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.example.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
@@ -0,0 +1,21 @@
+#import <XCTest/XCTest.h>
+
+@interface show_ppmsTests : XCTestCase
+
+@end
+
+@implementation show_ppmsTests
+
+- (void)setUp {
+ [super setUp];
+}
+
+- (void)tearDown {
+ [super tearDown];
+}
+
+- (void)testExample {
+ XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
+}
+
+@end
Submodule RSImg updated 2 files
+3 −3 RSImg.c
+9 −0 include-cpp/RSImg.h
Submodule RSUtil updated 4 files
+5 −0 README.md
+32 −0 RSUtil.c
+5 −0 RSUtil.h
+22 −0 include-cpp/RSUtil.h

0 comments on commit 6ee3013

Please sign in to comment.