【发布时间】:2017-09-27 15:06:41
【问题描述】:
我正在尝试从在 android 中使用 LibVLC 播放的视频中检索帧。作为参考,这就是我开始 LibVLC 的方式。 ffmpegSv 是一个 TextureView
public void startMediaPlayer() {
ArrayList<String> options = new ArrayList<>();
options.add("--no-drop-late-frames");
options.add("--no-skip-frames");
options.add("-vvv");
options.add("--no-osd");
options.add("--rtsp-tcp");
options.add("--no-snapshot-preview");
options.add("--no-video-title");
options.add("--no-spu");
videoVlc = new LibVLC(getActivity(), options);
TextureView surfaceView = (TextureView) getActivity().findViewById(R.id.streamView);
newVideoMediaPlayer = new org.videolan.libvlc.MediaPlayer(videoVlc);
final IVLCVout vOut = newVideoMediaPlayer.getVLCVout();
vOut.setVideoSurface(ffmpegSv.getSurfaceTexture());
vOut.setWindowSize(ffmpegSv.getWidth(), ffmpegSv.getHeight());
vOut.attachViews();
Media videoMedia = new Media (videoVlc, Uri.parse("rtsp://1.1.1.1/abc.mov"));
newVideoMediaPlayer.setMedia(videoMedia);
newVideoMediaPlayer.play();
}
这就是我试图从中获取位图的方式。我应该注意到这个方法在使用 android MediaPlayer 时可以正常工作。
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
if (mStream != null) {
if (idx++ % 10 == 0) {
(new Runnable() {
@Override
public void run() {
FileOutputStream out = null;
Bitmap b = ffmpegSv.getBitmap(ffmpegSv.getWidth(), ffmpegSv.getHeight());
Bitmap bm = Bitmap.createScaledBitmap(b2, 640, 480, true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 50, bos);
byte[] arr = bos.toByteArray();
mStream.onJpegFrame(arr, 0L);
b.recycle();
bm.recycle();
}
}).run();
idx = 0;
}
}
}
但是,正在生成的图像在边缘附近有来自 TextureView 的原始图像的一小部分,几乎像边框一样,但图像的其余部分被黑框遮挡。
我唯一能想到的是 VLC 对字幕等使用某种叠加层,当使用 getBitmap() 拉出时,它会失去透明度。但是,我不是 100% 肯定是这种情况。有没有办法检查是否是这种情况,或者禁用 VLC 可能添加的任何类型的覆盖?
编辑:我添加了一个示例图像来演示问题:
您可以只辨认出背景图像的底部、右侧和顶部,并在其顶部形成一个清晰的矩形。
【问题讨论】:
-
现在我有一个类似的问题,
de.mrmaffen:libvlc-android:2.1.12@aar从未达到onSurfaceTextureUpdated。来自玩家的事件到达,但纹理从未更新。 -
对我来说,在 Android 7 上测试时一切正常。我已切换到使用 libvlc for android >= a 和 stock MediaPlayer for 6 及更低版本。
-
应该是 >= 7