티스토리 뷰

라즈베리파이 슬로우 모션 카메라 

슬로우 모션 비디오는 영화산업에서 수십년동안 사용되었습니다. 

폭발로부터 점프하는 장면이나 영화 매트릭스에서 총알이 날아가는 장면이 유명했습니다. 

당신의 라즈베리파이와 카메라 모듈로 슬로오 모션 비디오를 쉽게 만들수 있습니다. 

라즈베리파이 파이썬의 짧은 코딩을 통해 30초 동안 저장되고, MP4로 컨버트 할 것입니다. 



스텝 1

카메라 모듈 연결

첫번째로 카메라 모듈을 라즈베리파이에 연결한다. 

라즈베리파이 전원을 오프 상태에서 연결한다. 


스텝 2

카메라 모듈 설정

터미널에서 sudo raspi-config => Enable Camera 로 설정하고 sudo reboot 


스텝 3

비디오 컨버터 설치

라즈베리파이 비디오 파일은 h.264이다. 이 파일은 대부분의 장치에서 쉽게 재생되지 않는다. 

그래서 gpac 을 설치한다. 

sudo apt-get update

sudo apt-get install gpac



스텝4 

카메라 테스트

간단한 명령어로 카메라가 정상 동작하는지 확인합니다. 

raspistill -o test.jpg

파일은 /home/pi 디렉토리에 저장됩니다.  

카메라가 정상 동작하지 않는다면 스텝1으로 돌아갑니다. 


스텝 5

파이션 스크립트 만들기 

에디터는 당신이 좋아하는 에디터를 사용하면 됩니다. 

nano slowmotion.py 

import os

import time


print("Starting program")

time.sleep(2)


##### Record the slow motion video #####

# ‘-w’ sets the width # ‘-h’ sets the height

# ‘-fps’ sets the frames per second (90 maximum - for slow motion)

# ‘t’ sets the time in milliseconds (30000 = 30 seconds)

# ‘-o’ sets the output filename


print("Recording started - 30 seconds")

os.system("raspivid -w 640 -h 480 -fps 90 -t 30000 -o vid.h264")

print("Recording complete. Please wait...")

time.sleep(2)


##### Convert the raw recorded video file to playable mp4 #####

# ‘-add’ is the name of the raw video we want to convert

# The second filename is the output mp4 file

# (we use the same name followed by ‘.mp4’)


print("Converting video. Please wait...")

os.system("rm -f vid.mp4")

os.system("MP4Box -add vid.h264 vid.mp4")

print("Video conversion complete")

time.sleep(2)

print("Closing program")

time.sleep(2)



스텝 6 슬로우모션 실행하기 

sudo python3 slowmotion.py

pi@raspberrypi:~ $ python3 slowmotion.py

Starting program

Recording started - 30 seconds

Recording complete. Please wait...

Converting video. Please wait...

AVC-H264 import - frame size 640 x 480 at 25.000 FPS

AVC Import results: 2643 samples - Slices: 45 I 2598 P 0 B - 0 SEI - 45 IDR

Saving to vid.mp4: 0.500 secs Interleaving

Video conversion complete                               

Closing program

그리고 omxplayer를 통해 동영상을 재생할 수 있습니다.

omxplayer vid.mp4


pi@raspberrypi:~ $ omxplayer vid.mp4

Video codec omx-h264 width 640 height 480 profile 100 fps 25.000000

Subtitle count: 0, state: off, index: 1, delay: 0

V:PortSettingsChanged: 640x480@25.00 interlace:0 deinterlace:0 anaglyph:0 par:1.25 display:0 layer:0 alpha:255 aspectMode:0

have a nice day ;)








댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
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
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글