diff --git a/README.md b/README.md index 00908dd..7f5b78e 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,13 @@ I wrote this to convert Judge Judy from ts files created by Plex to mkv files. T # help ``` -[info] ts-to-mkv.sh -- v2 +root@rn628x:/data/tv# ./ts-to-mkv.sh -h +[info] ./ts-to-mkv.sh -- v2 [help] -d, path to custom ffmpeg (default: /data/sourcecode/ffmpeg/ffmpeg-4.1.3-amd64-static/ffmpeg) +[help] -f, force overwriting existing files +[help} -n, never overwrite existing files [help] -k, keep the original ts file +[help] -q, disable output from ffmpeg (default: info) [help] -p, custom path to scan recursively (default: ./) ``` @@ -15,81 +19,56 @@ I wrote this to convert Judge Judy from ts files created by Plex to mkv files. T # Example Output ``` -root@rn628x:/data/tv# bash ts-to-mkv.sh +root@rn628x:/data/tv# bash ts-to-mkv.sh -f [info] ts-to-mkv.sh -- v2 +[debug] overwriting existing files [info] finding files -[info] working on ./Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .ts -[debug] Infile: ./Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .ts -[debug] Outfile: ./Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .mkv -ffmpeg version 4.1.3-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers - built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 - configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --ena -ble-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex - --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzvbi --enable-libzimg - libavutil 56. 22.100 / 56. 22.100 - libavcodec 58. 35.100 / 58. 35.100 - libavformat 58. 20.100 / 58. 20.100 - libavdevice 58. 5.100 / 58. 5.100 - libavfilter 7. 40.101 / 7. 40.101 - libswscale 5. 3.100 / 5. 3.100 - libswresample 3. 3.100 / 3. 3.100 - libpostproc 55. 3.100 / 55. 3.100 -Input #0, mpegts, from './Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .ts': - Duration: 00:17:33.44, start: 1.401556, bitrate: 16470 kb/s - Program 1 - Metadata: - service_name : Service01 - service_provider: FFmpeg - Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc - Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s - Stream #0:2[0x102](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s -Input #1, lavfi, from 'movie='./Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .ts'[out+subcc]': - Duration: N/A, start: 1.500100, bitrate: N/A - Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc - Stream #1:1: Subtitle: eia_608 -Stream mapping: - Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264)) - Stream #0:1 -> #0:1 (copy) - Stream #0:2 -> #0:2 (copy) - Stream #1:1 -> #0:3 (eia_608 (cc_dec) -> subrip (srt)) -Press [q] to stop, [?] for help -[libx264 @ 0x5536c00] using SAR=1/1 -[libx264 @ 0x5536c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 -[libx264 @ 0x5536c00] profile Progressive High, level 4.0, 4:2:0, 8-bit -[libx264 @ 0x5536c00] 264 - core 157 r2969 d4099dd - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 -Output #0, matroska, to './Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .mkv': - Metadata: - encoder : Lavf58.20.100 - Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 1k tbn, 29.97 tbc - Metadata: - encoder : Lavc58.35.100 libx264 - Side data: - cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 - Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 384 kb/s Stream #0:2(spa): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s Stream #0:3(eng): Subtitle: subrip (srt) - Metadata: - encoder : Lavc58.35.100 srt -[Parsed_movie_0 @ 0x53d3a40] EOF timestamp not reliable2.12 bitrate=4460.1kbits/s speed=0.724x -frame=31567 fps= 22 q=-1.0 Lsize= 575764kB time=00:17:33.33 bitrate=4477.8kbits/s speed=0.723x -video:500855kB audio:74061kB subtitle:90kB other streams:0kB global headers:0kB muxing overhead: 0.131831% -[libx264 @ 0x5536c00] frame I:397 Avg QP:18.31 size:131260 -[libx264 @ 0x5536c00] frame P:8915 Avg QP:22.13 size: 33958 -[libx264 @ 0x5536c00] frame B:22255 Avg QP:25.09 size: 7101 -[libx264 @ 0x5536c00] consecutive B-frames: 1.8% 2.6% 30.1% 65.4% -[libx264 @ 0x5536c00] mb I I16..4: 7.3% 89.3% 3.4% -[libx264 @ 0x5536c00] mb P I16..4: 1.6% 5.2% 0.2% P16..4: 49.9% 11.6% 8.2% 0.0% 0.0% skip:23.3% -[libx264 @ 0x5536c00] mb B I16..4: 0.1% 0.2% 0.0% B16..8: 35.5% 1.1% 0.2% direct: 1.1% skip:61.8% L0:41.5% L1:54.1% BI: 4.3% -[libx264 @ 0x5536c00] 8x8 transform intra:79.6% inter:90.9% -[libx264 @ 0x5536c00] coded y,uvDC,uvAC intra: 61.9% 65.4% 17.5% inter: 11.5% 17.0% 0.1% -[libx264 @ 0x5536c00] i16 v,h,dc,p: 24% 32% 12% 33% -[libx264 @ 0x5536c00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 20% 30% 3% 3% 4% 4% 4% 4% -[libx264 @ 0x5536c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 17% 44% 9% 4% 7% 6% 6% 4% 5% -[libx264 @ 0x5536c00] i8c dc,h,v,p: 43% 26% 24% 7% -[libx264 @ 0x5536c00] Weighted P-Frames: Y:0.5% UV:0.2% -[libx264 @ 0x5536c00] ref P L0: 58.2% 11.4% 23.3% 7.1% 0.0% -[libx264 @ 0x5536c00] ref B L0: 86.5% 11.3% 2.3% -[libx264 @ 0x5536c00] ref B L1: 96.2% 3.8% -[libx264 @ 0x5536c00] kb/s:3894.93 +[info] working on ./Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).ts +[debug] Infile: ./Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).ts +[debug] Outfile: ./Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).mkv +[info] ffmpeg version 4.1.3-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers +[info] built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 +[info] configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzvbi --enable-libzimg +[info] libavutil 56. 22.100 / 56. 22.100 +[info] libavcodec 58. 35.100 / 58. 35.100 +[info] libavformat 58. 20.100 / 58. 20.100 +[info] libavdevice 58. 5.100 / 58. 5.100 +[info] libavfilter 7. 40.101 / 7. 40.101 +[info] libswscale 5. 3.100 / 5. 3.100 +[info] libswresample 3. 3.100 / 3. 3.100 +[info] libpostproc 55. 3.100 / 55. 3.100 +[info] Input #0, mpegts, from './Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).ts': +[info] Duration: 00:20:20.87, start: 0.587722, bitrate: 14699 kb/s +[info] Program 1 +[info] Stream #0:0[0x101b]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], 14100 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc +[info] Stream #0:1[0x1033](eng): Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 192 kb/s +[info] Input #1, lavfi, from 'movie='./Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).ts'[out+subcc]': +[info] Duration: N/A, start: 0.587722, bitrate: N/A +[info] Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc +[info] Stream #1:1: Subtitle: eia_608 +[info] Stream mapping: +[info] Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264)) +[info] Stream #0:1 -> #0:1 (copy) +[info] Stream #1:1 -> #0:2 (eia_608 (cc_dec) -> subrip (srt)) +[info] Press [q] to stop, [?] for help +[libx264 @ 0x70bd980] [info] using SAR=1/1 +[libx264 @ 0x70bd980] [info] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 +[libx264 @ 0x70bd980] [info] profile Progressive High, level 4.0, 4:2:0, 8-bit +[libx264 @ 0x70bd980] [info] 264 - core 157 r2969 d4099dd - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 +[info] Output #0, matroska, to './Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).mkv': +[info] Metadata: +[info] encoder : Lavf58.20.100 +[info] Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 1k tbn, 29.97 tbc +[info] Metadata: +[info] encoder : Lavc58.35.100 libx264 +[info] Side data: +[info] cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 +[info] Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s +[info] Stream #0:2(eng): Subtitle: subrip (srt) +[info] Metadata: +[info] encoder : Lavc58.35.100 srt +... [info] successful conversion [debug] deleting original file -removed './Judge Judy/Season 23/Judge Judy (1996) - S23E214 - Ice Cream Parlor Owner Not so Sweet .ts' +removed 'working on ./Cops/Cops - S28E32 - No Helmet, No Ride (RawHD).ts' ``` diff --git a/ts-to-mkv.sh b/ts-to-mkv.sh index 2839ad9..8659e5d 100644 --- a/ts-to-mkv.sh +++ b/ts-to-mkv.sh @@ -3,7 +3,7 @@ ## functions ## vercomp () { - if [[ $1 == $2 ]] + if [[ "$1" == "$2" ]] then return 0 fi @@ -42,6 +42,7 @@ ffmpegcheck(){ ## Env ## SAVEIFS=$IFS IFS=$(echo -en "\n\b") +loglevel="level+info" FFMPEG="/data/sourcecode/ffmpeg/ffmpeg-4.1.3-amd64-static/ffmpeg" if [[ ! -f "$FFMPEG" ]]; then FFMPEG=$(/usr/bin/env which ffmpeg) @@ -59,7 +60,7 @@ version="2" ## Start ## echo "[info] $0 -- v$version" -while getopts d:hk:p: OPT; do +while getopts d:p:fnhkq OPT; do case "$OPT" in d) if [[ -e "$OPTARG" ]]; then @@ -68,27 +69,39 @@ while getopts d:hk:p: OPT; do else echo "[debug] no custom daemon; using $FFMPEG" fi ;; + f) + force="-y" + echo "[debug] overwriting existing files " ;; h) echo "[help] -d, path to custom ffmpeg (default: $FFMPEG)" + echo "[help] -f, force overwriting existing files" + echo "[help} -n, never overwrite existing files" echo "[help] -k, keep the original ts file" + echo "[help] -q, disable output from ffmpeg (default: info)" echo "[help] -p, custom path to scan recursively (default: $WORKPATH)" exit 0;; k) echo "[debug] keeping the original file" keepsource="1";; + n) + force="-n" + echo "[debug] not overwriting existing files " ;; p) - if [[ -e "$OPTARG" ]]; then + if [[ -d "$OPTARG" ]]; then WORKPATH="$OPTARG" echo "[debug] custom pathing: $OPTARG" else echo "[debug] no custom pathing; using $WORKPATH" - fi ;; + fi ;; + q) + loglevel="quiet" + echo "[debug] disabling ffmpeg output" ;; esac done -shift $(($OPTIND-1)) +shift $((OPTIND-1)) echo "[info] finding files" -filelist="$(find $WORKPATH -name "*.ts")" +filelist="$(find "$WORKPATH" -name "*.ts")" if [[ "$filelist" ]]; then for i in $filelist; do @@ -107,6 +120,8 @@ if [[ "$filelist" ]]; then -codec:a copy \ -codec:s srt \ -metadata:s:s:0 language=eng \ + $force \ + -loglevel "$loglevel" \ "${OUTFILE}" exitcode="$?"