LoginSignup
1
2

More than 5 years have passed since last update.

AndroidでVideoCaptureで動画が開けない

Posted at

環境

  • Windows 7
  • AndroidStudio 3.0
  • OpenCV for Android 3.4.0

結論

mp4動画ファイルをmjpegに変換したら開けた。ただし、拡張子はmjpegだと開けなかった。
↓OpenCV公式フォーラムに同じ問題で悩んでいる人がいた。
http://answers.opencv.org/question/126732/loading-video-files-using-videocapture-in-android/

ファイルの準備

適当な動画をmjpegに変換する。
拡張子をmp4 or aviにする。mjpegだと開けなかった。


"test.mp4"として→に格納 "storage/emulated/0/DCIM/test.mp4"

プログラム

スマホのカメラにアクセスするため、パーミッション追加。
WS000012.JPG

↓コード

MainActivity.java
public class MainActivity extends AppCompatActivity {

    static {
        System.loadLibrary("opencv_java3");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        File file = new File(Environment.getExternalStorageDirectory() + "/DCIM");

        if (file.exists())
        {
            File file2 = new File(file.getAbsolutePath() + "/test.mp4");

            if (file2.exists())
            {
                VideoCapture videoCapture = new VideoCapture();
                videoCapture.open(file2.getPath());

                TextView tw = (TextView) findViewById(R.id.textView);

                if (videoCapture.isOpened()) {
                    tw.setText("VideoCapture OK");
                }
                else
                {
                    tw.setText("VideoCapture NG");
                }
            }
        }
    }

実行結果↓
Screenshot_2018-06-05-20-59-47.png

今後

mjpegだとサイズが大きすぎる。H.264とかで開けるようにしたい。
やり方を調べる予定。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2