diff --git a/doc/APIchanges b/doc/APIchanges
index 7d720258c36378cd9fb3f709bd06d7ca127a3e16..1143d56d411c05bc1d35ecef5311325583bb4558 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -16,7 +16,10 @@ libavutil:     2012-10-22
 API changes, most recent first:
 
 
-2013-05-24 - xxxxxxx - lavc 55.7.0 - avcodec.h
+2013-05-24 - xxxxxxx - lavu 52.34.100 - cpu.h
+  Add av_cpu_count() function for getting the number of logical CPUs.
+
+2013-05-24 - xxxxxxx - lavc 55.12.100 - avcodec.h
   Add picture_structure to AVCodecParserContext.
 
 2013-05-17 - xxxxxxx - lavu 52.33.100 - opt.h
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 036d53bc4ff7f3fbc7def83e0702022f60179266..41d6d624fc5a79a8684f3ed57e31ab8a43d3e002 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -31,32 +31,12 @@
 
 #include "config.h"
 
-#if HAVE_SCHED_GETAFFINITY
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE
-#endif
-#include <sched.h>
-#endif
-#if HAVE_GETPROCESSAFFINITYMASK
-#include <windows.h>
-#endif
-#if HAVE_SYSCTL
-#if HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#endif
-#if HAVE_SYSCONF
-#include <unistd.h>
-#endif
-
 #include "avcodec.h"
 #include "internal.h"
 #include "thread.h"
 #include "libavutil/avassert.h"
 #include "libavutil/common.h"
+#include "libavutil/cpu.h"
 
 #if HAVE_PTHREADS
 #include <pthread.h>
@@ -168,42 +148,13 @@ typedef struct FrameThreadContext {
 
 int ff_get_logical_cpus(AVCodecContext *avctx)
 {
-    int ret, nb_cpus = 1;
-#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
-    cpu_set_t cpuset;
-
-    CPU_ZERO(&cpuset);
-
-    ret = sched_getaffinity(0, sizeof(cpuset), &cpuset);
-    if (!ret) {
-        nb_cpus = CPU_COUNT(&cpuset);
-    }
-#elif HAVE_GETPROCESSAFFINITYMASK
-    DWORD_PTR proc_aff, sys_aff;
-    ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff);
-    if (ret)
-        nb_cpus = av_popcount64(proc_aff);
-#elif HAVE_SYSCTL && defined(HW_NCPU)
-    int mib[2] = { CTL_HW, HW_NCPU };
-    size_t len = sizeof(nb_cpus);
-
-    ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0);
-    if (ret == -1)
-        nb_cpus = 0;
-#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
-    nb_cpus = sysconf(_SC_NPROC_ONLN);
-#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
-    nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
-#endif
-    av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
-
+    int nb_cpus = av_cpu_count();
     if  (avctx->height)
         nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);
 
     return nb_cpus;
 }
 
-
 static void* attribute_align_arg worker(void *v)
 {
     AVCodecContext *avctx = v;
@@ -843,9 +794,10 @@ static int frame_thread_init(AVCodecContext *avctx)
     int i, err = 0;
 
     if (!thread_count) {
-        int nb_cpus = ff_get_logical_cpus(avctx);
+        int nb_cpus = av_cpu_count();
         if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv)
             nb_cpus = 1;
+        av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
         // use number of cores + 1 as thread count if there is more than one
         if (nb_cpus > 1)
             thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index a1d1547033bf59740bca83b27d592cb039f443a7..0560ddbaf46733a4bee16ccd48f34a9ecc443e66 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -20,6 +20,27 @@
 #include "config.h"
 #include "opt.h"
 
+#if HAVE_SCHED_GETAFFINITY
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+#include <sched.h>
+#endif
+#if HAVE_GETPROCESSAFFINITYMASK
+#include <windows.h>
+#endif
+#if HAVE_SYSCTL
+#if HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+#if HAVE_SYSCONF
+#include <unistd.h>
+#endif
+
 static int flags, checked;
 
 void av_force_cpu_flags(int arg){
@@ -173,6 +194,40 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
 
     return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);
 }
+
+int av_cpu_count(void)
+{
+    int ret, nb_cpus = 1;
+#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
+    cpu_set_t cpuset;
+
+    CPU_ZERO(&cpuset);
+
+    ret = sched_getaffinity(0, sizeof(cpuset), &cpuset);
+    if (!ret) {
+        nb_cpus = CPU_COUNT(&cpuset);
+    }
+#elif HAVE_GETPROCESSAFFINITYMASK
+    DWORD_PTR proc_aff, sys_aff;
+    ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff);
+    if (ret)
+        nb_cpus = av_popcount64(proc_aff);
+#elif HAVE_SYSCTL && defined(HW_NCPU)
+    int mib[2] = { CTL_HW, HW_NCPU };
+    size_t len = sizeof(nb_cpus);
+
+    ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0);
+    if (ret == -1)
+        nb_cpus = 0;
+#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
+    nb_cpus = sysconf(_SC_NPROC_ONLN);
+#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
+    nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+
+    return nb_cpus;
+}
+
 #ifdef TEST
 
 #include <stdio.h>
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index c8f34e02724b186f98e5e55d4c294acc16e323d6..df8ef8728a942ce4cc509da300267a2181723432 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -100,6 +100,11 @@ int av_parse_cpu_flags(const char *s);
  */
 int av_parse_cpu_caps(unsigned *flags, const char *s);
 
+/**
+ * @return the number of logical CPU cores present.
+ */
+int av_cpu_count(void);
+
 /* The following CPU-specific functions shall not be called directly. */
 int ff_get_cpu_flags_arm(void);
 int ff_get_cpu_flags_ppc(void);
diff --git a/libavutil/version.h b/libavutil/version.h
index a88247b714e0ade22ff2c032fd7658f7a1f99a41..e234296b4106852eac6b45dce897f7d56b69c2a0 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  33
+#define LIBAVUTIL_VERSION_MINOR  34
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \