我有一个相机应用程序,锁定到景观.需要时,我会旋转从中获取的原始字节,onPreviewFrame()并使用它们对视频进行编码.
然而,这种方法在Nexus 5X和6设备中失败了,因为它们的反向传感器让我倒置了帧.
随着旋转的预览会不会帮助我在这种情况下,描述在这里:
这不影响在onPreviewFrame(byte [],Camera)中传递的字节数组的顺序
我想知道是否有任何方法可以检测相机传感器是否反转和/或原始帧是否颠倒,因此在旋转时会增加额外的校正.
我正在使用JavaCV FFmpegFrameRecorder类将Android的相机预览帧编码为视频.
目标是复制以下命令行的结果:
ffmpeg -i input.mp4 -metadata:s:v:0 rotate="90" output.mp4
Run Code Online (Sandbox Code Playgroud)
我修改了startUnsafe()如下方法,但无法生成所需的输出:
if ((video_st = avformat_new_stream(oc, video_codec)) != null) {
video_c = video_st.codec();
video_c.codec_id(oformat.video_codec());
video_c.codec_type(AVMEDIA_TYPE_VIDEO);
...
AVDictionary avDictionary = new AVDictionary(null);
av_dict_set(avDictionary, "rotate", "90", 0);
video_st.metadata(avDictionaty);
...
}
...
avformat_write_header(oc, (PointerPointer) null);
Run Code Online (Sandbox Code Playgroud)
这仍然可以正确编码视频,但添加的元数据永远不会出现在ffprobe上.如果有帮助,视频编码为h264.
顺便说一句,这是ffprobe输出:
ffprobe version 2.3.3 Copyright (c) 2007-2014 the FFmpeg developers
built on Jan 22 2015 18:22:57 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用gradle包含了一个项目:
compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
Run Code Online (Sandbox Code Playgroud)
哪个建好了.但每当我在启用proguard的情况下运行应用程序时,它显然会@Platform从包含的jar中删除注释.
我尝试使用基于http://proguard.sourceforge.net/manual/examples.html#annotations的以下内容
-keepattributes *Annotation*
-keep @org.bytedeco.javacpp.annotation interface * {
*;
}
Run Code Online (Sandbox Code Playgroud)
我还根据http://proguard.sourceforge.net/manual/troubleshooting.html#notkept尝试了以下内容
-keep @interface *
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.还有什么可以阻止proguard删除这些注释?我正在考虑使用-injars或者-libraryjars我相信gradle为你处理.
所以解决方案如下:
我在我的proguard规则中包含以下内容:
# JavaCV
-keep @org.bytedeco.javacpp.annotation interface * {
*;
}
-keep @org.bytedeco.javacpp.annotation.Platform public class *
-keepclasseswithmembernames class * {
@org.bytedeco.* <fields>;
}
-keepclasseswithmembernames class * {
@org.bytedeco.* <methods>;
}
-keepattributes EnclosingMethod
-keep @interface org.bytedeco.javacpp.annotation.*,javax.inject.*
-keepattributes *Annotation*, Exceptions, Signature, Deprecated, SourceFile, SourceDir, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, …Run Code Online (Sandbox Code Playgroud) 我在最近的Marshmallow构造中有关于相机的问题,更具体地说是手电筒.在任何预先Marshmallow版本上,我需要做的就是打开/关闭闪光灯,如下所示:
private void turnFlashOn(final Camera camera, int flashLightDurationMs) {
if (!isFlashOn()) {
final List<String> supportedFlashModes = camera.getParameters().getSupportedFlashModes();
if (supportedFlashModes != null && supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
mParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(mParams);
}
}
}
Run Code Online (Sandbox Code Playgroud)
和
private void turnFlashOff(Camera camera) {
if (camera != null) {
final List<String> supportedFlashModes = camera.getParameters().getSupportedFlashModes();
if (supportedFlashModes != null && supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_OFF)) {
mParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(mParams);
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,Marshmallow设备开始在野外崩溃.不知何故,camera.getParameters()并camera.setParameters()开始失败的消息,如:
RuntimeException:getParameters失败(空参数)
RuntimeException:setParameters失败
我尝试在获取参数之前启动并停止预览,这不再引发错误.但是,当我打电话时,预览不会恢复camera.startPreview().
我担心释放相机并重新打开它是不可能的,因为这需要几秒钟而且会产生糟糕的体验.
有关如何可靠地打开/关闭Marshmallow手电筒的任何建议吗?
camera android android-camera flashlight android-6.0-marshmallow
我在Android中使用Volley来执行我的应用程序请求.不幸的是,我收到以下错误:
com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x61e15f78: Failure in SSL library, usually a protocol error
error:1407743E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert inappropriate fallback (external/openssl/ssl/s23_clnt.c:744 0x5b647c58:0x00000000)
Run Code Online (Sandbox Code Playgroud)
我在Fragments内部使用两个,ViewPager在onResume期间请求他们的内容.请求url基本相同,但是对于查询参数(设置内容的类型,例如趋势与热).
网址是形式https://host/api/content?type={hot/trending}.授权通过请求标头完成.
关于此异常的奇怪部分是两个请求中只有一个失败,并且它不时变化.在我们之间添加延迟后,异常停止发生(奇怪地指向一些竞争条件?).但这似乎是一个糟糕的解决方法,我想以正确的方式解决这个问题.
关于它可能是什么原因的任何想法?
编辑:
请求以标准方式创建,使用提供队列的单例,如下所示:
final RequestQueue requestQueue = RequestQueueSingleton.getInstance(getActivity()).getRequestQueue();
final GsonRequestGet<SearchApiWrapper> gsonRequest = new GsonRequestGet<>(clazz, url,successListener, errorListener);
gsonRequest.setRetryPolicy(new DefaultRetryPolicy(3000, 3, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
gsonRequest.setTag(mTag);
requestQueue.add(gsonRequest);
Run Code Online (Sandbox Code Playgroud)
这是单身人士课程:
public class RequestQueueSingleton {
private static RequestQueueSingleton mInstance;
private RequestQueue mRequestQueue;
private Context mContext;
public RequestQueueSingleton(Context context) {
mContext = context;
mRequestQueue = getRequestQueue();
} …Run Code Online (Sandbox Code Playgroud) 我有一个简洁的功能,可以在视图上执行某些操作:
fun<T : View> Activity.withView(nr : Int, fn : T.()->Unit) {
(findViewById(nr) as T?)?.fn()
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在我的活动中使用此功能时:
withView<Spinner>(R.id.spinner_toolbar) {
adapter = AdapterIndeksuDlaSpinnera(this@NewMainActivity, PlaylistIndex)
Run Code Online (Sandbox Code Playgroud)
......在使用ProGuard之前一切正常.我可以看到AdapterIndeksuDlaSpinnera被破坏,正如预期的那样,但是当使用"无法加载类AdapterIndeksuDlaSpinnera"进行编程时应用程序失败(同时它应该抱怨错误的适配器名称).
我能够通过禁用可以在我的内部使用的所有适配器的修改来创建临时的解决方法 withView
-keep class pl.qus.xenoamp.adapter.** { *; }
Run Code Online (Sandbox Code Playgroud)
但我觉得这不是一个好的解决方案(我不知道其他类可以通过这种方式失败!).所以任何人都可以解释什么是问题,我应该添加什么ProGuard行来潜在地修复内部使用的其他类的类似事件withView?