谢谢你的关注!我想使用Android MediaCodec API对从Camera获取的视频帧进行编码,遗憾的是,我没有成功做到这一点!我仍然不熟悉MediaCodec API.以下是我的代码,我需要你的帮助来弄清楚我应该做什么.
1,相机设置:
Parameters parameters = mCamera.getParameters();
parameters.setPreviewFormat(ImageFormat.NV21);
parameters.setPreviewSize(320, 240);
mCamera.setParameters(parameters);
Run Code Online (Sandbox Code Playgroud)
2,设置编码器:
private void initCodec() {
try {
fos = new FileOutputStream(mVideoFile, false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mMediaCodec = MediaCodec.createEncoderByType("video/avc");
MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/avc",
320,
240);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 125000);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
mMediaCodec.configure(mediaFormat,
null,
null,
MediaCodec.CONFIGURE_FLAG_ENCODE);
mMediaCodec.start();
inputBuffers = mMediaCodec.getInputBuffers();
outputBuffers = mMediaCodec.getOutputBuffers();
}
private void encode(byte[] data) {
int inputBufferIndex = mMediaCodec.dequeueInputBuffer(0);
if (inputBufferIndex >= 0) {
ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
inputBuffer.clear(); …Run Code Online (Sandbox Code Playgroud) 
(这是Dialog在互联网上显示找到的随机图像.)
我一直在实施自定义Dialog.我可以处理对话框上的几乎所有内容,除了对话框本身下的默认黑色暗淡背景,但是在它后面的整个屏幕上.基本上我想改变它的颜色和alpha值.
我一直在浏览StackOverflow,但我发现只有改变Dialog自身背景的答案.无论如何,如果你需要它,这是我的简单代码.
public class HTDialog extends Dialog{
public HTDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setCanceledOnTouchOutside(true);
setContentView(R.layout.custom_dialog);
}
}
Run Code Online (Sandbox Code Playgroud)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="280dp"
android:background="@drawable/bg_popup"
android:paddingTop="20dp">
<ImageView
android:id="@+id/dialog_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/icon" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我在相机应用程序上拍摄基本照片.当我获得最佳的最佳预览尺寸时,我遇到了问题.
事实上,有了这个第一个代码:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (isPreviewRunning) {
mCamera.stopPreview();
}
Camera.Parameters parameters = mCamera.getParameters();
mCamera.setParameters(parameters);
mCamera.startPreview();
isPreviewRunning = true;
}
Run Code Online (Sandbox Code Playgroud)
图片质量很好:
http://img689.imageshack.us/i/04042011172937.jpg/
但是,使用此代码:
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (sizes == null) return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Try to find an size match aspect ratio and …Run Code Online (Sandbox Code Playgroud) 我有一个应该显示一些数据的Meteor模板.
Template.svg_template.rendered = function () {
dataset_collection = Pushups.find({},{fields: { date:1, data:1 }}, {sort: {date: -1}}).fetch();
a = moment(dataset_collection[0].date, "YYYY/M/D");
//more code follows that is also dependent on the collection being completely loaded
};
Run Code Online (Sandbox Code Playgroud)
有时它有效,有时我得到这个错误:
来自Deps afterFlush函数的异常:TypeError:无法读取undefined的属性'date'
我在任何情况下都不使用Deps.据我了解,该集合在完成加载之前就被引用了.
因此,我想弄清楚如何简单地说"等到收集之后才能找到收集品".应该是直截了当的,但找不到更新的解决方案.
我目前正在开发一个Wordpress项目,我应该在其中获得一些自定义的帖子元数据,将其转换为DateTime实例,然后使用它进行数学运算.
当我echoget_post_meta时,它看起来如下.
2016.04.30 PM 7:30
我用来获取DateTime实例的格式如下.
Ymd A g:我
但是返回值DateTime::createFromFormat是false.
// 2016.04.30 PM 7:30
$start_at = DateTime::createFromFormat( 'Y.m.d A g:i', get_post_meta(get_the_ID(), 'as_date', true));
if ($start_at === false) {
echo 'False format: ' . get_post_meta(get_the_ID(), 'as_date', true);
} else {
echo $start_at->getTimestamp();
}
Run Code Online (Sandbox Code Playgroud)
结果是False format: 2016.04.30 PM 7:30.
我在这里错过了什么?我认为这一定是微不足道的,但我无法通过.
我正在开发一个相机应用程序,你需要提取每帧预览的一些数据,所以我试图用onPreviewFrame来做,问题是我的代码onPreviewFrame只调用一次而调试时我没有得到错误所以我不知道该怎么办
这是我的代码
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "CameraPreview";
private SurfaceHolder mHolder;
private Camera mCamera;
public byte[] buffer;//for previewcallback
public CameraPreview(Context context, Camera camera) {
super(context);
Log.d("Function", "CameraPreview constructor iniciado");
mCamera = camera;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) { …Run Code Online (Sandbox Code Playgroud) 对于我们的应用程序,我们需要使用 hibernate 实现触发器。我们可以找到的一个最佳解决方案是使用 Annotation 的 Entity listerner,因为我们需要监听特定的实体更改。
除了带有命名查询的删除之外,一切都运行良好,它不提供任何事件。
代码实现 **实体**——这里我们添加了监听器
@Entity
@EventListeners(EmployeeEventListener.class)
public class Employee {
@Id
private String uid;
@Basic
private Calendar lastUpdated;
Run Code Online (Sandbox Code Playgroud)
实体监听器-
侦听器在执行预期操作时占用修改后的实体
public class EmployeeEventListener {
@PrePersist
public void prePersist(Object object) {
Employee employee = (Employee)object;
employee.setUID(UIDGenerator.newUUI());
employee.setLastUpdated(Calendar.getInstance());
}
@PostUpdate
public void postUpdate(Object object) {
Employee employee = (Employee)object;
employee.setLastUpdated(Calendar.getInstance());
}
Run Code Online (Sandbox Code Playgroud)
@PrePersist并且@PostUpdate运作良好,当我用节省或者saveOrUpdate在实体管理器。但是在执行删除命名查询时,我没有收到@PreRemove和@PostRemove
我也想得到一个删除事件。
我正在使用 将活动类分配给导航菜单current_page,但我认为我不明白是如何current_page工作的。
示例代码如下。
class HomeController < ApplicationController
def index
end
def menu
end
end
Run Code Online (Sandbox Code Playgroud)
<%= current_page?(controller: 'home', action: 'menu').to_s %>
<li><%= link_to(t('menu.title'), {controller: 'home', action: 'menu'}, class: current_page?(controller: 'home', action: 'menu')? 'active': '') %></li>
Run Code Online (Sandbox Code Playgroud)
当 in 时localhost:3000/menu,application.html.erb打印 false。
当 in 时localhost:3000/menu?locale=en,application.html.erb打印 true。
在 in 时localhost:3000/menu?locale=ko,application.html.erb也打印 true。
无论locale选项如何,我都希望它是“活跃的” 。根据APIDock,我所做的应该产生正确的结果,但它不像文档所说的那样工作。
# Let’s say we’re in the http://www.example.com/shop/checkout?order=desc action.
current_page?(action: 'process') …Run Code Online (Sandbox Code Playgroud) 正如Android文档所说:
对于除YV12之外的格式,缓冲区的大小通过将预览图像宽度,高度和每像素字节相乘来确定.可以从getPreviewSize()读取宽度和高度.可以getBitsPerPixel(int) / 8使用getPreviewFormat()的图像格式计算每像素的字节数.
但大多数在线代码使用bitsperpixel创建缓冲区而不是byteperpixel=bitsperpixel/8.
如果我使用下面的代码使用图像的确切大小(以字节为单位),将导致错误:E/Camera-JNI(3656):回调缓冲区太小了!预计1336320字节,但得到890880字节!这是为什么?为什么缓冲区需要8倍于图像大小?
Camera.Parameters parameters=mCamera.getParameters();
parameters.setPreviewSize(width,height);
mCamera.setParameters(parameters);
int previewFormat=parameters.getPreviewFormat();
int bitsperpixel=ImageFormat.getBitsPerPixel(previewFormat);
int byteperpixel=bitsperpixel/8;
Camera.Size camerasize=parameters.getPreviewSize();
int frame_bytesize=((camerasize.width*camerasize.height)*byteperpixel);
//create buffer
byte[]frameBuffer=new byte[frame_bytesize];
//buffer registry
mCamera.addCallbackBuffer(frameBuffer);
Run Code Online (Sandbox Code Playgroud)