Page 1 of 2

Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Mon Jul 18, 2016 2:15 pm
by galmok
I have a H265 file that I need to have transcoded as my TV, Sony HX800, cannot decode H265 files. Serviio handles the transcoding, but unfortunately it messes up the aspect ratio, making the resulting image flat/wide. It needs to become taller/narrower. I am already using the Sony Bravia TV (2010) profile, but I need to make it fix the aspect ratio. How do I do that? Are there any decent examples I can use?

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Mon Jul 18, 2016 4:30 pm
by galmok
I tried to implement a handler for h265 but it changed nothing. I cloned the sony2010 profile (called it sony2010test/Sony Bravia TV (2010) Test) added this to the profile as the last Video section:

<Video targetContainer="mpegts" targetVCodec="mpeg2video" maxVBitrate="18000" targetACodec="ac3" aBitrate="384" DAR="16:9" forceInheritance="true">
<Matches container="*" vCodec="h265" />
</Video>

Whether the config change means anything or not, I cannot say. There isn't exactly a manual for this configuration file. ;-)

The file I have is a mkv file and MediaInfo reports this about the video stream:

Video
ID : 1
Format : HEVC
Format/Info : High Efficiency Video Coding
Format profile : Main@L4@Main
Codec ID : V_MPEGH/ISO/HEVC
Duration : 42 min
Bit rate : 900 kb/s
Width : 1 916 pixels
Height : 1 076 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
Bit depth : 8 bits
Bits/(Pixel*Frame) : 0.018
Stream size : 275 MiB (82%)
Writing library : x265 1.9:[Windows][GCC 4.9.0][64 bit] 8bit
Encoding settings : wpp / ctu=64 / min-cu-size=8 / max-tu-size=32 / tu-intra-depth=1 / tu-inter-depth=1 / me=1 / subme=2 / merange=57 / no-rect / no-amp / max-merge=2 / temporal-mvp / no-early-skip / rdpenalty=0 / no-tskip / no-tskip-fast / strong-intra-smoothing / no-lossless / no-cu-lossless / no-constrained-intra / no-fast-intra / open-gop / no-temporal-layers / interlace=0 / keyint=240 / min-keyint=24 / scenecut=40 / rc-lookahead=20 / lookahead-slices=6 / bframes=4 / bframe-bias=0 / b-adapt=2 / ref=3 / limit-refs=3 / no-limit-modes / weightp / no-weightb / aq-mode=1 / qg-size=32 / aq-strength=1.00 / cbqpoffs=0 / crqpoffs=0 / rd=3 / psy-rd=2.00 / rdoq-level=0 / psy-rdoq=0.00 / signhide / deblock / sao / no-sao-non-deblock / b-pyramid / cutree / no-intra-refresh / rc=2 / pass / bitrate=900 / qcomp=0.60 / qpmin=0 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ipratio=1.40 / pbratio=1.30
Default : Yes
Forced : No
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709

The executed ffmpeg line is this:

C:\Program Files (x86)\Serviio\bin\\..\lib\ffmpeg.exe -threads 4 -i \\readyshare\USB_Storage\somevideo.mkv -y -threads 4 -c:v mpeg2video -pix_fmt yuv420p -b:v 18000k -maxrate:v 18000k -bufsize:v 18000k -r 24000/1001 -g 15 -c:a ac3 -b:a 384k -ac 6 -map 0:0 -map 0:1 -sn -f mpegts I:\TEMP\Serviio\transcoding-temp-64748-sony2010test-ORIGINAL.stf

The TV displays large black bars on top and bottom, compressing the video, making in unbearable to watch.

What can I try to fix the aspect ratio?

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 19, 2016 7:01 am
by DenyAll
The executed ffmpeg line is this:...
Where did you get that command line. There is nothing in the command that adds padding to the top/bottom of the transcoded file. Are you sure its not in the source?

Some other things to try:

Did you play with the aspect button on your remote to see if that helps?

Try removing the DAR="16:9" bit in your cloned profile. Remember to restart your PC/Serviio service after editing the profile. If this does work it will likely stuff up the aspect ratio of other files (those greater than 16:9 - movies generally).

Can you please post ffmpeg -i details for the file as well.

fyi: by default the sony2010 profile inherits its handler for h265 video from the sony2012 profile. Your cloned copy will take precedence though.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 19, 2016 7:39 am
by galmok
I got the command from serviio's debug output (log file, after adjusting log4j.xml to produce debug lines).

I have tried the aspect options on the TV, but they cannot correct for this distortion.

I have tried to remove the DAR="16:9" from the profile, but the result is the same command line (and the same experience on the TV). This is why I don't think the profile is being used.

ffmpeg -i output:

ffmpeg version 2.4.git Copyright (c) 2000-2014 the FFmpeg developers
built on Nov 19 2014 22:12:09 with gcc 4.7.2 (GCC)
configuration: --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-memalign-hack --enable-libmp3lame --enable-li
bass --enable-librtmp --enable-fontconfig --enable-libfreetype --enable-zlib --enable-libx264 --enable-libspeex --extra-libs='-lrtmp -lpolar
ssl -lws2_32 -lwinmm -lexpat -lfreetype -lfribidi -lz' --arch=x86 --enable-runtime-cpudetect --enable-pthreads --target-os=mingw32 --cross-p
refix=i686-w64-mingw32- --enable-gpl --pkg-config=pkg-config
libavutil 54. 14.100 / 54. 14.100
libavcodec 56. 12.101 / 56. 12.101
libavformat 56. 14.100 / 56. 14.100
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, matroska,webm, from '\\readyshare\USB_Storage\somefile.mkv':
Metadata:
encoder : libebml v1.3.3 + libmatroska v1.4.4
creation_time : 2016-07-09 19:03:57
Duration: 00:42:39.75, start: 0.000000, bitrate: 1094 kb/s
Stream #0:0: Video: hevc (Main), yuv420p(tv, bt709), 1916x1076 [SAR 1:1 DAR 479:269], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
Metadata:
BPS : 900485
BPS-eng : 900485
DURATION : 00:42:39.641000000
DURATION-eng : 00:42:39.641000000
NUMBER_OF_FRAMES: 61370
NUMBER_OF_FRAMES-eng: 61370
NUMBER_OF_BYTES : 288114856
NUMBER_OF_BYTES-eng: 288114856
_STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
_STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
_STATISTICS_WRITING_DATE_UTC: 2016-07-09 19:03:57
_STATISTICS_WRITING_DATE_UTC-eng: 2016-07-09 19:03:57
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1(eng): Audio: aac (HE-AAC), 48000 Hz, 5.1, fltp (default)
Metadata:
BPS : 191999
BPS-eng : 191999
DURATION : 00:42:39.659000000
DURATION-eng : 00:42:39.659000000
NUMBER_OF_FRAMES: 59992
NUMBER_OF_FRAMES-eng: 59992
NUMBER_OF_BYTES : 61431809
NUMBER_OF_BYTES-eng: 61431809
_STATISTICS_WRITING_APP: mkvmerge v9.2.0 ('Photograph') 64bit
_STATISTICS_WRITING_APP-eng: mkvmerge v9.2.0 ('Photograph') 64bit
_STATISTICS_WRITING_DATE_UTC: 2016-07-09 19:03:57
_STATISTICS_WRITING_DATE_UTC-eng: 2016-07-09 19:03:57
_STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
At least one output file must be specified

The file, when played with Media Player Classic (or VLC) has no black bars on top/bottom. Assuming square pixels, the video aspect ratio is very close to 16:9.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 19, 2016 7:41 am
by galmok
I modified the 17000 argument to 18000 just to see if the change made it through to the command line, and yes, it did. My profile change is in effect.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 19, 2016 8:04 am
by galmok
The black bars are a little bit over 7cm in both top and bottom and the total hight of the screen i a little bit over 57cm. This means approx 15cm out of 57cm is black bars (26%). The height needs to be 15/(57-15)-1=35% higher. I don't know if these numbers mean anything to anyone, but maybe. :)

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 19, 2016 10:14 pm
by DenyAll
Did you check that the bars aren't in the source file (play it on your PC). The Ffmpeg command is not adding the bars so we need to rule out that it's in the source.
Is this affecting one or multiple files?

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Thu Jul 21, 2016 9:07 am
by galmok
DenyAll wrote:Did you check that the bars aren't in the source file (play it on your PC). The Ffmpeg command is not adding the bars so we need to rule out that it's in the source.
Is this affecting one or multiple files?


I checked the files (multiple tested) with Media Player Classic and VLC and no, they do not have any black bars.

Edit: I believe it is the TV adding them, but why would it do that?

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Mon Jul 25, 2016 7:08 pm
by galmok
I guess Serviio needs some work still handling h265 files.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 26, 2016 3:13 am
by DenyAll
Not sure - from the ffmpeg command you posted Serviio is not adding the black bars???

On my devices black bars are not added to transcoded h265 files except where the aspect ratio is higher than 16:9, eg 2.35:1 common with movies, the ffmpeg command will pad the transcoded output with black bars so as to give the illusion of maintaining the aspect ratio.

Perhaps create a 10 second snippet of your original video and the transcoded video (see http://superuser.com/questions/377343/c ... ith-ffmpeg) and post it to dropbox or the like and I can have a look at it.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Jul 26, 2016 7:09 pm
by galmok
I'll do that. Just don't know a tool to cut in mkv files with... Suggestions?

Also, I don't think the resulting converted file has black bars in it, but there is something in the file that makes the TV add the black bars on its own.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Wed Jul 27, 2016 7:59 am
by DenyAll
Suggestions?
Yes, ffmpeg - see the link in my previous post :-), but basically:
    ffmpeg -i in.mkv -t 10 -c copy out.mkv
will copy the first 10 seconds of your mkv file (substituting "in.mkv" for your file). Also do it for the transcoded .stf file:
    ffmpeg -i in.stf -t 10 -c copy -f mpegts out.mpeg
You may have to rename the .stf to a .mpeg file first.
something in the file that makes the TV add the black bars on its own.
If it is the TV then the aspect or zoom button on your remote will generally fix it.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Fri Jul 29, 2016 4:22 pm
by galmok
I have now made 10 second samples of both the original file and the transcoded file.

Sample link:

https://www.dropbox.com/s/pedrbawg07u177o/sample.mkv?dl=0

Transcoded link:

https://www.dropbox.com/s/q0f9xy6hjiyiodo/transcoding-temp-64748-sony2010test-ORIGINAL.stf?dl=0

My tv's aspect/zoom button can only make it even more flat (or zoom it). It cannot just make it higher.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Sun Jul 31, 2016 1:54 am
by DenyAll
Well this isn't going to be particularly useful, but I have tested both the original and transcoded video's on my oldest TV - Panasonic 2010 - and they play fine (both play full screen 16:9). Also tested on my only Sony devices - PS3 and PS4 and same - worked fine.

So it does point to your TV - perhaps someone with a Sony 2010 model can test and advise. This may help tell you if it's a setting in your TV or if it's something else.

If this helps, some things I did note for anyone else following:
  • The transcoded video appears to be on my TV a 4:3 Anamorphic video (ie. the TV believes it is a 4:3 video) however the file header is set as 16:9 and the video stream has a different DAR again;
  • The original video frame size is 1916 x 1076 which is an aspect of slightly higher than 16:9. ffmpeg shows the video stream DAR as 479:269 - once again slightly higher than 16:9.
I think I know what the issue is - I may try a few things and get back to you (although if it's what I think, there won't be an automatic way to fix).

<Edit> Try this on your TV and let me know: https://www.dropbox.com/s/xrpa5d5dmku26 ... t.mpg?dl=0

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Sun Jul 31, 2016 5:51 am
by galmok
I really appreciate your help. :)

Regarding the mpg file, should I serve it via Serviio or play from a USB pen directly on the TV?

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Sun Jul 31, 2016 8:35 am
by galmok
I played the file via Serviio and the aspect ratio was perfect. No black bars on top out or bottom.

Can this be fixed via profile configuration or will I have to intercept the ffmpeg call, substituting my own?

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Sun Jul 31, 2016 11:18 am
by DenyAll
Try this in your profile (I cannot test if this will work):

  Code:
<Video targetContainer="mpegts" targetVCodec="mpeg2video" maxHeight="720" maxVBitrate="18000" targetACodec="ac3" aBitrate="384" DAR="16:9" forceInheritance="true">
   <Matches container="*" vCodec="h265" />
</Video>

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Sun Jul 31, 2016 3:51 pm
by galmok
Is the MaxHeight attribute vital for this hack? I will be using this for 1080p h265 transcoding sources and I'd like to preserve the resolution.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Mon Aug 01, 2016 1:00 am
by DenyAll
Yes, unfortunately. Its the only way I can think of to do this automatically in Serviio (if it works, I'm curious to see if it does), otherwise you will need to re-encode each video. Test it if you can, then we can move to the manual method.

Re: Aspect ratio issue with H265 to MPEG2 (Sony TV HX800)

PostPosted: Tue Aug 02, 2016 10:59 am
by galmok
It did not work. :-(