AndroidHDMI for Channels (ah4c): A virtual channel tuner using HDMI Encoder(s) + streaming stick(s)

Hopefully @spammedeeper or @kprice will see this, as I didn't write the osprey/dtvstream scripts.

They're not too complicated as I recall though. Do you have any sense of where they're failing?

1 Like

I think they are just trying to change channels too soon.

@krazijoe Two things:

  1. On Osprey make sure your resume/wake action goes to last channel, not Home Screen.

Settings > Preferences > Turn off “start at home”

  1. I did have a similar issue with premature tuning when box was not fully awake or there was small network latency. This became worse after recent updates, but not regular enough for me to commit changes to project. Your network is just different. Try the following change in the prebmitine.sh script.
  • Find section for adbwake (near bottom)
  • First line has the key code wake-up then a pause of sleep. Change sleep from 2 to 4. Should look something like this:

$adbTarget shell input keyevent KEYCODE_WAKEUP; sleep 4;

  • Increase that sleep number as much as you need to provide reliable tuning in your Environment.

Please note the wake-up time from deep sleep is slower, when Osprey has powered down for more than 4 hours. You will just need to play to tune best for your use case.

Excuse any Typos. Added this post via phone.

3 Likes

I got an ADTH tuner box, which I'm hoping to use as an android endpoint. Any way i can find out the deep links for the tuner itself?

thinking it's "com.tolka.airialtv_atsc_launcher" but I'm admittedly a little over my head on this one

Question. How would I delay sending video feed to channels for five or so seconds after my script issues the following command?

adb -s $TUNERIP shell "am start -a android.intent.action.VIEW -d  https://watch.sling.com/1/channel/"$content_id"/watch"

There's no easy way that I'm aware of -- however it may be possible...

There's support for a "T" process, using env var CMDx, where x corresponds to ENCODERx_URL. The value would typically be an ffmpeg command, and whatever is output from ENCODERx_URL would be the input, and stdout is sent to CDVR (using a "-" at the end of the ffmpeg command).

So, if you can craft an ffmpeg command that would delay output for 5 seconds, followed by passing the stream through -- that could work. Hopefully this could be done with minimal impact on the ah4c proxy. This is untested by me, but @KompilerDJ used this approach for taking input from various capture cards, and sending it to CDVR after some ffmpeg encoding.

You can look at a couple of examples of ffmpeg commands on the sullrich/ah4c GitHub repo. I believe he used this approach for Magewell and Hauppauge capture cards. Look for the .env files with those card names.

Figured it out. It required using the command section of the env file to direct the tuning process to a simple script.

I am using a uray network encoder and the goal was to have the video feed from slingtv or YouTube tv start when the program I am trying to tune starts instead of showing the home screen of the app and the launching process.

env looks like this:

CHANNELSIP="192.168.1.199"
IPADDRESS="192.168.1.199"
STREAMER_APP="scripts/onn/slingtv"
#STREAMER_APP="scripts/shieldtv/youtubetv"
NUMBER_TUNERS="3"
ALERT_SMTP_SERVER="smtp.gmail.com:587"
ALERT_AUTH_SERVER="smtp.gmail.com"
ALERT_EMAIL_FROM=""
ALERT_EMAIL_PASS=""
ALERT_EMAIL_TO=""
ALERT_WEBHOOK_URL=""
ALLOW_DEBUG_VIDEO_PREVIEW="FALSE"


CMD1="scripts/onn/test/tuner1.sh"
ENCODER1_URL="http://192.168.1.168/8.ts"
TUNER1_IP="192.168.1.133:5555"

tuner1.sh is a simple script to delay for a couple of seconds and then tune:

#!/bin/bash
sleep 6
ffmpeg  -i $ENCODER1_URL -f mpegts -codec\:v copy -codec\:a copy -

1 Like

@boukmandutty
I feed my channels through xteve/threadfin and I use this ffmpeg command to start the stream delayed.

ffmpeg -i [URL] -ss 3 -c:v copy -c:a copy -metadata:s:a:0 language=eng -f mpegts pipe:1

Been working really nicely for me, let me know how you go.

So mine works perfectly in terms of delay but each tuner requires its own tuner.sh script. Hoping somebody who knows more than rudimentary scripting can show me how to direct it all to one script where the variable changes according to which tuner calls in.

In the meantime it works with the desired delay and app startup process does not show in the recorded videos.

@boukmandutty

An ffmpeg command, used directly in CMDx, was more what I was recommending -- similar to what @tree2369 is suggesting. Simplifying his ffmpeg command slightly, I tested this and it works as a value for CMD1 (as an example):

ffmpeg -i $ENCODER1_URL -ss 5 -c:v copy -c:a copy -f mpegts -

I'm not seeing an upside to using an additional script, but if that's the way you want to do it, you could pass the encoder URL as an argument in the CMDx value:

CMD1="scripts/onn/test/tuner.sh $ENCODER1_URL"

with a tuner.sh something like this:

#!/bin/bash
sleep 6
ffmpeg -i $1 -f mpegts -codec\:v copy -codec\:a copy -
1 Like

Sorry for the delayed update. I did manage to get the CMDx value to work with the ffmpeg command using what @tree2369 suggested. The problem was apparently the method I was using to attempt the delay. Once I tried the -ss 5 instead of -itsoffset it worked fine.

I have the following Blackmagic card

Am I able to load this onto the machine with the card and it will be able to pick up the HDMI inputs automatically?

https://www.amazon.com/Blackmagic-Design-DeckLink-Quad-Recorder/dp/B07PGT6RQC?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A3HD8EJ3VC7GWS

Seems like it should work, as it's similar to the Magewell card @KompilerDJ has used. Check the sullrich/ah4c repo for an example of the env vars required. Look at magewell.env.

Will intel quicksync with an intel i5 gen 10 be good enough to handle 4 streams? Or will I need an additional GPU

With the network encoders, like the LinkPi or URayCoder, the whole idea is for the device to do the encoding and present the stream via URL. The system running ah4c is simply a proxy, with minimal requirements.

When it comes to these capture cards, you're somewhat on your own as far as figuring out what the requirements are -- as few use them with ah4c. If you already have the card, and everything to support using it -- go for it. But, if you're going to have to spend any money, you might be better off investing in a network encoder.

Understood! I will report back after I find time to test it. Is there a concisions streaming service that works best with deep linking? Are there deeplinking for Peacock Events?

Walmart has onn Google TV 4K Pro on sale for $39.00, and possibly $5 Walmart Cash for some accounts. Very similar to the popular $20 onn 4K, but this has Ethernet which makes it very interesting for the price.

Happy Streaming!

@bnhf
Been awhile but I am working on my scripts for the AppleTV Spectrum setup again...It is still working fantastic overall.
Currently still running bnhf/ah4c:appletv.test2

I have added "select" button press after a delay to clear the overlay on the few occasions it comes up. It doesn't mess anything up if the overlay isn't there... So this was easier than trying to implement tesseract for this.
Added to bmitune.sh file

sleep 45
atvremote --storage-filename /root/.android/.pyatv.conf -s $streamerIP select

I am working on solving 2 additional issues...

  1. Keep "tuner" running for a predetermined amount of time before completely closing the app. This allows faster tuning when surfing.
  2. Send key press after so long to keep "Are You Still Watching" from coming up.

Issue 1
I believe I have a solution for the first but am having problems implementing it. When stopbmitune.sh is called I am attempting to run a 2nd script from within it called stopdelay.sh

stopdelay.sh

#!/bin/bash

streamerIP="$1"

echo ""$$"" > /root/.android/$streamerIP.stop.txt
sleep 300
echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Killing Feed on ATV "$streamerIP""  >> /root/.android/$streamerIP.txt
atvremote --storage-filename /root/.android/.pyatv.conf -s $streamerIP home delay=250 home delay=5000 up delay=250 up delay=5000 home

This stopdelay.sh script passes the current streamerIP in from stopbmitune.sh. It then records the process number into a file that I use to kill this script in my bmitune.sh script if I tune another channel before the timer shuts down the stream.
All these scripts are located in the scripts directory and have the same attributes including the right to be executed.

Here is the stopbmitune.sh script I am trying to use...

#!/bin/bash

streamerIP="$1"
channelID="$2"

tunekill="$(< /root/.android/$streamerIP.tune.txt)"
kill $tunekill

echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Running stopbmitune.sh..."  >> /root/.android/$streamerIP.txt

/opt/scripts/atv/spectrum/stopdelay.sh $streamerIP &

I have tried many different versions to run the second script with no luck...
Here are some of them

stopdelay.sh $streamerIP
/opt/scripts/atv/spectrum/stopdelay.sh $streamerIP &
/opt/scripts/atv/spectrum/stopdelay.sh "192.168.1.54" &
/opt/scripts/atv/spectrum/stopdelay.sh $streamerIP

./opt/scripts/atv/spectrum/stopdelay.sh $streamerIP &
/bin/bash /opt/scripts/atv/spectrum/stopdelay.sh $streamerIP

And others I can't remember right now.
I believe I need the & at the end so this script runs but allows the stopbmitune.sh script to finish without waiting for stopdelay.sh to finish. This allows the tuner to be marked as "ready for use" and tune the next channel without waiting.

Also here is the bmitune.sh

#!/bin/bash

channelID="$1"
streamerIP="$2"

echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Running bmitune.sh..."  >> /root/.android/$streamerIP.txt
echo ""$$"" > /root/.android/$streamerIP.tune.txt
	
delaykill="$(< /root/.android/$streamerIP.stop.txt)"
kill $delaykill

echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Tuning Channel "$channelID" on ATV "$streamerIP""  > /root/.android/$streamerIP.txt
atvremote --storage-filename /root/.android/.pyatv.conf -s $streamerIP launch_app=spectrumTV://watch.spectrum.net/livetv/$channelID

sleep 45
atvremote --storage-filename /root/.android/.pyatv.conf -s $streamerIP select
echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Sent Select Command to Clear Menu on ATV "$streamerIP""  >> /root/.android/$streamerIP.txt

sleep 10
title="`atvremote --storage-filename /root/.android/.pyatv.conf -s $streamerIP title`"
echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Playing "$title""  >> /root/.android/$streamerIP.txt


sleep 13200
echo ""$(date +"%Y-%m-%d %I:%M:%S%p")" ...Sending Still Watching IR Commands" >> /root/.android/$streamerIP.txt
#No commands sent through atvremote work to stop "Are You Still Watching" from coming up.
#This will be used to send IR commands probably using curl to prevent this instead.

I think I just need to figure out how to run the stopdelay.sh inside of stopbmitune.sh and I will have this. I am not an expert on shell scripts and just can't seem to figure out the right way to do it :man_shrugging:

Issue2
IR commands... looking for the best/cheapest way to do this just using something really simple like curl commands from my scripts sent to a microcontroller like ESP8266 or ir hub that can receive curl commands and send to multiple "tuners". Don't want to add a bunch of extra stuff like HomeLab/HomeAssistant. Let me know if anyone has suggestions.

I believe I may have figured out Issue 1...
I created the bash file stopdelay.sh using Notepad++ on windows...
Even when I edited it to a very simple script and tried to run it I could not get it to run right.
Blank lines would even give errors running from the CLI

I made a copy of my working stopbmitune.sh and cleared everything out of it, renamed to stopdelay.sh and started puting stuff back in it.
Have now successfully ran a simple script from both command line and from inside scripts... :man_shrugging:

This is now working to call it from inside script...
/opt/scripts/atv/spectrum/stopdelay.sh $streamerIP &

Feeling pretty dumb about this now. :upside_down_face:

@bnhf

Apparently I am wrong about what tells the system that a tuner is available...
With my updated scripts the stopbmitune.sh script runs and finishes immediately after calling
/opt/scripts/atv/spectrum/stopdelay.sh $streamerIP &

I can then watch the tuners run out the timer in stopdelay.sh before shutting down...BUT the tuners are not freed up until this stopdelay.sh finishes so there must be another lock somewhere...
Is there a variable i can set to tell ah4c that the tuner is now available?

Edit #1:
Looking at logs and it looks like it is not "finishing" the stopbmitune.sh until after the stopdelay.sh finishes. So it looks like the & at the end is not doing what I thought it would...I will keep looking for the correct command structure.

Edit #2:
Using "exit 0" at end of stopbmitune.sh doesn't appear to work either.

Edit #3:
I verified that the proc for stopbmitune.sh is finishing within 5 seconds using ps -p $PID
I also used ...

/opt/scripts/atv/spectrum/stopdelay.sh $streamerIP &
job_id=$! # Get the job ID of the background process
disown -h $job_id #Disown the job

in the stopbmitune to make sure that the script is disowned...
Yet the log for ah4c keeps taking the full 5 min to say stopbmitune.sh has finished and release the tuner even though I can see in the command line that is has finished in 5 seconds and the process is now done and gone.