dotlinux blog

How to Stream Favorite Movies (MP4 Files) From Linux Terminal to Your Apple TV

Want to enjoy your personal movie collection on the big screen without juggling cables or transferring files? This guide shows you how to stream MP4 videos directly from your Linux terminal to your Apple TV. We'll leverage open-source tools and AirPlay technology to create a seamless streaming experience - all without leaving the comfort of your command line. Whether you're a terminal enthusiast or just looking for efficient media solutions, this method puts you in control of your media playback.

2026-05

Table of Contents#

  1. Prerequisites
  2. Installation Guide
  3. Discovering Your Apple TV
  4. Streaming with PyATV
  5. Alternative Methods
  6. Troubleshooting
  7. Security Considerations
  8. Conclusion
  9. 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 pyatv

Note: Use pip3 install --user pyatv if avoiding system-wide installs

3. Discovering Your Apple TV#

Scan your network to find the Apple TV's IP address and credentials:

atvremote scan

Example 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 pair

Follow 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.mp4

Advanced Control Options#

OptionDescriptionExample
--positionStart at specific time (HH:MM:SS)--position 00:15:30
--loopContinuously loop playback--loop
--muteStart with audio muted--mute
--no-progressHide 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:

CommandFunctionSyntax
PausePause playbackatvremote --id YOUR_DEVICE_ID pause
PlayResume playbackatvremote --id YOUR_DEVICE_ID play
StopEnd streamingatvremote --id YOUR_DEVICE_ID stop
SeekJump positionatvremote --id YOUR_DEVICE_ID set_position 3600 (in seconds)

5. Alternative Methods#

AirPlay via DLNA#

If AirPlay issues persist, use DLNA with minidlna:

  1. Install media server:

    sudo apt install minidlna
    sudo systemctl enable minidlna
  2. Configure /etc/minidlna.conf:

    media_dir=~/Videos
    friendly_name=Linux Media Server
  3. 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#

IssueSolution
Pairing failsRestart both devices and disable VPNs
Choppy playbackLower 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 syncCheck CPU usage: htop (transcoding overload)
DRM-protected filesDecrypt first with tools like HandBrake CLI
Black screen onlyConfirm video codec compatibility: ffprobe video.mp4

Enable debug logs:

atvremote --id YOUR_DEVICE_ID --debug stream_file video.mp4

7. 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.

9. References#

  1. PyATV Official Documentation
  2. FFmpeg Streaming Guide
  3. Apple AirPlay Specifications
  4. MiniDLNA Setup Guide
  5. Video Codec Compatibility Matrix