Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
28th December 2018, 18:52 | #1 | Link |
Registered User
Join Date: Dec 2018
Posts: 21
|
FFmpeg CLI Help Guide
I've been learning and playing around with FFmpeg for the past month, specifically HDR to SDR tonemapping, asking questions over at this thread. There are still many questions I have, and from what I can tell there are not a whole lot of threads here for FFmpeg general discussion and use.
I figure this thread can be where for those of us that need advanced help with FFmpeg can ask the more experienced users questions. I'll throw a few links down below that have helped me get started as a beginner. How to set up and use FFmpeg with Windows Emulating MadVR's HDR to SDR tonemapping using FFMPEG FFmpeg download link FFmpeg wiki |
28th December 2018, 18:56 | #2 | Link |
Registered User
Join Date: Dec 2018
Posts: 21
|
Here is what I'm currently working on and need help with:
Attempting to convert an UHD Blu Ray rip from HDR to SDR: ffmpeg.exe -i video.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx265 -crf 18 -preset slower output.mkv So far, the output is good. I would like to pass through the audio and adding "acodec copy" gives me the following "Too many packets buffered for output stream 0:1" Any help with the CLI would be appreciated. |
29th December 2018, 04:54 | #3 | Link |
MKV and tools user
Join Date: Apr 2014
Posts: 43
|
I might had also encountered such message myself, but I can't remember how I ended up with it.
What is the codec for the audio track of the source Video.mkv? Perhaps a workaround is to disable the audio track during the encoding process instead of lossless copy, via the "-an" option. Then after you end up with the new MKV without the audio track, use MKVToolNix to mux that new video file plus the audio track from the source MKV file. I think MKVToolNix has more chance to remux such problematic muxes. Of course sometimes FFmpeg is the more tolerant. |
29th December 2018, 05:01 | #4 | Link | |
Registered User
Join Date: Dec 2018
Posts: 21
|
Quote:
How would I instead encode the following audio tracks into the final output using CLI in FFmpeg: AC3 5.1 at 384kbps & an AAC 2.0 at 128kbps. |
|
29th December 2018, 05:28 | #5 | Link | ||
MKV and tools user
Join Date: Apr 2014
Posts: 43
|
Quote:
Quote:
Or the other two audio tracks from the source media file are those AC3 5.1 384kbps and AAC 2.0 128kbps, and you want to retain both of them? |
||
29th December 2018, 08:28 | #6 | Link | |
Registered User
Join Date: Dec 2018
Posts: 21
|
Quote:
Ideally, I want to be able to do this so that I don't have to turn to handbrake after an FFmpeg re-encode. I believe re-encoding an already re-encoded file is killing the quality more than if I just used FFmpeg to begin with. |
|
29th December 2018, 06:05 | #7 | Link |
MKV and tools user
Join Date: Apr 2014
Posts: 43
|
I just tested again, still using my previous Z.mkv (which contains the 3 audio tracks). To retain all 3 audio tracks with FFmpeg, I now used:
ffmpeg -i "Z.mkv" -c:v copy -map 0:v:0 -c:a copy -map 0:a:0 -map 0:a:1 -map 0:a:2 "Z3.mkv" 0:v:0 = 1st video track 0:a:0 = 1st audio track 0:a:1 = 2nd audio track 0:a:2 = 3rd audio track I just found out too that if I used mappings for the audio tracks, then I must also use mapping for the video track, because if I do not the output would only be the 3 audio tracks inside the MKV. |
31st December 2018, 08:08 | #8 | Link |
Registered User
Join Date: Dec 2018
Posts: 21
|
If someone could help me with the CLI, as I have very little idea of what I'm doing . I'd like to change audio to include the following from the default track: AC3 5.1 384kbps and AAC 2.0 128kbps
Also, would like to encode to h264, 1080p, .mp4 - Thanks! Just configure what I have already: ffmpeg.exe -i video.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx265 -crf 18 -preset slower output.mkv |
6th January 2019, 11:12 | #9 | Link |
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,277
|
You need to run 'ffmpeg -i video.mkv' to see the mapping ffmpeg assumes, based on that mapping adding (somewhere behind the loading of the inputs):
Code:
-c:a copy Code:
-c:a copy -map 0:a:0 Code:
-c:a copy -map 0:a:1 Code:
-c:a copy -map 0:a:0 -map 0:a:1 Looking at: Code:
-map A:a:B a sets that only audio streams should be looked at B sets the index of the streams from the selection (here 'a' = audio) |
6th January 2019, 12:42 | #10 | Link | |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
Quote:
"Passthrough all audio streams from first input file" is: Code:
-map 0:a -c:a copy Last edited by sneaker_ger; 6th January 2019 at 12:46. |
|
6th January 2019, 18:00 | #11 | Link |
Registered User
Join Date: Dec 2018
Posts: 21
|
Awesome thank you both. To limit how many times I re-encode, could either of you provide the code for "AC3 5.1 384kbps and AAC 2.0 128kbps"? My target is taking the UHD/HDR down to FHD/SDR with those two aforementioned audio streams for remote Emby/Plex streams. This will limit the need for the server to transcode the file.
Also, does FFmpeg encode to .mp4? If so, how do I tell it to? |
6th January 2019, 18:05 | #12 | Link |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
-c:a ac3
(it will downmix to 5.1 if necessary since the ac3 encoder doesn't support more than 6 channels anyways) -c:a aac -ac 2 For aac encoding with stereo downmix. Note that both of these will re-encode even if source is already ac3/aac. So use -c:a copy if that is the case to preserve 100% quality. mp4 output: If the output file name ends with ".mp4" ffmpeg will automatically create an mp4 file. Last edited by sneaker_ger; 6th January 2019 at 18:09. |
6th January 2019, 18:55 | #13 | Link |
...?
Join Date: Nov 2005
Location: Florida
Posts: 1,420
|
I don't know if/how well FFmpeg can handle LFE mixing. Most of the time when I process my (4K or not) Blu-ray rips for watching on my desktop, I use eac3to to downmix and mix the LFE channel into the stereo signal (then encode the result to Opus and remux with the original video stream) so that when watching it back with mpv it doesn't cause nasty clipping when I try to use any volume boosting.
Of course, if you've got the right speaker setup, this is probably a completely moot point, but it is something to consider if not. |
6th January 2019, 19:21 | #14 | Link | ||
Registered User
Join Date: Dec 2018
Posts: 21
|
Quote:
Quote:
In regards to the LFE, I think the client would handle this if they have an AC3 capable player and if not the server will force the AAC instead. So to recap my code will look like: ffmpeg.exe -i video.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:a ac3 -c:a aac -ac 2 -c:v libx265 -crf 18 -preset slower output.mp4 ffmpeg.exe -i video.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:a ac3 -c:a aac -ac 2 -c:v libx265 -crf 18 -preset slower output.mp4 EDIT: It only encoded the red. Last edited by EmKayVe; 6th January 2019 at 19:36. |
||
22nd February 2019, 16:42 | #15 | Link | ||||
Registered User
Join Date: Mar 2006
Posts: 1,049
|
Quote:
Usually LFE is ignored during downmixing (Dolby recommendation - personally i think this is due high risk of over-ranging but sane amount of LFE should be fine). Personally i use private down-mix: for more than 5.1 to 5.1 scheme (critical feedback appreciated - didn't found anything on this topic - also Dolby documentation not very helpful) Quote:
Quote:
or quite interesting HRTF based downmixed (main intention is headphone listening for example on your portable audio device 7.1 to 2.0@HRTF: Quote:
Last edited by tebasuna51; 31st October 2019 at 11:03. |
||||
6th January 2019, 19:50 | #16 | Link |
Registered User
Join Date: Dec 2002
Posts: 5,565
|
You want the same audio stream twice within the same output file? This wasn't clear to me from your other post. Then you have to map the same stream twice and use stream specifiers to tell ffmpeg which track the -c:a and -ac options apply to:
Code:
-map 0:v:0 -map 0:a:0 -map 0:a:0 -c:a:0 ac3 -c:a:1 aac -ac:a:1 2 |
6th January 2019, 19:56 | #17 | Link | |
Registered User
Join Date: Dec 2018
Posts: 21
|
Quote:
So something like this should work right? ffmpeg.exe -i D:\Videos\Media\Temp\video.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p,zscale=s=1920x1080 -map 0:v:0 -map 0:a:0 -map 0:a:0 -c:a:0 ac3 -c:a:1 aac -ac:a:1 2 -c:v libx265 -crf 20 -preset slower D:\Videos\Media\Temp\output.mp4 |
|
6th January 2019, 20:00 | #18 | Link |
ffx264/ffhevc author
Join Date: May 2007
Location: /dev/video0
Posts: 1,844
|
it is not recommended to turn off desat (desat=0). This was derived from testing on the broken HDR sample from Sony (Camp fire). This sample is known to have screwed up HDR data, thus an incorrect conclusion was made that you should always disable desat
|
7th January 2019, 05:09 | #20 | Link |
Registered User
Join Date: Dec 2018
Posts: 21
|
OK according to @Selur post here he is using desat=2. I have found his code to be significantly different than my HDR to SDR conversion code I've been using. I'm till learning gents... Can anyone decode the code for me? Would this be superior for an UHD/HDR conversion? Remember, I'm re-encoding "UHD - BD movies" to a target of 1080p/SDR/AC3 (.mp4).
Code:
ffmpeg -y -loglevel fatal -threads 8 -i "F:\TestClips&Co\files\HDR\4K sun HDR test.mp4" -map 0:0 -an -sn -vf zscale=tin=smpte2084:min=bt2020nc:pin=bt2020:rin=tv:t=smpte2084:m=bt2020nc:p=bt2020:r=tv,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=2.000:peak=0.000,zscale=t=bt709:m=bt709:r=tv -pix_fmt yuv420p10le -strict -1 -vsync 0 -f yuv4mpegpipe - | x265 --input - --output-depth 10 --y4m --profile main10 --qg-size 8 --limit-modes --no-open-gop --opt-ref-list-length-pps --radl 2 --lookahead-slices 0 --crf 18.00 --opt-qp-pps --cbqpoffs -2 --crqpoffs -2 --limit-refs 0 --ssim-rd --psy-rd 2.50 --rdoq-level 2 --psy-rdoq 10.00 --aq-mode 0 --deblock=-1:-1 --limit-sao --range limited --colormatrix bt709 --output "E:\Temp\00_35_54_2910_01.265" |
|
|