rigaya / NVEnc

NVENCによる高速エンコードの性能実験
https://rigaya34589.blog.fc2.com/blog-category-17.html
Other
1.07k stars 112 forks source link

Audio streams help and some small bugs #574

Closed Jigsawbg closed 5 months ago

Jigsawbg commented 6 months ago

About a month ago I stumbled across this encoder made by Rigaya and I am very impressed with the end result! nvencc64 performs better than ffmpeg for video encoding and for that I started using only nvencc64. But there is a difficulty with the audio streams. I would like to get some help.

1. I want to copy one or more of the original streams and at the same time I want to use one of the original streams as a source to create a second, third, fourth, etc. audio stream with a different codec and different settings for each subsequent audio stream. To be more clear, I show the ffmpeg commands with which I achieve the desired final result (I have omitted the video encoding commands). a:0 is Dolby TrueHD 5.1 or can be DTS-HD MA 5.1. ffmpeg.exe ^ -i "input" ^ -map 0:a:0 ^ -map 0:a:0 ^ -c:a:0 copy ^ -c:a:1 aac ^ -ac:a:1 2 ^ -ab:a:1 192k ^ -filter:a:1 "pan=stereo|c0=0.5 c2+0.707 c0+0.707 c4+0.5 c3|c1=0.5 c2+0.707 c1+0.707 c5+0.5 c3","volume=-4.0dB" ^ "output.mkv"

I tried various combinations with --audio-copy --audio-codec --audio-stream --audio-bitrate --audio-filter... but no luck.

2. How can I set "precision" parameter for "soxr" resampler? Default precision value is 20, but can be set up to 33. For 24bit input, a value greater than 20 must be used. The original a:0 stream is LPCM 96kHz: -c:a:0 pcm_s24le ^ -filter:a:0 "aresample=48000:resampler=soxr:precision=28"

I already noticed that nvencc64 automatically transcode LPCM (blue ray audio) to pcm_s24le or pcm_s16le. Thanks for this Rigaya!

3. I can't find way to reorder streams in output container (mkv for instance).

4. I think there is a bug with audio-disposition. If I set by mistake 1?default, instead of 2?default or 3?default: --audio-copy 2,3 ^ --audio-disposition 1?default ^ The output file also contains the first audio stream, which doesn't seem logical to me.

5. Also, if the output file contains Cyrillic characters or language-specific Latin characters like Złotych Piasków, there is a problem with log visualization in CMD. But nvencc64 works without problem.

Points 1 to 3 are connected by the same problem that I am trying to solve because I have concrete cases for it. I will explain it if necessary. Rigaya I hope I haven't been too annoying with my questions and asking for help.

rigaya commented 6 months ago

1. Please try below when you want to copy 1st track and encode 2nd track.

--audio-copy 1 --audio-codec 2?aac --audio-bitrate 2?aac --audio-filter 2?volume=-4dB

2. I haven't tried 96kHz audio, but below might work.

--audio-filter 1?aresample=48000:resampler=soxr:precision=28

3. I'm sorry but I have intentionally not added stream reordering to reduce implementation complexity.

4. Please add --audio-copy or --audio-codec for each track, otherwise the behavior is undefined. I'm not going in further into this, as it can be easily corrected.

5. Inside nvencc, characters are handled in Unicode so it should not be a problem at all.

Jigsawbg commented 6 months ago

Thanks for your responce Rigaya. Appreciates your attention!

But I get the impression that I am not understood correctly. Maybe I didn't express myself correctly. I am sorry about that.

1. I don't want to re-encode the second audio stream. I want to copy the first audio stream and create(by re-encode/transcode) a second audio stream(which until now did not exist), using as a source first audio audio stream.

In my first post in point 1, I have shown exactly such functionality, but with ffmpeg:

In this example 0:a:0 is the only one original DTS-HD MA 5.1 stream in container. In case with ffmpeg I have to use two times in a row -map 0:a:0, because first -map 0:a:0 is used by -c:a:0 copy to copy the first audio stream and the second -map 0:a:0 is used by -c:a:1 aac to create second audio stream, then I apply -ac:a:1 2(stereo) -ab:a:1 192k -filter:a:1 "pan=stereo... to already created second audio stream а:1. but that is specific ffmpeg syntax...Whatever

--audio-copy 1 --audio-codec 2?aac --audio-bitrate 192 --audio-filter 2?volume=-4dB

nvencc64 return -> avcuvid: could not find audio track #2

2.

--audio-codec 1?pcm_s24le ^
--audio-filter 1?aresample=48000:resampler=soxr:precision=28 ^

It doesn't seem to do anything. No error message. --debug-cmd-parser returns-> parsing 43: --audio-filter: OK But if I use:

--audio-codec 1?pcm_s24le ^
--audio-samplerate 1?48000 ^
--audio-resampler 1?soxr ^

Тhings work, but can't apply precision parameter. If I try, nvencc64 returns error.

3. To reorder the streams I use remux and thought it was easy to implement, but i'm probably wrong. But I understand. No problem, I'll use ffmpeg. If anyone needs it, use this:

ffmpeg.exe -hide_banner -loglevel info -stats ^
-analyzeduration 2147483647 ^
-probesize 2147483647 ^
-guess_layout_max 0 ^
-i "A.mkv" ^
-map 0:0 ^
-map 0:3 ^
-map 0:1 ^
-map 0:4 ^
-map 0:2 ^
-c copy ^
"A_remuxed.mkv"

of course taking into account his streams (-map Х:Х)

4. Actually --audio-copy works perfectly in the form: --audio-copy 2,4,5... and so on. The problem occurs when you write the wrong track number --audio-disposition 1?default. Then --audio-disposition behaves like --audio-copy 1. Even if I copy just one track and then add the wrong disposition track --audio-copy 2 --audio-disposition 1?default, again --audio-disposition behaves like --audio-copy. Of course, this is not something critical.

5. I mean this: rigaya1

Instead: rigaya2

To be honest, if I need to re-encode and re-organize the audio streams I use ffmpeg with the ability to copy the video stream. Then I use nvencc64 to re-encode just the video stream and --audio-copy. So I get everything I want the way I want it in two separate processes. Even sometimes with piping I combine ffmpeg and nvencc64 in a single encoding job. I get the best of both worlds :D But I was hoping to avoid ffmpeg entirely.

Anyway...I really appreciate and respect what you did with nvencc64!

rigaya commented 5 months ago
  1. As audio feature of NVEncC is not designed to apply complex audio transcoding, it is designed only for 1to1 conversion. I'm afraid it is not possible to extend to enable audio copy and audio encode from a same track.

  2. I were not actually able to reproduce the soxr error, NVEnc 7.49 might be able to work fine with --audio-samplerate 48000 --audio-resampler resampler=soxr:precision=28.

  3. I mean the characters are handling properly in unicode internally, so you will not get trouble with the actual encoding, it's only the console problem.

Jigsawbg commented 5 months ago

Thank you for response Rigaya!

1. OK. I understand.

2.

--audio-samplerate 1?48000
--audio-resampler 1?resampler=soxr:precision=28

Works as expected. Thanks!

4. Here I decided not to open a new Issue after some tests with 7.49. Like --audio-disposition, --audio-metadata clear also breaks the proper functionality of --audio-copy, but in different way. When I use --audio-metadata clear, --audio-copy stops selecting the streams. Always copies all streams.

5. OK. This is not a problem at all.

rigaya commented 5 months ago
  1. You also need to use --audio-metadata 1?clear style for that.

I can understand that these audio command line feature extracting audio streams is a bit confusing and not designed well, but at this time you need to always correctly select audio channel for all --audio-* options if you try selecting audio streams.

Jigsawbg commented 5 months ago

OK. Thanks for the replay Rigaya!

rigaya commented 4 months ago

NVEnc 7.53 will have a little better handling of problem "4." mentioned on this isssue, audio track(s) which is not selected by --audio-codec or --audio-copy shall not be included in the output even if --audio-xxx options (except --audio-codec or --audio-copy) are used without track selection.