--- Portfile.old	2018-02-13 22:06:37.000000000 -0600
+++ Portfile	2018-05-14 23:43:30.000000000 -0500
@@ -1,10 +1,11 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
 
 PortSystem 1.0
+PortGroup       muniversal 1.0
 
 name        transcode
 version     1.1.7
-revision    21
+revision        22
 epoch       1
 license     GPL-2+
 categories  multimedia
@@ -32,8 +33,22 @@
 
 use_bzip2       yes
 
-checksums       md5     9bb25a796a8591fb764de46ee87ce505 \
-                sha1    e35df68b960eb56ef0a59a4cdbed1491be56aee6
+checksums       transcode-1.1.7.tar.bz2 \
+                    rmd160  faa854acbbfd52faaa216505176f94d756d77841 \
+                    sha256  1e4e72d8e0dd62a80b8dd90699f5ca64c9b0cb37a5c9325c184166a9654f0a92 \
+                    size    2183627 \
+                transcode-ffmpeg3.patch \
+                    rmd160  bac993cb3bbe6ce69c995b596bb76e75fb185fa2 \
+                    sha256  728ec3101039d98116275e36ea5cf0434a23a0bb82aca830ea9612fb9d16b062 \
+                    size    50234 \
+                transcode-ffmpeg4.patch \
+                    rmd160  df5df5fb91b7051a580d697a52c3a6bd4d44e91a \
+                    sha256  2cc680666f705685a9fdc54b5a377e7728765bde6ed83c43b835634e27767721 \
+                    size    26970 \
+                transcode-imagemagick7.patch \
+                    rmd160  af4e4214203f4879c359b772afa73ef928710347 \
+                    sha256  4ede15540ea6932954ac332c12dde130bf48e7e4773d1e04d3c3f23038c6ac51 \
+                    size    34353
 
 depends_build   port:pkgconfig
 
@@ -45,24 +60,49 @@
 
 platforms       darwin
 
-patchfiles      patch-configure.diff \
-                patch-avilib-avidump.c.diff \
-                patch-ffmpeg-0.11.diff \
-                patch-filter-filter_pp.c.diff \
-                patch-encode-Makefile.in.diff \
-                patch-ffmpeg-2.0.diff \
-                patch-ffmpeg-2.4.diff \
-                patch-freetype-2.5.1.diff \
-                patch-ffmpeg-3.0.diff
+patch.pre_args  -p1
+patch.args      -b -V numbered
+patchfiles      \
+                avilib-avidump.c.diff \
+                configure.in.diff \
+                filter-subtitler-load_font.c.diff
+
+# https://www.archlinux.org/packages/community/x86_64/transcode/
+patch_sites     https://git.archlinux.org/svntogit/community.git/plain/trunk/?h=packages/transcode
+patchfiles-append \
+                transcode-ffmpeg3.patch \
+                transcode-ffmpeg4.patch
+
+# Simple macports-base/src/port1.0/fetch_common.tcl does not parse query in url.
+proc portfetch::assemble_url {site distfile} {
+	package require uri
+	set parts [uri::split $site]
+	if {[string index [dict get $parts path] end] ne "/"} {
+		set slash /
+	} else {
+		set slash ""
+	}
+	dict append parts path $slash [percent_encode ${distfile}]
+	set rval [uri::join {*}$parts]
+	return "$rval"
+}
+
+use_autoreconf  yes
+autoreconf.args -fiv
 
 configure.args  --disable-mmx \
                 --enable-libmpeg2 \
                 --enable-libmpeg2convert \
                 --without-x
 
-# Optional components
+# With muniversal configure needs help.  This configure's tests do not handle cross-compling, so we must set build and not just host alone.
+platform darwin {
+	lappend merger_configure_args(i386)  --build=i686-apple-${os.platform}${os.version}
+}
+
+default_variants +full +x11
 
-universal_variant no
+# Optional components
 
 variant mmx description {enable mmx optimizations} {
      configure.args-delete --disable-mmx
@@ -89,6 +129,9 @@
 variant imagemagick description {enable support for the manipulation of still images} {
     depends_lib-append port:ImageMagick
     configure.args-append --enable-imagemagick --with-imagemagick-prefix=${prefix}
+    if {![catch {set vers [lindex [registry_active ImageMagick] 0]}] && [vercmp [lindex $vers 1] 7.0] >= 0 } {
+        patchfiles-append transcode-imagemagick7.patch
+    }
 }
 
 variant libdv description {enable support for the Digital Video format via libdv} {
@@ -174,12 +217,6 @@
     configure.args-delete --without-x
 }
 
-default_variants +x11
-
-platform darwin {
-    configure.args-append --build=${build_arch}-apple-darwin${os.major}
-}
-
 livecheck.type  regex
-livecheck.url   ${master_sites}
+livecheck.url   [lindex ${master_sites} 0]
 livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
