March 27, 2020 Stardate: 73701.6 Tagged as: Ubuntu FFmpeg
GoPro outputs video in H.264 mp4 containers and the Hero6 and Hero7 now can output in the more efficient HVEC H.265 mp4 container. This is great because:
Yeah! But wait…. Not everything can read/play the new H.265 mp4.
FYI, here are some great posts by havecamerawilltravel that you should read:
My goal is to edit and color correct my home videos in Davinci Resolve 16 (DR16) but it turns out it doesn’t import these GoPro video files directly, at least not in the Linux free version.
In the support notes of DR16 it states that :
Handbrake is a GUI front-end to ffpmeg and is awesome, I’m sure it could do it but I wanted something that I could run from a shell script and I wasn’t exactly sure what it was doing under the hood. My goal was to preserve the highest resolution and quality during the conversion or “transcode” to work with in DR16.
This is pretty simple, as described in this tutorial instructions.
sudo apt install ffmpeg
In my research and experimentation I found success in two codecs; Apple ProRes and Avid DNxHD. You can view all the installed and available codecs on your machine with ffmpeg -codecs
. If you search through the long list you will see a bunch of H.264 decoders. I don’t know which ones are better or if they are, but I’ve seen these two used and recommended on the interwebs.
As I said, I tried both codecs and didn’t find any difference between the two. They both decoded high-res 4k video and converted AAC audio into PCM audio. I’ll tell you later why that’s important. The advantage of using ProRes is that the command line is a bit easier:
ffmpeg -i input.mp4 -c:v prores -profile:v 3 -c:a pcm_s16le output.mov
The advantage of using DNxHD is that you can specify all the nerdy details if you want to, but that’s a double edge sword because you can’t leave them out and still work. You must specify all the nerdy details.
Here is the final command, assuming 4k resolution at 23.967 (aka 24) fps.
ffmpeg -i input.mp4 \
-c:v dnxhd \
-profile:v dnxhr_hqx \
-vf "scale=3840:2160,fps=24000/1001,format=yuv422p10le" \
-b:v 110M \
-c:a pcm_s16le \
output.mov
Referring back to the Black Magic Support Codecs, we see that mp3 and AAC are not supported in either free nor Studio Linux version. That sucks…So this is why we have to convert the audio when we convert the video.
-i
defines the input file
-c:v
(or the alias -vcodec
) defines the codec to use for the video
-profile:v
defines the profile to use for the video.
Accepted values are: dnxhd
, dnxhr_444
, dnxhr_hqx
, dnxhr_hq
, dnxhr_sq
, dnxhr_lb
.
I was able to convert 1920x1080 videos but kept getting an error when attempting 4k 3840x2160 videos. I was stuck at this point for a while until I found a post on askubuntu explaining that a different profile was needed.
dnxhd
: The lists of available/possible resolutions can be looked up here, but they do not go bigger than 1080p.
dnxhr_lb
- Low Bandwidth. 8-bit 4:2:2 (yuv422p
). Offline Quality.dnxhr_sq
- Standard Quality. 8-bit 4:2:2 (yuv422p
). Suitable for delivery format.dnxhr_hq
- High Quality. 8-bit 4:2:2 (yuv422p
).dnxhr_hqx
- High Quality. 10-bit 4:2:2 (yuv422p10le
). UHD/4K Broadcast-quality delivery.dnxhr_444
- Finishing Quality. 10-bit 4:4:4 (yuv444p10le
). Cinema-quality delivery.The above list was adapted from DNxHR codec. Note that the pix_format must match the profile!
-vf
is as alias for -filter:v
and creates the filtergraph that is used to filter the stream. You can specify each value but this is easier, for example -pix_fmt=yuv422p10le
.
scale=
width x heightfps=
ntsc-film
)ntsc
)pix_fmts=
dnxhr_lb
, dnxhr_sq
, or dnr_hq
= yuv422pdnxhr_hqx
or dnxhr_444
= yuv422p10le-c:a
defines the codec to use for the audio
This is an automated list of software versions used during the writing of this article.
Software Version
OS Ubuntu 20.04 LTS
FFmpeg 4.2.2-1