2010-12-14 258 views
5

是否可以从视频网址获取缩略图图像?我需要列表视图中的视频缩略图。从视频网址获取视频的缩略图图像

+0

看到我的答案...... – Lokesh 2015-02-23 08:44:53

+0

@ user3726986是它的ContentProvider的地址或网址,如YouTube? – SMR 2015-02-23 11:23:33

回答

0

确定问题的组成部分非常重要。其实我说你有两个不同的问题:

  1. 下载从URL的文件。

  2. 从不完整的视频文件创建缩略图。

分别研究这两个,你会发现很多信息。

9

是的,它可以使用ThumbnailUtils获取视频的缩略图。

FileOutputStream out; 
File land=new File(Environment.getExternalStorageDirectory().getAbsoluteFile() 
       +"/portland.jpg");// image file use to create image u can give any path. 
Bitmap bitmap=ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);//filePath is your video file path. 
     ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
     byte[] byteArray = stream.toByteArray(); 

     out=new FileOutputStream(land.getPath()); 
     out.write(byteArray); 
     out.close(); 
+0

我不能使用这一行,它显示错误,File land = new File(Environment.getExternalStorageDirectory()。getAbsoluteFile() +“/ portland。jpg“); – Anitha 2015-03-30 10:31:13

+0

我从视频网址获取图像,然后我该怎么做?请帮助我。 – 2015-09-22 12:35:45

+0

最好的独特解决方案,因为与MINI_KIND和MICRO_KIND不同,FULL_SCREEN_KIND只存储在数据库中,不可能通过URI路径访问。 – MPaulo 2017-03-24 05:34:55

1

尝试ThumbnailUtils,从文件路径

ThumbnailUtils.createVideoThumbnail(filePath,MediaStore.Video.Thumbnails.MINI_KIND); 
+0

不是当你流媒体。 – 2015-02-24 06:48:45

2

获取视频的位图如果你是专门询问youtube影片则有自动4由YouTube所产生的图像。

http://img.youtube.com/vi/video_url_here/0.jpg 
http://img.youtube.com/vi/video_url_here/1.jpg 
http://img.youtube.com/vi/video_url_here/2.jpg 
http://img.youtube.com/vi/video_url_here/3.jpg 

标准图像尺寸

播放背景缩略图(480x360像素) http://i1.ytimg.com/vi/G0wGs3useV8/0.jpg

开始缩略图(120x90像素) http://i1.ytimg.com/vi/G0wGs3useV8/1.jpg

中的缩略图(120x90像素) http://i1.ytimg.com/vi/G0wGs3useV8/2.jpg

结束缩图(120x90像素) http://i1.ytimg.com/vi/G0wGs3useV8/3.jpg

高品质缩图(480x360像素) http://i1.ytimg.com/vi/G0wGs3useV8/hqdefault.jpg

中等质量缩图(看见320×180像素) http://i1.ytimg.com/vi/G0wGs3useV8/mqdefault.jpg

普通质量缩图(120x90像素) http://i1.ytimg.com/vi/G0wGs3useV8/default.jpg

标准清晰度缩略图(640x480像素) http://i1.ytimg.com/vi/G0wGs3useV8/sddefault.jpg

最大分辨率缩略图(1920×1080像素) http://i1.ytimg.com/vi/G0wGs3useV8/maxresdefault.jpg

0

它可以使用FFMPEG视频文件或网址,以获取缩略图。

FFMPEG必须使用NDK构建(或者您可以找到一些Android构建的FFMPEG二进制文件)。这里是一个GitHub的项目,建立FFMPEG:使用

https://github.com/guardianproject/android-ffmpeg

然后,您可以包括FFmpeg的二进制文件与您的应用程序,并在您的应用代码执行FFMPEG来从视频图像(本地或URL)命令,如:

ffmpeg -i videosite.com/video.flv -ss 00:00:15.000 -vframes 1 thumbnail_out.png 

有一点要考虑的是在什么寻道时间(选项-ss)你抢缩图为它是表示视频有意义的图像。

0

从URL获得缩略图,我只得到了一个解决方案到现在为止, 你必须使用This library

它支持文件,HTTP,HTTPS,MMS,mmsh和RTMP协议

它支持aac,acc +,avi,flac,mp2,mp3,mp4,ogg,3gp以及更多!格式(音频和视频):

1

可以从视频网址获取视频的缩略图图像。

如果您的视频类型是Vimeo的遵循以下步骤:

1)假设你的视频网址是: http://player.vimeo.com/video/17314292

2)获取的视频ID从以下网址:如。

与视频ID和XML格式; 3)呼叫WS http://vimeo.com/api/v2/video/17314292.xml

您将获得 “thumbnail_small”, “thumbnail_medium”, “thumbnail_large” 以XML格式视频拇指从视频ID

如果您的视频类型是的YouTube按照以下步骤进行:

1)视频网址: http://www.youtube.com/embed/Nl2iMF0yKW8

2)从网址获取视频ID:例如。 Nl2iMF0yKW8

3)在此URL http://i3.ytimg.com/vi/Nl2iMF0yKW8/default.jpg

注意更换视频ID:这里只是更换您的ID。

1

它是工作在我的情况

Uri videoUri = data.getData(); 
       String selectedPathVideo=""; 
       selectedPathVideo = ImageFilePath.getPath(getApplicationContext(), videoUri); 
       Log.i("Image File Path", ""+selectedPathVideo); 

       try { 
        Bitmap thumb = ThumbnailUtils.createVideoThumbnail(selectedPathVideo, MediaStore.Video.Thumbnails.MICRO_KIND); 


        imgFarmerVideo.setImageBitmap(thumb); 

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

的支持文件

public class ImageFilePath { 
    /** 
    * Method for return file path of Gallery image 
    * 
    * @param context 
    * @param uri 
    * @return path of the selected image file from gallery 
    */ 
    public static String getPath(final Context context, final Uri uri) 
    { 

     //check here to KITKAT or new version 
     final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 

     // DocumentProvider 
     if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { 

      // ExternalStorageProvider 
      if (isExternalStorageDocument(uri)) { 
       final String docId = DocumentsContract.getDocumentId(uri); 
       final String[] split = docId.split(":"); 
       final String type = split[0]; 

       if ("primary".equalsIgnoreCase(type)) { 
        return Environment.getExternalStorageDirectory() + "/" + split[1]; 
       } 
      } 
      // DownloadsProvider 
      else if (isDownloadsDocument(uri)) { 

       final String id = DocumentsContract.getDocumentId(uri); 
       final Uri contentUri = ContentUris.withAppendedId(
         Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); 

       return getDataColumn(context, contentUri, null, null); 
      } 
      // MediaProvider 
      else if (isMediaDocument(uri)) { 
       final String docId = DocumentsContract.getDocumentId(uri); 
       final String[] split = docId.split(":"); 
       final String type = split[0]; 

       Uri contentUri = null; 
       if ("image".equals(type)) { 
        contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 
       } else if ("video".equals(type)) { 
        contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; 
       } else if ("audio".equals(type)) { 
        contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 
       } 

       final String selection = "_id=?"; 
       final String[] selectionArgs = new String[] { 
         split[1] 
       }; 

       return getDataColumn(context, contentUri, selection, selectionArgs); 
      } 
     } 
     // MediaStore (and general) 
     else if ("content".equalsIgnoreCase(uri.getScheme())) { 

      // Return the remote address 
      if (isGooglePhotosUri(uri)) 
       return uri.getLastPathSegment(); 

      return getDataColumn(context, uri, null, null); 
     } 
     // File 
     else if ("file".equalsIgnoreCase(uri.getScheme())) { 
      return uri.getPath(); 
     } 

     return null; 
    } 

    /** 
    * Get the value of the data column for this Uri. This is useful for 
    * MediaStore Uris, and other file-based ContentProviders. 
    * 
    * @param context The context. 
    * @param uri The Uri to query. 
    * @param selection (Optional) Filter used in the query. 
    * @param selectionArgs (Optional) Selection arguments used in the query. 
    * @return The value of the _data column, which is typically a file path. 
    */ 
    public static String getDataColumn(Context context, Uri uri, String selection, 
             String[] selectionArgs) { 

     Cursor cursor = null; 
     final String column = "_data"; 
     final String[] projection = { 
       column 
     }; 

     try { 
      cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, 
        null); 
      if (cursor != null && cursor.moveToFirst()) { 
       final int index = cursor.getColumnIndexOrThrow(column); 
       return cursor.getString(index); 
      } 
     } finally { 
      if (cursor != null) 
       cursor.close(); 
     } 
     return null; 
    } 

    /** 
    * @param uri The Uri to check. 
    * @return Whether the Uri authority is ExternalStorageProvider. 
    */ 
    public static boolean isExternalStorageDocument(Uri uri) { 
     return "com.android.externalstorage.documents".equals(uri.getAuthority()); 
    } 

    /** 
    * @param uri The Uri to check. 
    * @return Whether the Uri authority is DownloadsProvider. 
    */ 
    public static boolean isDownloadsDocument(Uri uri) { 
     return "com.android.providers.downloads.documents".equals(uri.getAuthority()); 
    } 

    /** 
    * @param uri The Uri to check. 
    * @return Whether the Uri authority is MediaProvider. 
    */ 
    public static boolean isMediaDocument(Uri uri) { 
     return "com.android.providers.media.documents".equals(uri.getAuthority()); 
    } 

    /** 
    * @param uri The Uri to check. 
    * @return Whether the Uri authority is Google Photos. 
    */ 
    public static boolean isGooglePhotosUri(Uri uri) { 
     return "com.google.android.apps.photos.content".equals(uri.getAuthority()); 
    } 
}