How to encode a 4K HDR movie using ffmpeg while maintaining selected auio tracks intact from source
This is my second time writing about this. I had to take down the previous one due to an error I detected after publishing. But I’m confident we will be in a better shape now.
If you want to have the latest version of my code, please visit the project’s repo on Github. I may add more features or make some adjustments without notice, so make sure to to visit once in a while.
To start explaining how this script work, we will start by having a detailed look at mediainfo from a typical source file (in my case is a REMUX of some usual source material):
General
Complete name : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv
Format : Matroska
Format version : Version 4
File size : 57.0 GiB
Duration : 2 h 15 min
Overall bit rate mode : Variable
Overall bit rate : 60.0 Mb/s
Movie name : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Encoded date : UTC 2019-04-16 06:09:30
Writing application : mkvmerge v32.0.0 ('Astral Progressions') 64-bit
Writing library : libebml v1.3.7 + libmatroska v1.5.0
Cover : Yes
Attachments : cover_land.jpg / small_cover.jpg / small_cover_land.jpg / cover.jpgVideo
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Commercial name : HDR10
Format profile : Main 10@L5.1@High
Codec ID : V_MPEGH/ISO/HEVC
Duration : 2 h 15 min
Bit rate : 44.9 Mb/s
Width : 3 840 pixels
Height : 2 160 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0 (Type 2)
Bit depth : 10 bits
Bits/(Pixel*Frame) : 0.226
Stream size : 42.6 GiB (75%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : English
Default : No
Forced : No
Color range : Limited
Color primaries : BT.2020
Transfer characteristics : PQ
Matrix coefficients : BT.2020 non-constant
Mastering display color primaries : Display P3
Mastering display luminance : min: 0.0020 cd/m2, max: 1000 cd/m2
Maximum Content Light Level : 793 cd/m2
Maximum Frame-Average Light Level : 679 cd/m2Audio #1
ID : 2
Format : MLP FBA 16-ch
Format/Info : Meridian Lossless Packing FBA with 16-channel presentation
Commercial name : Dolby TrueHD with Dolby Atmos
Codec ID : A_TRUEHD
Duration : 2 h 15 min
Bit rate mode : Variable
Bit rate : 4 137 kb/s
Maximum bit rate : 7 701 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 1 200.000 FPS (40 SPF)
Compression mode : Lossless
Stream size : 3.93 GiB (7%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : English
Default : Yes
Forced : No
Number of dynamic objects : 13
Bed channel count : 1 channel
Bed channel configuration : LFEAudio #2
ID : 3
Format : DTS XLL
Format/Info : Digital Theater Systems
Commercial name : DTS-HD Master Audio
Codec ID : A_DTS
Duration : 2 h 15 min
Bit rate mode : Variable
Bit rate : 4 086 kb/s
Channel(s) : 8 channels
Channel layout : C L R LFE Lb Rb Lss Rss
Sampling rate : 48.0 kHz
Frame rate : 93.750 FPS (512 SPF)
Bit depth : 24 bits
Compression mode : Lossless
Stream size : 3.88 GiB (7%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : English
Default : No
Forced : NoAudio #3
ID : 4
Format : AC-3
Format/Info : Audio Coding 3
Commercial name : Dolby Digital
Codec ID : A_AC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 640 kb/s
Channel(s) : 6 channels
Channel layout : L R C LFE Ls Rs
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 622 MiB (1%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : English
Service kind : Complete Main
Default : No
Forced : NoAudio #4
ID : 5
Format : AC-3
Format/Info : Audio Coding 3
Commercial name : Dolby Digital
Codec ID : A_AC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 320 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 311 MiB (1%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : English
Service kind : Complete Main
Default : No
Forced : NoAudio #5
ID : 6
Format : AC-3
Format/Info : Audio Coding 3
Commercial name : Dolby Digital
Codec ID : A_AC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 640 kb/s
Channel(s) : 6 channels
Channel layout : L R C LFE Ls Rs
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 622 MiB (1%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : French
Service kind : Complete Main
Default : No
Forced : NoAudio #6
ID : 7
Format : E-AC-3
Format/Info : Enhanced AC-3
Commercial name : Dolby Digital Plus
Format profile : Blu-ray Disc
Codec ID : A_EAC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 1 024 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 995 MiB (2%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : French
Service kind : Complete Main
Default : No
Forced : NoAudio #7
ID : 8
Format : E-AC-3
Format/Info : Enhanced AC-3
Commercial name : Dolby Digital Plus
Format profile : Blu-ray Disc
Codec ID : A_EAC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 1 024 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 995 MiB (2%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : Spanish
Service kind : Complete Main
Default : No
Forced : NoAudio #8
ID : 9
Format : E-AC-3
Format/Info : Enhanced AC-3
Commercial name : Dolby Digital Plus
Format profile : Blu-ray Disc
Codec ID : A_EAC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 1 024 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 995 MiB (2%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : German
Service kind : Complete Main
Default : No
Forced : NoAudio #9
ID : 10
Format : E-AC-3
Format/Info : Enhanced AC-3
Commercial name : Dolby Digital Plus
Format profile : Blu-ray Disc
Codec ID : A_EAC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 1 024 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 995 MiB (2%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : Italian
Service kind : Complete Main
Default : No
Forced : NoAudio #10
ID : 11
Format : E-AC-3
Format/Info : Enhanced AC-3
Commercial name : Dolby Digital Plus
Format profile : Blu-ray Disc
Codec ID : A_EAC3
Duration : 2 h 15 min
Bit rate mode : Constant
Bit rate : 1 024 kb/s
Channel(s) : 8 channels
Channel layout : L R C LFE Ls Rs Lb Rb
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Compression mode : Lossy
Stream size : 995 MiB (2%)
Title : Movie.Name.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos
Language : Japanese
Service kind : Complete Main
Default : No
Forced : NoText #1
ID : 12
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Duration : 2 h 8 min
Bit rate : 49 b/s
Count of elements : 1501
Stream size : 46.5 KiB (0%)
Title : English-SRT
Language : English
Default : Yes
Forced : NoText #2
ID : 13
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Duration : 2 h 8 min
Bit rate : 51 b/s
Count of elements : 1647
Stream size : 49.0 KiB (0%)
Title : English-SDH-SRT
Language : English
Default : No
Forced : NoText #3
ID : 14
Format : UTF-8
Codec ID : S_TEXT/UTF8
Codec ID/Info : UTF-8 Plain Text
Duration : 1 h 12 min
Bit rate : 1 b/s
Count of elements : 27
Stream size : 674 Bytes (0%)
Title : English-FORCED-SRT
Language : English
Default : No
Forced : NoText #4
ID : 15
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 8 min
Bit rate : 34.4 kb/s
Count of elements : 3300
Stream size : 31.7 MiB (0%)
Title : English-PGS
Language : English
Default : No
Forced : NoText #5
ID : 16
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 30.6 kb/s
Count of elements : 2994
Stream size : 29.5 MiB (0%)
Title : French-PGS
Language : French
Default : No
Forced : NoText #6
ID : 17
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 24.2 kb/s
Count of elements : 2934
Stream size : 23.3 MiB (0%)
Title : French-PGS
Language : French
Default : No
Forced : NoText #7
ID : 18
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 31.5 kb/s
Count of elements : 3096
Stream size : 30.4 MiB (0%)
Title : Spanish-PGS
Language : Spanish
Default : No
Forced : NoText #8
ID : 19
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 8 min
Bit rate : 27.2 kb/s
Count of elements : 2902
Stream size : 25.1 MiB (0%)
Title : German-PGS
Language : German
Default : No
Forced : NoText #9
ID : 20
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 35.9 kb/s
Count of elements : 3076
Stream size : 34.7 MiB (0%)
Title : Italian-PGS
Language : Italian
Default : No
Forced : NoText #10
ID : 21
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 18.9 kb/s
Count of elements : 2668
Stream size : 18.2 MiB (0%)
Title : Japanese-PGS
Language : Japanese
Default : No
Forced : NoText #11
ID : 22
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 28.7 kb/s
Count of elements : 3072
Stream size : 27.7 MiB (0%)
Title : Norwegian-PGS
Language : Norwegian
Default : No
Forced : NoText #12
ID : 23
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 14 min
Bit rate : 23.8 kb/s
Count of elements : 1950
Stream size : 23.0 MiB (0%)
Title : Swedish-PGS
Language : Swedish
Default : No
Forced : NoText #13
ID : 24
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 1 h 12 min
Bit rate : 628 b/s
Count of elements : 56
Stream size : 333 KiB (0%)
Title : English-FORCED-PGS
Language : English
Default : No
Forced : NoText #14
ID : 25
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 12 min
Bit rate : 381 b/s
Count of elements : 32
Stream size : 369 KiB (0%)
Title : French-FORCED-PGS
Language : French
Default : No
Forced : NoText #15
ID : 26
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 12 min
Bit rate : 180 b/s
Count of elements : 18
Stream size : 175 KiB (0%)
Title : French-FORCED-PGS
Language : French
Default : No
Forced : NoText #16
ID : 27
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 12 min
Bit rate : 623 b/s
Count of elements : 76
Stream size : 605 KiB (0%)
Title : Spanish-FORCED-PGS
Language : Spanish
Default : No
Forced : NoText #17
ID : 28
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 1 h 12 min
Bit rate : 675 b/s
Count of elements : 62
Stream size : 358 KiB (0%)
Title : German-FORCED-PGS
Language : German
Default : No
Forced : NoText #18
ID : 29
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 12 min
Bit rate : 546 b/s
Count of elements : 72
Stream size : 529 KiB (0%)
Title : Italian-FORCED-PGS
Language : Italian
Default : No
Forced : NoText #19
ID : 30
Format : PGS
Muxing mode : zlib
Codec ID : S_HDMV/PGS
Codec ID/Info : Picture based subtitle format used on BDs/HD-DVDs
Duration : 2 h 12 min
Bit rate : 509 b/s
Count of elements : 68
Stream size : 493 KiB (0%)
Title : Japanese-FORCED-PGS
Language : Japanese
Default : No
Forced : NoMenu
00:00:00.000 : en:Chapter 01
00:03:28.666 : en:Chapter 02
00:13:31.727 : en:Chapter 03
00:17:57.826 : en:Chapter 04
00:22:25.260 : en:Chapter 05
00:33:20.415 : en:Chapter 06
00:41:27.276 : en:Chapter 07
00:51:37.094 : en:Chapter 08
00:58:23.958 : en:Chapter 09
01:07:40.347 : en:Chapter 10
01:16:21.994 : en:Chapter 11
01:24:42.744 : en:Chapter 12
01:32:17.698 : en:Chapter 13
01:37:06.237 : en:Chapter 14
01:49:12.963 : en:Chapter 15
01:55:03.563 : en:Chapter 16
02:01:11.347 : en:Chapter 17
02:06:21.991 : en:Chapter 18
NOTE: I use MediaInfo to get my metadata.
So basically every of those files will usually have the following catagories of objects: general file info, Video info, Audio Info, Subtitle info and Chapter info. That means we will have local information (at the category level) but also absolute information (at the file level), and each object will have some kind of ID at both levels. For example, this file has a DTS-HD MA audio track which locally is known as “Audio #2”, but it also has an absolute ID=3. Similarly, the Spanish language subtitle track has a local name as “Text #7” but ID=18. Understanding this structure is key to successfully map tracks and metadata to ffmpeg for processing.
The basic ffmpeg usage is as follows:
ffmpeg -i input.file output.file
I’m going to go ahead and paste most of the script here, then I will generally explain each part (be warned: I’m no expert in ffmpeg and/or video encoding):
ffmpeg -hide_banner \
-i "../storage/My.Source.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv" \
-pix_fmt yuv420p10le \
-map_chapters 0 \
-metadata title="My Awesome Movie (2019)" \
-map 0:0 -metadata:s:v:0 language=eng -metadata:s:v:0 title="My Awesome Movie (2019)" \
-map 0:1 -metadata:s:a:0 language=eng -metadata:s:a:0 title="Dolby TrueHD 7.1 (Atmos)" \
-map 0:7 -metadata:s:a:0 language=spa -metadata:s:a:1 title="EAC-3 7.1" \
-map 0:2 -metadata:s:a:0 language=eng -metadata:s:a:2 title="DTS-HD MA 7.1" \
-map 0:4 -metadata:s:a:0 language=eng -metadata:s:a:3 title="AC-3 2.0" \
-metadata:s:t:0 filename="" -metadata:s:t:0 mimetype="image/jpeg" \
-c:v libx265 -preset fast -crf 21 \
-x265-params keyint=60:bframes=3:vbv-bufsize=75000:vbv-maxrate=75000:hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte-st-2084:colormatrix=bt2020nc:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,500)" \
-c:a copy \
My.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv
One thing to note here is that ffmpeg indexes start at zero (while on file metadata starts at one), so to map an object we will have to rely on absolute IDs. More on this later.
-hide_banner: It hides tome information that ffmpeg will print to terminal and which I’m not interested in.
-i: input file. Can be absolute or relative location of course. ffmpeg accepts multiple input files, where the first one always is zero (remember I mentioned ffmpeg’s indexes start at zero).
-pix_fmt yuv420p101e: Sets the pixel format. I guess you could try a format with 4:4:0 cromacity, but 4:2:0 gives better compatibility
-map_chapters 0: This option will create a chapters category on our destination file. Our zero parameter means copy whatever is on our first (and only) input file.
-metadata: this option will add a metadata tag with parameter title, where we will specify our movie name. I recommend using the same name you will find on themoviedb.org
-map 0:0: this option adds a metadata entry for video track (-metadata:s:v:0) then, parameter language will define the language of that object based on a three-character code. Then within this, we will add yet another metadata entry for video and put it on our first category track (-metadata:s:v:0). Finally, we will add a title, which can be the same as the file metadata title.
-map 0:1: Similar to our step above, but this time this will be specifically for our Dolby TrueHD track. The zero means “take it from our firtsh input file”, the one means “take it from absolute ID=2–1=1”. Notice this time the entry is again zero on our destination track because this is a new category (now it is audio, previous step was video). After mapping that information to our first local audio track (-metadata:s:a:0), we add a title parameter.
-map 0:7: Similar as we did before, but this time we will get track with ID=8–1=7 and then specify spanish as language to our second audio track (-metadata:s:a:1)
I will skip -map 0:2 and -map 0:4 as you may have got the idea up to this point.
-metadata:s:t:0: This part is required for MKV container. A cover image can be specified on filename parameter. Mine is blank.
-c:v libx265: This option specifies we will be encoding to a HEVC video track using libx265 library
-preset: This will set our preset as defined by x265 library. Parameter on fast works fine for my needs
-crf: Constant Rate Factor. It is a number to help us set a subjective quality. I have balanced mine on 18-21 value. More info here.
-x265-params: Specific parameters for HEVC encoding. I recommend not altering any of these as it will guarantee you will have an HDR output compatible with many devices.
-c:a: This option specify we will be “encoding” a copy of our audio tracks to our destination file. No real encoding, just copy them as they are.
And finally we will be writing to file “My.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv”
HOWEVER (please keep reading!), before actually commiting to a long encoding job, I recommend to try first a section of your source file, just to encode a relatively quick version and check for quality. I prefer to encode exactly from 00:10:00 to 00:20:00 on every movie, so the script will end up in something like:
ffmpeg -hide_banner \
-i "../storage/My.Source.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv" \
-ss 00:10:00 -t 00:10:00 \
-pix_fmt yuv420p10le \
-map_chapters 0 \
-metadata title="My Awesome Movie (2019)" \
-map 0:0 -metadata:s:v:0 language=eng -metadata:s:v:0 title="My Awesome Movie (2019)" \
-map 0:1 -metadata:s:a:0 language=eng -metadata:s:a:0 title="Dolby TrueHD 7.1 (Atmos)" \
-map 0:7 -metadata:s:a:0 language=spa -metadata:s:a:1 title="EAC-3 7.1" \
-map 0:2 -metadata:s:a:0 language=eng -metadata:s:a:2 title="DTS-HD MA 7.1" \
-map 0:4 -metadata:s:a:0 language=eng -metadata:s:a:3 title="AC-3 2.0" \
-metadata:s:t:0 filename="" -metadata:s:t:0 mimetype="image/jpeg" \
-c:v libx265 -preset fast -crf 18 \
-x265-params keyint=60:bframes=3:vbv-bufsize=75000:vbv-maxrate=75000:hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte-st-2084:colormatrix=bt2020nc:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,500)" \
-c:a copy \
My.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv
Which will produce a 10-minute sample.
Finally, it is obvious that is not a good idea to have a job this long tied to our terminal session. So, we can use the nohup command to submit this job as a backgroud task and log it’s output to a file. Like this:
nohup ffmpeg -hide_banner \
-i "../storage/My.Source.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv" \
-pix_fmt yuv420p10le \
-map_chapters 0 \
-metadata title="My Awesome Movie (2019)" \
-map 0:0 -metadata:s:v:0 language=eng -metadata:s:v:0 title="My Awesome Movie (2019)" \
-map 0:1 -metadata:s:a:0 language=eng -metadata:s:a:0 title="Dolby TrueHD 7.1 (Atmos)" \
-map 0:7 -metadata:s:a:0 language=spa -metadata:s:a:1 title="EAC-3 7.1" \
-map 0:2 -metadata:s:a:0 language=eng -metadata:s:a:2 title="DTS-HD MA 7.1" \
-map 0:4 -metadata:s:a:0 language=eng -metadata:s:a:3 title="AC-3 2.0" \
-metadata:s:t:0 filename="" -metadata:s:t:0 mimetype="image/jpeg" \
-c:v libx265 -preset fast -crf 18 \
-x265-params keyint=60:bframes=3:vbv-bufsize=75000:vbv-maxrate=75000:hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte-st-2084:colormatrix=bt2020nc:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,500)" \
-c:a copy \
My.Movie.2019.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos.mkv > job.log &
Then, whenever we want to check the progress of our encoding, we can use:
tail -f job.log
As in many video encoding things, this may be a matter of trial and error. So make sure to tweak your parameters based on your particular requirements.
NOTE: This script was tested on Linux with ffmpeg version 3.x
I hope this helps.