Jump to content


Photo

FFmpeg Transcoding w/ CRF 0 doesn't work

FFmpeg CRF 0 Emby Server Beta Debian 8

  • Please log in to reply
14 replies to this topic

#1 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 10:52 PM

When setting the CRF option in the transcoding options to "0" the file fails to play and FFmpeg presents an error as shown below.

 

Probably missing something... :/

 

Ideas?

Application version: 3.2.36.2

http://192.168.0.3:40330/emby/videos/418d80970834ea0588c1bb0697edb255/hls1/main/0.ts?DeviceId=0f646ede5a6cee1566fe5433befcb07c53005e86&MediaSourceId=418d80970834ea0588c1bb0697edb255&VideoCodec=h264&AudioCodec=mp3,aac&AudioStreamIndex=1&VideoBitrate=59616000&AudioBitrate=384000&PlaySessionId=fd290cd71b4c488e96b899a3076fe5c1&api_key=99bd3ef4dc7841fbb78343b4dded2dce&CopyTimestamps=false&TranscodingMaxAudioChannels=2&EnableSubtitlesInManifest=false&Tag=f6d58280eee7c62ff832b22128ed19cd&RequireAvc=true&RequireNonAnamorphic=false&SegmentContainer=ts&MinSegments=1&BreakOnNonKeyFrames=True&h264-profile=high,main,baseline,constrainedbaseline&h264-level=51&h264-deinterlace=true

{"Protocol":"File","Id":"418d80970834ea0588c1bb0697edb255","Path":"/media/HDD/TV Shows/The Man in the High Castle/Season 2/S02E01 - The Tiger's Cave.mkv","Type":"Default","Container":"mkv,webm","Name":"1080P/HEVC/EAC3","IsRemote":false,"ETag":"f6d58280eee7c62ff832b22128ed19cd","RunTimeTicks":34244149248,"ReadAtNativeFramerate":false,"IgnoreDts":false,"IgnoreIndex":false,"GenPtsInput":false,"SupportsTranscoding":true,"SupportsDirectStream":true,"SupportsDirectPlay":true,"IsInfiniteStream":false,"RequiresOpening":false,"RequiresClosing":false,"SupportsProbing":true,"RequiresLooping":false,"VideoType":"VideoFile","MediaStreams":[{"Codec":"hevc","TimeBase":"1/1000","CodecTimeBase":"1/25","IsInterlaced":false,"BitRate":2264283,"RefFrames":1,"IsDefault":true,"IsForced":false,"Height":1080,"Width":1920,"AverageFrameRate":25,"RealFrameRate":25,"Profile":"Main","Type":"Video","AspectRatio":"16:9","Index":0,"IsExternal":false,"IsTextSubtitleStream":false,"SupportsExternalStream":false,"PixelFormat":"yuv420p","Level":120,"IsAnamorphic":false},{"Codec":"eac3","TimeBase":"1/1000","CodecTimeBase":"1/48000","DisplayTitle":"Dolby Digital+ 5.1 Default","IsInterlaced":false,"ChannelLayout":"5.1","BitRate":384000,"Channels":6,"SampleRate":48000,"IsDefault":true,"IsForced":false,"Type":"Audio","Index":1,"IsExternal":false,"IsTextSubtitleStream":false,"SupportsExternalStream":false,"Level":0,"IsAnamorphic":false},{"Codec":"ass","TimeBase":"1/1000","CodecTimeBase":"0/1","DisplayTitle":"Und","IsInterlaced":false,"IsDefault":false,"IsForced":false,"Type":"Subtitle","Index":2,"IsExternal":false,"IsTextSubtitleStream":true,"SupportsExternalStream":true,"Level":0,"IsAnamorphic":false},{"Codec":"srt","Language":"eng","DisplayTitle":"Eng","IsInterlaced":false,"IsDefault":false,"IsForced":false,"Type":"Subtitle","Index":3,"IsExternal":true,"IsTextSubtitleStream":true,"SupportsExternalStream":true,"Path":"/media/HDD/TV Shows/The Man in the High Castle/Season 2/S02E01 - The Tiger's Cave.eng.srt","IsAnamorphic":true}],"Formats":[],"Bitrate":2648283,"RequiredHttpHeaders":{}}

User policy for Mark: EnablePlaybackRemuxing: True EnableVideoPlaybackTranscoding: True EnableAudioPlaybackTranscoding: True

/var/lib/emby-server/ffmpeg/ffmpeg/ffmpeg -f matroska,webm -i file:"/media/HDD/TV Shows/The Man in the High Castle/Season 2/S02E01 - The Tiger's Cave.mkv" -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 libx264 -vf "scale=trunc(min(max(iw\,ih*dar)\,1920)/2)*2:trunc(ow/dar/2)*2" -pix_fmt yuv420p -preset veryslow -crf 0 -maxrate 4528566 -bufsize 9057132 -profile:v high -level 4.1 -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none -force_key_frames "expr:if(isnan(prev_forced_t),eq(t,t),gte(t,prev_forced_t+3))" -copyts -vsync -1 -codec:a:0 libmp3lame -ac 2 -ab 384000  -f segment -max_delay 5000000 -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 -start_at_zero -segment_time 3  -individual_header_trailer 0 -segment_format mpegts -segment_list_type m3u8 -segment_start_number 0 -segment_list "/media/HDD/Temp/transcoding-temp/58e3b1012a510bc152bd6ddf039e1517.m3u8" -y "/media/HDD/Temp/transcoding-temp/58e3b1012a510bc152bd6ddf039e1517%d.ts"

ffmpeg version N-88289-g783535a Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --enable-encoder=hevc_nvenc --enable-nonfree --enable-libx264 --enable-libx265 --enable-libfreetype --enable-libass --enable-gpl --enable-libvpx --enable-libtheora --enable-libopus --enable-libmp3lame --enable-libfdk-aac --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libgsm --enable-libspeex --enable-libxvid --enable-zlib
  libavutil      56.  0.100 / 56.  0.100
  libavcodec     58.  1.100 / 58.  1.100
  libavformat    58.  0.102 / 58.  0.102
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  0.101 /  7.  0.101
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.100 /  3.  0.100
  libpostproc    55.  0.100 / 55.  0.100
Input #0, matroska,webm, from 'file:/media/HDD/TV Shows/The Man in the High Castle/Season 2/S02E01 - The Tiger's Cave.mkv':
  Metadata:
    ENCODER         : Lavf57.25.100
  Duration: 00:57:04.42, start: 0.000000, bitrate: 2264 kb/s
    Stream #0:0: Video: hevc (Main), yuv420p(tv), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 25 tbc (default)
    Metadata:
      DURATION        : 00:57:04.411000000
    Stream #0:1: Audio: eac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
    Metadata:
      ENCODER         : Lavc57.24.102 eac3
      DURATION        : 00:57:04.415000000
    Stream #0:2: Subtitle: ass
    Metadata:
      ENCODER         : Lavc57.24.102 ass
      DURATION        : 00:54:12.606000000
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (eac3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
x264 [error]: high profile doesn't support lossless
[libx264 @ 0x328f700] Error setting profile high.
[libx264 @ 0x328f700] Possible profiles: baseline main high high10 high422 high444
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[libmp3lame @ 0x32c4dc0] 3 frames left in the queue on closing
Conversion failed!
ffmpeg version N-88289-g783535a Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --enable-encoder=hevc_nvenc --enable-nonfree --enable-libx264 --enable-libx265 --enable-libfreetype --enable-libass --enable-gpl --enable-libvpx --enable-libtheora --enable-libopus --enable-libmp3lame --enable-libfdk-aac --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libgsm --enable-libspeex --enable-libxvid --enable-zlib
  libavutil      56.  0.100 / 56.  0.100
  libavcodec     58.  1.100 / 58.  1.100
  libavformat    58.  0.102 / 58.  0.102
  libavdevice    58.  0.100 / 58.  0.100
  libavfilter     7.  0.101 /  7.  0.101
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.100 /  3.  0.100
  libpostproc    55.  0.100 / 55.  0.100
Input #0, matroska,webm, from 'file:/media/HDD/TV Shows/The Man in the High Castle/Season 2/S02E01 - The Tiger's Cave.mkv':
  Metadata:
    ENCODER         : Lavf57.25.100
  Duration: 00:57:04.42, start: 0.000000, bitrate: 2264 kb/s
    Stream #0:0: Video: hevc (Main), yuv420p(tv), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 25 tbc (default)
    Metadata:
      DURATION        : 00:57:04.411000000
    Stream #0:1: Audio: eac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
    Metadata:
      ENCODER         : Lavc57.24.102 eac3
      DURATION        : 00:57:04.415000000
    Stream #0:2: Subtitle: ass
    Metadata:
      ENCODER         : Lavc57.24.102 ass
      DURATION        : 00:54:12.606000000
Stream mapping:
  Stream #0:0 -> #0:0 (hevc (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (eac3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
x264 [error]: high profile doesn't support lossless
[libx264 @ 0x32d9700] Error setting profile high.
[libx264 @ 0x32d9700] Possible profiles: baseline main high high10 high422 high444
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[libmp3lame @ 0x330edc0] 3 frames left in the queue on closing
Conversion failed!


#2 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 10:57 PM

Why would you want to set CRF at 0? 15 or 16 is typically agreed to be visually lossless. I couldn't see there being any benefit setting it lower than 10.



#3 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 10:58 PM

I want it to be completely lossless. And, this shouldn't be an issue regardless if used or not.



#4 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:00 PM

From your log

high profile doesn't support lossless


#5 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 11:02 PM

Is there a way to change the profile in Emby?



#6 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:02 PM

From the ffmpeg documentation

Another optional setting is -profile:v which will limit the output to a specific H.264 profile. Omit this unless your target device only supports a certain profile (see Compatibility). Current profiles include: baseline, main, high, high10, high422, high444. Note that usage of -profile:v is incompatible with lossless encoding.


#7 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 11:04 PM

Then shouldn't Emby completely remove "-profile:v" if the CRF is 0? Or, will that prevent downscaling or transcoding or other FFmpeg things all together?



#8 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:04 PM

Is there a way to change the profile in Emby?

 

I don't believe so. High is probably selected by default for compatibility reasons.



#9 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:12 PM

Then shouldn't Emby completely remove "-profile:v" if the CRF is 0? Or, will that prevent downscaling or transcoding or other FFmpeg things all together?

 

That may be the case.

 

That being said I can think of zero reasons to set CRF to 0. If the video doesn't need to be transcoded the stream will be copied, it it does need to be transcoded it is likely due to bitrate constraints or player compatibility in which case it can't be a lossless encode anyways. 



#10 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 11:14 PM

Understandable. At what CRF value does the quality degradation start to become noticeable? And, is there really any FPS increase?


Edited by TehEpikDuckeh, 06 November 2017 - 11:15 PM.


#11 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:30 PM

Simple answer: 17-18

 

 

Complicated answer: It doesn't actually matter all that much in Emby because the in app quality/bitrate setting will ultimately be what determines quality. The in app quality setting will set a maxbitrate target so if your CRF target requests a bitrate higher than your maxbitrate your CRF will be lowered to meet that requirement. If you look at a transcoding log you will likely see the CRF value bounce around throughout the movie. Maxbitrate gets priority over CRF which is just a target.

 

If you your in app quality is equal to or greater than the file bitrate it should direct play or direct stream the file meaning the the video is untouched and therefore is no loss in quality. If you need to reduce the quality to a bitrate lower than original file the visual quality will be relative to the decrease in bitrate. Increasing the CRF value won't increase visually quality but changing the encoding preset may. 

 

In the case of the example you posted above when a video needs to be transcoded to another format (h265 to h264, or xvid to h264, etc) Emby will use the same bitrate as the source file. For example a 25 Mbps h265 video will be converted to a 25 Mbps h264 video.

 

To be completely honest the CRF setting in Emby is pretty pointless and could probably be removed. 


Edited by Jdiesel, 06 November 2017 - 11:33 PM.


#12 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:37 PM

What device/app are you playing the video on in the log you attached?



#13 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 11:38 PM

The web app via Chrome.



#14 Jdiesel OFFLINE  

Jdiesel

    Advanced Member

  • Members
  • 2584 posts
  • Local time: 02:28 PM
  • LocationRegina, SK

Posted 06 November 2017 - 11:45 PM

That explains why the video is being transcoded in the first place as Chrome does not have h.265 support. You may want to try using the Edge browser as a comparison as it supports h.265 if you have supported hardware and run Windows 10 and should play the video without need to modify the original video.


Edited by Jdiesel, 06 November 2017 - 11:46 PM.


#15 TehEpikDuckeh OFFLINE  

TehEpikDuckeh

    Advanced Member

  • Members
  • 94 posts
  • Local time: 12:28 PM

Posted 06 November 2017 - 11:49 PM

This was mainly for testing as I wanted to get a baseline (CRF=0) and experiment around a bit. And, I have an Apple TV that doesn't support squat (albeit HEVC quite new) and need to accommodate that. However, now I'm trying to figure out the values for CRF and for the encoding preset. I want the encoding preset to be either "slow" or "slower" to maintain a good enough CRF, given CRF changes throughout playback.







Also tagged with one or more of these keywords: FFmpeg, CRF 0, Emby Server Beta, Debian 8

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users