Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avcodec.py issue... #779

Closed
shpankey opened this issue Aug 6, 2017 · 10 comments
Closed

avcodec.py issue... #779

shpankey opened this issue Aug 6, 2017 · 10 comments

Comments

@shpankey
Copy link

shpankey commented Aug 6, 2017

in the avcodec.py file,

class NVEncH265(H265Codec):
"""
Nvidia H.265/AVC video codec.
"""
codec_name = 'nvenc_h265'
ffmpeg_codec_name = 'nvenc_hevc'

...but shouldn't that be: hevc_nvenc on that last line instead? Also, should read HEVC instea of AVC. So I replaced mine with the following...

class NVEncH265(H265Codec):
"""
Nvidia H.265/HEVC video codec.
"""
codec_name = 'nvenc_h265'
ffmpeg_codec_name = 'hevc_nvenc'

@shpankey
Copy link
Author

shpankey commented Aug 6, 2017

Also, since switching that around, I FINALLY got hevc encoding to work via nvenc hardware, but on a rare occasion I will get something like the following... (otherwise, it's working AWESOME!)

C:\Users\chads\Desktop\sickbeard_mp4_automator-master>manual.py -a
Manual processor started.
C:\Python27\python.exe
32bit Python.
Enter path to file:
#: T:\Movies
Processing file T:\Movies\MOVIENAME.mkv
Reading video stream.
Video codec detected: h264.
Pix Fmt: yuv420p.
Reading audio streams.
Audio detected for stream #1: flac [eng].
Creating audio stream 0 from source audio stream 1 [iOS-audio].
Audio track is number 0 setting disposition to default
Creating audio stream 1 from source stream 1.
Audio Track is number 1 setting disposition to none
Adding copy of original audio track in format flac
Reading subtitle streams.
Subtitle detected for stream #2: subrip [eng].
Creating subtitle stream 0 from source stream 2.
Subtitle detected for stream #3: subrip [eng].
Creating subtitle stream 1 from source stream 3.
Subtitle detected for stream #4: hdmv_pgs_subtitle [eng].
Subtitle detected for stream #5: hdmv_pgs_subtitle [eng].
Subtitle detected for stream #6: hdmv_pgs_subtitle [fre].
Subtitle detected for stream #7: hdmv_pgs_subtitle [spa].
{
"preopts": [
"-fix_sub_duration"
],
"subtitle": {
"0": {
"map": 2,
"codec": "mov_text",
"language": "eng",
"encoding": null
},
"1": {
"map": 3,
"codec": "mov_text",
"language": "eng",
"encoding": null
}
},
"format": "mp4",
"postopts": [
"-threads",
"auto"
],
"video": {
"map": 0,
"codec": "nvenc_h265",
"crf": 17,
"level": 4.1
},
"audio": {
"0": {
"map": 1,
"language": "eng",
"channels": 2,
"codec": "aac",
"disposition": "default",
"bitrate": 256,
"filter": null
},
"1": {
"map": 1,
"language": "eng",
"channels": 8,
"codec": "eac3",
"disposition": "none",
"bitrate": 2048,
"filter": null
},
"2": {
"map": 1,
"codec": "copy",
"disposition": "none",
"language": "eng"
}
}
}
Starting conversion.
[ ] 0%Error converting file, FFMPEG error.
Traceback (most recent call last):
File "C:\Users\chads\Desktop\sickbeard_mp4_automator-master\mkvtomp4.py", line 694, in convert
for timecode in conv:
File "C:\Users\chads\Desktop\sickbeard_mp4_automator-master\converter_init_.py", line 243, in convert
timeout=timeout, preopts=preopts, postopts=postopts):
File "C:\Users\chads\Desktop\sickbeard_mp4_automator-master\converter\ffmpeg.py", line 548, in convert
total_output, pid=p.pid)

FFMpegConvertError: <FFMpegConvertError error="Exited with code 1", pid=12760,
cmd="C:\ffmpeg\bin\ffmpeg.exe -fix_sub_duration -i T:\Movies\MOVIENAME.mkv -vcodec hevc_nvenc -map 0:0 -crf 17 -level 4.1 -tag:v hvc1 -c:a:0 aac -map 0:1 -disposition:a:0 default -ac:a:0 2 -b:a:0 256k -metadata:s:a:0 language=eng -strict experimental -c:a:1 eac3 -map 0:1 -disposition:a:1 none -ac:a:1 8 -b:a:1 640k -metadata:s:a:1 language=eng -c:a:2 copy -map 0:1 -metadata:s:a:2 language=eng -disposition:a:2 none -c:s:0 mov_text -map 0:2 -metadata:s:s:0 language=eng -c:s:1 mov_text -map 0:3 -metadata:s:s:1 language=eng -f mp4 -threads auto -y T:\Movies\MOVIENAME.mp4">
C:\ffmpeg\bin\ffmpeg.exe -fix_sub_duration -i T:\Movies\MOVIENAME.mkv -vcodec hevc_nvenc -map 0:0 -crf 17 -level 4.1 -tag:v hvc1 -c:a:0 aac -map 0:1 -disposition:a:0 default -ac:a:0 2 -b:a:0 256k -metadata:s:a:0 language=eng -strict experimental -c:a:1 eac3 -map 0:1 -disposition:a:1 none -ac:a:1 8 -b:a:1 640k -metadata:s:a:1 language=eng -c:a:2 copy -map 0:1 -metadata:s:a:2 language=eng -disposition:a:2 none -c:s:0 mov_text -map 0:2 -metadata:s:s:0 language=eng -c:s:1 mov_text -map 0:3 -metadata:s:s:1 language=eng -f mp4 -threads auto -y

T:\Movies\MOVIENAME.mp4
ffmpeg version N-86935-g44e9783 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.1.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
libavutil 55. 69.101 / 55. 69.101
libavcodec 57.102.100 / 57.102.100
libavformat 57. 76.100 / 57. 76.100
libavdevice 57. 7.100 / 57. 7.100
libavfilter 6. 97.100 / 6. 97.100
libswscale 4. 7.101 / 4. 7.101
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100
[matroska,webm @ 0000000002f67fc0] Could not find codec parameters for stream 4 (Subtitle: hdmv_pgs_subtitle): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[matroska,webm @ 0000000002f67fc0] Could not find codec parameters for stream 5 (Subtitle: hdmv_pgs_subtitle): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[matroska,webm @ 0000000002f67fc0] Could not find codec parameters for stream 6 (Subtitle: hdmv_pgs_subtitle): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[matroska,webm @ 0000000002f67fc0] Could not find codec parameters for stream 7 (Subtitle: hdmv_pgs_subtitle): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, matroska,webm, from 'T:\Movies\MOVIENAME.mkv':
Metadata:
title :
encoder : libebml v1.3.3 + libmatroska v1.4.4
creation_time : 2016-06-04T22:25:29.000000Z
Duration: 01:43:34.79, start: 0.000000, bitrate: 11236 kb/s
Chapter #0:0: start 0.000000, end 355.605000
Metadata:
title : 00:00:00.000
Chapter #0:1: start 355.605000, end 892.517000
Metadata:
title : 00:05:55.605
Chapter #0:2: start 892.517000, end 1158.157000
Metadata:
title : 00:14:52.517
Chapter #0:3: start 1158.157000, end 1451.992000
Metadata:
title : 00:19:18.157
Chapter #0:4: start 1451.992000, end 1941.940000
Metadata:
title : 00:24:11.992
Chapter #0:5: start 1941.940000, end 2579.243000
Metadata:
title : 00:32:21.940
Chapter #0:6: start 2579.243000, end 2867.740000
Metadata:
title : 00:42:59.243
Chapter #0:7: start 2867.740000, end 3217.089000
Metadata:
title : 00:47:47.740
Chapter #0:8: start 3217.089000, end 3420.626000
Metadata:
title : 00:53:37.089
Chapter #0:9: start 3420.626000, end 3790.745000
Metadata:
title : 00:57:00.626
Chapter #0:10: start 3790.745000, end 4280.193000
Metadata:
title : 01:03:10.745
Chapter #0:11: start 4280.193000, end 4549.420000
Metadata:
title : 01:11:20.193
Chapter #0:12: start 4549.420000, end 5061.265000
Metadata:
title : 01:15:49.420
Chapter #0:13: start 5061.265000, end 5299.085000
Metadata:
title : 01:24:21.265
Chapter #0:14: start 5299.085000, end 5851.512000
Metadata:
title : 01:28:19.085
Chapter #0:15: start 5851.512000, end 6214.792000
Metadata:
title : 01:37:31.512
Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709/unknown/unknown, progressive), 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: flac, 48000 Hz, 7.1, s32 (24 bit) (default)
Stream #0:2(eng): Subtitle: subrip
Metadata:
title : English
Stream #0:3(eng): Subtitle: subrip
Metadata:
title : English SDH
Stream #0:4(eng): Subtitle: hdmv_pgs_subtitle
Stream #0:5(eng): Subtitle: hdmv_pgs_subtitle
Stream #0:6(fre): Subtitle: hdmv_pgs_subtitle
Stream #0:7(spa): Subtitle: hdmv_pgs_subtitle
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
Stream #0:1 -> #0:1 (flac (native) -> aac (native))
Stream #0:1 -> #0:2 (flac (native) -> eac3 (native))
Stream #0:1 -> #0:3 (copy)
Stream #0:2 -> #0:4 (subrip (srt) -> mov_text (native))
Stream #0:3 -> #0:5 (subrip (srt) -> mov_text (native))
Press [q] to stop, [?] for help
[AVFilterGraph @ 0000000004832260] [Eval @ 00000000005fe290] Undefined constant or missing '(' in 'auto'
[AVFilterGraph @ 0000000004832260] Unable to parse option value "auto"
[AVFilterGraph @ 0000000004d0f300] [Eval @ 00000000005fe290] Undefined constant or missing '(' in 'auto'
[AVFilterGraph @ 0000000004d0f300] Unable to parse option value "auto"
[eac3 @ 0000000004dd8600] Specified channel layout '7.1' is not supported
Error initializing output stream 0:2 -- Error while opening encoder for output stream #0:2 - maybe incorrect parameters such as bit_rate, rate, width or height

[aac @ 0000000004dd72c0] Qavg: 1048.422
[aac @ 0000000004dd72c0] 2 frames left in the queue on closing
Conversion failed!

@shpankey
Copy link
Author

shpankey commented Aug 6, 2017

Looking back now, looks like maybe the FLAC audio caused an issue w/ eac3?

@shpankey
Copy link
Author

shpankey commented Aug 6, 2017

Changing from eac3 to ac3 corrected the issue. It now works on all files. Re-encoding using this method has given me back 600 Gigs by running 2 threads overnight, in a single night.

@mdhiggins
Copy link
Owner

Good catch, I just pushed a commit that fixed that encoder being wrong

@mdhiggins
Copy link
Owner

Also 600 is no joke, how's the quality on all these videos? Any noticeable loss?
And just for my own knowledge can you post your autoProcess settings? I have many terabytes and it would be nice to reclaim some space

@shpankey
Copy link
Author

shpankey commented Aug 8, 2017

Sorry for taking so long, I was away. Anyhow, it was a marked decline in picture quality. I was doing S1 of 24 (the old one) and filesize of each episode went from ~ 4.1g down to ~700m, but it was enough of a drop in IQ to go ahead and stop processing my library, as much as I wanted to keep doing it to save space. The Nvidia encoder is super fast, but the quality just isn't there (without some tweaks of some kind).

I've been experimenting w/ StaxRip and encoding using both Intel H.265 and Nvidia H.265. It has a nice graphical user interface to enable various options, but I'm not up to speed on which options do what. But setting both of these to encode the same movie, max settings (a few options have "best" or "quality" avail, so using those) it's clear to me that the Intel H.265 is lightyears beyond nVidia's (mind you, I'm using Kaby Lake here), not in speed, Nvidia encoder clearly has that crown, but in image quality.

If this helps:

StaxRip Intel H.265 settings....
--codec hevc --quality best --profile main --level 4.1 --output-buf 64 --videoformat ntsc --colormatrix auto --colorprim auto --transfer auto --fallback-rc --cqp 24:26:27

StaxRip Nvidia H.265 settings...
--cqp 20:23:25 --codec h265 --preset quality --level 4.1 --max-bitrate 30000 --output-buf 128 --videoformat ntsc --colormatrix auto --colorprim auto --transfer auto

Taking a 30G movie file in h264, Intel H.265 takes it down to about 9g whereas Nvidia H.265 takes it down to 4-5g but the Intel H.265 looks every bit as good as the original (to my eye) and the Nvidia one has a noticeable decline in IQ (but way better than just using ffmpeg via the script, so those options in StaxRip definitely made a difference in IQ).

@mdhiggins
Copy link
Owner

I would think the Intel vs NVidia shouldn't make a difference in size or quality, but rather you're getting a different quality setting with the lower sized one which is why it looks worse

@shpankey
Copy link
Author

shpankey commented Aug 8, 2017

Yup, that makes sense, I just am not sure what settings are doing what. I would love to find some IQ settings to enable for the Nvidia one, but I'm not familiar with what does what. This is what the -help has on it (sorry for the long post following)...

Encoder hevc_nvenc [NVIDIA NVENC hevc encoder]:
    General capabilities: delay
    Threading capabilities: none
    Supported pixel formats: yuv420p nv12 p010le yuv444p yuv444p16le bgr0 rgb0 cuda
hevc_nvenc AVOptions:
  -preset            <int>        E..V.... Set the encoding preset (from 0 to 11) (default medium)
     default                      E..V....
     slow                         E..V.... hq 2 passes
     medium                       E..V.... hq 1 pass
     fast                         E..V.... hp 1 pass
     hp                           E..V....
     hq                           E..V....
     bd                           E..V....
     ll                           E..V.... low latency
     llhq                         E..V.... low latency hq
     llhp                         E..V.... low latency hp
     lossless                     E..V.... lossless
     losslesshp                   E..V.... lossless hp
  -profile           <int>        E..V.... Set the encoding profile (from 0 to 4) (default main)
     main                         E..V....
     main10                       E..V....
     rext                         E..V....
  -level             <int>        E..V.... Set the encoding level restriction (from 0 to 186) (default auto)
     auto                         E..V....
     1                            E..V....
     1.0                          E..V....
     2                            E..V....
     2.0                          E..V....
     2.1                          E..V....
     3                            E..V....
     3.0                          E..V....
     3.1                          E..V....
     4                            E..V....
     4.0                          E..V....
     4.1                          E..V....
     5                            E..V....
     5.0                          E..V....
     5.1                          E..V....
     5.2                          E..V....
     6                            E..V....
     6.0                          E..V....
     6.1                          E..V....
     6.2                          E..V....
  -tier              <int>        E..V.... Set the encoding tier (from 0 to 1) (default main)
     main                         E..V....
     high                         E..V....
  -rc                <int>        E..V.... Override the preset rate-control (from -1 to INT_MAX) (default -1)
     constqp                      E..V.... Constant QP mode
     vbr                          E..V.... Variable bitrate mode
     cbr                          E..V.... Constant bitrate mode
     vbr_minqp                    E..V.... Variable bitrate mode with MinQP (deprecated)
     ll_2pass_quality              E..V.... Multi-pass optimized for image quality (deprecated)
     ll_2pass_size                E..V.... Multi-pass optimized for constant frame size (deprecated)
     vbr_2pass                    E..V.... Multi-pass variable bitrate mode (deprecated)
     cbr_ld_hq                    E..V.... Constant bitrate low delay high quality mode
     cbr_hq                       E..V.... Constant bitrate high quality mode
     vbr_hq                       E..V.... Variable bitrate high quality mode
  -rc-lookahead      <int>        E..V.... Number of frames to look ahead for rate-control (from 0 to INT_MAX) (default 0)
  -surfaces          <int>        E..V.... Number of concurrent surfaces (from 0 to 64) (default 0)
  -cbr               <boolean>    E..V.... Use cbr encoding mode (default false)
  -2pass             <boolean>    E..V.... Use 2pass encoding mode (default auto)
  -gpu               <int>        E..V.... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from -2 to INT_MAX) (default any)
     any                          E..V.... Pick the first device available
     list                         E..V.... List the available devices
  -delay             <int>        E..V.... Delay frame output by the given amount of frames (from 0 to INT_MAX) (default INT_MAX)
  -no-scenecut       <boolean>    E..V.... When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts (default false)
  -forced-idr        <boolean>    E..V.... If forcing keyframes, force them as IDR frames. (default false)
  -spatial_aq        <boolean>    E..V.... set to 1 to enable Spatial AQ (default false)
  -temporal_aq       <boolean>    E..V.... set to 1 to enable Temporal AQ (default false)
  -zerolatency       <boolean>    E..V.... Set 1 to indicate zero latency operation (no reordering delay) (default false)
  -nonref_p          <boolean>    E..V.... Set this to 1 to enable automatic insertion of non-reference P-frames (default false)
  -strict_gop        <boolean>    E..V.... Set 1 to minimize GOP-to-GOP rate fluctuations (default false)
  -aq-strength       <int>        E..V.... When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive) (from 1 to 15) (default 8)
  -cq                <float>      E..V.... Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0)
  -aud               <boolean>    E..V.... Use access unit delimiters (default false)
  -bluray-compat     <boolean>    E..V.... Bluray compatibility workarounds (default false)
  -init_qpP          <int>        E..V.... Initial QP value for P frame (from -1 to 51) (default -1)
  -init_qpB          <int>        E..V.... Initial QP value for B frame (from -1 to 51) (default -1)
  -init_qpI          <int>        E..V.... Initial QP value for I frame (from -1 to 51) (default -1)
  -qp                <int>        E..V.... Constant quantization parameter rate control method (from -1 to 51) (default -1)
  -weighted_pred     <int>        E..V.... Set 1 to enable weighted prediction (from 0 to 1) (default 0)

@shpankey
Copy link
Author

shpankey commented Aug 8, 2017

Almost forgot, you asked for these (assuming you just want the mp4 part here). Also, I was going for speed over everything else, since Plex doesn't need tags or posters or subtitles (using plex channel for those, if needed). I used CRF 14 to try and get a better picture from the Nvidia encodes. Nothing special in mine really....

[MP4]
ffmpeg = C:\ffmpeg\bin\ffmpeg.exe
ffprobe = C:\ffmpeg\bin\ffprobe.exe
threads = auto
output_directory =
copy_to =
move_to =
output_extension = mp4
output_format = mp4
delete_original = True
relocate_moov = True
video-codec = nvenc_h265,hevc_nvenc,hevc,nvenc_hevc,nvenc_h265,h265_nvenc,h265nvenc,h265hevc,h265qsv,h265vaapi,h265,x265,h.265,VP9,h264qsv,h264_nvenc,h264vaapi,h264,x264,h.264
video-bitrate =
video-crf = 14
video-max-width =
h264-max-level = 4.1
use-qsv-decoder-with-encoder = True
ios-audio = True
ios-first-track-only = True
ios-audio-filter =
ios-move-last = False
max-audio-channels =
audio-codec = ac3,eac3,aac
audio-language = eng
audio-default-language = eng
audio-channel-bitrate = 256
audio-filter =
audio-copy-original = True
subtitle-codec = mov_text
subtitle-language = eng
subtitle-default-language = eng
subtitle-encoding =
fullpathguess = True
convert-mp4 = True
tagfile = False
tag-language = en
download-artwork = False
download-subs = False
embed-subs = True
sub-providers = addic7ed,podnapisi,thesubdb,opensubtitles
permissions = 0777
post-process = False
pix-fmt =
aac_adtstoasc = False
preopts =
postopts =

@shpankey
Copy link
Author

shpankey commented Aug 31, 2017

Just wanted to update the above for you mdhiggins. I've changed my settings, getting excellent results running 2 instances of this at the same time. With these settings, I did Grey's Anatomy (13 seasons) with ~1.4 to 1.5 gig mkv files, and is outputting .4 to .5 gig mp4 files in hevc via nvenc. Quality is not too bad. Not a deal breaker for the savings in space, imo.

If I could just get someone to tell me how the preopts and postopts options work (below), I could add some more nvidia custom settings to my options below to make it even better, but as it stands now, I only can pull off 1 option for each.

[MP4]
ffmpeg = C:\ffmpeg\bin\ffmpeg.exe
ffprobe = C:\ffmpeg\bin\ffprobe.exe
threads = auto
output_directory =
copy_to =
move_to =
output_extension = mp4
output_format = mp4
delete_original = True
relocate_moov = True
video-codec = nvenc_h265,hevc_nvenc,nvenc_hevc,h265_nvenc,h265nvenc,h265,x265,h.265,hevc,hevc1,h265qsv,h265vaapi
video-bitrate =
video-crf = 14
video-max-width =
h264-max-level = 4.1
use-qsv-decoder-with-encoder = True
ios-audio = True
ios-first-track-only = True
ios-audio-filter =
ios-move-last = False
max-audio-channels =
audio-codec = ac3,eac3,aac
audio-language = eng
audio-default-language = eng
audio-channel-bitrate = 256
audio-filter =
audio-copy-original = True
subtitle-codec = srt
subtitle-language = eng
subtitle-default-language = eng
subtitle-encoding =
fullpathguess = True
convert-mp4 = True
tagfile = False
tag-language = en
download-artwork = False
download-subs = False
embed-subs = False
sub-providers = addic7ed,podnapisi,thesubdb,opensubtitles
permissions = 0777
post-process = False
pix-fmt = nv12
aac_adtstoasc = False
postopts = -rc, constqp
preopts = -vsync, 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants