# How to Configure RTMP Streaming to YouTube Live with Stream Key Using AtomCam Tools

> Learn how to configure RTMP streaming to YouTube Live using your stream key with AtomCam Tools. Easily broadcast your feed by following simple setup steps.

- Repository: [Mitsuru Nakada/atomcam_tools](https://github.com/mnakada/atomcam_tools)
- Tags: how-to-guide
- Published: 2026-03-07

---

**Enable RTMP in the web UI, set the audio codec to AAC or off, and enter your full YouTube RTMP URL including the stream key to start broadcasting.**

AtomCam Tools enables direct RTMP broadcasting from compatible cameras to platforms like YouTube Live without external software. This guide explains how to configure RTMP streaming to YouTube Live with stream key using the built-in web interface and underlying shell scripts. The entire pipeline runs inside the container, reading settings from [`/tmp/hack.ini`](https://github.com/mnakada/atomcam_tools/blob/main//tmp/hack.ini) and forwarding the local RTSP stream via `go2rtc`.

## Prerequisites: Audio Codec Requirements

Before enabling RTMP, you must configure the audio codec correctly. According to the source code in [`web/source/vue/Setting.vue`](https://github.com/mnakada/atomcam_tools/blob/main/web/source/vue/Setting.vue) (lines 267–272), the RTMP toggle is **disabled unless** the audio is set to **AAC** or turned **off** entirely.

The UI enforces this restriction because YouTube Live requires AAC audio for RTMP ingestion. The `SettingSwitch` component checks these conditions before allowing activation:

```javascript
:value="(config.RTSP_VIDEO0 == 'on' && (config.RTSP_AUDIO0 == 'AAC' || config.RTSP_AUDIO0 == 'off')) ? config.RTMP_ENABLE : 'off'"
:disabled="config.RTSP_VIDEO0 !== 'on' || (config.RTSP_AUDIO0 !== 'AAC' && config.RTSP_AUDIO0 !== 'off')"

```

Navigate to the audio settings first and verify `RTSP_AUDIO0` is set to `AAC` before proceeding.

## Configuring RTMP in the Web UI

Once the audio codec is compatible, enable RTMP streaming through the Settings page:

1. Open the AtomCam Tools web interface and locate the **RTMP** section.
2. Toggle **RTMP Enable** to `on`.
3. Enter the complete RTMP URL in the **RTMP URL** field.

The URL must follow YouTube's format:

```

rtmp://a.rtmp.youtube.com/live2/<YOUR_STREAM_KEY>

```

Paste your YouTube stream key after the final slash. Do not add extra query parameters or paths. The UI saves these values to [`/tmp/hack.ini`](https://github.com/mnakada/atomcam_tools/blob/main//tmp/hack.ini) as `RTMP_ENABLE` and `RTMP_URL`.

## How the RTMP Pipeline Works

The streaming pipeline is orchestrated by [`overlay_rootfs/scripts/rtspserver.sh`](https://github.com/mnakada/atomcam_tools/blob/main/overlay_rootfs/scripts/rtspserver.sh). When the service starts, it reads the configuration and prepares the environment:

### Environment Variable Export

At lines 101–104 of [`rtspserver.sh`](https://github.com/mnakada/atomcam_tools/blob/main/rtspserver.sh), the script extracts the RTMP URL and sets a publish flag:

```bash
export RTMP_URL=$(awk -F "=" '/^RTMP_URL *=/ {print $2}' $HACK_INI)
[ "$RTMP_ENABLE" = "on" -a "$RTMP_URL" != "" ] && export PUBLISH="publish"

```

This `PUBLISH` variable controls whether go2rtc attempts to forward the stream.

### go2rtc Configuration Generation

The script dynamically builds [`/tmp/go2rtc.yaml`](https://github.com/mnakada/atomcam_tools/blob/main//tmp/go2rtc.yaml). Lines 22–25 contain a conditional block that only activates when `PUBLISH` is set:

```yaml
${PUBLISH:'zzzz'}:
    video0:
        - ${RTMP_URL:}

```

When `PUBLISH=publish` is exported, this expands to create an active stream destination using your provided URL.

### Process Launch

At line 80, the script launches the streaming service:

```bash
/usr/bin/go2rtc $option >> /tmp/log/go2rtc.log &

```

go2rtc pulls video from the local v4l2rtspserver and pushes it to the YouTube RTMP endpoint defined in your configuration.

## Setting the YouTube Stream Key

The stream key is embedded directly in the RTMP URL. In [`hack.ini`](https://github.com/mnakada/atomcam_tools/blob/main/hack.ini), the configuration appears as:

```ini
RTMP_ENABLE=on
RTMP_URL=rtmp://a.rtmp.youtube.com/live2/abcd-efgh-ijkl-mnop
RTSP_AUDIO0=AAC

```

Replace `abcd-efgh-ijkl-mnop` with your actual YouTube Live stream key. The system forwards the entire URL to go2rtc, which handles the RTMP handshake and authentication automatically.

## Enabling Periodic Restart for 24/7 Streams

YouTube Live may terminate connections after approximately 24 hours. To maintain uninterrupted broadcasting, enable the **RTMP Restart Interval** in the UI (default: 240 minutes).

The watchdog logic at lines 46–52 of [`rtspserver.sh`](https://github.com/mnakada/atomcam_tools/blob/main/rtspserver.sh) monitors the elapsed time and restarts go2rtc periodically:

```bash

# Watchdog mode that restarts go2rtc every N minutes

if [ "$RTMP_RESTART" -gt 0 ]; then
    sleep $(($RTMP_RESTART * 60))
    restart_go2rtc
fi

```

Setting this value to `240` creates a fresh connection every four hours, preventing the daily timeout that disrupts long-duration streams.

## Configuration File Reference

The system stores runtime settings in [`/tmp/hack.ini`](https://github.com/mnakada/atomcam_tools/blob/main//tmp/hack.ini). A complete RTMP configuration for YouTube Live looks like this:

```ini
RTMP_ENABLE=on
RTMP_URL=rtmp://a.rtmp.youtube.com/live2/your-secret-stream-key
RTMP_RESTART=240
RTSP_VIDEO0=on
RTSP_AUDIO0=AAC

```

Ensure `RTMP_RESTART` is set to a positive integer (minutes) to enable the watchdog functionality.

## Summary

- **Audio requirement**: Set codec to **AAC** or **off** before enabling RTMP; the UI enforces this in [`Setting.vue`](https://github.com/mnakada/atomcam_tools/blob/main/Setting.vue).
- **URL format**: Use `rtmp://a.rtmp.youtube.com/live2/<STREAM_KEY>` with your key appended.
- **Pipeline**: [`rtspserver.sh`](https://github.com/mnakada/atomcam_tools/blob/main/rtspserver.sh) exports `RTMP_URL` and `PUBLISH`, then injects them into [`/tmp/go2rtc.yaml`](https://github.com/mnakada/atomcam_tools/blob/main//tmp/go2rtc.yaml).
- **Restart interval**: Configure a 240-minute restart interval to avoid YouTube's 24-hour connection limit.
- **Config location**: Settings persist in [`/tmp/hack.ini`](https://github.com/mnakada/atomcam_tools/blob/main//tmp/hack.ini) and are read by the startup script.

## Frequently Asked Questions

### Why is the RTMP toggle disabled in the web interface?

The toggle requires the audio codec to be set to **AAC** or **off**. According to [`web/source/vue/Setting.vue`](https://github.com/mnakada/atomcam_tools/blob/main/web/source/vue/Setting.vue), the component checks `config.RTSP_AUDIO0` and disables the switch if any other codec (like PCM or MP3) is selected. YouTube Live requires AAC audio for RTMP streams.

### Where do I find my YouTube stream key?

In YouTube Studio, navigate to **Go Live** > **Stream**. Copy the **Stream URL** and **Stream Key**, then combine them into a single URL: `rtmp://a.rtmp.youtube.com/live2/<KEY>`. Paste this complete string into the AtomCam Tools RTMP URL field.

### How do I keep the stream running for more than 24 hours?

Set the **RTMP Restart Interval** to `240` (minutes) in the UI. The [`rtspserver.sh`](https://github.com/mnakada/atomcam_tools/blob/main/rtspserver.sh) watchdog monitors this value and restarts go2rtc every four hours, preventing YouTube from dropping the connection after the daily timeout window.

### Can I stream to other platforms besides YouTube?

Yes. Any RTMP endpoint works as long as you provide the full URL including the stream key. The system is platform-agnostic; simply replace the YouTube URL with your custom RTMP server address in the `RTMP_URL` field.