<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rory Wilson on Medium]]></title>
        <description><![CDATA[Stories by Rory Wilson on Medium]]></description>
        <link>https://medium.com/@rory.wilson?source=rss-4f6e2ce1f71b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*54e0No83i8BOPV5H</url>
            <title>Stories by Rory Wilson on Medium</title>
            <link>https://medium.com/@rory.wilson?source=rss-4f6e2ce1f71b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:30:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rory.wilson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A CMS-backed website for a few pennies a month]]></title>
            <link>https://medium.com/@rory.wilson/a-cms-backed-website-for-a-few-pennies-a-month-e9f4c41d3ca7?source=rss-4f6e2ce1f71b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9f4c41d3ca7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[contentful]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Rory Wilson]]></dc:creator>
            <pubDate>Tue, 01 Sep 2026 12:57:11 GMT</pubDate>
            <atom:updated>2026-09-01T12:57:11.658Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B2gXk76Qr9PiEw8KKY5jGw.jpeg" /></figure><p><em>How to put Contentful in front of a statically exported Next.js site, host it on S3, point a real domain at it with Route 53, and rebuild automatically when an editor hits Publish.</em></p><p>Most “headless CMS” tutorials assume you’ll deploy the front end on Vercel, Netlify or a container that stays warm. That is a reasonable default. It is also more infrastructure than a small static website needs.</p><p>A chamber choir website is a good example. It changes a few times a year: a new concert title, a date, a TicketSource link, a YouTube embed, a paragraph about the musical director. It doesn’t need a Node server. It does need someone who is not a developer to change the content.</p><p>The pattern below does that on AWS static hosting. Content lives in <a href="https://www.contentful.com/">Contentful</a>. The site is still just files in a bucket. A webhook rebuilds those files when something is published.</p><p>Typical monthly cost for a site of this size, once the domain is paid for: <strong>low single-digit pounds</strong>, often less.</p><h3>The idea</h3><p>next export (or output: ‘export’ on newer <a href="https://nextjs.org/">Next.js</a>) turns the app into HTML, CSS and JS. There is no server left to ask Contentful anything at request time. So Contentful is queried <strong>during the build</strong>, the pages are written to disk, and those files are uploaded to S3.</p><p>When an editor publishes in Contentful, nothing on S3 changes by itself. A webhook has to start a new build.</p><pre>Editor hits Publish<br>        │<br>        ▼<br>Contentful webhook<br>        │<br>        ▼<br>GitHub repository_dispatch<br>        │<br>        ▼<br>GitHub Actions<br>  npm ci<br>  next build &amp;&amp; next export<br>  aws s3 sync out/ s3://your-bucket<br>  (optional) CloudFront invalidation<br>        │<br>        ▼<br>Live site updates a few minutes later</pre><p>That delay — two to five minutes, not two to five seconds — is the trade-off. For concert listings that’s no problem.</p><h3>Part 1 — A static site on AWS</h3><p>You need four pieces for a proper public site:</p><ol><li>An S3 bucket to hold the files</li><li>CloudFront in front of it (HTTPS, and the bucket can stay private)</li><li>A certificate in ACM</li><li>Route 53 records for example.org and <a href="http://www.example.org/">www.example.org</a></li></ol><p>S3’s own “static website hosting” endpoint is HTTP only. AWS is explicit about this: use CloudFront if you want HTTPS.</p><h3>1. Bucket</h3><p>Create a bucket. The name does not have to match the domain if CloudFront is the public face, but matching it (example.org) keeps things obvious.</p><ul><li>Block all public access: <strong>on</strong></li><li>Versioning: optional</li><li>Default encryption: SSE-S3 is enough</li></ul><p>Don’t tick “static website hosting”. CloudFront will read the objects directly via Origin Access Control.</p><h3>2. Certificate</h3><p>In <strong>ACM</strong>, switch the region to <strong>us-east-1</strong>. CloudFront only accepts certificates from that region.</p><p>Request a public certificate for:</p><ul><li>example.org</li><li><a href="http://www.example.org/">www.example.org</a></li></ul><p>Validate it with DNS. If the domain is already in Route 53, ACM can write the CNAME for you.</p><h3>3. CloudFront</h3><p>Create a distribution:</p><ul><li>Origin: the bucket’s REST endpoint (bucket.s3.region.amazonaws.com), not the website endpoint</li><li>Origin access: <strong>Origin Access Control (OAC)</strong></li><li>Viewer protocol policy: <strong>Redirect HTTP to HTTPS</strong></li><li>Alternate domain names: example.org and <a href="http://www.example.org/">www.example.org</a></li><li>Custom SSL certificate: the one from ACM</li><li>Default root object: index.html</li></ul><p>Next.js with trailingSlash: true exports concert pages as /concerts/2025/index.html. That plays nicely with S3 and CloudFront. If you do not use trailing slashes, add a CloudFront function or custom error response so /concerts/2025 still finds the file.</p><p>After the distribution is created, open the S3 bucket policy that CloudFront suggests and allow this distribution to s3:GetObject. Nobody else needs to read the bucket.</p><h3>4. Route 53</h3><p>In the hosted zone for the domain, create two <strong>A</strong> records, both aliases:</p><p>Name | Alias target</p><p>example.org | the CloudFront distribution</p><p><a href="http://www.example.org/">www.example.org</a> | the same distribution</p><p>Alias records to CloudFront are not billed as ordinary Route 53 queries.</p><p>If the domain is registered elsewhere, point the registrar’s nameservers at the Route 53 hosted zone and wait for DNS. That is the only part of this stack that cannot be rushed.</p><h3>5. Upload a first build by hand</h3><p>From the Next.js project:</p><pre>npm run build<br>npx next export          # Next 12<br># or, on Next 13+: output: &#39;export&#39; in next.config.js, then npm run build</pre><pre>aws s3 sync out/ s3://example.org --delete<br>aws cloudfront create-invalidation \<br>  --distribution-id EXXXXXXXXX \<br>  --paths &quot;/*&quot;</pre><p>Open the domain. If you see the site on HTTPS, the hosting half is done.</p><h3>Part 2 — Build pages from Contentful</h3><p>Install the Delivery SDK. Use the <strong>Content Delivery</strong> token, never the management token.</p><pre>npm install contentful</pre><pre>// lib/contentful.js<br>import { createClient } from &quot;contentful&quot;;</pre><pre>export const client = createClient({<br>  space: process.env.CONTENTFUL_SPACE_ID,<br>  accessToken: process.env.CONTENTFUL_DELIVERY_TOKEN,<br>});</pre><pre>export async function getHomepage() {<br>  const { items } = await client.getEntries({<br>    content_type: &quot;homepage&quot;,<br>    include: 2,<br>    limit: 1,<br>  });<br>  return items[0]?.fields ?? null;<br>}</pre><pre>export async function getConcerts() {<br>  const { items } = await client.getEntries({<br>    content_type: &quot;concert&quot;,<br>    order: &quot;-fields.date&quot;,<br>  });<br>  return items.map((item) =&gt; ({ id: item.sys.id, ...item.fields }));<br>}</pre><p>On the Pages Router (Next 12 and the style of many older sites):</p><pre>export async function getStaticProps() {<br>  return {<br>    props: {<br>      homepage: await getHomepage(),<br>      concerts: await getConcerts(),<br>    },<br>  };<br>}</pre><p>No revalidate. The HTML is fixed at export.</p><p>A content model that maps onto a small arts site:</p><pre>| Type | Userful fields |<br>| Homepage | next concert title, date, venue, blurb, ticket URL, hero image, YouTube id, press quote |<br>| Concert | title, date, venue, programme (rich text), flyer, year |<br>| Page | title, heading image, body |</pre><h3>Part 3 — Rebuild on publish</h3><p>GitHub Actions already knows how to install Node, run a build and talk to AWS. You just need two triggers: a push to main for code, and a repository_dispatch for content.</p><pre># .github/workflows/deploy.yml<br>name: Deploy site</pre><pre>on:<br>  push:<br>    branches: [main]<br>  repository_dispatch:<br>    types: [contentful-publish]<br>  workflow_dispatch:</pre><pre>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-node@v4<br>        with:<br>          node-version: 20<br>          cache: npm<br>      - run: npm ci<br>      - run: npm run build &amp;&amp; npx next export<br>        env:<br>          CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }}<br>          CONTENTFUL_DELIVERY_TOKEN: ${{ secrets.CONTENTFUL_DELIVERY_TOKEN }}<br>      - uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          aws-region: eu-west-2<br>      - run: aws s3 sync out/ s3://example.org --delete<br>      - run: &gt;<br>          aws cloudfront create-invalidation<br>          --distribution-id ${{ secrets.CLOUDFRONT_ID }}<br>          --paths &quot;/*&quot;</pre><p>— delete keeps S3 from accumulating old concert pages. Skip it until you are confident the out/ folder is the whole site.</p><p>Store these in the repo’s Actions secrets:</p><ul><li>CONTENTFUL_SPACE_ID</li><li>CONTENTFUL_DELIVERY_TOKEN</li><li>AWS_ACCESS_KEY_ID</li><li>AWS_SECRET_ACCESS_KEY</li><li>CLOUDFRONT_ID</li></ul><p>A dedicated IAM user that can only s3:PutObject, s3:DeleteObject, s3:ListBucket on that bucket, plus cloudfront:CreateInvalidation on that distribution, is enough. Better still, use GitHub OIDC and drop long-lived keys entirely.</p><p>Run the workflow by hand once from the Actions tab. If the site updates, the pipeline works. Only then add Contentful.</p><h3>Part 4 — The Contentful webhook</h3><p>Contentful does not “know” about GitHub Actions. It just POSTs JSON to a URL. GitHub’s URL is:</p><pre>https://api.github.com/repos/&lt;user&gt;/&lt;repo&gt;/dispatches</pre><p>Method: <strong>POST</strong>.<br>Triggers: Entry <strong>Publish</strong> and <strong>Unpublish</strong> (add Delete if removals should rebuild too).</p><h3>The Authorization header</h3><p>This is the part that fails first, usually with a 403.</p><p>GitHub expects:</p><pre>Authorization: Bearer ghp_xxxxxxxx</pre><p>In the Contentful webhook UI that is two fields:</p><p>Authorization: Bearer ghp_xxxxxxxx</p><p>Bearer is part of the <strong>value</strong>, with a space, then the token. It is not part of the key. Do not add quotes. Mark the header as <strong>secret</strong> so the token does not appear in webhook logs.</p><p>Add three ordinary headers as well:</p><p>Accept: application/vnd.github+json</p><p>User-Agent: Contentful-Webhook</p><p>X-GitHub-Api-Version: 2022–11–28</p><p>GitHub rejects requests with no User-Agent.</p><p>Finally change the payload to custom JSON:</p><pre>{<br>  &quot;event_type&quot;: &quot;contentful-publish&quot;<br>}</pre><p>That string must match types: [contentful-publish] in the workflow.</p><h3>The token</h3><p>A <strong>classic</strong> personal access token with the repo scope is the easiest option. Fine-grained tokens work if they have <strong>Contents: Read and write</strong> on that one repository. “Actions: read” is not enough for repository_dispatch.</p><h3>Test the token before you test Contentful</h3><pre>curl -i -X POST \<br>  -H &quot;Accept: application/vnd.github+json&quot; \<br>  -H &quot;Authorization: Bearer ghp_yourtoken&quot; \<br>  -H &quot;X-GitHub-Api-Version: 2022-11-28&quot; \<br>  -H &quot;User-Agent: Contentful-Webhook&quot; \<br>  https://api.github.com/repos/USER/REPO/dispatches \<br>  -d &#39;{&quot;event_type&quot;:&quot;contentful-publish&quot;}&#39;</pre><p>When curl returns 204, use Contentful’s <strong>Send test event</strong>. Then publish a real entry and watch the Actions tab.</p><h3>What this costs</h3><p><strong>AWS</strong>, for a choir-sized site (a few hundred megabytes, a few thousand visits a month):</p><ul><li>S3 storage: pennies</li><li>CloudFront: the free allowance covers this traffic</li><li>Route 53 hosted zone: £<strong>0.50 / month</strong></li><li>ACM certificate: free</li></ul><p><strong>GitHub Actions:</strong> public repos are inexpensive; private repos include a monthly minute allowance that is plenty for a handful of publishes.</p><p><strong>Contentful:</strong> the Free plan is enough to learn the shape of this stack (one starter space, 10 users, 100k API calls and 50 GB asset bandwidth a month). Read their current terms before you rely on Free for a production organisation — it is described as a learning plan. Lite exists if you outgrow that.</p><h3>What you give up</h3><ul><li><strong>Publish is not instant.</strong> Budget a few minutes.</li><li><strong>Draft preview</strong> needs a second pipeline or a hosted preview environment.</li></ul><h3>A sensible order of work</h3><ol><li>Export the Next site and serve it from S3 + CloudFront + Route 53 on HTTPS.</li><li>Put one content type in Contentful — the homepage is a good place to start — and read it in getStaticProps.</li><li>Add the GitHub Actions workflow and run it manually until S3 updates.</li><li>Add the webhook last.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9f4c41d3ca7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make a virtual choir — automatically]]></title>
            <link>https://medium.com/@rory.wilson/how-to-make-a-virtual-choir-automatically-bf8c2feb2111?source=rss-4f6e2ce1f71b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf8c2feb2111</guid>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[virtual-choir]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[choir]]></category>
            <dc:creator><![CDATA[Rory Wilson]]></dc:creator>
            <pubDate>Thu, 28 May 2020 13:37:56 GMT</pubDate>
            <atom:updated>2020-05-28T13:37:56.287Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to make a virtual choir — automatically</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V41Tb63wHOxaMrgnr8Ke2Q.png" /><figcaption>Javascript code</figcaption></figure><p>In my <a href="https://medium.com/@rory.wilson/how-to-make-a-virtual-choir-8aa4aca58821">last article</a> I went through the various ways in which you can put together a virtual choir, from how to think about the piece you choose, to your instruction materials and the tools you can use to put the final video together.</p><p>The process I went through was, on the whole, quite manual. You have to manually align your audio, manually arrange your videos, cut and crop things yourself, etc. As I’m a software developer with a bit of experience in pipeline video editing I thought about how much of this process could we automate? What challenges would we have, and how much manual labour could we replace with something faster.</p><p>If you want to skip to the end, you can take a look at my <a href="https://github.com/rory-wilson/virtual-choir-tools">virtual choir tools repo</a> on github.</p><h3>Ffmpeg is awesome</h3><p><a href="https://ffmpeg.org/">FFmpeg</a> is a great open source tool for managing audio and video. It’s run completely from the command line, which means that we can write scripts to automate the process and call various commands when appropriate. It can be a bit daunting and opaque, so I’ve laid out the steps I’ve taken.</p><h3>The approach</h3><p>I decided I wanted a tool to do the following things:</p><ol><li>Extract the mp3 audio from all the videos</li><li>Detect the first noise (which should be a clap) then use that to</li><li>Create an audio and video clip starting at the first noise, deinterlaced</li></ol><p>Using the output from those clips to create an final video with a series of cuts, with different files in a grid.</p><p>This would allow me to fully automate the video production pipeline.</p><h3>1 Extracting the audio</h3><p>Video files are big. Audio files are not (as big!). It makes sense to extract the audio first and use the audio as our guide when we’re cropping etc.</p><p>This is straightforward:</p><blockquote>ffmpeg -i in.mov -y -map 0:a -c libmp3lame -q:a 2 out.mp3</blockquote><h3>2 Detect the first noise</h3><p>Ffmpeg has a tool for detecting silences, which we can run against the audio we just extracted (which will be a lot faster than running it against the video):</p><blockquote>ffmpeg -i in.mp3 -af silencedetect=n=50dB:d=0.5,ametadata=print:file=out.txt -f null -</blockquote><p>What we’re doing here is detecting the silences and outputting it to a file (out.txt). The format of this is:</p><blockquote>frame:20 pts:21935 pts_time:0.497392<br>lavfi.silence_start=0<br>frame:317 pts:364079 pts_time:8.25576<br>lavfi.silence_end=8.27592</blockquote><p>Which is not bad, but not great. We need to parse it to JSON. To do that I wrote a simple RegEx parser to match the end times:</p><blockquote>/lavfi.silence_end=([\d.\d]+)/g;</blockquote><p>That way we can do match[0] to get the end of the first silence. Which should be our clap.</p><h3>3 Create a clip using the first clap as our starting point</h3><p>This is now straightforward. We just run ffmpeg’s clip command armed with our starting point. The only niggle is that the silence detection returns the values in seconds and the clip syntax requires a timecode. So I’ve installed moment to handle the formatting.</p><blockquote>const startString = moment().startOf(‘day’).seconds(output[0].end).format(‘HH:mm:ss’);</blockquote><blockquote>ffmpeg -y -ss ${startString} -i in.mov -c copy out.mov</blockquote><p>We also might as well create an MP3 from this file, since it will start at the clap and make lining up the audio easier. Just use the same command as in 1.</p><blockquote>ffmpeg -i out.mov -y -map 0:a -c libmp3lame -q:a 2 out.mp3</blockquote><p>Great. Now we have all our files lined up for free.</p><h3>4 Create a final video with a series of cuts</h3><p>Given we now have a bunch of videos that all start at the same time, we should be able to automate the process of assembling them.</p><h3>Making the grid</h3><p>Ffmpeg has commands for stacking videos both horizontally and vertically, so we should be able to use those to create the grid of singers we want. However, the commands for doing that also don’t scale the videos to size, so we also need to scale those videos while we stack them.</p><p>What we want is to create a series of grids, controlling how many videos are on screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/0*a4jLKgXp6ZYC_63b" /></figure><p>And we can use the xstack plugin for that:</p><blockquote>ffmpeg -i input0.mov -i input1.mov -i input2.mov -i input3.mov -filter_complex “[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]” -map “[v]” output</blockquote><p>This looks fairly complex, but if we break it up into sections you can see we specify the four videos we want as input files (-i input0.mov -i input1.mov etc), and then define our filter. Set set the number of inputs to 4 (inputs=4) and choose our layout, in this case “0_0|w0_0|0_h0|w0_h0“. There’s an <a href="https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos%20using%20xstack">excellent how-to</a> on the ffmpeg wiki that does into detail about the layout syntax but the way to think about this that the pipe | separates the individual videos, and 0_0 is the top-left video. The second video w0_0 will then be horizontally adjacent and the third vertically adjacent. The last will be both horizontally and vertically adjacent and therefore in the bottom right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/0*3UfUCEW9OtyDP-RT" /></figure><p>That’s for four (2x2). We can also do 9 (3x3), 16 (4x4), 25 (5x5) and 36 (6x6) or any other combination you see fit to use:</p><ul><li>4: ‘0_0|0_h0|w0_0|w0_h0’,</li><li>9: ‘0_0|w0_0|w0+w1_0|0_h0|w0_h0|w0+w1_h0|0_h0+h1|w0_h0+h1|w0+w1_h0+h1’,</li><li>16: ‘0_0|w0_0|w0+w1_0|w0+w1+w2_0|0_h0|w0_h0|w0+w1_h0|w0+w1+w2_h0|0_h0+h1|w0_h0+h1|w0+w1_h0+h1|w0+w1+w2_h0+h1|0_h0+h1+h2|w0_h0+h1+h2|w0+w1_h0+h1+h2|w0+w1+w2_h0+h1+h2’,</li><li>25: ‘0_0|w0_0|w0+w1_0|w0+w1+w2_0|w0+w1+w2+w3_0|0_h0|w0_h0|w0+w1_h0|w0+w1+w2_h0|w0+w1+w2+w3_h0|0_h0+h1|w0_h0+h1|w0+w1_h0+h1|w0+w1+w2_h0+h1|w0+w1+w2+w3_h0+h1|0_h0+h1+h2|w0_h0+h1+h2|w0+w1_h0+h1+h2|w0+w1+w2_h0+h1+h2|w0+w1+w2+w3_h0+h1+h2|0_h0+h1+h2+h3|w0_h0+h1+h2+h3|w0+w1_h0+h1+h2+h3|w0+w1+w2_h0+h1+h2+h3|w0+w1+w2+w3_h0+h1+h2+h3’,</li><li>36: ‘0_0|w0_0|w0+w1_0|w0+w1+w2_0|w0+w1+w2+w3_0|w0+w1+w2+w3+w4_0|0_h0|w0_h0|w0+w1_h0|w0+w1+w2_h0|w0+w1+w2+w3_h0|w0+w1+w2+w3+w4_h0|0_h0+h1|w0_h0+h1|w0+w1_h0+h1|w0+w1+w2_h0+h1|w0+w1+w2+w3_h0+h1|w0+w1+w2+w3+w4_h0+h1|0_h0+h1+h2|w0_h0+h1+h2|w0+w1_h0+h1+h2|w0+w1+w2_h0+h1+h2|w0+w1+w2+w3_h0+h1+h2|w0+w1+w2+w3+w4_h0+h1+h2|0_h0+h1+h2+h3|w0_h0+h1+h2+h3|w0+w1_h0+h1+h2+h3|w0+w1+w2_h0+h1+h2+h3|w0+w1+w2+w3_h0+h1+h2+h3|w0+w1+w2+w3+w4_h0+h1+h2+h3|0_h0+h1+h2+h3+h4|w0_h0+h1+h2+h3+h4|w0+w1_h0+h1+h2+h3+h4|w0+w1+w2_h0+h1+h2+h3+h4|w0+w1+w2+w3_h0+h1+h2+h3+h4|w0+w1+w2+w3+w4_h0+h1+h2+h3+h4’</li></ul><p>This is only part of the issue though. If we run the command above for 36 videos it will keep them individually at the original size! We’ll end up with a 16k video, which is crazy!</p><p>We need to scale the individual videos down, and also resize the output, to ensure all our grids are rendered at the right size. I chose 720p since I’m working on youtube.</p><p>Depending on the number of videos in your grid you can resize to different scales to retain quality. If you have 4 videos on screen you want to resize less than if you have 36.</p><p>I recommend the following built-in sizes:</p><ul><li>4: ‘vga’ 640x480</li><li>9: ‘qvga’ 320x240</li><li>16: ‘qvga’ 320x240</li><li>25: ‘qqvga’ 160x120</li><li>36: ‘qqvga’ 160x120</li></ul><p>We do this by amending the command above to:</p><blockquote>ffmpeg -i input0.mov -i input1.mov -i input2.mov -i input3.mov -s 1280x720 -filter_complex “[0:v] setpts=PTS-STARTPTS, scale=vga [a0];[1:v] setpts=PTS-STARTPTS, scale=vga [a1];[2:v] setpts=PTS-STARTPTS, scale=vga [a2];[3:v] setpts=PTS-STARTPTS, scale=vga [a3];[a0][a1][a2][a3]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]” -map “[v]” output</blockquote><p>This also adds the attribute <em>-s 1280x720</em> which ensures our output size will always be 720p.</p><h3>Making the cuts</h3><p>If we run the command above for our videos we’ll end up creating full-length videos. What if we want to cut between different grids? We need to only create grids for defined periods.</p><p>To do that, we need to specify start times and durations for our clips. Using the command above to create the grid, we need to add start (-ss) and duration (-t) switches:</p><blockquote>ffmpeg -ss 00:00:00 -t 30 -i input0.mov -ss 00:00:00 -t 30 -i input1.mov -ss 00:00:00 -t 30 -i input2.mov -ss 00:00:00 -t 30 -i input3.mov -s 1280x720 -filter_complex “[0:v] setpts=PTS-STARTPTS, scale=vga [a0];[1:v] setpts=PTS-STARTPTS, scale=vga [a1];[2:v] setpts=PTS-STARTPTS, scale=vga [a2];[3:v] setpts=PTS-STARTPTS, scale=vga [a3];[a0][a1][a2][a3]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]” -map “[v]” output</blockquote><p>This will now create a grid for the first 30 seconds of all the videos.</p><h3>Concatenating the videos</h3><p>Now we have several videos, with different grids of singers and we need to join them together.</p><p>We do this by running the concat command, but there’s a twist, we have to create a file to read that from, rather than just specifying all the files as inputs.</p><p>We create a file called filelist.txt that looks like this:</p><blockquote>file ‘grid0.mp4’<br>file ‘grid1.mp4’<br>file ‘grid2.mp4’<br>file ‘grid3.mp4’</blockquote><p>Then we can run the ffmpeg command:</p><blockquote>ffmpeg -y -f concat -safe 0 -i filelist.txt final.mov</blockquote><p>This adds all the files together with cuts into one finished video.</p><h3>5 Automating the automation</h3><p>This is good, but still fairly manual. I have to remember all these ffmpeg commands, and some of them are long. I’m lazy and don’t like typing.</p><p>Instead, I build a nodeJS application to automate the running of these scripts. You can see it at my <a href="https://github.com/rory-wilson/virtual-choir-tools">virtual choir tools repo</a>.</p><p>There’s two scripts: preprocessor and make.</p><p><strong>Preprocessor</strong> works by running against a folder. For every video it extracts the audio, crops it and copies it into an output folder.</p><p><strong>Make</strong> works using a JSON configuration file. We have an array of clips with start times, durations and the videos to include in order. Based on the number of videos it will automatically choose the layout and scale. It’ll create a video for each grid, and then in a final pass concatenate them into one video.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*woOQ0K7ElnY7kIuuAWt8yw.png" /></figure><p>This JSON file will create a minute long video, made up of two grids — one of 4 and one of 9 — both 30 seconds each, synchronised to each other at 720p resolution.</p><p>All I have to do now is mix my audio and add some titles.</p><h3>The Future</h3><p>It would be straightforward to port this to an AWS server-less architecture, where we could run these scripts in the cloud using beefier servers than my puny 2015 MacBook pro. Videos could be uploaded to an S3 bucket and jobs kicked off via an SQS queue. Not that it’s slow. Currently it takes &lt; 10 seconds per video to preprocess and 7 minutes to assemble a 3 minute video with 8 cuts: a considerable improvement on 2 days doing it by hand in DaVinci!</p><p>I’d also like to think about other repetitive jobs like noise cancellation and sound mix enhancements. ffmpeg has commands for that sort of stuff, but playing with it didn’t yield very good results, and needs a certain amount of user feedback to determine if it’s good. I’ve written some audacity macros to do the same job and they work pretty well.</p><p>However, since we have a silence map for each file, we should be able to use that silence as the training model for noise cancellation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf8c2feb2111" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make a virtual choir]]></title>
            <link>https://medium.com/@rory.wilson/how-to-make-a-virtual-choir-8aa4aca58821?source=rss-4f6e2ce1f71b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aa4aca58821</guid>
            <category><![CDATA[choir]]></category>
            <category><![CDATA[coronavirus]]></category>
            <category><![CDATA[virtual-choir]]></category>
            <dc:creator><![CDATA[Rory Wilson]]></dc:creator>
            <pubDate>Fri, 22 May 2020 12:35:19 GMT</pubDate>
            <atom:updated>2020-05-22T12:35:19.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A laptop showing video editing software" src="https://cdn-images-1.medium.com/max/1024/1*O0BAv7Sm1CHJhUlIE8hBnQ.jpeg" /></figure><p>In these times of lockdown, where we can’t get within 2 meters of each other and when singing together seems like a distant memory, one thing that has started to appear more and more online are so-called virtual choirs. These audio-only or video recordings are amazing: where tens or even hundreds of voices recorded separately come together in one sound.</p><p>They can vary tremendously from looking like a Zoom call to complex and <a href="https://www.youtube.com/watch?v=D7o7BrlbaDs">beautifully-produced</a> videos. However, if you’re a choir leader who wants to create one with your singers, I want to give you some hints and tips on how to produce your own.</p><h3>The basics</h3><p>For all that a virtual choir video can look like a zoom call, there’s no way to actually record all your singers in one go. Zoom is great, but as you’ll know if you’ve ever tried to use it for a rehearsal, it can’t cope with all the different time lags between each singer. It usually sounds a bit of a mess.</p><p>Instead, a virtual choir is really just lots of individual recordings that are then audio mixed and edited together. This has all the challenges of a usual choir performance — keeping good time, being together at the start and ends of phrases, vowel sounds etc. — mixed with all the I.T. challenges that lockdown has brought with it. Depending on your choir, some people may never have used their phone or computer to record themselves before.</p><p>It’s a job that will require you to have good planning, patience, good I.T. support skills and lots of time. It will get easier with each one you do!</p><h3>Preparation</h3><p>Time spent here can really save you effort later on, so this is worth considering before you charge head-long into the exciting stuff.</p><p>The first thing is to consider the piece of music. The more well-known it is by your choir the easier this will be to record and put together. If you’ve rehearsed it together then (hopefully!) a lot of the things you’d want in a performance will remain when people sing it on their own. Here’s some other things to consider:</p><ul><li>Homophonic is easier than polyphonic</li><li>Slow music is easier than fast music moving together</li><li>Accompanied is easier than unaccompanied</li><li>A consistent tempo is easier than a changing tempo</li></ul><p>Once you’ve chosen your piece of music, you need to make sure you have a digital edition of the music to work from — a PDF from CPDL is great.</p><p>To begin you need to create a couple of things for your singers to work from:</p><ul><li>A conducting video</li><li>A backing track</li><li>Instructions</li></ul><h3>Your conducting video</h3><p>This is optional, but I’ve found better results with it than without it. Singers are comforted by your presence (hopefully!) and it makes the beginnings and ends of phrases more together.</p><p>The chances are the best video camera you own is your mobile phone. The camera in your laptop won’t be as good, especially in low light. If you have a tripod, get a mobile phone mount for it. If not, a willing partner with a steady hand will do! Make sure you record using the rear camera too (the front camera on a phone tends to be poor quality).</p><p>Set up your phone/camera so that where you are standing you will be visible from your waist to your head. Try to stand in front of a clear background to make your motion easier to follow. Make sure you are well-lit (either with good natural light or some strategically placed lamps) and that you are facing straight on to the camera. Finally, make sure you are filming in landscape, not portrait.</p><p>How to record video on an smartphone</p><ol><li>Launch the Camera app on your iPhone or Android phone.</li><li>Tap on Video or swipe right to switch to Video mode.</li><li>Tap the red Record button to begin filming.</li><li>Tap on the red Stop button to end the video.</li><li>Anything captured automatically gets saved to your device’s Photo Library.</li></ol><p>At the start of the video, give a countdown of 3, 2, 1 and then clap. We will use this countdown to help synchronize all the videos you receive from your choir, as well as synchronizing all the audio and video later on.</p><p>After the countdown leave a 3–4 second pause.</p><p>Then, conduct the piece as you want it performed. You can listen to a recording if you want to but do make sure you do this through headphones. All we need at this stage is a video of you conducting the piece.</p><p>When you’re done, watch it back and check that you are in frame, that you can see your gestures, that the countdown and clap are clear and that you’ve captured the whole piece.</p><p>Do this a few times. It’s important that this is right — It’ll save you hours later!</p><h3>The backing track</h3><p>Whether your piece is accompanied or not, you will need a backing track. This will help the singers keep pitch and aid their tempo.</p><p>Open up your conducting video on your phone and put it on your piano music rack (or somewhere visible) and practice playing against your own conducting. Once you’re satisfied then record your backing track.</p><p>When you make the recording do a quick check and play the loudest couple of bars and play it back. Make sure that you can hear the piano and that it doesn’t distort the sound. If it distorts, move the microphone away or adjust the gain.</p><p>Join in with the countdown (3, 2, 1 and then clap!) in time with the conducting video. In the 3–4 second space play the starting note or chord to give your singers the pitch. Then play the accompaniment, or vocal reduction, along to your conducting.</p><p>Once you’re done, check the audio against the conducting track. Any variance or difference will be confusing for your singers and make your life mixing the audio much harder, so do make sure this is right before you carry on.</p><h3>The instructions</h3><p>Now you have your backing track and your conducting video you can prepare your instruction materials.</p><p>Rather than give your singers your PDF music, a conducting video and a backing track all to keep track of at the same time, it is best to produce a video that combines all three. This way their attention is focussed on you and you make the recording easier for your singers! Also, it’s good practice for all the video editing you’re going to have to do later!</p><p>Open up your video editing software. I use <a href="https://www.blackmagicdesign.com/uk/products/davinciresolve/">Davinci Resolve</a>. It’s free and very powerful for what I need. You can use your own product of course — Adobe Premiere, Final Cut Pro etc. Just make sure it’s got enough features to make editing possible. Some beginner video editing software — iMovie for example — just doesn’t give you enough control.</p><p>Using Resolve I create a new project and Import my backing track and conducting video. In <strong>Cut</strong> mode, I drag both on to the timeline, and then drag the backing track until the audio spike of the clap lines up with the video. Then I make sure to detach the audio from the conducting track and delete it. Now I have a video with my accompaniment playing with my conducting.</p><p>This can be a perfect place to finish, but sometimes I like to also add the music to the video, so that the singers don’t have to keep referring to a separate sheet they have to print out, or another window on their computer.</p><p>Switching to <strong>Edit</strong> mode, I <strong>crop</strong> my video to half the size, so that only my body is visible, and <strong>resize</strong> the video to take up the right hand side of the screen. This leaves a black space on the left hand side for your music to go into.</p><p>Depending on the piece there are a number of ways to proceed here. For a hymn, or something with repeated music per verse, I have found putting the music at the top of the screen and changing the words per verse to be very effective. <a href="https://www.youtube.com/watch?v=CvCFKn3YN5M">https://www.youtube.com/watch?v=CvCFKn3YN5M</a></p><p>For longer pieces I open up the PDF in photoshop, copy each line into a new image to make one long continuous scroll. Then I import that image into Resolve. Drag that into your timeline, but make sure it is not the top-level layer. In <strong>Edit</strong> mode, <strong>resize</strong> it up to the height of your video and drag it all the way to the start.</p><p>Then, use in the Inspector panel, create a start keyframe, then move the score along to the left in time with the music. I find listening for a few bars and then dragging the score into the position I want works well. Then you can end up with this: <a href="https://www.youtube.com/watch?v=TsMuA8cyWU4">https://www.youtube.com/watch?v=TsMuA8cyWU4</a></p><p>Keeping the music moving is better than simply switching between images as the singers can anticipate the notes coming next, and keeping it as large as possible is good for those who struggle with their eyesight or singers who might not be able to view the video full screen when they record.</p><p>Once you’re done, upload that somewhere unlisted to youtube (that means that it’s publicly available but won’t show up in search results).</p><h3>Supporting your singers</h3><p>If your choir is like the one I’ve been dealing with, you’ll have a real range of singers with a range of devices and familiarity with I.T. Make yourself available and be prepared to jump on phone calls or facebook messenger videos to help them through the process.</p><p>Common issues are things like not knowing what software to use, or how to have the conductor video and their recording software on screen at the same time. Talk them through <a href="https://support.microsoft.com/en-gb/help/4051785/windows-10-create-or-edit-video">how to use the Photos app on windows </a>or <a href="https://www.youtube.com/watch?v=ABAkzPoaosc">Quicktime on a Mac</a>, and how to have the web browser in a window with youtube in <a href="https://www.youtube.com/watch?v=mCVDoakxdnw">Theatre mode </a>alongside their video.</p><p>It’s best if they record video on their phone as the camera is better than their webcam or laptop, and this can help if they have the equipment — but they also need a tripod or some other way to keep their phone steady. Keep it simple, friendly and check in on more vulnerable members to make sure they’re taking part too.</p><h3>Recording</h3><p>Asking your singers to record audio or video might be daunting for them. They may not feel they have the I.T. skills, or they may feel nervous about singing on their own. Anything you can do to keep this process simple and fun for them will encourage them to take part. Having a clear instruction video is a good start.</p><p>The most important thing is to have a realistic deadline. Not too long, not too short. A week to ten days is a good start. Make sure you’re giving yourself enough time to mix and edit it all together too.</p><p>When you ask them to record, give them the URL of the instruction video and the URL of the PDF of the music (some like to print it out rather than look at it on screen). I tend to create a dropbox space per video and share the PDF from there.</p><p>Give your singers the following instructions:</p><h3>Before you start, make sure that:</h3><ul><li>you are in a well-lit place and we can see your face</li><li>you are in front of a plain wall if possible</li><li>background noise is kept to a minimum (difficult I know!)</li><li>you are somewhere not too echoey if possible. A room with some carpet is great.</li><li>you are recording in landscape (longer on the bottom) and not portrait (longer on the sides)</li><li>you are in frame, with your head and shoulders clearly visible straight on like a passport photograph</li><li>you are not too far away that we can’t hear you and that you’re not too close that your sound is distorted. Record yourself singing a scale and watch it back to see if you’re visible.</li></ul><h3>How to record your video</h3><ol><li>Open the video at [YOUR VIDEO URL HERE] — do watch this through first before recording. It does have the score embedded, but you can also open the PDF of the music at [YOUR MUSIC URL HERE]</li><li>Listen to the video on headphones</li><li>Start to record either your audio or video</li><li>Clap your hands at the end of the countdown along with the video (this is to help synchronise the recordings). Make sure you clap onscreen!</li><li>Sing, watching the conductor</li><li>Watch your video back and make sure you’re happy with it, that you didn’t make too many mistakes and that you can hear and see yourself. It’s okay to do it a few times.</li></ol><h3>How to upload your video</h3><p>I set up a <a href="https://help.dropbox.com/files-folders/share/create-file-request">dropbox file request </a>for each project, and give out the URL of that along with my instructions. Most singers can manage this, but some still struggle and send their files via email. Either way I ask that they save their file &lt;voice part&gt;_&lt;name&gt;.mp3 so that I can group them together. Dropbox file requests come through with the name already attached so that’s even easier. If you’re comfortable, you can ask them to send you videos through their own google drives or dropbox accounts, but since video files can get very large indeed I’ve found it easier just to set up a dropbox space.</p><p>Whatever you choose, include the instructions on how to upload their file into the email you send out.</p><p>You know your singers, so make sure to also give them any tips you think they’ll need.</p><h3>Mixing the audio</h3><p>Once all your videos (or audio-only files) are in, it’s time to mix them together. For that I use the free tool <a href="https://www.audacityteam.org/">audacity</a>.</p><p>If you are creating a video, first you’ll need to <em>extract your audio</em>. See below.</p><p>Create a new project and import all your audio. The first thing I do is to select everything and mix everything down to mono (Tracks -&gt; Mix -&gt; Stereo to Mono) and also resample everything to 44100.</p><p>Next, you have to remove background noise. Go through each track individually and highlight an empty section — you’ll see the spike of the clap and then the wave of them singing. Somewhere in there is perfect. And choose Effects -&gt; Noise Reduction. Click Get Noise Profile. Then select the whole track and choose Effect -&gt; Noise Reduction again, this time clicking just OK.</p><p>Next line up all your tracks. Drag each clip until the spike of each clap is at the start of the audio. Now, click play and have a listen. It probably won’t be together, but it will be in the neighbourhood.</p><p>Unfortunately, this is where you’ll spend most of your time. I tend to go through each track listening for mistakes first of all (wrong notes, wrong words) and just silence those sections. If you’ve only got a few singers you may want to go back to them and ask them to patch in fixes, but if you’ve a lot then you can just edit this way. Next I pick a nice consonant somewhere in the last beat of the third bar and line up each track against that — that one tends to be the most in time. Sometimes I have to do that for each verse and so I split each verse using clip boundaries, delete the silence between each verse and that gives me a second of wiggle room to line things up.</p><p>Lastly, I go through the starts and ends of each verse or phrase and check for early entries (and silence them) or late ends (especially s or t) and silence them too. You can get away with only a couple consonants and it still sounds great.</p><p>Once everything is aligned, you need to blend it together.</p><p>Go to View -&gt; Show Clipping and that will highlight in red any distortion that you might be hearing. You can simply select those sections and choose Effect -&gt; Clip Fix to resolve those.</p><p>I find that the best way to mix is to turn everyone’s gain down to -15, then open the Mixer Board (View -&gt; Mixer Board), play the track and adjust the gain individually until the green is in the middle of the range. Tinker with this until you’re happy with it.</p><h3>Editing the video</h3><p>This process can really take as long as you want, depending on how fancy you want to get. The basic Zoom call version of having everyone on screen all the time is relatively straightforward, but you may also want to edit to highlight different singers, or only show singers who are singing at a point in time. Remember that every edit will add more time.</p><h3>Extract the audio</h3><p>It’s easier and quicker to work in audacity to mix your audio. The first thing you need to do is extract your audio so you can do that. I use a tool called <a href="https://ffmpeg.org/">ffmpeg</a>. This can appear a little daunting but all you really need is to install this tool, open a terminal and go to the folder all your videos are in and then run:</p><blockquote>for i in *.*; do ffmpeg -i “$i” -map 0:a -c libmp3lame -q:a 2 “mp3/$i.mp3”; done</blockquote><p>This will extract all the audio into mp3 format.</p><h3>Fix the video</h3><p>Unless you have a super computer with lots of memory, you’re going to need to be kind to it in terms of how you work with video. My first step is to watch all the videos I’ve received and be critical of the composition. Is it in landscape, is the singer positioned well in the frame (is there a lot of blank space, or are they too far away). For any videos I think could be touched up, I open them one at a time in Resolve and quickly treat them.</p><p>In Edit mode, I’ll crop or reposition them so that they look better and more uniform. If I’m feeling fancy I also<a href="https://www.youtube.com/watch?v=akPJJ_ggaVc"> remove noise</a>.</p><p>If your video is flickering or looks stuttery it’s because it’s interlaced. You can fix this using ffmpeg too:</p><blockquote>ffmpeg -i input.mp4 -vf yadif -c:v libx264 -preset slow -crf 19 -c:a aac -b:a 256k output.mp4</blockquote><p>Or just choose Clip Attributes &gt; Deinterlace in Resolve.</p><p>I then render each video out separately.</p><h3>Make a plan</h3><p>Using Resolve is good because it’s non-destructive. Which means that any cuts or edits you make wont change the source video. However, any changes you make later on down the line can undo hours of work. It’s best to have a plan.</p><p>Listen to your piece again, and think about how you want to present it. Do you just want everyone on screen all the time? Do you know there are sections you just want sopranos, or whatever. Is there a solo? Get a piece of paper and mark out different sections you want to show visually. Ideally keep those sections over 4 seconds as any cuts quicker than that can appear a bit frantic (but, you’ll know your piece. Maybe it is frantic!). Listen to the music and mark the time codes on your piece of paper. Watch the videos and see who is particularly expressive at a given point, or who is not singing and take a note of that.</p><p>At the end of this phase you should know how you plan to edit your video, even if it’s just a case of having:</p><ul><li>0–10 seconds: everyone</li><li>10–40 seconds: sopranos and tenors</li><li>50–65 seconds: solo</li><li>65–90-seconds: everyone</li></ul><p>Think about how you can arrange your singers. Everyone should be in the same 16:9 rectangle, but you can crop people into all sorts of shapes.</p><p>The first thing I do is count how many I have, and how many by voice part, and think what grid that would make. 36 singers? 6x6. 12? 4x3 etc.</p><h3>Edit</h3><p>The first thing to do is import all your videos and drag them onto the timeline, use the clap to synchronize all the videos, then remove their audio and delete it.</p><p>Add your mixed audio track and synchronize that too.</p><p>Leaving all your video full screen for just now, go through each track and check that the video and audio line up. I just play the first few bars to check, then hide that track and then check with the layer underneath, and repeat until I’m done. It’s important everything lines up now, as it’s harder to fix later.</p><h4>Easy editing</h4><p>Since you’ve figured out your starting grid, this is easy. Go into Edit mode and resize and move every clip into position. You can use the Inspector on the right hand side to enter the X and Y coordinates of every clip so that they line up. This will take some time, but it’s your starting position.</p><p>You won’t be able to playback and listen at the same time. You probably won’t have enough memory for that.</p><p>Once you’re done, click Quick Export, go make a cup of tea and let it render to H.264.</p><h3>Complex editing</h3><p>My laptop starts to slow to a crawl when I have over 6 videos at once, so I’ve started to work in a more complicated way.</p><p>Firstly, I hide all my video and go through the audio track adding Markers when I want scenes to change, based on my plan. I work out in advance what layouts I want (which singers where) and then create duplicate projects per voice part. This reduces the number of singers I have to deal with at a time, and I can work much quicker. I just cut and create scenes where I’ve decided I need them.</p><p>Then I render these out. Finally, I create another project, import the voice parts and the master audio mix and composite them together using cropping. With 36 voices this allows me to work almost in real time. Whereas, all 36 videos in one project brings my laptop to its knees.</p><h3>Useful Links</h3><p>Davinci Resolve Tutorial <a href="https://www.youtube.com/watch?v=52vK5mzl1jQ">https://www.youtube.com/watch?v=52vK5mzl1jQ</a></p><p>Audacity Tutorial <a href="https://www.youtube.com/watch?v=8ClwSNm362E">https://www.youtube.com/watch?v=8ClwSNm362E</a></p><p><a href="https://www.audacityteam.org/">https://www.audacityteam.org/</a></p><p><a href="https://www.blackmagicdesign.com/products/davinciresolve/">https://www.blackmagicdesign.com/products/davinciresolve/</a></p><p><a href="https://ffmpeg.org/">https://ffmpeg.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aa4aca58821" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>