Convert2MKV - New Options; New Hardware Logic! - WIP [UPDATED 27/01/19]

@bjønness said:

@ntrevena said:
Just be sure, I am working on it. Will post as soon as I can.

PS. Thanks for the info, that’s helpful. Out of curiosity, you’re running the script on unRAID?

Great!
Yep, running the script in a docker on Unraid. How did you know? B-)

Wait, who made an unraid docker for this and where can I get it?!?

@don.alcombright said:
Wait, who made an unraid docker for this and where can I get it?!?

@bjønness did. Sounds like he’s making good progress too. :slight_smile:

You can find his docker info here:

https://hub.docker.com/r/bjonness406/convert2mkv/~/dockerfile/

@bjønness Hey, I’ve been looking at your repo, and think I may have found the issue!

You’re not using bash, you’re using /bin/sh as you environment!

Try switching your environment to bash with:

#!/bin/bash

At the top of your script?

Let me know if that works.

Cheers!

@don.alcombright said:

@bjønness said:

@ntrevena said:
Just be sure, I am working on it. Will post as soon as I can.

PS. Thanks for the info, that’s helpful. Out of curiosity, you’re running the script on unRAID?

Great!
Yep, running the script in a docker on Unraid. How did you know? B-)

Wait, who made an unraid docker for this and where can I get it?!?

I do make it now, will post back when it is finished.

@ntrevena Will try more after work, thanks! Did not even notice it myself…
I tried really quick before I had to go, but got this message. Wil take a new look when I get home.
/config/convert2mkv.sh: 26: /config/convert2mkv.sh: Syntax error: "(" unexpected

@bjønness said:
@ntrevena Will try more after work, thanks! Did not even notice it myself…
I tried really quick before I had to go, but got this message. Wil take a new look when I get home.
/config/convert2mkv.sh: 26: /config/convert2mkv.sh: Syntax error: "(" unexpected

Cool. Can you try and change your env over properly? Here are some details on how to do it: How to change from csh to bash as default shell - Unix & Linux Stack Exchange

The first answer has sorted for ya. Nice and easy :slight_smile:

@ntrevena said:

@bjønness said:
@ntrevena Will try more after work, thanks! Did not even notice it myself…
I tried really quick before I had to go, but got this message. Wil take a new look when I get home.
/config/convert2mkv.sh: 26: /config/convert2mkv.sh: Syntax error: "(" unexpected

Cool. Can you try and change your env over properly? Here are some details on how to do it: How to change from csh to bash as default shell - Unix & Linux Stack Exchange

The first answer has sorted for ya. Nice and easy :slight_smile:

Fixed it, changed
sh /config/convert2mkv.sh
to
bash /config/convert2mkv.sh

Thanks!

Docker is finished now.
https://hub.docker.com/r/bjonness406/convert2mkv/

@don.alcombright said:

@bjønness said:

@ntrevena said:
Just be sure, I am working on it. Will post as soon as I can.

PS. Thanks for the info, that’s helpful. Out of curiosity, you’re running the script on unRAID?

Great!
Yep, running the script in a docker on Unraid. How did you know? B-)

Wait, who made an unraid docker for this and where can I get it?!?

Take a look here

@bjønness said:
Fixed it, changed
sh /config/convert2mkv.sh
to
bash /config/convert2mkv.sh

Thanks!

Oh that’s great! Glad to hear it’s all up and running for you. I’m still working on the script to make it more compatible. I found an error with the FPS setting, and am adding the fix to the next update.

@bjønness said:
Docker is finished now.
Docker
[Support] Bjonness406's repo - Docker Containers - Unraid

DOOD! That’s awesome! I’ll put your Docker on the README.md if you like :slight_smile:

@ntrevena said:

@bjønness said:
Fixed it, changed
sh /config/convert2mkv.sh
to
bash /config/convert2mkv.sh

Thanks!

Oh that’s great! Glad to hear it’s all up and running for you. I’m still working on the script to make it more compatible. I found an error with the FPS setting, and am adding the fix to the next update.

Nice :-bd Tell me when spaces in filename is allowed :smiley:

@ntrevena said:

@bjønness said:
Docker is finished now.
Docker
[Support] Bjonness406's repo - Docker Containers - Unraid

DOOD! That’s awesome! I’ll put your Docker on the README.md if you like :slight_smile:

That would be great! :wink:

@bjønness said:
Nice :-bd Tell me when spaces in filename is allowed :smiley:

Now! Just pushed the update. Should be able to handle spaces fine now :slight_smile:
Also pushed the FPS fix.

@bjønness said:
That would be great! :wink:

Already done :slight_smile:

Current Updates

Fixes

  • Fixed issues with not detecting FPS of incoming video
  • Fixed issues with filenames that contain whitespace/spaces

Contributions

@ntrevena said:

@bjønness said:
Nice :-bd Tell me when spaces in filename is allowed :smiley:

Now! Just pushed the update. Should be able to handle spaces fine now :slight_smile:
Also pushed the FPS fix.

@bjønness said:
That would be great! :wink:

Already done :slight_smile:

Nice :-bd
So so you know, unRAID has nothing to do with docker. I just run the docker on unRAID myself.
Docker is kind of a own small “virtualized” Linux machine, and you can run it on almost everything (linux, windows, MacOS etc) without requiring different setups, just use the appropriate docker run command.

I’ve started following this thread because I run my Plex setup on unRAID and am really interested in the ability to use a docker to convert newly arrived video files either before they are added to my Plex library or after (I suspect after is the most useful as I am also trialling the DVR setup and really want to post-process the recorded files into a standard format to make them most compatible with my clients.

Between you @ntrevena and @bjønness both appear to have done a large chunk of the hard work for me. :smiley:

I have two questions:

  1. how can I update or configure your script to create the output in a format I want? my ideal profile is .mkv container, h.264 video in original resolution (or if above 720p then no more than that), with 2 audio tracks; AAC Stereo and AAC 5.1 if multi-channel is present in the original file, keeping as a minimum Foreign Audio Scan and English subtitles.
  2. With all my various apps being in separate dockers am not clear how I could trigger the docker to be started once I have a file in the right place for it to convert, or how I would know it has finished (the calling scripts are likely to be inside another docker so this seems complicated…)

Yes I am a know nothing useless user when it comes to Linux based stuff so I apologise for that at the start :">

@bjønness said:
Nice :-bd
So so you know, unRAID has nothing to do with docker. I just run the docker on unRAID myself.
Docker is kind of a own small “virtualized” Linux machine, and you can run it on almost everything (linux, windows, MacOS etc) without requiring different setups, just use the appropriate docker run command.

I thought perhaps unRAID had a specific fork of Docker that ran in a specific way. Would you like me to just list it as “Docker”, instead of “unRAID Docker”?

:slight_smile:

@DavidIrwin said:
I’ve started following this thread because I run my Plex setup on unRAID and am really interested in the ability to use a docker to convert newly arrived video files either before they are added to my Plex library or after (I suspect after is the most useful as I am also trialling the DVR setup and really want to post-process the recorded files into a standard format to make them most compatible with my clients.

Between you @ntrevena and @bjønness both appear to have done a large chunk of the hard work for me. :smiley:

I have two questions:

  1. how can I update or configure your script to create the output in a format I want? my ideal profile is .mkv container, h.264 video in original resolution (or if above 720p then no more than that), with 2 audio tracks; AAC Stereo and AAC 5.1 if multi-channel is present in the original file, keeping as a minimum Foreign Audio Scan and English subtitles.
  2. With all my various apps being in separate dockers am not clear how I could trigger the docker to be started once I have a file in the right place for it to convert, or how I would know it has finished (the calling scripts are likely to be inside another docker so this seems complicated…)

Yes I am a know nothing useless user when it comes to Linux based stuff so I apologise for that at the start :">

  1. Edit the script in the config directory, don’t know if you can do all that ( @ntrevena needs to answer that).
  2. You need to start the docker, it will automatically stop when the script is finished.
    You can always look in the log for more info if needed.

@ntrevena said:

@bjønness said:
Nice :-bd
So so you know, unRAID has nothing to do with docker. I just run the docker on unRAID myself.
Docker is kind of a own small “virtualized” Linux machine, and you can run it on almost everything (linux, windows, MacOS etc) without requiring different setups, just use the appropriate docker run command.

I thought perhaps unRAID had a specific fork of Docker that ran in a specific way. Would you like me to just list it as “Docker”, instead of “unRAID Docker”?

:slight_smile:

That could be nice :slight_smile:
I will add the docker run command to the readme file later, don’t have the time atm (later today or tomorrow i guess).

@bjønness said:
That could be nice :slight_smile:
I will add the docker run command to the readme file later, don’t have the time atm (later today or tomorrow i guess).

No Problems. Will fix that up for you :slight_smile:

@DavidIrwin said:

  1. how can I update or configure your script to create the output in a format I want? my ideal profile is .mkv container, h.264 video in original resolution (or if above 720p then no more than that), with 2 audio tracks; AAC Stereo and AAC 5.1 if multi-channel is present in the original file, keeping as a minimum Foreign Audio Scan and English subtitles.

@bjønness is right. If that’s what you want, you’d have to add some detection logic to the script, that would detect the resolution of the incoming video, and change the output resolution based on input.

The same goes with the audio. Basically, you need to make the script ask a question like “Is the incoming audio 5.1? If it is, then convert it to AAC 5.1. If it isn’t, then convert it to AAC 2.0.”

The main issue here is that it sounds like your videos are inconsistent in format and video/audio streams. The script I’ve been working on assumes that you want a single type of output, with a single audio and subtitle stream.

I’ve yet to add multiple stream support, but it is something I’d like to add in the future.

You could however do it relatively easily with the -map 0 and -c:a copy options for ffmpeg/avconv. Trial and error :slight_smile:

@DavidIrwin said:
2. With all my various apps being in separate dockers am not clear how I could trigger the docker to be started once I have a file in the right place for it to convert, or how I would know it has finished (the calling scripts are likely to be inside another docker so this seems complicated…)

Yup, @bjønness is your goto for this one :slight_smile:

@DavidIrwin said:
Yes I am a know nothing useless user when it comes to Linux based stuff so I apologise for that at the start :">

No need to apologize buddy. It’s all part of learning!

Now that I have this up and running in docker (thanks @bjønness) is this a straight remux of the container or does it tweak other things as well? What I don’t want it lose quality. I tested it out on a 480p avi file and it went from 1.3GB to 750MB, which is troublesome to me.

`------------------------Starting container ------------------------

[Info] Script already downloaded, skipping download. If you want to redownload the script, delete convert2mkv.sh in you appdata
[Info] Starting script
Arthur Christmas (2011) - 480p.avi
codec_name=mpeg4
codec_name=ac3
ffmpeg version 2.8.8-0ubuntu0.16.04.1 Copyright © 2000-2016 the FFmpeg developers

built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 20160609
configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv

libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Input #0, avi, from ‘Arthur Christmas (2011) - 480p.avi’:
Metadata:
title : VIDEO_DVD.Title1.DVDRip
album : VIDEO_DVD
encoder : Lavf53.21.0
Duration: 01:33:34.04, start: 0.000000, bitrate: 2011 kb/s
Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 650x348 [SAR 1:1 DAR 325:174], 1615 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 384 kb/s
Please use -q:a or -q:v, -qscale is ambiguous
[libx264 @ 0x6a1620] -qscale is ignored, -crf is recommended.
[libx264 @ 0x6a1620] using SAR=1/1
[libx264 @ 0x6a1620] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x6a1620] profile High, level 3.1
[libx264 @ 0x6a1620] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=16 deblock=1:0:0 analyse=0x3:0x133 me=umh subme=10 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=24 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=11 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=8 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to ‘Arthur Christmas (2011) - 480p.mkv’:
Metadata:
title : VIDEO_DVD.Title1.DVDRip
album : VIDEO_DVD
encoder : Lavf56.40.101
Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 650x348 [SAR 1:1 DAR 325:174], q=-1–1, 25 fps, 1k tbn, 25 tbc
Metadata:
encoder : Lavc56.60.100 libx264
Stream #0:1: Audio: aac ([255][0][0][0] / 0x00FF), 44100 Hz, 5.1(side), fltp, 128 kb/s
Metadata:
encoder : Lavc56.60.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (ac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[mpeg4 @ 0xcc80e0] Video uses a non-standard and wasteful way to store B-frames (‘packed B-frames’). Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.
video:701777kB audio:87755kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.339300%
[libx264 @ 0x6a1620] frame I:1506 Avg QP:14.87 size: 34784
[libx264 @ 0x6a1620] frame P:48977 Avg QP:19.24 size: 9295
[libx264 @ 0x6a1620] frame B:89866 Avg QP:24.90 size: 2348
[libx264 @ 0x6a1620] consecutive B-frames: 8.4% 15.2% 29.5% 25.0% 8.3% 12.1% 0.5% 0.3% 0.6%
[libx264 @ 0x6a1620] mb I I16…4: 8.5% 76.0% 15.5%
[libx264 @ 0x6a1620] mb P I16…4: 2.7% 12.9% 1.6% P16…4: 30.3% 14.8% 15.5% 0.7% 0.2% skip:21.3%
[libx264 @ 0x6a1620] mb B I16…4: 0.4% 2.0% 0.2% B16…8: 36.3% 7.5% 2.0% direct: 2.4% skip:49.1% L0:40.8% L1:40.7% BI:18.5%
[libx264 @ 0x6a1620] 8x8 transform intra:75.2% inter:70.5%
[libx264 @ 0x6a1620] direct mvs spatial:95.1% temporal:4.9%
[libx264 @ 0x6a1620] coded y,uvDC,uvAC intra: 67.6% 65.7% 32.0% inter: 17.3% 15.6% 5.1%
[libx264 @ 0x6a1620] i16 v,h,dc,p: 27% 50% 9% 14%
[libx264 @ 0x6a1620] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 28% 28% 3% 3% 4% 4% 4% 6%
[libx264 @ 0x6a1620] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 29% 7% 5% 8% 9% 9% 6% 7%
[libx264 @ 0x6a1620] i8c dc,h,v,p: 31% 38% 22% 9%
[libx264 @ 0x6a1620] Weighted P-Frames: Y:2.9% UV:2.1%
[libx264 @ 0x6a1620] ref P L0: 58.5% 11.5% 11.0% 3.8% 2.6% 2.3% 2.0% 1.4% 1.3% 1.1% 0.9% 0.8% 0.7% 0.8% 0.8% 0.7%
[libx264 @ 0x6a1620] ref B L0: 81.9% 7.8% 3.1% 1.4% 1.2% 0.9% 0.9% 0.5% 0.5% 0.4% 0.4% 0.3% 0.3% 0.3% 0.1%
[libx264 @ 0x6a1620] ref B L1: 92.2% 7.8%
[libx264 @ 0x6a1620] kb/s:1024.03
*.3gp`

@don.alcombright said:
Now that I have this up and running in docker (thanks @bjønness) is this a straight remux of the container or does it tweak other things as well? What I don’t want it lose quality. I tested it out on a 480p avi file and it went from 1.3GB to 750MB, which is troublesome to me.

It is just running the script from @ntrevena , no tweaks.

@don.alcombright said:
Now that I have this up and running in docker (thanks @bjønness) is this a straight remux of the container or does it tweak other things as well? What I don’t want it lose quality. I tested it out on a 480p avi file and it went from 1.3GB to 750MB, which is troublesome to me.

Hey mate. Thanks for the feedback.

This is kind of a difficult question to answer.

Basically, the AVI container uses XVID/mpeg4 video codec. It’s quite inferior by comparison to that of h.264 or h.265. The compression algorithms used in h.265 are extremely good at creating a high quality output file, at a much smaller file size. On average, I can create an output file of h.265/MKV that is around 30-50% smaller than the input, with minimal loss.

To the question of video quality loss: You will always get some loss in any form of compression of video. Think of it like copying a cassette tape in the old ghetto blasters of the 80’s/90’s. If you copy the tape once, it’s a pretty good quality copy. If you copy the copy, then the quality decreases. If you keep doing this over and over, you will eventually end up with just white noise, as the quality decreases with each copy.

That said, I’ve tweaked the script to give as good a quality output as possible (in my eyes at least), with a good amount of compression.

If you want to see what the script is doing, you can add echo to the beginning of line 216. It will show you the command it is running, instead of actually running it.

Like this: echo avconv -i "$i" $vconvert $fps -crf $crf -map_metadata 0 -map_chapters 0 -c:s copy $aconvert "${i%.*}."$container

It means you can compare the output as required.

Hope that helps!

@ntrevena said:

@don.alcombright said:
Now that I have this up and running in docker (thanks @bjønness) is this a straight remux of the container or does it tweak other things as well? What I don’t want it lose quality. I tested it out on a 480p avi file and it went from 1.3GB to 750MB, which is troublesome to me.

Hey mate. Thanks for the feedback.

This is kind of a difficult question to answer.

Basically, the AVI container uses XVID/mpeg4 video codec. It’s quite inferior by comparison to that of h.264 or h.265. The compression algorithms used in h.265 are extremely good at creating a high quality output file, at a much smaller file size. On average, I can create an output file of h.265/MKV that is around 30-50% smaller than the input, with minimal loss.

To the question of video quality loss: You will always get some loss in any form of compression of video. Think of it like copying a cassette tape in the old ghetto blasters of the 80’s/90’s. If you copy the tape once, it’s a pretty good quality copy. If you copy the copy, then the quality decreases. If you keep doing this over and over, you will eventually end up with just white noise, as the quality decreases with each copy.

That said, I’ve tweaked the script to give as good a quality output as possible (in my eyes at least), with a good amount of compression.

If you want to see what the script is doing, you can add echo to the beginning of line 216. It will show you the command it is running, instead of actually running it.

Like this: echo avconv -i "$i" $vconvert $fps -crf $crf -map_metadata 0 -map_chapters 0 -c:s copy $aconvert "${i%.*}."$container

It means you can compare the output as required.

Hope that helps!

thanks and sounds good. Ya, I was only testing it with a crappy file. I have about 50 movies in weird formats that I want to switch over to mkv.

@don.alcombright said:
thanks and sounds good. Ya, I was only testing it with a crappy file. I have about 50 movies in weird formats that I want to switch over to mkv.

I understand. Just don’t delete the originals until you are sure you’re happy with the output :slight_smile: