Android YouTube Image Wallpaper

 Android YouTube Image Wallpaper


I've been using a live view of the beautiful Charles River in Boston as my Android wallpaper and lockscreen image for about a year now. Beside being beautiful, this gives me an idea of the weather when I'm not near a window. Up until yesterday, I was using the great app HelloMundo. HelloMundo periodically grabs any image (not video) from the web and uses that as the Android wallpaper and lockscreen image. Yesterday, HelloMundo stopped working. It could be that the image source I was using from the Museum of Science went away to be replaced by a live streaming YouTube video. I figured there must be some combination of open source tools plus Tasker that I could use to replace this functionality.


Parts List


This entire project is based on this excellent post.

Get a Single Frame from a YouTube Video

This is done with a combination of youtube-dl and ffmpeg. youtube-dl gets the video and ffmpeg saves one frame as an image at the timestamp you specify. For a live streaming video like mine, the timestamp is alway 0:00.

ffmpeg -ss "0:00" -i $(youtube-dl -f 95 --get-url \
 "") \
 -vframes 1 -q:v 2 -y "/usr/local/ampps/www/MOS.jpg"

(I placed a few escaped newlines, "\", in that command for the post. Feel free to remove them.)

The -ss is followed by the video timestamp, the -f is which quality video to download (use -F to list all possible qualities), the -vframes is how many frames to save and the -y is to where to save the frame. I save the frame to the DocumentRoot of my Apache web server on the same machine. MOS is short for Museum of Science as that is where the webcam is located. BTW, this command takes 4 minutes to run regardless of video quality.

Add a Timestamp Watermark to the Image

I wanted to know how current the image is that ends up being my "Weather Conditions Wallpaper". I found that Imagemagick can add anything as a watermark, so I used Imagemagick to add the current date and time to the image.

convert /usr/local/ampps/www/MOS.jpg -fill white -pointsize 20 \
 -annotate +10+670  "`date`" /usr/local/ampps/www/MOS_Date.jpg
Pretty self-explanatory command. Add the current date and time in white at position 10,670 to the image resulting in a new image.

Create a Shell Script and Run Every 30 Minutes

I added those two commands to a shell script I named and added a cron entry to run every 30 minutes. You use the crontab -e command to add an entry to cron.

# Pull a frame from the MOS live stream every 30 minutes and drop in web root for Tasker
*/30 * * * * /bin/bash /home/dennis/ > /dev/null 2>&1

Create Task and Profile in Tasker to Get and Use the Image

This is pretty standard if you have used Tasker before. I have included the full Tasker XML export below for you to import into your copy of Tasker. Just change the task to reflect the IP/FQDN of your web server. 

  • Create a Tasker HTTP Request Task that gets the image from your webserver, updates wallpaper, updates lockscreen
  • Create a Tasker Profile to run this task every N minutes. I set my profile to run every 15 minutes as I was not sure if I would miss the 30 minute cron job by one minute and be 59 minutes behind. 

Tasker XML for Import

<TaskerData sr="" dvi="1" tv="5.10.1">
<Profile sr="prof6" ve="2">
<nme>Wallpaper 15 Minutes</nme>
<Time sr="con0">
<Task sr="task5">
<Action sr="act0" ve="7">
<Bundle sr="arg0">
<Vals sr="val">
<>&lt;StringArray sr=""&gt;&lt;;%http_file_output
File Output
Will always contain the file's full path even if you specified a directory as the File to save.&lt;/;&lt;;%http_response_code
Response Code
The HTTP Code the server responded&lt;/;&lt;;%http_cookies
The cookies the server sent in the response in the Cookie:COOKIE_VALUE format. You can use this directly in the 'Headers' field of the HTTP Request action&lt;/;&lt;;%http_headers()
Response Headers
The HTTP Headers the server sent in the response. Each header is in the 'key:value' format&lt;/;&lt;;%http_response_length
Response Length
The size of the response in bytes&lt;/;&lt;/StringArray&gt;</>
<Int sr="arg1" val="0"/>
<Int sr="arg10" val="0"/>
<Int sr="arg11" val="0"/>
<Str sr="arg2" ve="3">http://[IP-OF-YOUR-WEBSERVER]/MOS_Date.jpg</Str>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3">Pictures/Wallpapers</Str>
<Int sr="arg8" val="30"/>
<Int sr="arg9" val="0"/>
<Action sr="act1" ve="7">
<Int sr="arg0" val="0"/>
<Str sr="arg1" ve="3">Pictures/Wallpapers/MOS_Date.jpg</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Action sr="act2" ve="7">
<Int sr="arg0" val="1"/>
<Str sr="arg1" ve="3">Pictures/Wallpapers/MOS_Date.jpg</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>

Thank You

That's it. Not earth-shattering, but I thought writing this down might help someone else. Thank you for taking the time to read this post and I welcome your feedback.