Raspberry Pi&5110&视频播放

具体思路:
a. 读取视频文件 – 读取帧 – 转换image – 播放
b. 当初就想到树莓派的cpu太弱,肯定会很卡,结果就是卡的我无法直视了。。。。
c. 而且使用了openCV来解码视频,无限报错“No accelerated colorspace conversion found from yuv420p to bgr24”,重新下载编译都花了大半天还是报错,坑了。
d. 反正也实现了基本功能,干脆就贴下吧。视频解码使用openCV的。
1  openCV的安装
[code]sudo apt-get install libopencv-dev python-opencv[/code]
如果以上安装了报错,就采用下面的方法,不过编译要花很多时间,要有心理准备,当然也可以用pc来编译会快些

sudo aptitude remove ffmpeg
cd /usr/src
sudo mkdir ffmpeg
sudo chown `whoami`:users ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure
make
sudo make install

2  5110player
openCV是不支持音频解码的,所以只有画面。。。

import time
import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI
import Image
import cv2
print 'Press Ctrl-C to quit.'
# Raspberry Pi hardware SPI config:
DC = 23
RST = 24
SPI_PORT = 0
SPI_DEVICE = 0
# Hardware SPI usage:
disp = LCD.PCD8544(DC, RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=400000))
# Initialize library.
disp.begin(contrast=60)
# Clear display.
disp.clear()
disp.display()
# Open "1.mp4"
videoCapture = cv2.VideoCapture('1.mp4')
# Get fps
fps = videoCapture.get(cv2.cv.CV_CAP_PROP_FPS)
# Time starting display image
timesta = time.time()
# The number of frames which have been read
n = 0
time.sleep(0.1)
while True:
# Time now
timenow = time.time()
# Calculate the frame nx to display
nx = int((timenow - timesta) * fps) + 1
for x in range(1,nx - n):
success, frame = videoCapture.read()
n = nx
image = Image.fromarray(frame).resize((LCD.LCDWIDTH, LCD.LCDHEIGHT), Image.ANTIALIAS).convert('1')
disp.image(image)
disp.display()

Leave a Reply

Your email address will not be published. Required fields are marked *

Raspberry Pi&5110&视频播放

具体思路:
a. 读取视频文件 – 读取帧 – 转换image – 播放
b. 当初就想到树莓派的cpu太弱,肯定会很卡,结果就是卡的我无法直视了。。。。
c. 而且使用了openCV来解码视频,无限报错“No accelerated colorspace conversion found from yuv420p to bgr24”,重新下载编译都花了大半天还是报错,坑了。
d. 反正也实现了基本功能,干脆就贴下吧。视频解码使用openCV的。
1  openCV的安装
[code]sudo apt-get install libopencv-dev python-opencv[/code]
如果以上安装了报错,就采用下面的方法,不过编译要花很多时间,要有心理准备,当然也可以用pc来编译会快些

sudo aptitude remove ffmpeg
cd /usr/src
sudo mkdir ffmpeg
sudo chown `whoami`:users ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure
make
sudo make install

2  5110player
openCV是不支持音频解码的,所以只有画面。。。

import time
import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI
import Image
import cv2
print 'Press Ctrl-C to quit.'
# Raspberry Pi hardware SPI config:
DC = 23
RST = 24
SPI_PORT = 0
SPI_DEVICE = 0
# Hardware SPI usage:
disp = LCD.PCD8544(DC, RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=400000))
# Initialize library.
disp.begin(contrast=60)
# Clear display.
disp.clear()
disp.display()
# Open "1.mp4"
videoCapture = cv2.VideoCapture('1.mp4')
# Get fps
fps = videoCapture.get(cv2.cv.CV_CAP_PROP_FPS)
# Time starting display image
timesta = time.time()
# The number of frames which have been read
n = 0
time.sleep(0.1)
while True:
# Time now
timenow = time.time()
# Calculate the frame nx to display
nx = int((timenow - timesta) * fps) + 1
for x in range(1,nx - n):
success, frame = videoCapture.read()
n = nx
image = Image.fromarray(frame).resize((LCD.LCDWIDTH, LCD.LCDHEIGHT), Image.ANTIALIAS).convert('1')
disp.image(image)
disp.display()

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »