Initial commit
[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 -- most popular 
26
27         +-----------------------+ 3
28         |               data -> +---------------------o +3.3V
29         |      ______________   |
30         |     /                 |
31         |    (                  | 2  
32         |     \______________ + +---------------------o GND
33         |                       |
34         |                       | 1
35         |                     - +---------------------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            MOSFET         |
52              ___      |---'
53       o-----|___|-----|
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     irw
235
236 Record your own (if you have no compatible remote control or incomplete config)
237
238     systemctl stop lircd.socket
239     systemctl stop lircd.service
240     
241     record with own key names
242     irrecord --disable-namespace
243
244     systemctl start lircd.socket
245     systemctl start lircd.service
246
247 Force raw record mode (normally not required)
248     
249     irrecord -f -d /dev/lirc0 ~/lirc.conf
250
251 ## Main package installation
252
253     cd /home/pi/
254     git clone <this repo> (see above)
255     cd BABOOSHKA.TV/
256
257 Make sure that all .sh files inside are executable (have x flag)
258
259     ls --all 
260
261 if required make them *chmod +x *.sh*
262
263 ### Early stage systemd service (launching led driver and creating splash image)
264
265 Create */etc/systemd/system/splash.service* file and add there
266
267     [Unit]  
268     DefaultDependencies=no  
269     After=local-fs.target  
270     
271     [Service]  
272     StandardInput=tty  
273     StandardOutput=tty  
274     ExecStart=/home/pi/BABOOSHKA.TV/early_init.sh  
275       
276     [Install]  
277     WantedBy=sysinit.target  
278
279 Activate the service 
280
281     sudo systemctl enable splash.service
282
283 ### On boot launcher
284
285 Add this line to */etc/rc.local*
286
287    sudo -H -u pi /home/pi/babooshka.tv/start.babooshka.sh > /dev/null &
288
289 reboot and test :)
290
291         systemctl reboot
292
293 if everything has been done properly, you will see the splash babooshka.tv logo
294
295 - add testing video in *~/BABOOSHKA.TV/VIDEO/* directory
296 - check playlist (that the video link has been added)
297 - click PLAY on your remote 
298 - if something went wrong, see Debug section below
299
300 ## Cosmetic polishing 
301
302 Edit */boot/cmdline.txt*. Make sure that you have *console=tty3 quiet consoleblank=0* and *logo.nologo*, this is my cmdline: 
303
304     console=serial0,115200 console=tty3 quiet consoleblank=0 loglevel=1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait logo.nologo
305
306 Disable blinking cursor (probably not required)
307
308     vt.global_cursor_default=0
309
310 Remove tty login service to eliminate blinking cursor
311     
312     sudo systemctl disable getty@tty1 
313
314 ## Additional software 
315
316 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. 
317
318     apt install mkvtoolnix python-pip
319     pip install -U youtube-dl
320
321 ## Usage
322
323 converting video (note -level 3.0 option! it is required for RPi HW codec)
324
325     ffmpeg -i FILEIN -vcodec libx264 -preset slow -level 3.0 -b 700k -s 720x404 FILEOUT
326
327 upload new video from local PC 
328
329     scp <your_super_cool_kitten_flick.mp4>  <babooshka>:BABOOSHKA.TV/VIDEO/
330
331 download new video from youtube (on device)
332
333     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>
334
335 click PLAY button and enjoy :)
336
337 ## Debug
338
339     tail -F /tmp/babooshka.log
340
341 ## Known bugs
342
343 - Not changing the state on finish (WATCHED) if video has been resumed (time of resuming is disregarded)
344
345 ## Todo
346
347 - WiFi auto-reconnect, probably *sudo iw dev wlan0 set power_save off* would be helpful
348 - youtube-dl, autoupdate
349 - youtube-dl download from downloadlist
350 - check free storage space
351 - auto removing of old videos + commenting in playlist
352 - splash info, Nth video from COUNT videos
353 - Make a single package
354
355 ## Extras 
356
357 Download this nice babooshka.tv [sticker and logo](https://repository.interplaymedium.org/babooshka.tv/babooshka_sticker.svg)
358
359 ![babooshka.tv found enclosure and cool sticker](https://repository.interplaymedium.org/babooshka.tv/babooshka.tv.enclosure_front.jpeg)
360
361 ## License
362
363 Copyright © 2020 Dmitry Shalnov [interplaymedium.org]
364
365 Licensed under the Apache License, Version 2.0 (the "License");
366 you may not use this files except in compliance with the License.
367 You may obtain a copy of the License at
368
369     http://www.apache.org/licenses/LICENSE-2.0
370
371 Unless required by applicable law or agreed to in writing, software
372 distributed under the License is distributed on an "AS IS" BASIS,
373 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
374 See the License for the specific language governing permissions and
375 limitations under the License.
376
377
378
379
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717