GoPro Filenames

GoPro Filenames

I have a GoPro Hero4 Session. This little camera was amazing when it came out. I still think it’s still pretty amazing today. (Aside from one annoyance: I can’t get Quik to connect to it from my Android phone because it insists that there’s a PIN set on it.) It does what I want it to do. Takes half decent action videos in 1080p at 50Hz and wide-angled quite average stills. In good light the photos are pretty usable as happy snaps. It’s waterproof without needing a case. And it comes with all manner of mounts. It’s currently being used on the front of my bike to capture any excitement that might happen as I ride around the place.

But where it falls over completely is file naming convention. Videos start off with a perfectly fine “GOPR6014.mp4” format. The 6,014th photo or video shot on the camera. Perfect. But then, when that video gets to the filesize limit, it creates a second file with the name GP016014.mp4. And the next file it creates is GP026014.mp4.

This means that when you sort the files by name, you get a list of all of the second files for the videos, then third files for the videos, then fourth, etc., until you get to a list of all the base files.

It’s horrible and makes a mess of any storyboarding file editing software you can imagine. (Unless there are ones out there that will accept this horrid GoPro standard that I’ve not yet found).

Some part of the Star of Greece taken with said GoPro

Anyway – Python and regex to the rescue.

import os
import re

# Get all files in the current directory and skip directories
for filename in os.listdir('.'):
    if not os.path.isfile(filename):
        continue

    name, ext = os.path.splitext(filename)

    # Rename GOPR files: GOPR6014.mp4 → 6014-00.mp4
    if name.startswith("GOPR"):
        new_name = name[4:] + "-00" + ext
        os.rename(filename, new_name)
        print(f"Renamed {filename} → {new_name}")

    # Rename GP files: GP016015.mp4 → 6015-01.mp4
    elif name.startswith("GP"):
        match = re.match(r"GP(\d{2})(\d+)", name)
        if match:
            suffix = match.group(1)
            main_number = match.group(2)
            new_name = f"{main_number}-{suffix}{ext}"
            os.rename(filename, new_name)
            print(f"Renamed {filename} → {new_name}")

This takes all the files in the directory that you launch the script from and renames them into a more sensible structure.

GOPR6014.mp4 becomes 6014-00.mp4.
GP016014.mp4 becomes 6014-01.mp4.
GP026014.mp4 becomes 6014-02.mp4.
and so on.

This now sorts properly, and makes life much easier.

Enjoy.

Test this before you use it on something important.

.

.