View previous topic :: View next topic |
Author |
Message |
geki Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/6492771464812613355c0e.png)
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Sun Oct 28, 2018 2:40 pm Post subject: [HOWTO] transcode MKV 10bit x264 to MKV 8bit x264 hardsubs |
|
|
I have not found a simple how to on fgo, there we are. I know here are some knowledgeable people about transcoding on fgo. Let me know, if the steps could be made any simpler, or less error-prone. The simple steps below produce good enough MKV 8bit x264 encodes for me to watch the anime show.
Remember
Test your source and encode with at least one file before generating a pile of useless corrupted data.
Source
https://hatsuyuki-fansubs.com/projects/anime-current/157-ac-one-piece
Destination
Panasonic TV EXW604 4K HDR
- supports MKV/MP4 8bit x264
- x265 transcodes on-the-fly, no fast-forward/rewind
- 10bit is not supported
- subtitles are not styled, fonts are ignored
Medium
USB harddrive*
* I simply do not want to wire up my laptop to the tv - just in case it pops up in your head.
___
Step 1: Prepare
Disable 10bit on media-libs/x264 with useflag[-10bit]. Enable fontconfig, libass, truetype and x264 on media-video/ffmpeg with useflag[fontconfig libass truetype x264].
Code: | # emerge -pv x264 ffmpeg
[binary R ] media-libs/x264-0.0.20170701:0/152::gentoo USE="pic threads -10bit (-altivec) -interlaced -opencl -static-libs" ABI_X86="(64) -32 (-x32)" CPU_FLAGS_X86="sse" 0 KiB
[binary R #] media-video/ffmpeg-4.0.2:0/56.58.58::gentoo USE="alsa bluray bzip2 cdio encode fdk fontconfig gme gpl iconv jpeg2k libass libcaca libressl libsoxr lzma mp3 network openal opencl opengl opus pic postproc pulseaudio speex svg theora threads truetype twolame vaapi vdpau vorbis vpx webp x264 x265 xcb xvid zlib -X (-altivec) -amr -amrenc (-appkit) -bs2b (-celt) -chromaprint -chromium -codec2 -cpudetection -debug -doc -flite -frei0r -fribidi -gcrypt -gmp -gnutls -gsm -hardcoded-tables -iec61883 -ieee1394 -jack -kvazaar -ladspa -libaom -libdrm -libilbc -librtmp -libv4l -lv2 (-mipsdspr1) (-mipsdspr2) (-mipsfpu) (-mmal) -modplug -openh264 -openssl -oss -rubberband -samba -sdl -snappy -ssh -static-libs -test -v4l -wavpack -zeromq -zimg -zvbi" ABI_X86="(64) -32 (-x32)" CPU_FLAGS_X86="aes avx mmx mmxext sse sse2 sse3 sse4_1 sse4_2 ssse3 -3dnow -3dnowext -avx2 -fma3 -fma4 -xop" FFTOOLS="-aviocat -cws2fws -ffescape -ffeval -ffhash -fourcc2pixfmt -graph2dot -ismindex -pktdumper -qt-faststart -sidxindex -trasher" VIDEO_CARDS="-nvidia" 0 KiB |
Step 2: Transcode 10bit to 8bit and add subtitles as hardsubs
Use hardsubs to not depend on destination to properly visualize subtitles with fonts; even if they are present as streams within video file.
Helper script. Latest version can be found here.
transcode_10bit_to_8bit_hardsubs.sh: | #!/bin/sh
die()
{
local exit_code=${?}
echo "${1}"
exit ${exit_code}
}
transcode_videos()
{
local p d f o s
p="$(realpath "${1}")"
d="${p//10bit/8bit}"
mkdir -p "${d}" \
|| die "failed to create destination path: ${d}"
for f in "${p}"/*.mkv
do
o="${f//10bit/8bit}"
s="$(printf '%q' "${f}")"
ffmpeg -i "${f}" -map 0:v -map 0:a -vf subtitles="${s}" \
-c:v libx264 -preset veryfast -tune animation -crf 23 -r 23.976 \
-c:a copy -f matroska "${o}" \
|| die "failed to transcode video from file: ${f}"
done
}
if [ ! -d "${1}" ]
then
die "parameter not a directory: ${1}"
fi
if [ ! -x "$(which realpath)" ]
then
die "realpath binary not found"
fi
if [ ! -x "$(which ffmpeg)" ]
then
die "ffmpeg binary not found"
fi
transcode_videos "${1}"
exit ${?} |
Put this helper into a base folder. The helper needs the source folder as parameter and puts final 8bit encode with hardsubs to destination folder(replacing "10bit" by "8bit" in paths). Once done, test encoded file, copy final data and remove now superfluous data.
Have fun! ![Razz :P](images/smiles/icon_razz.gif) _________________ hear hear
Last edited by geki on Sat Dec 15, 2018 12:42 pm; edited 8 times in total |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
DawgG l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/141141986446bd852be0016.jpg)
Joined: 17 Sep 2003 Posts: 874
|
Posted: Tue Oct 30, 2018 12:26 pm Post subject: |
|
|
i think it might be easier with ffmpeg because it can produce an MKV-file directly. For me the "secret" was the -map option which maps the streams in the output file. and since you are already re-encoding you could also do other stuff like crop etc. streams can also be be just copied by type (useful for subs which ffmpeg cannot encode) or re-encoded (audio) etc.
Code: | ffmpeg -i INFILE.mkv -map 0:0 -map 0:1 -map 0:2 -map 0:3 -c:v libx264 -preset veryfast -tune animation [more x264/video-options] -r 23.976 -c:a copy -c:s copy -f matroska OUTFILE.MKV |
-c:a copy just copies all audio-streams; -c:s copy does the same for subs
usually video is stream 0 in the outfile, audio 1 is 1, audio 2 is 2, subs 1 is 3 and so on.
you should check the libx264 and video options for your purpose since i usually only do dvd/bluray-encoding and use completely different settings for that (preset veryslow, tune film, crf 18, ...) if you have an nvidia-vga and have compiled ffmpeg with USE="nvenc" you can use very fast hardware-encoding. _________________ DUMM KLICKT GUT. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
geki Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/6492771464812613355c0e.png)
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Tue Oct 30, 2018 7:47 pm Post subject: |
|
|
In handbrake, there is this option for video: RF: 23. I guess I would have to set crf to 23 then? ffmpeg wiki says so. ![Surprised :o](images/smiles/icon_surprised.gif) _________________ hear hear |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
DawgG l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/141141986446bd852be0016.jpg)
Joined: 17 Sep 2003 Posts: 874
|
Posted: Wed Oct 31, 2018 12:29 pm Post subject: |
|
|
i use -crf on (uncompressed) source material from dvd/bluray. it's upposed to be (close to) uncompressed visual dvd-quality at the expense of speed/filesize (if i remember correctly). using -crf N on already (x264-)compressed source material might not be useful.
i think video encoding settings is a whole (esoteric) universe of itself :wink: you could just test different settings and see if you like them (i.e. their resulting output). i've run some "tests" where a three-foot-long line of encoding options did not yield an output noticeably different from a simple -preset X (except for a coupla' megs filesize on a 3GB file and visual differences only with my eyes very close to a 4K-monitor but not from the couch to the TV).
HAVE FUN! _________________ DUMM KLICKT GUT. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
geki Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/6492771464812613355c0e.png)
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Thu Nov 01, 2018 11:37 am Post subject: |
|
|
I adjusted the command to map all from stream, reencode the video and copy all audio, subtitles and attachments:
Code: | ffmpeg -i <input_file>.mkv -map 0 -c:v libx264 -preset veryfast -tune animation -crf 23 -r 23.976 -c:a copy -c:s copy -c:t copy -f matroska <output_file>.mkv |
Sadly, my laptop cannot burn subtitles into video stream as ffmpeg gets killed. flag:
Code: | -filter_complex "[0:v][0:s]overlay" |
_________________ hear hear |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
geki Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/6492771464812613355c0e.png)
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Thu Nov 01, 2018 3:43 pm Post subject: |
|
|
JFYI, these ffmpeg commands I found to be useful. Finally, I can transcode from 10bit to 8bit with hardsubs. So, I do not depend on destination to visualize subs properly, which that panasonic tv does not.
Code: | # transcode video, audio, ...
ffmpeg -i <input_file>.mkv -map 0 -c:v libx264 -preset veryfast -tune animation -crf 23 -r 23.976 -c:a copy -c:s copy -c:t copy \
-f matroska <output_file>.mkv
# extract subtitles to srt
ffmpeg -i <input_file>.mkv -map 0:s -c:s srt <output_file>.srt
# extract subtitles to ass
ffmpeg -i <input_file>.mkv -map 0:s -c:s ass <output_file>.ass
# extract all attachments
ffmpeg -dump_attachment:t "" -i <input_file>.mkv
# remove subs
ffmpeg -i <output_file>.mkv -map 0:v -map 0:a -c:v copy -c:a copy -f matroska <output_file>_no_subs.mkv
# recode with hardsubs
ffmpeg -i <output_file>_no_subs.mkv -vf ass="<output_file>.ass":fontsdir=fonts -c:a copy -f matroska <output_file>_hardsubs.mkv |
I am going to update first post later.
Thanks DawgG for pointing me at ffmpeg and looking closer at its feature set. ![Surprised :o](images/smiles/icon_surprised.gif) _________________ hear hear |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
geki Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/6492771464812613355c0e.png)
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Thu Nov 01, 2018 9:51 pm Post subject: |
|
|
Last update for now: simplified helper script to burn subtitles and fonts from source mkv into final encode. no longer any temporary data necessary. _________________ hear hear |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
geki Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/6492771464812613355c0e.png)
Joined: 13 May 2004 Posts: 2387 Location: Germania
|
Posted: Fri Nov 02, 2018 8:39 am Post subject: |
|
|
Tested the crf setting, 18 versus 23. No visual difference, nor encoding time benefit, but filesize. I still prefer crf 23. Result:
Code: | 438M '[Hatsuyuki]_One_Piece_841_-_845_[10bit][x264][1280x720]/[Hatsuyuki]_One_Piece_843_[10bit][x264][1280x720][D9D46F01].mkv'
348M '[Hatsuyuki]_One_Piece_841_-_845_[8bit][x264][1280x720]/[Hatsuyuki]_One_Piece_843_[8bit][x264][1280x720][D9D46F01]_crf18.mkv'
215M '[Hatsuyuki]_One_Piece_841_-_845_[8bit][x264][1280x720]/[Hatsuyuki]_One_Piece_843_[8bit][x264][1280x720][D9D46F01]_crf23.mkv' |
_________________ hear hear |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
pjp Administrator
![Administrator Administrator](/images/ranks/rank-admin.gif)
![](images/avatars/1154772887439692d88303b.jpg)
Joined: 16 Apr 2002 Posts: 20589
|
Posted: Mon Nov 05, 2018 3:11 am Post subject: |
|
|
Moved from Multimedia to Documentation, Tips & Tricks. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|