首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在android中对视频流进行图像处理?

如何在android中对视频流进行图像处理?
EN

Stack Overflow用户
提问于 2012-03-07 14:22:28
回答 1查看 778关注 0票数 0

我想采取(实时)视频流,并在图像上做一些简单的图像处理。例如,我想要对构成视频流的所有图像制作直方图(这意味着我需要对制作视频的所有图像制作直方图)

问题:如何拍摄实时视频?如何实时访问设备视频,并对构成视频的图像进行分离?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-07 15:29:52

代码语言:javascript
复制
public class WatchVideo extends Activity {
    VideoView mVideoView; 
    String TAG = "------------------";
    String current = "";
    String mPath="";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

         mVideoView=new VideoView(this);

       //specify video path
        String path = ?;

        playVideo(path);
    }

     private void playVideo(String path) 
     {
                    try {   

                        Log.v(TAG, "path: " + path);
                        if (path == null || path.length() == 0) {
                            Toast.makeText(WatchVideo.this, "File URL/path is empty",
                                    Toast.LENGTH_LONG).show();

                        } else {
                            // If the path has not changed, just start the media player
                            if (path.equals(current) && mVideoView != null) {
                                mVideoView.start();
                                mVideoView.requestFocus();
                                return;
                            }
                            current = path;

                            mVideoView.setVideoPath(getDataSource(path));
                            mVideoView.start();
                            mVideoView.requestFocus();


                        }
                    } catch (Exception e) {
                     Log.e(TAG, "error: " + e.getMessage(), e);
                        if (mVideoView != null) {
                            mVideoView.stopPlayback();
                        }
                    }
                }

                private String getDataSource(String path) throws IOException {
                    if (!URLUtil.isNetworkUrl(path)) {
                        return path;
                    } else {
                        URL url = new URL(path);
                        URLConnection cn = url.openConnection();
                        cn.connect();
                        InputStream stream = cn.getInputStream();
                        if (stream == null)
                            throw new RuntimeException("stream is null");
                        File temp = File.createTempFile("mediaplayertmp", "dat");
                        temp.deleteOnExit();   
                        String tempPath = temp.getAbsolutePath();
                        FileOutputStream out = new FileOutputStream(temp);
                        byte buf[] = new byte[128];
                        do {
                            int numread = stream.read(buf);
                            if (numread <= 0)
                                break;
                            out.write(buf, 0, numread);
                        } while (true);
                        try {
                            stream.close();
                        } catch (IOException ex) {
                         Log.e(TAG, "error: " + ex.getMessage(), ex);
                     }
                    return tempPath;
                 }



                }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9596757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档