반응형

라즈베리 파이 카메라를 이용해 실시간 영상 스트리밍을 해 보자.


실시간 영상 스트리밍은 기본 설치되어 있는 cvlc(command-line vlc)를 이용한다. 만약 vlc가 설치되어 있지 않다면 설치하고 위 명령어를 입력한다.


위와 같이 대기 상태가 된다. (명령어 끝에 &를 붙여주면 백그라운드로 실행 할 수 있다)


다른 컴퓨터(우분투)에서 VLC를 실행한다. Media - Open Network Stream... 을 선택하고 '라즈베리파이 IP 주소:9000/'을 입력하면 스트리밍된 영상이 플레이 된다.


윈도우에서도 VLC를 설치하면 영상을 플레이 할 수 있다.


■ raspivid 옵션

  • -t, --timeout: Time (in ms) to capture for. If not specified, set to 5s. Zero to disable

  • -d, --demo: Run a demo mode (cycle through range of camera options, no capture)

  • -fps, --framerate: Specify the frames per second to record

  • -k, --keypress: Cycle between capture and pause on ENTER

  • -w, --width: Set image width <size>

  • -h, --height: Set image height <size>

  • -o, --output: Output filename <filename> (to write to stdout, use '-o -'). If not specified, no file is saved

  • -v, --verbose: Output verbose information during run

  • -cs, --camselect: Select camera <number>. Default 0

  • -p, --preview: Preview window settings <'x,y,w,h'>

  • -f, --fullscreen: Fullscreen preview mode

  • -op, --opacity: Preview window opacity (0-255)

  • -n, --nopreview: Do not display a preview window

  • -dn, --dispnum: Display on which to display the preview window (dispmanx/tvservice numbering)

  • -sh, --sharpness: Set image sharpness (-100 to 100)

  • -co, --contrast: Set image contrast (-100 to 100)

  • -br, --brightness: Set image brightness (0 to 100)

  • -sa, --saturation: Set image saturation (-100 to 100)

  • -ISO, --ISO: Set capture ISO

  • -rot, --rotation: Set image rotation (0, 90, 180, or 270)

  • -hf, --hflip: Set horizontal flip

  • -vf, --vflip: Set vertical flip

  • -roi, --roi: Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])

  • -a, --annotate: Enable/Set annotate flags or text

  • -ae, --annotateex: Set extra annotation parameters (text size, text colour(hex YUV), bg colour(hex YUV), justify, x, y)


반응형
Posted by J-sean
:
반응형

You can stream a video file with VideoView.


<AndroidManifest.xml>

1
    <uses-permission android:name="android.permission.INTERNET"/>



<MainActivity.java>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
public class MainActivity extends AppCompatActivity {
 
    VideoView videoView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        videoView = findViewById(R.id.videoView);
 
        MediaController mediaController = new MediaController(this);
        videoView.setMediaController(mediaController);
 
        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                videoView.setVideoURI(Uri.parse("http://nexoft.tk/data/WhileYouWereSleeping.mp4")); // or your video file url.
                videoView.requestFocus();
                videoView.start();
            }
        });
 
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                Toast.makeText(getApplicationContext(), "Video play completed", Toast.LENGTH_SHORT).show();
            }
        });
 
        videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                String message;
 
                switch (what) {
                    case MediaPlayer.MEDIA_ERROR_UNKNOWN:
                        message = "MEDIA_ERROR_UNKNOWN";
                        break;
 
                    case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                        message = "MEDIA_ERROR_SERVER_DIED";
                        break;
 
                    default:
                        message = "No what";
                }
 
                switch (extra) {
                    case MediaPlayer.MEDIA_ERROR_IO:
                        message += ", MEDIA_ERROR_IO";
                        break;
 
                    case MediaPlayer.MEDIA_ERROR_MALFORMED:
                        message += ", MEDIA_ERROR_MALFORMED";
                        break;
 
                    case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
                        message += ", MEDIA_ERROR_UNSUPPORTED";
                        break;
 
                    case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
                        message += ", MEDIA_ERROR_TIMED_OUT";
                        break;
 
                    default:
                        message += ", No extra";
                }
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
 
                //    Returns true if the method handled the error, false if it didn't. Returning false, or not having an OnErrorListener
                //    at all, will cause the OnCompletionListener to be called.
                return true;
            }
        });
    }
}




Run the app and click the PLAY button.


It may not be able to stream the video and show an error message in AVD.


It can stream the video in the actual device.


반응형
Posted by J-sean
: