...
 
Commits (3)
......@@ -19,6 +19,7 @@ include(cmake/macros.cmake)
set(BUILD_EXAMPLES ON CACHE BOOL "Build Examples?")
set(BUILD_CYTHON ON CACHE BOOL "Build Python Module?")
set(BUILD_PYTHON3 OFF CACHE BOOL "Use Python3?")
set(BUILD_TESTING ON CACHE BOOL "Build unit tests?")
set(BUILD_FFMPEG ON CACHE BOOL "Build with FFMPEG video support?")
......
......@@ -4,7 +4,7 @@
# NUMPY_FOUND, If false, do not try to use numpy headers.
if (NOT NUMPY_INCLUDE_DIR)
exec_program ("${PYTHON_EXECUTABLE}"
ARGS "-c 'import numpy; print numpy.get_include()'"
ARGS "-c 'import numpy; print(numpy.get_include())'"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
RETURN_VALUE NUMPY_NOT_FOUND)
if (NUMPY_INCLUDE_DIR MATCHES "Traceback")
......
......@@ -19,7 +19,7 @@
#include "kimage.h"
#include "internal/kvideo.h"
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define DEBUG 0
static void my_log_callback(void *ptr, int level, const char *fmt, va_list vargs)
......@@ -63,6 +63,34 @@ static KColorSpace _get_color_type(const AVPixFmtDescriptor *desc) {
}
//returns char that lives in global; no need to free
KAZE_API
const char* kvideo_codec_name (KObject* kobj)
{
assert (KOBJECT_VIDEO == kobject_type(kobj));
KVideo* kvid = to_kvideo (kobj);
return kvid->ffmpeg_pVideoStream->codec->codec->name;
}
//this is just average framerate
KAZE_API
double kvideo_fps(KObject* kobj)
{
assert(KOBJECT_VIDEO == kobject_type(kobj));
KVideo* kvid = to_kvideo(kobj);
int fpsn = kvid->ffmpeg_pVideoStream->avg_frame_rate.num;
int fpsd = kvid->ffmpeg_pVideoStream->avg_frame_rate.den;
//Exact framerate:?
// AVCodecContext* avctx = kvid->ffmpeg_pVideoStream->codec;
// double fps = 1.0 / av_q2d(avctx->time_base) / MAX(avctx->ticks_per_frame, 1);
return fpsn/fpsd;
}
KAZE_API
KColorSpace kvideo_frame_color_type (KObject* kobj)
{
......
......@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8.5)
cmake_policy(SET CMP0022 NEW)
if (BUILD_CYTHON)
if (BUILD_PYTHON3)
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6 3.7)
set(PYTHONLIBS_VERSION_STRING "3.5")
endif ()
find_package (Cython)
find_package (Numpy)
endif ()
......
......@@ -122,6 +122,8 @@ cdef extern from "kvideo.h":
int64_t kvideo_duration (KObject* vid)
size_t kvideo_width (KObject* vid)
size_t kvideo_height (KObject* vid)
double kvideo_fps(KObject* kobj)
const char* kvideo_codec_name (KObject* kobj)
ctypedef enum KColorSpace:
FF_COLOR_NA
......
......@@ -8,6 +8,8 @@ cimport cpython.ref as ref
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
cnp.import_array()
import sys
cdef _pythonize_kimage (KObject* img):
"""
Get a new Image() instance and wrap it around the supplied KObject*
......@@ -613,10 +615,20 @@ cdef class Video:
return kvideo_frame_next(self.kobj)
def frame_next_type(self, ftype_target):
return kvideo_frame_next_type(self.kobj, <char>ord(ftype_target.encode()[0]))
#Python3 handles strings differently
if sys.version_info[0] is 3:
return kvideo_frame_next_type(self.kobj, <char>str.encode(ftype_target[0])[0])
else:
return kvideo_frame_next_type(self.kobj, <char>ord(ftype_target.encode()[0]))
def frame_type(self):
return chr(kvideo_frame_type(self.kobj))
def codec_name(self):
return kvideo_codec_name(self.kobj).decode()
def fps(self):
return kvideo_fps(self.kobj)
def frame_PTS(self):
return kvideo_frame_current_PTS(self.kobj)
......@@ -649,7 +661,7 @@ cdef class Video:
return kvideo_frame_pixel_format(self.kobj)
def frame_pix_fmt_name(self):
return kvideo_frame_pix_fmt_name(self.kobj)
return kvideo_frame_pix_fmt_name(self.kobj).decode()
def analyze_gop_structure(self):
#proceeds from current position to end of file, scanning the frame types
......
......@@ -69,6 +69,12 @@ KObject* kvideo_frame_to_kimage_decoded (KObject* video);
KAZE_API
KObject* kvideo_frame_to_kimage (KObject* video);
KAZE_API
const char* kvideo_codec_name (KObject* kobj);
KAZE_API
double kvideo_fps(KObject* kobj);
KAZE_API
KColorSpace kvideo_frame_color_type (KObject* video);
......