ChromeCast will randomly show the photos stored in Google Photos, so I'm happy to have a memory story with my family. However, since only the photos are shown, I was wondering if I could somehow play the movie, but orz does not add any functions at all. Even if you cast a movie with a smartphone app, it's only a function to randomly play all the movies from the Youtube playlist, and if a long movie (such as a movie of a playground) starts to flow in these apps, it will be the last , It doesn't end until all of it is played, so I feel that this is not the case. It seemed that I could easily play mp4 using pychromecast, so I made it quickly.
--Linux environment (I use WSL) --HTTP server (I use apache)
Put the movie in a suitable folder that can be seen on WSL. I think I put about 1,000. These movies need to be in a format that can be played directly on ChromeCast. Convert unsupported movies with ffmpeg and align the time stamps. (The following is a movie with the extension .MOV converted and saved using the extension .m4v.)
for i in *.MOV; do ffmpeg -y -i $i -s 1920x1080 -vcodec libx264 -r 30 -b 1024k -acodec aac -ac 2 -ar 44100 -ab 128k -f mp4 `basename $i .MOV`.m4v; done
for i in *.MOV; do day=`date '+%Y%m%d%H%M' -r $i`; touch -t $day `basename $i .MOV`.m4v; done
Set up so that those movie files can be displayed on the http server. For apache, you can create a symbolic link under/var/www/html.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
import time
import pychromecast
import random
import os
import datetime
from datetime import datetime as dt
playtime=20
waittime=3 #The time this program will wait for the time it takes to switch videos on ChromeCast
moviefolder="/mnt/e/movie/" #Where the movie is stored on the server
httpurl="http://192.168.1.10/movie/" #The location of the movie on the server as seen from ChromeCast
# List chromecasts on the network, but don't connect
services, browser = pychromecast.discovery.discover_chromecasts()
# Shut down discovery
pychromecast.discovery.stop_discovery(browser)
# Discover and connect to chromecasts named Living Room
chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=["Living"])
[cc.device.friendly_name for cc in chromecasts]
cast = chromecasts[0]
# Start worker thread and wait for cast device to be ready
cast.wait()
print(cast.device)
print(cast.status)
mc = cast.media_controller
stopflag=0
while stopflag == 0:
tempfile=random.choice(os.listdir(moviefolder))
print(tempfile)
filepath = moviefolder+tempfile
dt = datetime.datetime.fromtimestamp(os.stat(filepath).st_mtime)
key = dt.strftime('%Y/%m/%d %H:%M:%S')
print(key)
parser = createParser(filepath)
meta = extractMetadata(parser)
duration = meta.get("duration")
print(duration.seconds)
starttime=int(random.uniform(0,duration.seconds-playtime))
if starttime < 0:
starttime = 0
mc.play_media(httpurl+tempfile, 'video/mp4', current_time=starttime)
if duration.seconds < playtime:
time.sleep(duration.seconds+waittime)
else:
time.sleep(playtime+waittime)
After that, if you open the terminal and run this program, it will automatically play the randomly selected movie for 20 seconds. The children looked nostalgic. Occasionally, wedding movies come out and I think it's hard to see without such an app. It seems that the manner of pychromecast will change considerably, so it seems better to look at Honke HP. Actually, I kick it from PHP and start it, automatically reload the page in 20 seconds, and play it only while the browser is open on the smartphone.
https://blog.sky-net.pw/article/26
Recommended Posts