输出自定义尺寸视频

最近要做的一个项目中要拍摄视频,于是就开始来研究视频。看了几遍 AVFoundation Programming Guide 之后也写了个 Demo,把基本功能都过了一遍。这其中有意思的一件事情是我发现微信拍摄短视频的尺寸是 540x944, 这尺寸很奇怪,不是任何一个预设值。不清楚微信为什么用这么一个尺寸,但我想搞清楚怎么输出自定义尺寸的视频。

AVFoundation 捕获数据输出时,各组件的关系如下:

要想输出自定义尺寸的视频,我们可以从输入端和输出端着手。但是从文档来看,并没有提供可以自定捕获尺寸的方法,所以只能从输出端着手。

继续阅读

AVFoundation 使用笔记

使用一个框架时,我们可能有这么三个问题:

  1. 这个框架是做什么的?
  2. 为什么要使用这个框架而不是其他的框架?
  3. 怎么用这个框架?

这个框架是做什么的?

Apple 在 iOS Technology Overview 中的 Audio Technologies 和 Video Technologies 分别是这么介绍 AVFoundation 的:

AV Foundation is an Objective-C interface for managing the recording and playback of audio and video. Use this framework for recording audio and when you need fine-grained control over the audio playback process.

AV Foundation provides advanced video playback and recording capabilities. Use this framework in situations where you need more control over the presentation or recording of video. For example, augmented reality apps could use this framework to layer live video content with other app-provided content.

从这两个介绍中我们可以知道 AVFoundation 是用来播放和录制音频和视频的。

在 AVFoundation Programming Guide 中则是这么介绍的:

AVFoundation is one of several frameworks that you can use to play and create time-based audiovisual media. It provides an Objective-C interface you use to work on a detailed level with time-based audiovisual data. For example, you can use it to examine, create, edit, or reencode media files. You can also get input streams from devices and manipulate video during realtime capture and playback.

从这里我们可以知道它不仅可以播放和创建基于时间的视听媒体,还可以让我们在很细微的层面去操作这些视听数据。例如,你可以使用它检查、创建、编辑或者重编码媒体文件。你还可以用它从设备那里拿到输出流,并且可以在实时的捕获和播放过程中操作视频。

所以结论就是:这个框架是处理音频和视频的,而且处理的粒度可以非常细。

继续阅读

Android开发问题汇总(三)

1. How to define custom attributes?

A:Currently the best documentation is the source. You can take a look at it here(arrts.xml).

You can define attributes in the top <resources> element or inside of a <declare-styleable> element. If I’m going to use an attr in more than on place I put it in the root element. Note , all attributes share the same global namespace. That means that even if you create a new attribute inside of a <declare-styleable> element it can be used outside of it and you cannot create another attribute with the same name of a different type.

An <attr> element has two xml attributes name and format. name lets you call it something and this how you end up refering to it in code, e.g., R.attr.my_attribute. The format attribute can have different values depending on the type of attribute you want.

  • reference - if it references another resource id(e.g, “@color/my_color”, “@layout/my_layout”)
  • color
  • boolean
  • dimension
  • float
  • integer
  • string
  • fraction
  • enum - normally implicitly defined
  • flag - normally implicitly defined

You can set the format to multiple types by using |, e.g., format="reference|color".

enum attributes can be defined as follows:

1
2
3
4
<attr name="my_enum_attr"> 
    <enmu name="value1" value="1" />
    <enmu name="value2" value="2" />
</attr>

flag attributes are similar except the values need to defined so they can be bit ored together:

1
2
3
4
<attr name="my_flag_attr">
    <flag name="fuzzy" value="0x01" />
    <flag name="cold" value="0x02" />
</attr>
继续阅读