From Firefox's media codec support table:
To avoid patent issues, support for MPEG 4, H.264 and MP3 is not built
directly into Firefox. Instead it relies on support from the OS or
hardware (the hardware also needs to be able to support the profile
used to encode the video, in the case of MP4). ... Linux since Firefox
26.0 (relies on GStreamer codecs) ...
https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
From GStreamers plugin lists:
gst-plugins-ugly
lame — Encode MP3s with LAME
x264 — libx264-based H264 plugins
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-ugly-plugins/html/ch02.html
Ubuntu:
patent and copyright restrictions (see Ubuntu License Policy)
complicate distribution of software to support non-free formats. ...
However, you can install the ability to play popular non-free media
formats ... by following the instructions below.
...
Legal Notice Patent and copyright laws operate differently depending
on which country you are in. Please obtain legal advice if you are
unsure whether a particular patent or restriction applies to a media
format you wish to use in your country.
...
Manual Install
If you are using regular, stock Ubuntu:
sudo apt-get install ubuntu-restricted-extras
https://help.ubuntu.com/community/RestrictedFormats