2012-03-07 54 views
0

我想实时拍摄视频流并对图像进行一些简单的图像处理。 例如 - 我想使所有的视频流图像(这意味着我需要使所有的图像,使视频直方图)直方图我如何在android中的视频流上进行图像处理?

问题: 我怎么能把真正的时间视频? 如何实时访问设备视频并分离制作视频的图像?

回答

0
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; 
       } 



       } 

} 
+1

但这不是实时的..这是在现有的视频剪辑:( – Yanshof 2012-03-07 09:00:47