DEV Community

Alex Creatune
Alex Creatune

Posted on

How to Fit a Christmas Song into a 30-Second Video: Measure, Then Cut

A 30-second greeting video needs a 30-second song, and a Christmas track rarely arrives at that length. The sample songs on Creatune's public Christmas page run from 1:39 to 3:44. This guide shows how to measure a song file with Python, choose the 30 seconds you want, cut them, and confirm the result lands inside a tolerance you set.

I'm Alex from the Creatune team. On November 11, 2026, I checked our public Christmas song generator and audio cutter pages, then ran every script below on a synthetic 74-second stand-in file, so you can reproduce the numbers without a song of your own. The measurements describe that stand-in file and the cutter's output.

What you need

  • The video length in seconds (30.0 here)
  • A song file: a download from the generator, or any WAV or MP3 you have the rights to use
  • Python 3 (the standard library is enough)
  • Optional: ffprobe, for formats that Python's wave module cannot read

Decide the tolerance before you start. At 30 frames per second one frame lasts 0.0333 s, so a tolerance of ±0.1 s is three frames. That is a number you can write in a delivery note and check with a script.

Step 1: Describe the song and download it

Open the Christmas song generator. On the Simple tab, type your idea into the prompt box, which accepts up to 500 characters. The page also offers an Instrumental Only checkbox and style chips such as Christmas Pop, Sleigh Bells, Cozy, Acoustic, Choir, Jazz, and Kids. This prompt is a good starting point for a neighbor greeting:

A warm Christmas greeting song for my neighbors, acoustic guitar, sleigh bells, one short chorus, female vocal
Enter fullscreen mode Exit fullscreen mode

The public Christmas song generator with the example prompt typed into the Simple tab; the Sleigh Bells style chip is highlighted

Whatever the prompt says about length, the downloaded file is what counts. Keep the download as it is and use the steps below on it. Plan on trimming: the samples on the page last 3:44, 1:39, 2:42, and 2:53.

Step 2: Measure the source

To follow along without a song, this script writes a 74-second stereo WAV. It plays a four-note pattern (C, E, G, E) at 96 BPM, so one beat lasts 0.625 s and one four-beat bar lasts 2.5 s:

import math
import struct
import wave

RATE = 44100
SECONDS = 74
NOTES = [261.63, 329.63, 392.00, 329.63]  # C4 E4 G4 E4, one note per beat at 96 BPM
BEAT = 60 / 96

frames = bytearray()
for n in range(RATE * SECONDS):
    t = n / RATE
    freq = NOTES[int(t / BEAT) % len(NOTES)]
    value = 0.25 * math.sin(2 * math.pi * freq * t)
    sample = struct.pack("<h", round(value * 32767))
    frames.extend(sample * 2)  # same sample in left and right

with wave.open("standin-74s.wav", "wb") as audio:
    audio.setnchannels(2)
    audio.setsampwidth(2)
    audio.setframerate(RATE)
    audio.writeframes(frames)
Enter fullscreen mode Exit fullscreen mode

Now read the length from the file itself. For an uncompressed WAV, duration is frames divided by sample rate:

import wave

for name in ("standin-74s.wav", "cut-30s.wav"):
    with wave.open(name, "rb") as audio:
        rate = audio.getframerate()
        frames = audio.getnframes()
        print(f"{name}: rate={rate} channels={audio.getnchannels()} "
              f"frames={frames} seconds={frames / rate:.4f}")
Enter fullscreen mode Exit fullscreen mode

Run it once now. The second file does not exist yet, so Python stops with a FileNotFoundError after printing the first line:

standin-74s.wav: rate=44100 channels=2 frames=3263400 seconds=74.0000
Enter fullscreen mode Exit fullscreen mode

The source is 74.0 s, so 44.0 s has to go. Because this track has a steady tempo, cut on bar lines so the music starts and ends on a downbeat. Bar 5 begins at 4 × 2.5 = 10.0 s, and 30 s later is 40.0 s, which is the start of bar 17. For your own song, replace 96 BPM with its tempo: seconds per bar = 4 × 60 / BPM.

Step 3: Cut the section

Open the audio cutter and choose your file with Choose audio. The page lists MP3, WAV, M4A, FLAC, and OGG, keeps local audio on your device, and states a limit of 50 MB per file and five minutes at the time of my check.

After the file loads, the page shows its name and length (74.0 s here) plus Start (s) and End (s) fields. Enter 10 and 40. The label at the lower left changes to Total: 30.0 s. Open the format menu, which offers MP3, WAV, and FLAC, choose WAV so the file can be measured frame by frame, and select Download.

The public audio cutter with the 74-second stand-in file loaded, Start set to 10, End set to 40, Total 30.0 s, and WAV selected as the output format

The browser suggested standin-74s-audio-cutter.wav. Save a copy as cut-30s.wav next to the source so the measuring script finds it.

Step 4: Verify the cut

Run the same measuring script again:

standin-74s.wav: rate=44100 channels=2 frames=3263400 seconds=74.0000
cut-30s.wav: rate=44100 channels=2 frames=1323000 seconds=30.0000
Enter fullscreen mode Exit fullscreen mode
File Sample rate Channels Frames Duration
standin-74s.wav 44,100 Hz 2 3,263,400 74.0000 s
cut-30s.wav 44,100 Hz 2 1,323,000 30.0000 s

1,323,000 frames ÷ 44,100 Hz is exactly 30 s, so the difference from the target is 0.0000 s, inside the ±0.1 s tolerance.

If your download is an MP3 or another format wave cannot open, ask ffprobe for the duration instead:

ffprobe -v error -show_entries stream=codec_name,sample_rate,channels:format=duration -of default=nw=1 cut-30s.mp3
Enter fullscreen mode Exit fullscreen mode

Finish with a short acceptance record you can keep next to the project:

Video length: 30.0 s
Tolerance: ±0.1 s
Source: standin-74s.wav, 74.0000 s
Cut: 10.0 s to 40.0 s (bar 5 to bar 17 at 96 BPM)
Delivered: cut-30s.wav, 1,323,000 frames at 44,100 Hz = 30.0000 s
Result: within tolerance
Enter fullscreen mode Exit fullscreen mode

Questions that come up

What if the song is shorter than 30 seconds? Nothing needs cutting. Decide whether the video can wait for a longer version of the track, and measure again after any change.

Should the cut end on the last frame of the video? The cut fixes the length; a fade-out is a separate edit. Add the fade in your video editor so the music does not stop in the middle of a note. A fade changes loudness over time, not the file's duration.

The start sounds abrupt. Can I move it? Yes. Shift both Start and End by the same amount so the total stays at 30.0 s, and run the measuring script again.

My video is 24 fps, not 30. Does the tolerance change? One frame is 0.0417 s, so ±0.1 s is about two frames. Tighten the tolerance if your delivery spec asks for it.

Related reading from our team

If a clip is still a few seconds off after cutting, changing playback speed alters its length by a predictable ratio. This earlier guide measures that on real exports: How to Check Audio Duration After a Speed Change

For planning the start point, end point, and tail of a short video's music on one sheet, see the cut-planning sheet for short-video BGM (in Japanese).

Top comments (0)