wseemann.media.FFmpegMediaMetadataRetriever Java Examples

The following examples show how to use wseemann.media.FFmpegMediaMetadataRetriever. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FFmpegMediaMetadataRetrieverImpl.java    From MediaMetadataRetrieverCompat with MIT License 5 votes vote down vote up
protected int getWidth() {
    try {
        if (mWidth == null) {
            mWidth = Integer.parseInt(mRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
        }
        return mWidth;
    } catch (NumberFormatException ignored) {
        return 0;
    }
}
 
Example #2
Source File: FFmpegMediaMetadataRetrieverImpl.java    From MediaMetadataRetrieverCompat with MIT License 5 votes vote down vote up
protected int getHeight() {
    try {
        if (mHeight == null) {
            mHeight = Integer.parseInt(mRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
        }
        return mHeight;
    } catch (NumberFormatException ignored) {
        return 0;
    }
}
 
Example #3
Source File: FFmpegMediaMetadataRetrieverImpl.java    From MediaMetadataRetrieverCompat with MIT License 5 votes vote down vote up
protected int getRotationDegrees() {
    try {
        if (mRotation == null) {
            mRotation = Integer.parseInt(mRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
        }
        return mRotation;
    } catch (NumberFormatException ignored) {
        return 0;
    }
}
 
Example #4
Source File: VideoThumbnailUriModel.java    From sketch with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected Bitmap getContent(@NonNull Context context, @NonNull String uri) throws GetDataSourceException {
    FFmpegMediaMetadataRetriever mediaMetadataRetriever = new FFmpegMediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(getUriContent(uri));
    try {
        return readVideoThumbnail(context, uri, mediaMetadataRetriever);
    } finally {
        mediaMetadataRetriever.release();
    }
}
 
Example #5
Source File: VideoThumbnailUriModel.java    From sketch with Apache License 2.0 5 votes vote down vote up
@NonNull
private Bitmap readVideoThumbnail(Context context, String uri, FFmpegMediaMetadataRetriever mediaMetadataRetriever) throws GetDataSourceException {
    FFmpegMediaMetadataRetriever.Metadata metadata = mediaMetadataRetriever.getMetadata();
    int videoWidth = metadata.getInt(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
    int videoHeight = metadata.getInt(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);

    // 限制读取的帧的尺寸
    ImageSizeCalculator sizeCalculator = Sketch.with(context).getConfiguration().getSizeCalculator();
    MaxSize maxSize = sizeCalculator.getDefaultImageMaxSize(context);
    int inSampleSize = sizeCalculator.calculateInSampleSize(videoWidth, videoHeight, maxSize.getWidth(), maxSize.getHeight(), false);
    int finalWidth = SketchUtils.calculateSamplingSize(videoWidth, inSampleSize);
    int finalHeight = SketchUtils.calculateSamplingSize(videoHeight, inSampleSize);

    // 大于30分钟的一般是电影或电视剧,这类视频开头一般都一样显示出来也没有意义,所以显示中间的部分
    long timeUs;
    long duration = metadata.getLong(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
    int second = (int) (duration / 1000);
    int minute = second / 60;
    if (minute > 30) {
        timeUs = duration / 2 * 1000;
    } else {
        timeUs = -1;
    }

    Bitmap frameBitmap = mediaMetadataRetriever.getScaledFrameAtTime(timeUs, finalWidth, finalHeight);

    // 偶尔会有读取中间帧失败的情况,这时候换到三分之一处再读一次
    if (frameBitmap == null && timeUs != -1) {
        timeUs = duration / 3 * 1000;
        frameBitmap = mediaMetadataRetriever.getScaledFrameAtTime(timeUs, finalWidth, finalHeight);
    }

    if (frameBitmap == null || frameBitmap.isRecycled()) {
        String cause = String.format("Video thumbnail bitmap invalid. %s", uri);
        SLog.e(NAME, cause);
        throw new GetDataSourceException(cause);
    }
    return frameBitmap;
}
 
Example #6
Source File: FFmpegMediaMetadataRetrieverImpl.java    From Mrthumb with Apache License 2.0 4 votes vote down vote up
public FFmpegMediaMetadataRetrieverImpl() {
    this.mRetriever = new FFmpegMediaMetadataRetriever();
}
 
Example #7
Source File: VideoDetailsFetcher.java    From Beedio with GNU General Public License v2.0 4 votes vote down vote up
public void fetchDetails(final String url, final FetchDetailsListener listener) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                metadataRetriever.setDataSource(url);
                String filename = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_FILENAME);
                String title = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_TITLE);
                String vcodec = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_CODEC);
                String acodec = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_AUDIO_CODEC);
                String duration = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
                String filesize = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_FILESIZE);
                String width = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
                String height = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
                String bitrate = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VARIANT_BITRATE);
                String framerate = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_FRAMERATE);
                String encoder = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ENCODER);
                String encodedBy = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ENCODED_BY);
                String date = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DATE);
                String creationTime = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_CREATION_TIME);
                String artist = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ARTIST);
                String album = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM);
                String albumArtist = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM_ARTIST);
                String track = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_TRACK);
                String genre = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_GENRE);
                String composer = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_COMPOSER);
                String performaer = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_PERFORMER);
                String copyright = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_COPYRIGHT);
                String publisher = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_PUBLISHER);
                String language = metadataRetriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_LANGUAGE);

                StringBuilder sb = new StringBuilder();
                if (filename != null) sb.append("\nFile: ").append(filename);
                if (title != null) sb.append("\nTitle: ").append(title);
                sb.append("\nVideo Codec: ").append((vcodec != null) ? vcodec : "none");
                sb.append("\nAudio Codec: ").append((acodec != null) ? acodec : "none");
                String durationFormatted = formatDuration(duration);
                if (durationFormatted != null)
                    sb.append("\nDuration: ").append(durationFormatted);
                String filesizeFormatted = formatFilesize(filesize);
                if (filesizeFormatted != null)
                    sb.append("\nFilesize: ").append(filesizeFormatted);
                if (width != null) sb.append("\nWidth: ").append(width);
                if (height != null) sb.append("\nHeight: ").append(height);
                if (bitrate != null) sb.append("\nBitrate: ").append(bitrate);
                if (framerate != null)
                    sb.append("\nFramerate: ").append(framerate).append(" fps");
                if (encoder != null) sb.append("\nEncoder: ").append(encoder);
                if (encodedBy != null) sb.append("\nEncoded By: ").append(encodedBy);
                if (date != null) sb.append("\nDate: ").append(date);
                if (creationTime != null) sb.append("\nCreation Time: ").append(creationTime);
                if (artist != null) sb.append("\nArtist: ").append(artist);
                if (album != null) sb.append("\nAlbum: ").append(album);
                if (albumArtist != null) sb.append("\nAlbum Artist: ").append(albumArtist);
                if (track != null) sb.append("\nTrack: ").append(track);
                if (genre != null) sb.append("\nGenre: ").append(genre);
                if (composer != null) sb.append("\nComposer: ").append(composer);
                if (performaer != null) sb.append("\nPerformer: ").append(performaer);
                if (copyright != null) sb.append("\nCopyright: ").append(copyright);
                if (publisher != null) sb.append("\nPublisher: ").append(publisher);
                if (language != null) sb.append("\nLanguage: ").append(language);

                if (sb.length() > 0) {
                    sb.deleteCharAt(0);
                }

                listener.onFetched(sb.toString());
            } catch (IllegalArgumentException e) {
                listener.onUnFetched(e.getMessage());
            }
        }
    }).start();
}
 
Example #8
Source File: MediaMetadataResource.java    From MediaMetadataRetrieverCompat with MIT License 4 votes vote down vote up
public static KeyCompat getKey(String keyCode) {
    if (mKeyMap == null) {
        mKeyMap = new LinkedHashMap<>();
        mKeyMap.put(MediaMetadataKey.WIDTH, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH, FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
        mKeyMap.put(MediaMetadataKey.HEIGHT, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT, FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
        mKeyMap.put(MediaMetadataKey.DURATION, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_DURATION, FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION));
        mKeyMap.put(MediaMetadataKey.ROTATION, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION, FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
        mKeyMap.put(MediaMetadataKey.FRAMERATE, new KeyCompat(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? MediaMetadataRetriever.METADATA_KEY_CAPTURE_FRAMERATE : null, FFmpegMediaMetadataRetriever.METADATA_KEY_FRAMERATE));
        mKeyMap.put(MediaMetadataKey.ALBUM, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_ALBUM, FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM));
        mKeyMap.put(MediaMetadataKey.ARTIST, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_ARTIST, FFmpegMediaMetadataRetriever.METADATA_KEY_ARTIST));
        mKeyMap.put(MediaMetadataKey.ALBUMARTIST, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM_ARTIST));
        mKeyMap.put(MediaMetadataKey.COMPOSER, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_COMPOSER, FFmpegMediaMetadataRetriever.METADATA_KEY_COMPOSER));
        mKeyMap.put(MediaMetadataKey.DATE, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_DATE, FFmpegMediaMetadataRetriever.METADATA_KEY_CREATION_TIME));
        mKeyMap.put(MediaMetadataKey.GENRE, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_GENRE, FFmpegMediaMetadataRetriever.METADATA_KEY_GENRE));
        mKeyMap.put(MediaMetadataKey.TITLE, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_TITLE, FFmpegMediaMetadataRetriever.METADATA_KEY_TITLE));
        mKeyMap.put(MediaMetadataKey.NUM_TRACKS, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS, FFmpegMediaMetadataRetriever.METADATA_KEY_TRACK));
        mKeyMap.put(MediaMetadataKey.DISC_NUMBER, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, FFmpegMediaMetadataRetriever.METADATA_KEY_DISC));
        //android
        mKeyMap.put(MediaMetadataKey.CD_TRACK_NUMBER, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, null));
        mKeyMap.put(MediaMetadataKey.AUTHOR, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_AUTHOR, null));
        mKeyMap.put(MediaMetadataKey.YEAR, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_YEAR, null));
        mKeyMap.put(MediaMetadataKey.WRITER, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_WRITER, null));
        mKeyMap.put(MediaMetadataKey.MIMETYPE, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_MIMETYPE, null));
        mKeyMap.put(MediaMetadataKey.COMPILATION, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_COMPILATION, null));
        mKeyMap.put(MediaMetadataKey.HAS_AUDIO, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_HAS_AUDIO, null));
        mKeyMap.put(MediaMetadataKey.HAS_VIDEO, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO, null));
        mKeyMap.put(MediaMetadataKey.BITRATE, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_BITRATE, null));
        mKeyMap.put(MediaMetadataKey.LOCATION, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_LOCATION, null));
        mKeyMap.put(MediaMetadataKey.HAS_IMAGE, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_HAS_IMAGE, null));
        mKeyMap.put(MediaMetadataKey.IMAGE_COUNT, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_IMAGE_COUNT, null));
        mKeyMap.put(MediaMetadataKey.IMAGE_PRIMARY, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_IMAGE_PRIMARY, null));
        mKeyMap.put(MediaMetadataKey.FRAME_COUNT, new KeyCompat(MediaMetadataRetriever.METADATA_KEY_VIDEO_FRAME_COUNT, null));
        //ffmpeg
        mKeyMap.put(MediaMetadataKey.COMMENT, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_COMMENT));
        mKeyMap.put(MediaMetadataKey.COPYRIGHT, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_COPYRIGHT));
        mKeyMap.put(MediaMetadataKey.ENCODER, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_ENCODER));
        mKeyMap.put(MediaMetadataKey.ENCODED_BY, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_ENCODED_BY));
        mKeyMap.put(MediaMetadataKey.FILENAME, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_FILENAME));
        mKeyMap.put(MediaMetadataKey.LANGUAGE, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_LANGUAGE));
        mKeyMap.put(MediaMetadataKey.PERFORMER, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_PERFORMER));
        mKeyMap.put(MediaMetadataKey.PUBLISHER, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_PUBLISHER));
        mKeyMap.put(MediaMetadataKey.SERVICE_NAME, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_SERVICE_NAME));
        mKeyMap.put(MediaMetadataKey.SERVICE_PROVIDER, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_SERVICE_PROVIDER));
        mKeyMap.put(MediaMetadataKey.AUDIO_CODEC, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_AUDIO_CODEC));
        mKeyMap.put(MediaMetadataKey.VIDEO_CODEC, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_CODEC));
        mKeyMap.put(MediaMetadataKey.ICY_METADATA, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_ICY_METADATA));
        mKeyMap.put(MediaMetadataKey.CHAPTER_START_TIME, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_CHAPTER_START_TIME));
        mKeyMap.put(MediaMetadataKey.CHAPTER_END_TIME, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_CHAPTER_END_TIME));
        mKeyMap.put(MediaMetadataKey.CHAPTER_COUNT, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_CHAPTER_COUNT));
        mKeyMap.put(MediaMetadataKey.FILESIZE, new KeyCompat(FFmpegMediaMetadataRetriever.METADATA_KEY_FILESIZE));
    }
    return mKeyMap.get(keyCode);
}
 
Example #9
Source File: FFmpegMediaMetadataRetrieverImpl.java    From MediaMetadataRetrieverCompat with MIT License 4 votes vote down vote up
public FFmpegMediaMetadataRetrieverImpl() {
    this.mRetriever = new FFmpegMediaMetadataRetriever();
}