Introduction
I have a couple of kids who play minor sports and I regularly record video their team games using GoPro cameras. There is a lot of video footage created from one game. Using two cameras at a hockey game creates about two hours of video. Editing all of that video into one nice final cut can be tedious to say the least. GoPro has an application called Quik to extract clips from video, but the process is way too long and the workflow is tedious. I tried a few open source applications as well including ShotCut but nothing seemed to make life easier. I then found the FFMPEG library and the command line application ffmpeg.exe. Using the proper command line parameters, I could extract a video clip in less than a second. This article is a brief discussion of the GUI that was made to select the starting point and length of the clip to create batch files for ffmpeg
.
Background
One of the problems with editing high resolution 2K/4K video is the enormous file sizes which are typically 4GB each. Most computers can play the videos but quickly jumping around in time is glitchy. The GoPro cameras also record a low resolution video with an extension LRV. This is actually an MP4 video file and can be renamed and watched using any video player. The low resolution videos are used to find the wanted clips and then ffmpeg
is used to extract them from the higher resolution videos. I used the Windows Media Player control and embedded it into a Windows Forms application to allow me to control the video playback. There isn't a lot of code required to make this work since ffmpeg
is doing the heavy lifting for us.
The contents of a typical GoPro folder are displayed below where the low resolution files are highlighted.
The main window for this application is an MDI window as shown below. The intention was to be able to open the videos from two or more cameras in separate forms.
Clicking the New Extractor button will open a new video extraction form as shown below:
The first step of the process is to rename GoPro LRV files. This will open the file open dialog to select the files.
We then Open Videos to add the low resolution videos.
This will add all of the selected videos to the listbox
. Selecting a video in the listbox
will open it in the Media Player control as shown below:
The default media player buttons and scroll bar can be used to pause/play and skip through the video. However, it is much more efficient to use the keyboard. The following keys can be used to control the media player. The right arrow skips the video forward by one second. The left arrow skips the video back by two seconds. The Spacebar is used to toggle the play and pause states. The Enter key is used to mark the beginning of the clip to extract.
Each time, the Enter key is pressed, a new clip extraction macro is created and added to the clip list box. This is shown below where five clips have been added to the list box. Notice that the filename has been changed from the low-resolution video GL010232.mp4 to the high-resolution file GH010232.mp4 in the macro. The low-resolution file is used because it speeds up the processing. The high-resolution video is what is going to be extracted from the files. There is a combo box named Clip Time that can be used to select the length of the clip. The default value is ten seconds.
The clip macros are simply instructions that get passed to the ffmepg.exe application. Before these instructions can be executed, they must be saved to batch file. This is done using the Save button. The default filename is extractClip.bat and the default folder for saving is the source of the video files. The contents of this file are shown below. Each line calls the program ffmeg.exe and passes the starting point of the clip, the filename to extract the clip from, the length of the clip, and the output filename. The output files are named clipN.mp4 where N is an integer starting from one and ending in the number of clips.
Since this is just a text file, it can be modified in any text editor if slight changes are required to the starting or ending times of the clips. To extract all of the video clips, simply double click on the extractClips.bat file that was saved. This requires the ffmpeg.exe file to be in the same directory as the batch file.
Points of Interest
There isn't much code or interesting details behind the project. It's just the fastest way that I've found to extract clips from the GoPro video files to date. It might be a starting point for someone else to extend upon or maybe someone else has the need to extract clips from GoPro videos.
History
- November 28th, 2018: V1.0 Initial release