diff --git a/src/native/build.xml b/src/native/build.xml
index c9cf429b79e9fcf0b504b5c0e308c540d3b5275a..363ab34e1519388196992ffb843bf624a24364de 100644
--- a/src/native/build.xml
+++ b/src/native/build.xml
@@ -116,6 +116,18 @@
     <isset property="is.running.macos"/>
   </condition>
 
+  <!-- The path to the dpkg-buildpackage tool -->
+  <property name="dpkg-buildpackage" value="/usr/bin/dpkg-buildpackage"/>
+  <!-- The path to the dh_testdir tool -->
+  <property name="dh_testdir" value="/usr/bin/dh_testdir"/>
+  <condition property="is.running.debian">
+    <and>
+        <isset property="is.running.linux"/>
+        <available file="${dpkg-buildpackage}"/>
+        <available file="${dh_testdir}"/>
+    </and>
+  </condition>
+
   <!--
   <echo message="ffmpeg library: ${ffmpeg}" />
   <echo message="x264 library: ${x264}" />
@@ -205,9 +217,17 @@
 
       <!-- Linux-specific flags -->
       <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />
+      <!-- some debian specific -->
+      <compilerarg value="-D_FORTIFY_SOURCE=2" if="is.running.debian"/>
+      <compilerarg value="-g" if="is.running.debian"/>
+      <compilerarg value="-fstack-protector" if="is.running.debian"/>
+      <compilerarg value="--param=ssp-buffer-size=4" if="is.running.debian"/>
+      <compilerarg value="-Werror=format-security" if="is.running.debian"/>
+      <compilerarg value="-Wformat" if="is.running.debian"/>
 
       <linkerarg value="-L${system.JAVA_HOME}/jre/lib/i386" if="is.running.linux" />
       <linkerarg value="-L${system.JAVA_HOME}/jre/lib/amd64" if="is.running.linux" />
+      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
       <linkerarg value="-lXv" location="end" if="is.running.linux" />
       <linkerarg value="-lX11" location="end" if="is.running.linux" />
 
@@ -272,6 +292,7 @@
       <compilerarg value="-O2" />
       <compilerarg value="-std=c99" />
       <compilerarg value="-Wall" />
+      <compilerarg value="-D_JITSI_LIBAV_" if="LIBAV"/>
 
       <linkerarg value="-L${ffmpeg}/libavcodec" />
       <linkerarg value="-L${ffmpeg}/libavfilter" />
@@ -286,6 +307,7 @@
       <linkerarg value="-L${lame}/libmp3lame/.libs" />
       <linkerarg value="-L${x264}" />
       <linkerarg value="-m${arch}" />
+      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
       <!--
         Static libraries MUST be at the end otherwise they will not be added to
         the shared library.
@@ -388,7 +410,9 @@
 
       <!-- Linux-specific flags -->
       <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />
+      <compilerarg value="-D_FORTIFY_SOURCE=2" if="is.running.debian"/>
 
+      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
       <!-- Static libraries MUST be at the end; otherwise, they will not be
            added to shared library.
       -->
@@ -591,6 +615,7 @@
             <compilerarg value="-I/usr/include/opus" if="is.running.linux"/>
             <compilerarg value="-D_JNI_IMPLEMENTATION_" />
 
+            <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
             <linkerarg value="-L${opus}/.libs" />
 
             <!-- Linux specific flags -->
@@ -738,6 +763,7 @@
 
       <linkerarg value="-m32" if="cross_32" />
       <linkerarg value="-m64" if="cross_64" />
+      <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
 
       <fileset dir="${src}/native/linux/video4linux2" includes="*.c"/>
     </cc>
@@ -872,6 +898,7 @@
                 <compilerarg value="-D_REENTRANT" />
 
                 <linkerarg value="-Wl,--no-undefined" />
+                <linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
                 <linkerarg value="-lpulse" />
                 <linkerarg value="-ldl" />
 
diff --git a/src/native/ffmpeg/org_jitsi_impl_neomedia_codec_FFmpeg.c b/src/native/ffmpeg/org_jitsi_impl_neomedia_codec_FFmpeg.c
index 0aa8eb06249cac8a81b860b70b7891a61084f10b..bbf7b5f75a0ba812c0ae3b1223b8d3b2ed15d5fe 100644
--- a/src/native/ffmpeg/org_jitsi_impl_neomedia_codec_FFmpeg.c
+++ b/src/native/ffmpeg/org_jitsi_impl_neomedia_codec_FFmpeg.c
@@ -17,8 +17,12 @@
 #include <libavfilter/avfilter.h>
 #include <libavfilter/avfiltergraph.h>
 #include <libavfilter/buffersrc.h>
+
+#ifndef _JITSI_LIBAV_
 #include <libavfilter/formats.h> /* ff_default_query_formats, ff_make_format_list, ff_set_common_formats */
 #include <libavfilter/internal.h> /* ff_request_frame */
+#endif
+
 #include <libswscale/swscale.h>
 
 #define DEFINE_AVCODECCONTEXT_F_PROPERTY_SETTER(name, property) \
@@ -512,7 +516,11 @@ ffsink_query_formats(AVFilterContext *ctx)
     int err;
 
     /* Find buffer. */
+#ifdef _JITSI_LIBAV_
+    while (src && src->inputs && src->inputs)
+#else
     while (src && src->nb_inputs && src->inputs)
+#endif
     {
         AVFilterLink *link = src->inputs[0];
 
@@ -527,11 +535,21 @@ ffsink_query_formats(AVFilterContext *ctx)
     {
         const int pix_fmts[] = { src->outputs[0]->in_formats->formats[0], -1 };
 
+#ifdef _JITSI_LIBAV_
+        avfilter_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+#else
         ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
+#endif
+
         err = 0;
     }
     else
+#ifdef _JITSI_LIBAV_
+        err = query_formats(ctx);
+#else
         err = ff_default_query_formats(ctx);
+#endif
+
     return err;
 }