Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Multimedia
  • Search

[solved] Re-encoding mkv in x265

Help with creation, editing, or playback of sounds, images, or video. Amarok, audacious, mplayer, grip, cdparanoia and anything else that makes a sound or plays a video.
Post Reply
Advanced search
11 posts • Page 1 of 1
Author
Message
maxmat
n00b
n00b
Posts: 12
Joined: Thu Jun 30, 2011 11:06 pm

[solved] Re-encoding mkv in x265

  • Quote

Post by maxmat » Sat Oct 21, 2017 9:07 am

Hi all,

I have some videos I'd like to re-encode using x265 codec.
I found that link which explain how to proceed: https://unix.stackexchange.com/question ... ality-loss

Unfortunately when I proceed I get the following error:

Code: Select all

ffmpeg -c:v x265 -preset ultrafast -x265-params lossless=1 -c:a copy -i input.mkv output.mkv 
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Gentoo 5.4.0-r3 p1.4, pie-0.6.5)
  configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --docdir=/usr/share/doc/ffmpeg-3.3.4/html --mandir=/usr/share/man --enable-shared --cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --optflags='-march=haswell -O3 -pipe -fomit-frame-pointer -mno-tls-direct-seg-refs' --disable-static --enable-avfilter --enable-avresample --disable-stripping --enable-version3 --disable-indev=v4l2 --disable-outdev=v4l2 --disable-indev=oss --disable-indev=jack --disable-outdev=oss --enable-bzlib --disable-runtime-cpudetect --disable-debug --disable-gcrypt --enable-gnutls --disable-gmp --enable-gpl --enable-hardcoded-tables --enable-iconv --enable-lzma --enable-network --disable-openssl --enable-postproc --enable-libsmbclient --enable-ffplay --enable-sdl2 --disable-vaapi --disable-vdpau --enable-xlib --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-zlib --disable-libcdio --disable-libiec61883 --enable-libdc1394 --disable-libcaca --disable-openal --enable-opengl --disable-libv4l2 --enable-libpulse --disable-libopencore-amrwb --disable-libopencore-amrnb --disable-libfdk-aac --disable-libopenjpeg --disable-libbluray --disable-libcelt --disable-libgme --disable-libgsm --disable-mmal --enable-libmodplug --disable-libopus --disable-libilbc --disable-librtmp --disable-libssh --disable-libschroedinger --disable-libspeex --enable-libvorbis --disable-libvpx --disable-libzvbi --disable-libbs2b --disable-chromaprint --disable-libflite --disable-frei0r --disable-libfribidi --enable-fontconfig --disable-ladspa --disable-libass --enable-libfreetype --disable-librubberband --disable-netcdf --disable-libzmq --disable-libzimg --disable-libsoxr --enable-pthreads --disable-libvo-amrwbenc --enable-libmp3lame --disable-libkvazaar --disable-nvenc --disable-libopenh264 --disable-libsnappy --enable-libtheora --disable-libtwolame --enable-libwavpack --disable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --disable-amd3dnow --disable-amd3dnowext --disable-aesni --disable-avx --disable-avx2 --disable-fma3 --disable-fma4 --disable-sse3 --disable-ssse3 --disable-sse4 --disable-sse42 --disable-xop --cpu=haswell --disable-doc --disable-htmlpages --enable-manpages
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Unknown decoder 'x265'
I've tried to use "libx265" as in link in place of "x265", I also tried the full path to the library... with no luck.

media-libs/x265 is installed and was installed before ffmpeg:

Code: Select all

*  media-libs/x265
      Latest version available: 2.2
      Latest version installed: 2.2
      Size of files: 1 176 KiB
      Homepage:      http://x265.org/
      Description:   Library for encoding video streams into the H.265/HEVC format
      License:       GPL-2
ldd seems to show compilation was good:

Code: Select all

ldd /usr/bin/ffmpeg | grep 265
        libx265.so.102 => /usr/lib64/libx265.so.102 (0x00007f308f4bd000)
And I don't know where to look for my mistake.

Anyone can help on that?

Cheers,

mathias
Last edited by maxmat on Sun Oct 22, 2017 2:47 pm, edited 1 time in total.
Top
paluszak
Apprentice
Apprentice
Posts: 274
Joined: Mon Jun 28, 2004 4:27 pm
Location: Warsaw, Poland

Re: Re-encoding mkv in x265

  • Quote

Post by paluszak » Sat Oct 21, 2017 10:33 am

Do you have x265 flag enabled in ffmpeg?
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4691
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sat Oct 21, 2017 11:35 am

paluszak wrote:Do you have x265 flag enabled in ffmpeg?
The x265 USE-flag is there because of '--enable-libx265'.
Unknown decoder 'x265'
You're applying the -c:v to input file.
Specify input video as the first argument to ffmpeg.

Like

Code: Select all

ffmpeg -i h264_video.mp4 -c:v libx265 -preset fast -crf 0 -x265-params lossless=1 -c:a copy -c:s copy h256_video.mkv
Note that there I specified autio and subtitle streams to be copied so that they don't lose quality.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Jaglover
Watchman
Watchman
User avatar
Posts: 8291
Joined: Sun May 29, 2005 1:57 am
Location: Saint Amant, Acadiana

  • Quote

Post by Jaglover » Sat Oct 21, 2017 1:31 pm

This would be possible if H.265 codec could read H.264 and enhance the compression. I don't think this is happening. I believe it decodes H.264 and re-encodes with H.265. Adding lossless=1 will make the output file bigger, maybe bigger than the input. I may be wrong.
My Gentoo installation notes.
Please learn how to denote units correctly!
Top
duby2291
Guru
Guru
User avatar
Posts: 583
Joined: Sun Oct 17, 2004 4:47 am

  • Quote

Post by duby2291 » Sat Oct 21, 2017 1:56 pm

I'm not sure if my thinking is actually sound or not, but it seems to me that every time you re-encode a video your gonna lose some quality. It's not gonna be lossless. In all honesty you'll probably be better off just leaving it alone.
Top
maxmat
n00b
n00b
Posts: 12
Joined: Thu Jun 30, 2011 11:06 pm

  • Quote

Post by maxmat » Sat Oct 21, 2017 2:07 pm

Thank you Zucca! The whole thing was I didn't put -i input_file at the beginning.

Stupid lazy me! I pushed away the input filename to change more easily options...

I'll come back once I'll have performed tests to answer Jaglover and duby2291...

Thanks again Zucca ;)

Have a nice week-end all
Top
Hu
Administrator
Administrator
Posts: 24385
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Sat Oct 21, 2017 9:49 pm

duby2291 wrote:I'm not sure if my thinking is actually sound or not, but it seems to me that every time you re-encode a video your gonna lose some quality. It's not gonna be lossless.
That depends entirely on the output codec. While lossy codecs are common because people usually don't notice the loss, any codec designed to be lossless should be able to exactly reproduce the original data in the alternate form.
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4691
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun Oct 22, 2017 9:25 am

Hu wrote:any codec designed to be lossless should be able to exactly reproduce the original data in the alternate form.
If I may nitpick a little... If the destination codec does not support the same pixel format as the source codec, there may be some loss in color reproduction.
Conversions like rgb24 to bgr24 should convert losslessly. Pixel formats like yuv are another story that I'm not too familiar with.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
maxmat
n00b
n00b
Posts: 12
Joined: Thu Jun 30, 2011 11:06 pm

  • Quote

Post by maxmat » Sun Oct 22, 2017 10:56 am

@Jaglover: regarding lossless you were right. At least with the follwoing command:

Code: Select all

ffmpeg -i input.mkv -c:v x265 -preset ultrafast -x265-params lossless=1 -c:a copy output.mkv
The resulting file was 17.9GB for 580MB of input file.

So I removed lossless=1 and tried with two pass to improve compression without too much downgrading quality. The command is the one the following script:

Code: Select all

#!/bin/bash

input_file="$1"
output_file="$2"

preset="medium"

nice -n 19 ffmpeg -y -i $input_file -c:v libx265 -preset $preset -b:v 2048k -x265-params pass=1 -c:a copy -f mp4 /dev/null && \
nice -n 19 ffmpeg    -i $input_file -c:v libx265 -preset $preset -b:v 2048k -x265-params pass=2 -c:a copy $output_file
Right now I'm re-encoding a 5GB file with preset medium. As it's not finished yet I can't give you the resulting size or quality. I'll be back later editing this post.

Yesterday I tried that script using preset=slow which was... slow.
The result was very appreciable anyway: using an input file of 580MB the resulting file was 270MB including audio.
Once extracted only video flux files are 537MB for input and 228MB for output.
The video quality is still very good: I can't see any difference between these two video streams when watching or pausing the video. The display is 4K, the video size is full HD.
Initial encoding was x264.

@duby2291: all is relative. No offence meant but you can't say it's better to not re-encode video without knowing the context. All is contextual. Always.
Last edited by maxmat on Sun Oct 22, 2017 2:30 pm, edited 1 time in total.
Top
duby2291
Guru
Guru
User avatar
Posts: 583
Joined: Sun Oct 17, 2004 4:47 am

  • Quote

Post by duby2291 » Sun Oct 22, 2017 12:29 pm

maxmat wrote: @duby2291: all is relative. No offence meant but you can't say it's better to not re-encode video without knowing the context. All is contextual. Always.
None taken. :D In the end we try and experiment and do what works the best. It's better to have done it and learned there's no visual difference than to not have done it at all. :D
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4691
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun Oct 22, 2017 1:15 pm

If there is only lossy encode available I tend not to convert it to any format (for archival purposes). Whatever codec you use, you'll only end up it taking more space or have lower quality. You can get close to same quality with less size, but the loss of quality is always there. Exception is if you can enhance the comppression ratio of the original codec without decoding it. I don't know if that's even possible...
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Post Reply

11 posts • Page 1 of 1

Return to “Multimedia”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic