Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how take screen shot of currently playing video?

Tags:

android

video

I'm trying to take a screenshot of the currently playing video. I'm trying with code that successfully takes a screenshot of web view but get not success in taking photo of currently playing video.

The code as follow for web view.

WebView w = new WebView(this);

w.setWebViewClient(new WebViewClient()
{
    public void onPageFinished(WebView view, String url)
    {
         Picture picture = view.capturePicture();
         Bitmap  b = Bitmap.createBitmap( picture.getWidth(),
         picture.getHeight(), Bitmap.Config.ARGB_8888);

         Canvas c = new Canvas( b );

         picture.draw( c );

         FileOutputStream fos = null;

         try {
             fos = new FileOutputStream( "/sdcard/yahoo_" +System.currentTimeMillis() + ".jpg" );

             if ( fos != null )
             {
                 b.compress(Bitmap.CompressFormat.JPEG, 90, fos );

                 fos.close();
             }

         } catch( Exception e )
         {
             //...
         }
    }
});

setContentView( w );

w.loadUrl( "http://www.yahoo.com");
like image 210
milind Avatar asked Nov 15 '11 17:11

milind


2 Answers

Easier Solution (But not guaranteed to work always): MediaMetadataRetriever

Solution from another SO question that you can modify to get the desired output. Find the time in milliseconds that you want to capture and pass this time to MediaMetadataRetriever to get the frame.

Not so Easier Solution (Always will work, provided the codec is supported): FFMPEG

like image 196
AjOnFire Avatar answered Oct 14 '22 12:10

AjOnFire


To expand on 66CLSjY's answer, FFmpegMediaMetadataRetriever has the same interface as MediaMetadataRetriever but it uses FFmpeg as the backend. If the default configuration won't work with your video format you can enable/disable codecs by recompiling. Here is some sample code:

FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(mUri);
mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_CODEC);
Bitmap b = getFrameAtTime(3000);
mmr.release();
like image 1
William Seemann Avatar answered Nov 14 '22 15:11

William Seemann