View previous topic :: View next topic |
Author |
Message |
maxmat n00b
Joined: 30 Jun 2011 Posts: 12
|
Posted: Sat Oct 21, 2017 9:07 am Post subject: [solved] Re-encoding mkv in x265 |
|
|
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/questions/230800/re-encoding-video-library-in-x265-hevc-with-no-quality-loss
Unfortunately when I proceed I get the following error:
Code: | 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: | * 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: | 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 |
|
Back to top |
|
|
paluszak Apprentice
Joined: 28 Jun 2004 Posts: 265 Location: Warsaw, Poland
|
Posted: Sat Oct 21, 2017 10:33 am Post subject: Re: Re-encoding mkv in x265 |
|
|
Do you have x265 flag enabled in ffmpeg? |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3343 Location: Rasi, Finland
|
Posted: Sat Oct 21, 2017 11:35 am Post subject: |
|
|
paluszak wrote: | Do you have x265 flag enabled in ffmpeg? |
The x265 USE-flag is there because of '--enable-libx265'.
Quote: | Unknown decoder 'x265' | You're applying the -c:v to input file.
Specify input video as the first argument to ffmpeg.
Like Code: | 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 :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
Jaglover Watchman
Joined: 29 May 2005 Posts: 8291 Location: Saint Amant, Acadiana
|
Posted: Sat Oct 21, 2017 1:31 pm Post subject: |
|
|
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! |
|
Back to top |
|
|
duby2291 Guru
Joined: 17 Oct 2004 Posts: 583
|
Posted: Sat Oct 21, 2017 1:56 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
maxmat n00b
Joined: 30 Jun 2011 Posts: 12
|
Posted: Sat Oct 21, 2017 2:07 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21629
|
Posted: Sat Oct 21, 2017 9:49 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3343 Location: Rasi, Finland
|
Posted: Sun Oct 22, 2017 9:25 am Post subject: |
|
|
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 :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
maxmat n00b
Joined: 30 Jun 2011 Posts: 12
|
Posted: Sun Oct 22, 2017 10:56 am Post subject: |
|
|
@Jaglover: regarding lossless you were right. At least with the follwoing command:
Code: | 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: | #!/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 |
|
Back to top |
|
|
duby2291 Guru
Joined: 17 Oct 2004 Posts: 583
|
Posted: Sun Oct 22, 2017 12:29 pm Post subject: |
|
|
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. 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. |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3343 Location: Rasi, Finland
|
Posted: Sun Oct 22, 2017 1:15 pm Post subject: |
|
|
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 :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
|