diff --git a/configure b/configure
index dd9608540e..1bc0338f15 100755
--- a/configure
+++ b/configure
@@ -1976,6 +1976,7 @@ SYSTEM_FUNCS="
     PeekNamedPipe
     posix_memalign
     pthread_cancel
+    pthread_setname_np
     sched_getaffinity
     SetConsoleTextAttribute
     SetConsoleCtrlHandler
@@ -5765,6 +5766,7 @@ fi
 
 if enabled pthreads; then
   check_func pthread_cancel
+  check_func pthread_setname_np
 fi
 
 enabled pthreads &&
diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index 6cf1a68fe7..3ec82dfe2a 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -62,6 +62,8 @@ static void * attribute_align_arg worker(void *v){
     ThreadContext *c = avctx->internal->frame_thread_encoder;
     AVPacket *pkt = NULL;
 
+    avpriv_thread_setname("lavc-frame-enc");
+
     while(!c->exit){
         int got_packet, ret;
         AVFrame *frame;
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 363b139f71..749ced42d6 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -169,6 +169,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
     AVCodecContext *avctx = p->avctx;
     const AVCodec *codec = avctx->codec;
 
+    avpriv_thread_setname("lavc-frame");
+
     pthread_mutex_lock(&p->mutex);
     while (1) {
         while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die)
diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c
index 60f5b78891..a1b1402f7f 100644
--- a/libavcodec/pthread_slice.c
+++ b/libavcodec/pthread_slice.c
@@ -70,6 +70,8 @@ static void* attribute_align_arg worker(void *v)
     int thread_count = avctx->thread_count;
     int self_id;
 
+    avpriv_thread_setname("lavc-slice");
+
     pthread_mutex_lock(&c->current_job_lock);
     self_id = c->current_job++;
     for (;;){
diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
index c7a00210d6..f4ecd39057 100644
--- a/libavfilter/pthread.c
+++ b/libavfilter/pthread.c
@@ -61,6 +61,8 @@ static void* attribute_align_arg worker(void *v)
     unsigned int last_execute = 0;
     int ret, self_id;
 
+    avpriv_thread_setname("lavfi-worker");
+
     pthread_mutex_lock(&c->current_job_lock);
     self_id = c->current_job++;
 
diff --git a/libavformat/async.c b/libavformat/async.c
index 54dbd2312a..8e7dd34401 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -181,6 +181,8 @@ static void *async_buffer_task(void *arg)
     int           ret  = 0;
     int64_t       seek_ret;
 
+    avpriv_thread_setname("lavf-async-buf");
+
     while (1) {
         int fifo_space, to_copy;
 
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 3835f989c4..1aaf577b57 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -36,6 +36,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/thread.h"
 #include "libavutil/time.h"
 #include "internal.h"
 #include "network.h"
@@ -502,6 +503,8 @@ static void *circular_buffer_task_rx( void *_URLContext)
     UDPContext *s = h->priv_data;
     int old_cancelstate;
 
+    avpriv_thread_setname("udp-circ-buf");
+
     pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
     pthread_mutex_lock(&s->mutex);
     if (ff_socket_nonblock(s->udp_fd, 0) < 0) {
diff --git a/libavutil/thread.h b/libavutil/thread.h
index f108e20052..b82d7e34c4 100644
--- a/libavutil/thread.h
+++ b/libavutil/thread.h
@@ -29,6 +29,10 @@
 #if HAVE_PTHREADS
 #include <pthread.h>
 
+#if HAVE_PTHREAD_SETNAME_NP && defined(__linux__)
+#include <sys/prctl.h>
+#endif
+
 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
 
 #include "log.h"
@@ -127,6 +131,17 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_
 #define pthread_once           strict_pthread_once
 #endif
 
+static inline void avpriv_thread_setname(const char *name)
+{
+#if HAVE_PTHREAD_SETNAME_NP
+#if defined(__APPLE__)
+    pthread_setname_np(name);
+#elif defined(__linux__)
+    prctl(PR_SET_NAME, name);
+#endif
+#endif
+}
+
 #elif HAVE_OS2THREADS
 #include "compat/os2threads.h"
 #else
