Table of Contents#
- Prerequisites
- Installation Guide
- Discovering Your Apple TV
- Streaming with PyATV
- Alternative Methods
- Troubleshooting
- Security Considerations
- Conclusion
- References
1. Prerequisites#
Before starting, ensure you have:
- Linux machine (Debian/Ubuntu used in examples)
- Apple TV (3rd gen or later with AirPlay enabled)
- Both devices on the same local network
- Terminal access with sudo privileges
- MP4 videos (H.264/AAC codecs recommended for compatibility)
- Minimum Python 3.7 installed
2. Installation Guide#
Install required packages:
# Update package list
sudo apt update
# Install core dependencies
sudo apt install -y python3-pip ffmpeg
# Install pyatv
pip3 install pyatvNote: Use
pip3 install --user pyatvif avoiding system-wide installs
3. Discovering Your Apple TV#
Scan your network to find the Apple TV's IP address and credentials:
atvremote scanExample output:
========================================
Name: Living Room Apple TV
Model/SW: Apple TV 4K, tvOS 17.0
Address: 192.168.1.42
MAC: AA:BB:CC:DD:EE:FF
Deep Sleep: False
Identifiers:
- 00000000-AAAA-BBBB-CCCC-123456789ABC
Note the IP address and identifier. Pair your Linux machine:
atvremote --id 00000000-AAAA-BBBB-CCCC-123456789ABC --protocol airplay pairFollow the on-screen pairing instructions on your Apple TV. Credentials save automatically to ~/.pyatv.conf.
4. Streaming with PyATV#
Basic Streaming Command#
Stream an MP4 file using this syntax:
atvremote --id YOUR_DEVICE_ID stream_file "path/to/video.mp4"Example:
atvremote --id 00000000-AAAA-BBBB-CCCC-123456789ABC stream_file ~/Videos/TheMatrix.mp4Advanced Control Options#
| Option | Description | Example |
|---|---|---|
--position | Start at specific time (HH:MM:SS) | --position 00:15:30 |
--loop | Continuously loop playback | --loop |
--mute | Start with audio muted | --mute |
--no-progress | Hide terminal progress bar | --no-progress |
Complete example:
atvremote --id YOUR_DEVICE_ID --position 00:05:00 stream_file "~/Movies/Inception.mp4"Playback Controls During Streaming#
Send commands while streaming:
| Command | Function | Syntax |
|---|---|---|
| Pause | Pause playback | atvremote --id YOUR_DEVICE_ID pause |
| Play | Resume playback | atvremote --id YOUR_DEVICE_ID play |
| Stop | End streaming | atvremote --id YOUR_DEVICE_ID stop |
| Seek | Jump position | atvremote --id YOUR_DEVICE_ID set_position 3600 (in seconds) |
5. Alternative Methods#
AirPlay via DLNA#
If AirPlay issues persist, use DLNA with minidlna:
-
Install media server:
sudo apt install minidlna sudo systemctl enable minidlna -
Configure
/etc/minidlna.conf:media_dir=~/Videos friendly_name=Linux Media Server -
Restart service:
sudo systemctl restart minidlna
Browse to Linux server via Apple TV's Computers app
Real-Time FFmpeg Transcoding#
For unsupported formats (MKV/AVI):
ffmpeg -i input.mkv -c:v h264_videotoolbox -c:a aac -f mpegts - | \
atvremote --id YOUR_DEVICE_ID stream_file -6. Troubleshooting#
| Issue | Solution |
|---|---|
| Pairing fails | Restart both devices and disable VPNs |
| Choppy playback | Lower resolution: ffmpeg -i input.mp4 -s hd720 ... |
| "No device found" | Verify network connection and firewall settings: sudo ufw allow out to 192.168.1.0/24 |
| Audio/video sync | Check CPU usage: htop (transcoding overload) |
| DRM-protected files | Decrypt first with tools like HandBrake CLI |
| Black screen only | Confirm video codec compatibility: ffprobe video.mp4 |
Enable debug logs:
atvremote --id YOUR_DEVICE_ID --debug stream_file video.mp47. Security Considerations#
- Restrict credentials access:
chmod 600 ~/.pyatv.conf - Revoke unused pairings: Settings > Remotes and Devices > AirPlay on Apple TV
- Stream over VPN for public networks
- Avoid running commands as root
8. Conclusion#
Streaming MP4 movies from Linux terminal to Apple TV provides a lightweight alternative to cloud services and USB transfers. Once configured, the atvremote solution offers quick access to your entire library while avoiding the overhead of graphical interfaces. For collections with varied formats, pairing FFmpeg transcoding with PyATV creates a versatile streaming pipeline. This terminal-based approach proves especially valuable for remote administration, low-resource systems, or simply satisfying that hacker-esque desire to control everything from command line.