version added
[BABOOSHKA.TV] / README.md
1 # [babooshka.tv](https://babooshka.tv) old-school tv-box video player
2
3 This simple and lightweight package could turn your RPi into a video player. The package is designed primarily for your grandparents, for whom the use of a computer is a difficult task. You can upload your home kittens-kids videos or add videos from Youtube/Vimeo that you like. 
4
5 The package is fully written in bash. 
6
7 ![babooshka.tv RPi based prototype](https://repository.interplaymedium.org/babooshka.tv/babooshka.tv.rpi.jpeg)  
8
9 ## Wiring
10
11 [Pi Zero IO Pinout](https://pinout.xyz/pinout/io_pi_zero)
12
13 The yellow LED connected to +3,3v via 470R 
14
15         GPIO 0  BCM17   LED green, booting  
16         GPIO 2  BCM27   LED red, video status  
17
18 Lowering resistors are required for all diodes (Red LEDs normally brighter, so I would recommend ~470R for yellow and green and about 1K for red)
19
20 ### Infrared interface
21
22         GPIO 3  BCM22   IR TX  
23         GPIO 4  BCM23   IR RX  
24
25         38kHz -- standard 
26
27         +-----------------------+ 3
28         |                       +---------------------o +3.3V
29         |      ______________   |
30         |     /                 |
31         |    (                  | 2  
32         |     \______________   +---------------------o GND
33         |                       |
34         |                       | 1
35         |               data -> +---------------------o GPIO 4 (BCM23)
36         +-----------------------+
37
38
39         950nm emitting diode (e.g. TSUS5400)
40
41                          +5V
42                           o
43                           |
44                          | |  51 Ohm (depending on MOSFET maybe not required)
45                          |_|
46                           |
47                          _|_
48                          \ / 
49                          ---  IR LED
50                           |
51                           |
52              ___      |---'
53       o-----|___|-----|       MOSFET
54              10K      |->--
55         GPIO 3 (BCM22)     |
56                            |
57                         ----- GND
58                          ---
59                           - 
60
61 ### Analog Audio 
62
63         GPIO 1  BCM18   R AUDIO
64         GPIO 23 BCM13   L AUDIO
65
66 ![RPi Zero Audio](https://repository.interplaymedium.org/babooshka.tv/pi-zero-audio_bb.jpg)  
67 Picture taken [from here](https://shallowsky.com/blog/hardware/pi-zero-audio.html), thanks :)  
68
69 ### Analog video pin
70
71 ![RPi TV out](https://repository.interplaymedium.org/babooshka.tv/RPi_TV_out.jpeg)  
72 Picture taken [from here](https://magpi.raspberrypi.org/articles/rca-pi-zero), thanks :)  
73
74 ## Setup
75
76 Download, copy to microSD and install oficial [Raspberry Pi OS Lite image](https://www.raspberrypi.org/downloads/raspberry-pi-os/)
77
78 The procedure of adding a login and password for your access point, as well as the ssh configuration is omitted. It is assumed that you know how to do so :)  
79 If you not sure, [ddg it](https://duckduckgo.com/?q=RPi+headless+how+setup+and+ssh).
80
81 Further operations are performed on device.
82
83         ssh <your RPi device>
84
85 Update repository list and install dependencies 
86
87         apt update  
88         apt install mc fbi omxplayer sox
89
90 Try to install freefonts (required by omxplayer)
91
92         apt install freefonts
93
94 By some reason recently *freefonts* package has been removed from official RPi repository. So in case of unsuccess just copy included freefonts to /usr/share/fonts/truetype/...  
95 do it with *sudo*
96
97         cp -r freefont /usr/share/fonts/truetype/freefont  
98         chown root:root /usr/share/fonts/truetype/freefont  
99         chown root:root /usr/share/fonts/truetype/freefont/*
100
101 ### IR interface setup
102
103         apt install lirc
104
105 edit /etc/lirc/hardware.conf
106
107         # Run "lircd --driver=help" for a list of supported drivers.  
108         DRIVER="default"
109
110         # usually /dev/lirc0 is the correct setting for systems using udev  
111         DEVICE="/dev/lirc1"  
112         MODULES="gpio_ir_recv"
113
114 edit /etc/lirc/lirc_options.conf
115 NOTE! add new line in the end of the file !!!! [known bug](https://forum.odroid.com/viewtopic.php?t=32181)
116
117         driver            = default  
118         device            = /dev/lirc1
119
120 First try to find you device using 
121
122         irdb-get find YOUR_DEVICE  
123
124 In case of unsiccess try to find and copy YOUR_DEVICE.conf for your remote controller to */etc/lirc/lircd.conf.d/* 
125 Here is a [list of devices](http://lirc-remotes.sourceforge.net/remotes-table.html) supported by Lirc 'from the box'. However, you always can record your own, see below... 
126
127 Copy template lircd.conf
128
129         cp /etc/lirc/lircd.conf.dist /etc/lirc/lircd.conf
130
131 Make changes in */boot/config.txt* to set up PAL video output and run appropriate kernel overlays for IR interface:
132
133         disable_splash=1
134         
135         # disable_overscan=1
136
137         framebuffer_width=720
138         framebuffer_height=576
139
140         # enable PWM audio (add this line)
141         dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4
142
143         # uncomment for composite PAL
144         sdtv_mode=2
145
146         # uncomment if hdmi display is not detected and composite is being output
147         # hdmi_force_hotplug=1
148
149         # Uncomment this to enable the gpio-ir module
150         dtoverlay=gpio-ir,gpio_pin=23,gpio_pull=up
151         dtoverlay=gpio-ir-tx,gpio_pin=22
152
153 ### Make IR works as TX and RX simultanoiously
154
155 This part taken from [this GitHub comment](https://github.com/raspberrypi/linux/issues/2993#issuecomment-497420228) thank you [@elmicha](https://github.com/elmicha) :)
156
157 Add these rules in */etc/udev/rules.d/71-lirc.rules* to get stable */dev/lirc-rx* and */dev/lirc-tx* device names:
158
159         ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="gpio_ir_recv", SYMLINK+="lirc-rx"
160         ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="gpio-ir-tx", SYMLINK+="lirc-tx"
161         ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="pwm-ir-tx", SYMLINK+="lirc-tx"
162
163 Change the device and listening address in /etc/lirc/lirc_options.conf:
164
165         device            = /dev/lirc-rx
166         listen            = 0.0.0.0:8766
167
168 Copy lirc_options.conf to lirc_tx_options.conf and edit these lines:
169
170         device            = /dev/lirc-tx
171         output            = /var/run/lirc/lircd-tx
172         pidfile          = /var/run/lirc/lircd-tx.pid
173         listen            = 0.0.0.0:8765
174         connect          = 127.0.0.1:8766
175
176 Create */etc/systemd/system/lircd-tx.service* (from the output of *systemctl cat lircd*) and edit it like this:
177
178         [Unit]  
179         Documentation=man:lircd(8)  
180         Documentation=http://lirc.org/html/configure.html  
181         Description=Second lircd, the transmitter  
182         Wants=lircd-setup.service  
183         After=network.target lircd-setup.service lircd.service  
184         
185         [Service]  
186         Type=simple  
187         ExecStart=/usr/sbin/lircd --nodaemon --options-file /etc/lirc/lirc_tx_options.conf  
188         
189         [Install]  
190         WantedBy=multi-user.target  
191         Create /etc/systemd/system/lircd-tx.socket (from the output of systemctl cat lircd.socket) and edit it:  
192         
193         [Socket]  
194         ListenStream=/run/lirc/lircd-tx  
195         
196         [Install]  
197         WantedBy=sockets.target  
198         Also=lircd-tx.service  
199
200
201 Create /usr/local/bin/irsend and make it executable
202
203         #! /bin/sh  
204         exec /usr/bin/irsend --device=/var/run/lirc/lircd-tx "$@"
205
206 Start lircd-tx (with *sudo*)
207
208         systemctl daemon-reload
209         systemctl start lircd-tx
210         systemctl enable lircd-tx
211
212 Enable RX (with *sudo*)
213         systemctl enable lircd.service
214         systemctl enable lircd.socket
215
216         systemctl restart lircd
217
218 NOTE: there maybe the Warning of duplication of "begin remote .. end remote", it is fine. Ignore it. 
219
220 Reboot and check status :)
221
222         systemctl reboot
223
224         systemctl status lircd.service
225         systemctl status lircd.socket
226
227 ### Test IR 
228
229 Send some command. replace vendor and command with your
230
231         irsend SEND_ONCE SONY-TV KEY_1
232
233 Read RX 
234
235         irw
236
237 Record your own (if you have no compatible remote control or incomplete config)
238
239         systemctl stop lircd.socket
240         systemctl stop lircd.service
241         
242         record with own key names
243         irrecord --disable-namespace
244
245         systemctl start lircd.socket
246         systemctl start lircd.service
247
248 Force raw record mode (normally not required)
249         
250         irrecord -f -d /dev/lirc0 ~/lirc.conf
251
252 ## Main package installation
253
254         cd /home/pi/
255         git clone <this repo> (see above)
256         cd BABOOSHKA.TV/
257
258 Make sure that all .sh files inside are executable (have x flag)
259
260         ls --all 
261
262 if required make them *chmod +x *.sh*
263
264 ### Early stage systemd service (launching led driver and creating splash image)
265
266 Create */etc/systemd/system/splash.service* file and add there
267
268         [Unit]  
269         DefaultDependencies=no  
270         After=local-fs.target  
271         
272         [Service]  
273         StandardInput=tty  
274         StandardOutput=tty  
275         ExecStart=/home/pi/BABOOSHKA.TV/early_init.sh  
276           
277         [Install]  
278         WantedBy=sysinit.target  
279
280 Activate the service 
281
282         sudo systemctl enable splash.service
283
284 ### On boot launcher
285
286 Add this line to */etc/rc.local*
287
288    sudo -H -u pi /home/pi/babooshka.tv/start.babooshka.sh > /dev/null &
289
290 reboot and test :)
291
292         systemctl reboot
293
294 if everything has been done properly, you will see the splash babooshka.tv logo
295
296 - add testing video in *~/BABOOSHKA.TV/VIDEO/* directory
297 - check playlist (that the video link has been added)
298 - click PLAY on your remote 
299 - if something went wrong, see Debug section below
300
301 ## Cosmetic polishing 
302
303 Edit */boot/cmdline.txt*. Make sure that you have *console=tty3 quiet consoleblank=0* and *logo.nologo*, this is my cmdline: 
304
305         console=serial0,115200 console=tty3 quiet consoleblank=0 loglevel=1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait logo.nologo
306
307 Disable blinking cursor (probably not required)
308
309         vt.global_cursor_default=0
310
311 Remove tty login service to eliminate blinking cursor
312         
313         sudo systemctl disable getty@tty1 
314
315 ## Additional software 
316
317 If' you're going to watch videos from YouTube, Vimeo and so on, this packages would be required. Most porbably probably would beed to install youtube-dl globally. So do that with *sudo -H ...*. It would be recommended wor futher compatibility. 
318
319         apt install mkvtoolnix python-pip
320         pip install -U youtube-dl
321
322 ## Usage
323
324 converting video (note -level 3.0 option! it is required for RPi HW codec)
325
326         ffmpeg -i FILEIN -vcodec libx264 -preset slow -level 3.0 -b 700k -s 720x404 FILEOUT
327
328 upload new video from local PC 
329
330         scp <your_super_cool_kitten_flick.mp4>  <babooshka>:BABOOSHKA.TV/VIDEO/
331
332 download new video from youtube (on device)
333
334         youtube-dl -f 'bestvideo[vcodec=avc1][height<=720]+bestaudio/best[abr<=120]' --merge-output-format mp4 -o '%(playlist_index)s - %(title)s.%(ext)s' <youtube link>
335
336 click PLAY button and enjoy :)
337
338 ## Debug
339
340         tail -F /tmp/babooshka.log
341
342 ## Known bugs
343
344 - Not changing the state on finish (WATCHED) if video has been resumed (time of resuming is disregarded)
345
346 ## Todo
347
348 - WiFi auto-reconnect, probably *sudo iw dev wlan0 set power_save off* would be helpful
349 - youtube-dl, autoupdate
350 - youtube-dl download from downloadlist
351 - check free storage space
352 - auto removing of old videos + commenting in playlist
353 - splash info, Nth video from COUNT videos
354 - Make a single package
355
356 ## Extras 
357
358 Download this nice babooshka.tv [sticker and logo](https://repository.interplaymedium.org/babooshka.tv/babooshka_sticker.svg)
359
360 ![babooshka.tv found enclosure and cool sticker](https://repository.interplaymedium.org/babooshka.tv/babooshka.tv.enclosure_front.jpeg)
361
362 ## License
363
364 Copyright © 2020 Dmitry Shalnov [interplaymedium.org]
365
366 Licensed under the Apache License, Version 2.0 (the "License");
367 you may not use this files except in compliance with the License.
368 You may obtain a copy of the License at
369
370         http://www.apache.org/licenses/LICENSE-2.0
371
372 Unless required by applicable law or agreed to in writing, software
373 distributed under the License is distributed on an "AS IS" BASIS,
374 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
375 See the License for the specific language governing permissions and
376 limitations under the License.
377
378
379
380
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717