How not to seek to keyframes

巧了我就是萌 提交于 2020-01-31 18:28:28

问题


I've tried to find a solution to seek frame by frame (not only to keyframes) in my android app.

  1. approach: A simple VideoView of the android sdk:
    Here I've got a onSeekCompleteListener of the base class MediaPlayer from the onPreparedListener of VideoView and pause the playback right after started it and moved to a preferred position.
    Problem: Only seeks to keyframes!

  2. approach: MediaMetaRetriever: I have got something like this:

    MediaMetadataRetriever retriever;
    long Position;
    ImageView video;
    TextView lbPosition;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        video = (ImageView)findViewById(R.id.imVideo);
        lbPosition = (TextView)findViewById(R.id.lbPosition);
        bnTake = (Button)findViewById(R.id.bntake);
        retriever.setDataSource(this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.vid));
    
        video.setOnClickListener(new ImageView.OnClickListener() {
            @Override
            public void onClick(View arg0) {
               Position += 100000;
               Bitmap frame = retriever.getFrameAtTime(Position, MediaMetadataRetriever.OPTION_CLOSEST);
               video.setImageBitmap(frame);
               lbPosition.setText(String.valueOf(Position));
           }            
        });
    
        bnTake.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                startActivityForResult(takeVideoIntent, 123123);
            }
        }); 
    }
    

When I use OPTION_CLOSESTS in retriever.getFrameAtTime it gives me a getFrameAtTime: videoFrame is a NULL pointer error. When I don't use this option, it goes through keyframes.

Maybe possible solutions:

  1. approach: Record video with more keyframes. If I would record the video with an higher keyframe rate in my android app, could that be a solution? Is this possible?

  2. approach (I haven't tried!): I've heard something of video player 3rd party libraries for android that use FFMPEG. Is there any library that can seek while in pause state and update the position for the video on the screen?


回答1:


Have you tried FFmpegMediaMetadataRetriever?



来源:https://stackoverflow.com/questions/21318835/how-not-to-seek-to-keyframes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!