- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用 grafika 的 MoviePlayer和 bigFlake 的 ExtractMpegFramesTest在我们的应用程序中实现搜索和提取帧功能。这些对我们的大多数用户来说工作正常,但是他们中的一些人在设置 ExtractMpegFramesTest
时在 MediaCodec.configure
上遇到 IllegalStateException
(这发生在三星 Galaxy S4 mini、三星 Galaxy J7、三星 Galaxy A5、华为 Ascend G7)。相关代码如下:
电影播放器
public void prepareResources() throws IOException {
// The MediaExtractor error messages aren't very useful. Check to see if the input
// file exists so we can throw a better one if it's not there.
if (!mSourceFile.canRead()) {
throw new FileNotFoundException("Unable to read " + mSourceFile);
}
try {
mExtractor = new MediaExtractor();
mExtractor.setDataSource(mSourceFile.toString());
mTrackIndex = selectTrack(mExtractor);
if (mTrackIndex < 0) {
throw new RuntimeException("No video track found in " + mSourceFile);
}
mExtractor.selectTrack(mTrackIndex);
MediaFormat format = mExtractor.getTrackFormat(mTrackIndex);
// Create a MediaCodec decoder, and configure it with the MediaFormat from the
// extractor. It's very important to use the format from the extractor because
// it contains a copy of the CSD-0/CSD-1 codec-specific data chunks.
String mime = format.getString(MediaFormat.KEY_MIME);
mDecoder = MediaCodec.createDecoderByType(mime);
mDecoder.configure(format, mOutputSurface, null, 0);
mDecoder.start();
mDecoderInputBuffers = mDecoder.getInputBuffers();
} catch (Exception e) {
e.printStackTrace();
}
}
ExtractMpegFramesTest
private void extractMpegFrames() throws IOException {
MediaCodec decoder = null;
CodecOutputSurface outputSurface = null;
MediaExtractor extractor = null;
/*int saveWidth = 640;
int saveHeight = 480;*/
try {
long start1 = System.currentTimeMillis();
File inputFile = new File(mInputVideoPath); // must be an absolute path
// The MediaExtractor error messages aren't very useful. Check to see if the input
// file exists so we can throw a better one if it's not there.
if (!inputFile.canRead()) {
throw new FileNotFoundException("Unable to read " + inputFile);
}
extractor = new MediaExtractor();
extractor.setDataSource(inputFile.toString());
int trackIndex = selectTrack(extractor);
if (trackIndex < 0) {
throw new RuntimeException("No video track found in " + inputFile);
}
extractor.selectTrack(trackIndex);
MediaFormat format = extractor.getTrackFormat(trackIndex);
if (VERBOSE) {
Log.d(TAG, "Video size is " + format.getInteger(MediaFormat.KEY_WIDTH) + "x" +
format.getInteger(MediaFormat.KEY_HEIGHT));
}
// Could use width/height from the MediaFormat to get full-size frames.
outputSurface = new CodecOutputSurface(format.getInteger(MediaFormat.KEY_WIDTH), format.getInteger(MediaFormat.KEY_HEIGHT));
// Create a MediaCodec decoder, and configure it with the MediaFormat from the
// extractor. It's very important to use the format from the extractor because
// it contains a copy of the CSD-0/CSD-1 codec-specific data chunks.
String mime = format.getString(MediaFormat.KEY_MIME);
decoder = MediaCodec.createDecoderByType(mime);
decoder.configure(format, outputSurface.getSurface(), null, 0); //fails right here
decoder.start();
long end1 = System.currentTimeMillis();
Timber.d("extractMpegFrames(): FRAME_EXTRACT setup in: %d millis", (end1-start1));
long start2 = System.currentTimeMillis();
doExtract(extractor, trackIndex, decoder, outputSurface);
long end2 = System.currentTimeMillis();
Timber.d("extractMpegFrames(): FRAME_EXTRACT doExtract in: %d millis", (end2-start2));
} finally {
// release everything we grabbed
if (outputSurface != null) {
outputSurface.release();
outputSurface = null;
}
if (decoder != null) {
decoder.stop();
decoder.release();
decoder = null;
}
if (extractor != null) {
extractor.release();
extractor = null;
}
}
}
我知道这个question ,但是我不明白的是为什么 MediaCodec
可以在 MoviePlayer
中正常配置(视频运行正常)但在 ExtractMpegFramesTest
中却失败了.起初,我认为该设备在 OpenGL 设置方面存在一些问题,但后来证明是 MediaCodec 问题。
任何见解将不胜感激。
编辑:在获得 Galaxy S4 mini 测试设备后,我能够获得更有帮助的日志:
D/MoviePlayer: Extractor selected track 0 (video/avc): {max-input-size=1572864, height=1080, csd-0=java.nio.ByteArrayBuffer[position=0,limit=20,capacity=20], width=1920, durationUs=5131211, csd-1=java.nio.ByteArrayBuffer[position=0,limit=9,capacity=9], mime=video/avc, isDMCMMExtractor=1}
D/MoviePlayer: Video size is 1920x1080
D/MoviePlayer: Extractor selected track 0 (video/avc): {max-input-size=1572864, height=1080, csd-0=java.nio.ByteArrayBuffer[position=0,limit=20,capacity=20], width=1920, durationUs=5131211, csd-1=java.nio.ByteArrayBuffer[position=0,limit=9,capacity=9], mime=video/avc, isDMCMMExtractor=1}
I/OMXClient: Using client-side OMX mux.
E/ACodec: [OMX.qcom.video.decoder.avc] storeMetaDataInBuffers failed w/ err -2147483648
E/ACodec: configureCodec multi window instance fail appPid : 3283
E/ACodec: [OMX.qcom.video.decoder.avc] configureCodec returning error -38
E/MediaCodec: Codec reported an error. (omx error 0x80001001, internalError -38)
W/System.err: java.lang.IllegalStateException
W/System.err: at android.media.MediaCodec.native_configure(Native Method)
W/System.err: at android.media.MediaCodec.configure(MediaCodec.java:262)
W/System.err: at co.test.testing.player.MoviePlayer.prepareResources(MoviePlayer.java:237)
W/System.err: at co.test.testing.activities.VideoActivity.surfaceCreated(VideoActivity.java:276)
W/System.err: at android.view.SurfaceView.updateWindow(SurfaceView.java:602)
W/System.err: at android.view.SurfaceView.access$000(SurfaceView.java:94)
W/System.err: at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
W/System.err: at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:891)
W/System.err: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2201)
W/System.err: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1256)
W/System.err: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6635)
W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:813)
W/System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:613)
W/System.err: at android.view.Choreographer.doFrame(Choreographer.java:583)
W/System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:799)
W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:146)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5593)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
这些是从有此问题的设备中检索到的编解码器信息:
OMX.qcom.video.encoder.avc
OMX.SEC.avc.enc
OMX.Exynos.AVC.Encoder
奇怪的是 Galaxy S4 mini 可以很好地处理 720p 视频,它只是在处理 1080p 视频时遇到问题。
最佳答案
好的,这里再次回答我自己的问题:
首先,为什么我在使用MoviePlayer
显示视频后无法使用ExtractMpegFramesTest
提取帧:
某些设备似乎无法同时处理 2 个 MediaCodec
实例以播放高分辨率视频(在 Galaxy S4 mini 上为 >720p),因此您必须正确释放一个MediaCodec
的实例,然后再启动另一个实例,如下所示:
public void releaseResources() {
// release everything we grabbed
if (mDecoder != null) {
try {
mDecoder.stop();
mDecoder.release();
mDecoder = null;
} catch (Exception e) {
Timber.d("releaseResources(): message %s cause %s", e.getMessage(), e.getCause());
e.printStackTrace();
}
}
if (mExtractor != null) {
try {
mExtractor.release();
mExtractor = null;
} catch (Exception e) {
Timber.d("releaseResources(): message %s cause %s", e.getMessage(), e.getCause());
e.printStackTrace();
}
}
}
其次,为什么 MoviePlayer
无法配置 1080p 视频。在我的例子中,因为我从一个媒体选择器 Activity 开始这个 Activity ,其中有一个 VideoView
用于预览,它有一个 MediaPlayer.OnErrorListener()
注册来检测错误的视频。问题是 onError()
回调在 Galaxy S4 mini 上有一些非常奇怪的行为,而它在我的开发设备上工作得很好。我的疯狂猜测是 MediaPlayer.OnErrorListener()
使 MediaCodec
处于不良状态,这会在以后引起很多麻烦。
因此解决方案是设置一个空白的 OnErrorListener()
并在使用 MediaCodec
执行任何其他操作之前正确释放 VideoView
。像这样:
mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return true;
}
});
.....
mVideoView.stopPlayback();
doOtherThingWithMediaCodec();
这解释了在不同设备上发生的许多奇怪的事情。我希望这可以帮助其他人调试他们的应用程序。
关于android - MediaCodec.configure 因 1080p 视频的 IllegalStateException 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39523215/
我正在使用 Ubuntu 16.04。 当我更新时,我收到以下消息 $ sudo apt-get update .... E: dpkg was interrupted, you must manua
似乎有些autoconf项目使用configure.in文件生成configure脚本,有些使用configure.ac。 使用一种或另一种之间的区别/优势是什么? 最佳答案 这只是风格问题。历史上
我正在尝试按如下方式配置 logback,但它抛出了这个错误。配置文件如下: %d{ISO8601} %-5p [%c] %msg%n
从Miguel de Icaza: We use a library profile that is better suited for mobile devices, so we removed f
我有两个 .config 文件,我需要一个 System.Configuration.Configuration那是它们之间的部分合并? 我可以将文件读取为 XML 并轻松创建所需的合并,但它是一个字
我似乎无法理解这两个注释。我尝试阅读 javadocs 但仍然无法弄清楚。任何人都可以用简单的代码来解释这两个吗? 非常感谢。 最佳答案 您使用 @Configuration作为配置 Spring b
我正在为一个简单的问题而焦头烂额。我的 .NET Core 3 应用程序中有一些设置,我认为最好将其移至我的 appsettings.json 文件。我按照本指南这样做:https://www.c-s
我正在为一个简单的问题而焦头烂额。我的 .NET Core 3 应用程序中有一些设置,我认为最好将其移至我的 appsettings.json 文件。我按照本指南这样做:https://www.c-s
我有以下测试方法: [TestMethod] public void TestHarvestMethod() { HarvestTargetTimeRangeUTC time = new Ha
我的以下代码没有产生预期的输出: public static void main(String[] args) throws MalformedURLException { Configura
我知道要从源代码编译和安装某些东西,在 Unix 系统中,涉及的三个步骤是: 1) ./configure 2) make 3) make install 当我检查OpenCV from source
我有以下片段: static void Main(string[] args) { var container = new UnityContainer(); container.Re
我想好像 apache 的 commons-configuration 可能/支持从属性文件中获取属性作为 map 到目前为止,我已经设法使用以下代码片段间接地做到了这一点 Map map = ne
我正在寻找任何技巧来使用 CKEditor 配置中的参数配置我的插件。我必须传递一些只能在显示 View 时传递的参数。 我想要这样的东西(带有 jQuery 适配器的示例): jQuery('t
在我正在玩的代码中,我看到一些地方是 @Configuration 类除了定义静态类之外什么都不做。格式各不相同,但通常是这样的: @Configuration public class someAu
我们在带有 JRE 7 的 Windows 7 中安装了 Cassandra 2.0.6,我们更新了 cassandra.yaml 文件,如下所示: 数据文件目录:D:\cassandra_data\
我在启动类中收到“'Startup.Configuration' 和'Startup.Configuration' 之间的歧义”错误。我不知道我做了什么导致这个问题。我所做的只是创建了一个 DBCon
我已经安装了 Cygwin64,现在我想安装 extundelete . 所以我下载了它,解压了文件,但是当我运行 ./configure 时它说: $ ./configure Configuring
为什么需要做(在容器目录内): # cd /container/directory/ # ./configure 代替: # pwd /external/path # /container/direc
我正在尝试编译qucs-0.0.19但是当我放置./configure时,它给了我以下错误: checking Checking if admsXml is working... no config
我是一名优秀的程序员,十分优秀!