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

I don't use this "tee" feature myself -- but I don't believe the approach you're using is quite right. With a device like this, my understanding is that you need specify the device, and then tee the output to ffmpeg for processing.

Something like this, based on the Magewell example in the repo:

CMD1_DEVICE="/dev/video0"
CMD1="ffmpeg -thread_queue_size 1024 -y -hwaccel cuda -hwaccel_output_format cuda -f v4l2 -i $CMD1_DEVICE -thread_queue_size 1024 -f pulse -i  alsa_input.pci-0000_08_00.0.stereo-fallback  -c:v h264_nvenc -b:v 70M -minrate 50M -maxrate 95M -bufsize 150M  -vf 'hqdn3d=1.5:1.5:6:6,scale=3840:2160:flags=lanczos,unsharp=5:5:1.5:5:5:0.0' -c:a eac3 -strict -2 -b:a 6144000 -ar 48000 -af 'volume=2.0' -vsync 1 -async 1 -f mpegts -"

I don't think the Magewell capture utility factors in...

I see...

I was using the magewellts application because it appears to use far less system resources than the ffmpeg command, and because it allows for the loading of an EDID that allows bistreaming.

magewell2ts -i 1 -w EDID/ProCaptureHDMI-Atmos.bin -s 100 -c h264_qsv -q 10 -m

When ffmpeg is used it seems to umpix stereo to multichannel instead of pushing the original multichannel through.

The problem with the command above though is that the video begins to record at the Home Screen before the app is loaded and so the first couple of seconds registers as stereo audio . This leads to the video being identified in channels dvr as having two channels.

When the same video is viewed with vlc with the codec information displayed I can see that the moment the app (youtubetv or max for eg.) is loaded and the show starts the audio format changes to multichannel (5.1).

If I use a video editor to trim the part of the show that displays the android tv Home Screen then channels dvr displays the correct audio information. I figured if I could combine the command with ffmpeg I could delay when the recording of the show begins and do away with the android tv Home Screen section.

I wonder if you could start magewell2ts (and load your app) either in prebmitune.sh, or bmitune.sh (before the virtual tuning process begins) and send the output to a named pipe (use nohup and execute it in the background so the script continues).

That pipe name would be the same one you specify for CMD1_DEVICE. You could then do whatever other post processing you want with ffmpeg using CMD1.

The unknown here would be whether ah4c would accept a named pipe as a device, but I think it'd be worth a shot.

Still cant seem to get the delay going even when I move the turning function around. Can you say a bit more about the named pipe?

prebmitune.sh

#!/bin/bash
MAX_LAUNCH="com.wbd.stream"
MAX_NAME="com.wbd.beam.BeamActivity"
APP_NAME="com.google.android.apps.youtube.tvunplugged.activity.MainActivity"
APP_LAUNCH="com.google.android.youtube.tvunplugged"
content_file="/opt/opendct/contentid.txt"
content_id=
TUNERIP="$1"
STATIONIP="$2"

#Make Sure adb is up and connected
#sh /home/moisebuntu/Scripts/startadb.sh

# Wake up
sh startsystem.sh
adb -s $TUNERIP shell input keyevent KEYCODE_WAKEUP

# Read content_id from file
if [ -f "$content_file" ]; then
  content_id=$(grep -w "^$2" "$content_file" | cut -d " " -f3)
fi

# Check if content_id is empty
if [ -z "$content_id" ]; then
  echo "Invalid option or content_id not found in $content_file"
  exit 1
fi

#make sure adb is connected to device
adb connect $1

#check channel number and tune accordingly
if (( 810 <= $2 && $2 <= 818  ));then
        adb -s $1 shell "am start -a android.intent.action.VIEW -d https://play.max.com/channel/watch/"$content_id"" -n $MAX_LAUNCH/$MAX_NAME
	
    else

        adb -s $1 shell "am start -a android.intent.action.VIEW -d  https://tv.youtube.com/watch/"$content_id"" -n $APP_LAUNCH/$APP_NAME
fi


exit

And bmitune.sh:

#!/bin/bash

echo "$1"  > /tmp/temp.txt
echo "$2" >> /tmp/temp.txt
echo "$3" >> /tmp/temp.txt

STATION="$1"
TUNERIP="$2"
CONTENT_FILE="contentid.txt"
CONTENT_ID=""


#activate device
sleep 5 &
wait 

if [ $2 == "192.168.1.12" ]; then 


magewell2ts -i 1 -w /home/christophe/ah4c/EDID/ProCaptureHDMI-Atmos.bin -s 100 -c h264_qsv -q 10  -m

fi

if [ $2 == "192.168.1.13" ]; then 

magewell2ts -i 2 -w /home/christophe/ah4c/EDID/ProCaptureHDMI-Atmos.bin -s 100 -c h264_qsv -q 10  -m  

fi

if [ $2 == "192.168.1.14" ]; then 

magewell2ts -i 3 -w /home/christophe/ah4c/EDID/ProCaptureHDMI-Atmos.bin -s 100 -c h264_qsv -q 10  -m  

fi

if [ $2 == "192.168.1.15" ]; then 

magewell2ts -i 4 -w /home/christophe/ah4c/EDID/ProCaptureHDMI-Atmos.bin -s 100 -c h264_qsv -q 10  -m

fi

exit

Just to clarify, this project only supports MPEG-TS from the encoders correct? I have an issue with one of my encoders where when it sees the signal drop from my providers stb (don't ask lol) it trashes the timestamps in the recording and therefore channels playback gets messed up.

Was wanting to try HLS instead but I don't think any of the encoder projects here support that.

Update: if the code is just doing http proxy from encoder to channels, HLS should work.

Solved. Had to make things a little less elegant by adding an extra bash script in the mix to facilitate the desired delay.

@andi330 I use Xfinity remotely myself with ah4c and a LinkPi encoder. This works very well. In fact, I've developed an autocrop feature specifically for this combination of app and encoder, that eliminates the black borders on 4 sides present on a number of the premium movie channels. Specifically, the black borders on the sides are removed while maintaining the aspect ratio.

While having a remote ah4c setup, with a remote CDVR server (which can feed a local CDVR server) is a proven approach, there's another way that should work. You should be able to have a local ah4c setup, with a local CDVR server, provided the streaming sticks connected to the encoder are running Tailscale with the remote location as an exit node.

If I were using that approach, I'd incorporate a tailscale ping into the tuning script to confirm the streaming stick is connected via Tailscale before executing the rest of the virtual tune. Also, it's important for either approach, that both the local and remote locations have decent Internet -- with good upload and download speeds.

@bnhf @spammedeeper

Link Pi w/ (3) Osprey units

Everything is going great with the above setup. Decided to move it from my Study floor to the equipment closet. Just shut down power to encoder and boxes and moved.

Had to reenable Adb control to each box after the move. Will that be the norm if I lose extended power or is there a way to maintain that setting? Units are on a UPC but that's only short term power.

Not the norm. Are you using the recommended ah4c Docker Compose, and do you have the binding-related env vars set to a writable directory?

Yes, I’m using the standard compose. I checked the data folder and in the Adb folder, the adbkey and the adbkey.pub are from a couple of months ago (from when installed). The adbkey.5037 was written today.

Maybe it’s a setting on the Osprey devices. I'll relook at those.

The only time I have needed to accept key again is after a major update to Android on the Osprey. I think this happened once (Android 10 to 11). Possible you got an update? Or maybe you didn't fully "remember" the RSA key pairing last time you accepted?

There are email notifications in AH4C if you want to get notified on failures. For the most part, my AH4C has been running issue free with Osprey's and a LinkPi for 18 months. So well I don't really think about it.

I think I figured why. When I added the 3rd Osprey a couple of months ago, I had to reauthorize all units but I failed to reserve the ip on my router. After I moved them, only Osprey 3 popped up on the Allow screen. Once I reauthorized that one, it overwrote the file and I had to reauthorize the other two.

I figure Osprey 3's ip changed and that caused the issue. Osprey 3 is on a separate switch (need a 16 port switch rather than a daisy chain)

Has anyone figured out how to tune into Cartoon Network on DTVStream with this? I have an onn device and firetv and it selects the first thing it finds and its the schedule to the Channel and not the stream. Bizarre. Any ways to work around that?
Example

Using a deeplink?

Yeah...that didn't work when I tried that. I may have to modify the script based on "special" channels like that. Not that hard

OK, I figured it out. Modifying this seems to work.

  directvTune="input keyevent KEYCODE_MEDIA_PLAY_PAUSE; sleep 1; \
               input keyevent KEYCODE_DPAD_DOWN; \
               input keyevent KEYCODE_DPAD_DOWN; \
               input keyevent KEYCODE_DPAD_DOWN; \
               input keyevent KEYCODE_DPAD_RIGHT; \
               input keyevent KEYCODE_DPAD_CENTER; \
               input keyevent KEYCODE_DPAD_CENTER"

If that works, great. The deeplink would obviously be best. Where did you get your deeplink from?

The best I got is

CNe~2336facb-8e11-c83b-b49f-4e54682104e3

but I tried that and I got a black screen

I don't think deeplinks work anymore. Either that or I'm doing it wrong. I got a firetv and a onn puck

EDIT: Spoke too soon. Had to modify the bmitune.sh file a bit. We're good :smiley:

Been a while since I commented in this thread. Been playing with ADBTuner a bunch lately, mostly for fun. Looked at my AH4C setup and realize it's been running for about a year, reliably without having to touch anything. Just wanted to say thanks again to BNHF and contributors.

2 Likes

For you DirecTV Users, something I'm watching. DirecTV is doing all sorts of bundles, some channels and some apps. Where it's cool to get ad-Tier apps thrown in, that's is not terribly interesting.

What I am watching is the mention of partnerships to bundle apps into a single Interface when you use a Gemini Device. Since DirecTV loves to add everything to the guide, I hope this means all the live channels from the Apps end up as channel numbers tunable by AH4C.

I will keep you posted.

Reference: DIRECTV Users Will Get Access to ESPN's New Service at Launch This Fall | Cord Cutters News

I'm not anticipating much at this junction. I've seen a couple of screen shots in other forums showing the "Hulu App" and "ESPN App" channel in the guide. Hopefully, we’ll be able to log into the Hulu and Disney apps with our DTV credentials. We can already do that with the ESPN app. I’m thinking about getting another Osprey to monitor this as I really don’t want to tinker with my AH4C Osprey's which are working great.