This repository provides kinds of shell scrips to help you convert media that may be not well-supported on macOS
. The most important one is mkv_to_mp4.sh
, converting mkv files with HEVC/AVC and FLAC codec.
Author: Yang-Xijie https://github.com/Yang-Xijie
If you want to figure out how to use this script and how to create MAD with the best quality, check serial tutorials on Bilibili (Chinese).
Sometimes we want to create our own MAD using great clips in some animation. We download the resources (often BDrip
because it's rather smaller than BDMV
and with great quality) from BT or PT sites or somewhere else. But these files have a container mkv
(often with HEVC
(video) and FLAC
(audio) codec) which is unable to import into FCP (because mkv is not an official container format).
To convert BDrip
, one way is to transcode it. However, to extrat and re-package them into a compatitable continer is much more efficient and keep the original quality. This script is to realize it.
Convert anime BDrip
(with mkv
container format, track 0 HEVC
, track 1 FLAC
) to mp4
in order to make it importable in FCP
without transcoding (just extract and re-package). (Note: also importable in Compressor
so that you can further convert it to other codecs that are well-supported on macOS
such as Apple Prores
.)
- (Once) Get the script
mkv_to_mp4.sh
: download the zip of this repo / clone this repo / open the script on GitHub and copy the content to a newly created text file and rename it - (Once) Make the script executable: run command
chmod x mkv_to_mp4.sh
. - (Once) Install the required tools: run command
brew install mkvtoolnix ffmpeg mp4box
. (brew, one of the best package managers for macOS, should be installed before. Run commandbrew update
before installing new packages.) - Change the shell working directory to the folder with mkv files: run command
cd <folder>
. Check the codec of mkv tracks -- this script only supports track 0HEVC(h265)
, track 1FLAC
. To convert mkv files withAVC(h264)
codec, change allh265
toh264
in this script.) - Copy the script to the current directory.
- Run the script: run command
./mkv_to_mp4.sh
.
Theoretically command ffmpeg -i <input>.mkv -vcodec copy -acodec alac <output>.mp4
works. But FCP cannot import the <output>.mp4
for its restriction on the description of video codec. (check StackExchange | Reason for -vtag and Apple Developer Documentation | HLS Authoring Specification for Apple Devices | Video 1.10 for more information).
Moreover, if you use command ffmpeg -i <input>.mkv -map 0:0 -map 0:1 -vcodec copy -acodec alac -vtag hvc1 "<output>.mov"
, the frame-rate goes wrong (from 23.98 to 23.81, CFR to VFR). (check reddit | Framerate issue in fcp (23.98-23.81 FPS) for more information). That ffmpeg doesn't obey standard mp4 boxing might be the reason.
You should make slight adjustment in the script if your media has a codec different from mkv format, track 0 HEVC, track 1 FLAC
.
(after importing mp4 files into FCP) For editing in FCP
, it's better to use Apple Prores
to make rendering faster. Choose proxy
in FCP
if your Mac
lacks performance, or transcode the media to Apple Prores 422
.
Notice Import output files (.mp4
) directly into FCP
because they have the original quality. Don't transcode them using other apps which may decrease the quality. (converting to Apple Prores 422 HQ / 422
just slightly decrease quality and it's convenient if you have a workflow with large storage. To learn more, check Apple Prores White Paper.)
Here are some other scripts that convert specific kinds of media.
BDMV
owns the best quality of anime. Convert them to mov in order to import them into FCP
with the best quality.
Convert BDMV
anime (with m2ts format, track 0 H264/AVC
, track 1 PCM
) to mov
in order to make it importable in FCP
without transcoding.
FLAC
is a codec for lossless audio. However, FCP
or Compressor
(and also Music.app
) doesn't support that not-for-industry audio codec.
ALAC
is a codec for lossless audio designed by Apple
. So it has a great support in macOS
.
The function of this script is to convert FLAC
file (with a suffix .flac
) to ALAC
(with a suffix .m4a
).
You may think command ffmpeg -i song.flac -acodec alac song.m4a
or ffmpeg -i song.flac song.m4a
is enough. But unfortunately sometimes it fails. Check Stack Overflow for details.
- English is not my native language; please excuse typing errors. Suggestions on my expression is welcome!
- Any advice or discussion will be appreciated!