<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Colas.Nahaboo.net - video</title>
    <subtitle>Colas Nahaboo personal site, with discussions about programming code, web and computing topics, surfing and SUPing, and various musings.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://colas.nahaboo.net/tags/video/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://colas.nahaboo.net"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-12-02T00:00:00+00:00</updated>
    <id>https://colas.nahaboo.net/tags/video/atom.xml</id>
    <entry xml:lang="en">
        <title>liverec: a YouTube recorder for split-track live streams</title>
        <published>2026-12-02T00:00:00+00:00</published>
        <updated>2026-12-02T00:00:00+00:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://colas.nahaboo.net/code/liverec-a-go-recorder-for-split-track-live-streams/"/>
        <id>https://colas.nahaboo.net/code/liverec-a-go-recorder-for-split-track-live-streams/</id>
        
        <content type="html" xml:base="https://colas.nahaboo.net/code/liverec-a-go-recorder-for-split-track-live-streams/">&lt;p&gt;On the 25th of November, my France Inter recording script broke. Not gracefully, not with a warning: every capture simply failed with &lt;code&gt;ERROR: [dailymotion] x17qw0a: Requested format is not available&lt;/code&gt;. I record the France Inter live stream regularly (I listen to it at 3x speed in the evening, see my &lt;a href=&quot;/blog/why-a-walkpad-and-which-one&quot;&gt;walkpad&lt;/a&gt; for what I do while listening), and this had worked for years.&lt;/p&gt;
&lt;h2 id=&quot;what-broke&quot;&gt;What broke?&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-broke&quot; aria-label=&quot;Anchor link for: what-broke&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Both Dailymotion and YouTube stopped offering a single combined live stream. They now publish video-only and audio-only HLS tracks, side by side. My old bash script asked yt-dlp for &lt;code&gt;-f best&lt;/code&gt;, and &lt;code&gt;best&lt;/code&gt; means &quot;best single file with both video and audio&quot;. That format does not exist anymore, so yt-dlp refused to start.&lt;/p&gt;
&lt;p&gt;The obvious fix was &lt;code&gt;-f bv*+ba/b&lt;/code&gt;: best video plus best audio, and let yt-dlp merge them with ffmpeg. I patched the bash script, it worked, done. But alas, I kept noticing something else on the longer recordings.&lt;/p&gt;
&lt;h2 id=&quot;the-desync&quot;&gt;The desync&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-desync&quot; aria-label=&quot;Anchor link for: the-desync&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;When yt-dlp downloads two separate HLS tracks, it runs two independent downloaders that write their own files, then ffmpeg muxes them at the end. On a live stream that lasts hours, the two downloaders drift. I got recordings where the audio slowly slid out of sync with the video, and once a one-hour capture where the video froze completely while the audio kept going. The bash script had no watchdog, so it happily recorded forty minutes of a still image.&lt;/p&gt;
&lt;p&gt;I have been recording live streams since the youtube-dl days, and this fragility was always there, hidden because the combined stream was a single download. The split tracks made it visible.&lt;/p&gt;
&lt;h2 id=&quot;what-i-decided-to-do-is-write-it-in-go&quot;&gt;What I decided to do is write it in Go&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-decided-to-do-is-write-it-in-go&quot; aria-label=&quot;Anchor link for: what-i-decided-to-do-is-write-it-in-go&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;So I wrote &lt;strong&gt;&lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/ColasNahaboo/liverec&quot;&gt;liverec&lt;/a&gt;&lt;/strong&gt;, a small Go recorder for exactly these split-track live streams. The core idea is one ffmpeg process per segment, with both HLS inputs given to ffmpeg at the same time, so ffmpeg&#39;s own HLS demuxer keeps the tracks aligned by PTS. No independent downloaders, thus no drift.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #4C4F69; background-color: #EFF1F5;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #1E66F5;font-style: italic;&quot;&gt;./liverec&lt;/span&gt;&lt;span style=&quot;color: #40A02B;&quot;&gt; -mode master -failover dmfi 2h /0/FranceInter/show.mp4 fi&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The details that matter, all learned the hard way during four one-hour test runs (2 modes × 2 sites) on 2026-11-26:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;master mode&lt;/strong&gt; (the default, and the reliable one): liverec fetches the master playlist, pins the chosen video variant and the best audio rendition to local files, and ffmpeg reads those. In my tests, feeding the two media-playlist URLs directly to ffmpeg (the &lt;code&gt;tracks&lt;/code&gt; mode) once froze the video on Dailymotion while audio continued; master mode had no failure in any run.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A stall watchdog on video frames only.&lt;/strong&gt; Because it watches the video, a frozen picture with running audio triggers a segment restart. That is precisely the failure yt-dlp never noticed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hourly rotation&lt;/strong&gt; into crash-safe &lt;code&gt;.ts&lt;/code&gt; segments, then a faststart MP4 remux at the end if you asked for &lt;code&gt;.mp4&lt;/code&gt;, so you lose at most the current segment on a crash.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ffprobe validation&lt;/strong&gt; of each segment&#39;s A/V start offset (my runs: ≤ 50 ms), and an optional failover URL, so France Inter on Dailymotion can fall back to the YouTube stream.&lt;/li&gt;
&lt;li&gt;URL resolution still goes through yt-dlp, of course, that part it does well.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;why-go&quot;&gt;Why Go?&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-go&quot; aria-label=&quot;Anchor link for: why-go&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The old script was bash, and bash is fine until you need a watchdog, a state machine for segment restarts, and playlist parsing. Then it is a thousand lines of quoting. The whole of liverec is under a thousand lines of Go, single static binary, standard library only, and it cross-compiles to my NAS in one command. See my &lt;a href=&quot;/blog/go-single-binary-fanatic&quot;&gt;go-single-binary-fanatic&lt;/a&gt; post, nothing new there.&lt;/p&gt;
&lt;h2 id=&quot;why-not-patch-yt-dlp&quot;&gt;Why not patch yt-dlp&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-not-patch-yt-dlp&quot; aria-label=&quot;Anchor link for: why-not-patch-yt-dlp&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Yt-dlp refuses to accept any issue or patch that has been made with the help of AI, even only brainstorming with it. It is their right, so I just made this small dedicated program instead of submitting a bug report or even a patch to them.&lt;/p&gt;
&lt;h2 id=&quot;installation-usage-and-more-info&quot;&gt;Installation, Usage, and more info&lt;a class=&quot;zola-anchor&quot; href=&quot;#installation-usage-and-more-info&quot; aria-label=&quot;Anchor link for: installation-usage-and-more-info&quot;&gt;🔗&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/ColasNahaboo/liverec&quot;&gt;github.com/ColasNahaboo/liverec&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;AI co-written: don&#39;t like, don&#39;t use.&lt;/p&gt;
</content>
        
    </entry>
</feed>
