{"id":7430,"date":"2021-11-21T23:13:22","date_gmt":"2021-11-22T04:13:22","guid":{"rendered":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/?p=7430"},"modified":"2022-07-01T08:57:37","modified_gmt":"2022-07-01T12:57:37","slug":"video-autoplay-on-pi-zero-w","status":"publish","type":"post","link":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/2021\/11\/video-autoplay-on-pi-zero-w\/","title":{"rendered":"Video Autoplay on Pi Zero W"},"content":{"rendered":"<p>Brett&#8217;s working on a new RC car featuring an entertainment center. The media&#8217;s powered by a <a href=\"https:\/\/www.raspberrypi.com\/products\/raspberry-pi-zero-w\/\">Raspberry Pi Zero W<\/a>. A <a href=\"https:\/\/www.waveshare.com\/wiki\/2inch_LCD_Module\">Waveshare 2 inch LCD<\/a> currently provides the display. The instructions from Waveshare at the link are actually very good, but the following has a few additional notes and collected links.<\/p>\n<p><a href=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7431\" src=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-1024x768.jpg\" alt=\"\" width=\"530\" height=\"398\" srcset=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-1024x768.jpg 1024w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-300x225.jpg 300w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-768x576.jpg 768w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-1536x1152.jpg 1536w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001392292-2048x1536.jpg 2048w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/><\/a><\/p>\n<h2>Connection<\/h2>\n<p>I&#8217;m trying to do all this setup without hooking up a keyboard or display. I spent a good while trying to configure networking via USB OTG but that&#8217;s still a work-in-progress. So instead I set up WiFi so I could SSH in.<\/p>\n<p>First order of business is imaging the micro-SD card with Raspberry Pi OS using the <a href=\"https:\/\/www.raspberrypi.com\/software\/\">Raspberry Pi Imager<\/a>, available for Arch via the <a href=\"https:\/\/aur.archlinux.org\/packages\/rpi-imager\/\">AUR<\/a>. In this article I&#8217;m working with:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nLinux raspberrypi 5.10.63+ #1459 Wed Oct 6 16:40:27 BST 2021 armv6l GNU\/Linux\r\n<\/pre>\n<p>On the imaged micro-SD card you <code>touch boot\/ssh<\/code> to enable SSH.<\/p>\n<p>In <code>boot<\/code> on the micro-SD card create the file <code>wpa_supplicant.conf<\/code> with contents:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncountry=US # Your 2-digit country code\r\nctrl_interface=DIR=\/var\/run\/wpa_supplicant GROUP=netdev\r\nnetwork={\r\n    ssid=&quot;YOUR_NETWORK_NAME&quot;\r\n    psk=&quot;YOUR_PASSWORD&quot;\r\n    key_mgmt=WPA-PSK\r\n}\r\n<\/pre>\n<h2>Display<\/h2>\n<p>Next is configuration to enable the display.<\/p>\n<p>Add the following in <code>boot\/config.txt<\/code> on the micro-SD card:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n    hdmi_force_hotplug=1\r\n    hdmi_cvt=640 480 60 1 0 0 0\r\n    hdmi_group=2\r\n    hdmi_mode=1\r\n    hdmi_mode=87\r\n    display_rotate=0\r\n<\/pre>\n<p>Also in <code>boot\/config.txt<\/code>, comment out:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n    dtoverlay=vc4-fkms-v3d\r\n    max_framebuffers=2\r\n<\/pre>\n<p>Pop the micro-SD into the device and boot. If you don&#8217;t have Bonjour or Avahi setup to resolve <code>raspberrypi.local<\/code>, look on your router&#8217;s devices table to get the IP address for the Pi. The default login is <code>pi<\/code>\/<code>raspberry<\/code>. Change the password with <code>passwd<\/code> to be extra safe.<\/p>\n<p>Enable SPI via <code>raspi-config<\/code>, under the Interfaces menu, and reboot.<\/p>\n<p>Install the <a href=\"http:\/\/www.airspayce.com\/mikem\/bcm2835\/\">BCM2835 library<\/a> from AirSpayce.<\/p>\n<p>Install <a href=\"http:\/\/wiringpi.com\/\">wiringPi<\/a>. It&#8217;s seemingly no longer included in the Pi OS default image or its repositories so you&#8217;ll have to download &amp; install manually.<\/p>\n<p>Install and run <a href=\"https:\/\/www.waveshare.com\/wiki\/2inch_LCD_Module\">Waveshare&#8217;s demos<\/a> to make sure the display&#8217;s wiring is correct.<\/p>\n<p>Install framebuffer copy and start it running:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install -y cmake p7zip-full\r\nwget https:\/\/www.waveshare.com\/w\/upload\/8\/8d\/Waveshare_fbcp-main.7z\r\n7z x Waveshare_fbcp-main.7z\r\ncd waveshare_fbcp-main\r\nmkdir build\r\ncd build\r\ncmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..\r\nmake -j\r\nsudo .\/fbcp &amp;\r\n<\/pre>\n<p>Install VLC using the <code>vlc<\/code> package.<\/p>\n<p>In SSH, use <code>cvlc -f movie.mp4<\/code> to run the video after uploading it to the device.<\/p>\n<div style=\"width: 530px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-7430-1\" width=\"530\" height=\"530\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001501472.mp4?_=1\" \/><a href=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001501472.mp4\">https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0001501472.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<h2>Autoplay<\/h2>\n<p>To have the video autoplay at boot, create the file <code>\/etc\/xdg\/autostart\/movie-autoplay.desktop<\/code> with contents:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n  &#x5B;Desktop Entry]\r\n  Name=Movie Autoplay\r\n  Exec=cvlc -f --loop --no-video-title \/home\/pi\/Videos\/autoplay.mp4\r\n<\/pre>\n<p>You also need to have <code>fbcp<\/code> start on boot, via adding it to <code>\/etc\/rc.local<\/code> (just before <code>exit<\/code>).<\/p>\n<h2>Video Crop<\/h2>\n<p>For what it&#8217;s worth, the video playing above is captured from <a href=\"https:\/\/www.youtube.com\/watch?v=EL-D9LrFJd4\">YouTube<\/a>. That video has black borders, which can be measured and cropped out quickly using ffmpeg. Use the <code>cropdetect<\/code> utility filter to determine the border size:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffmpeg -i cowboy-bebop.mp4  -vf cropdetect -f null -\r\n<\/pre>\n<p>This will report a bunch of lines like the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;Parsed_cropdetect_0 @ 0x558f57561c00] x1:52 x2:373 y1:0 y2:239 w:320 h:240 x:54 y:0 pts:2156154 t:89.839750 crop=320:240:54:0\r\n<\/pre>\n<p>The reported crop parameters can then be passed to <code>ffplay<\/code> to test and <code>ffmpeg<\/code> to recut the video:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nffplay -vf crop=320:240:54:0 cowboy-bebop.mp4\r\nffmpeg -i cowboy-bebop.mp4 -vf crop=320:240:54:0 -c:a copy cowboy-bebop-320px.mp4\r\n<\/pre>\n<h2>Splash Screen<\/h2>\n<p>To replace the bootloader splash screen, just replace <code>\/usr\/share\/plymouth\/themes\/pix\/splash.png<\/code>. The image will seemingly work best if it&#8217;s 1024&#215;768 even though that&#8217;s not the display resolution.<\/p>\n<p><a href=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7433\" src=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-1024x768.jpg\" alt=\"\" width=\"530\" height=\"398\" srcset=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-1024x768.jpg 1024w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-300x225.jpg 300w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-768x576.jpg 768w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-1536x1152.jpg 1536w, https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2021\/11\/PXL_20211122_0003055072-2048x1536.jpg 2048w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brett&#8217;s working on a new RC car featuring an entertainment center. The media&#8217;s powered by a Raspberry Pi Zero W. A Waveshare 2 inch LCD currently provides the display. The instructions from Waveshare at the link are actually very good, but the following has a few additional notes and collected links. Connection I&#8217;m trying to &hellip; <a href=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/2021\/11\/video-autoplay-on-pi-zero-w\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":7431,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[257,400],"class_list":["post-7430","post","type-post","status-publish","format-standard","hentry","category-code","tag-featured","tag-pi"],"_links":{"self":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts\/7430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/comments?post=7430"}],"version-history":[{"count":10,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts\/7430\/revisions"}],"predecessor-version":[{"id":7445,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts\/7430\/revisions\/7445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/media\/7431"}],"wp:attachment":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/media?parent=7430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/categories?post=7430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/tags?post=7430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}