Re: [FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-03-02 Thread Richard Kern

> On Mar 2, 2016, at 12:11 AM, wm4  wrote:
> 
> On Tue, 01 Mar 2016 14:57:29 +
> Timothy Gu > wrote:
> 
>> Hi,
>> 
>> On Mon, Feb 29, 2016 at 9:42 PM Rick Kern  wrote:
>> 
>>> Autodetected by default. Encode using -codec:v vtenc.
>>> 
>>> Signed-off-by: Rick Kern 
>>> ---
>>> MAINTAINERS|1 +
>>> configure  |   19 +
>>> libavcodec/Makefile|1 +
>>> libavcodec/allcodecs.c |1 +
>>> libavcodec/vtenc.c | 1339
>>> 
>>> 5 files changed, 1361 insertions(+)
>>> create mode 100644 libavcodec/vtenc.c
>>> 
>> 
>> We already have videotoolbox AVHWAccel. Maybe it would be better to change
>> the name of the file to videotoolboxenc.c so that it's easier to associate
>> these two files?
> 
> I don't mind. They're pretty different after all.
Sounds good. I’ll rename it.

> 
>> 
>>> +AVCodec ff_vtenc_encoder = {  
>> 
>>> +.name = "vtenc",
>>> +.long_name= NULL_IF_CONFIG_SMALL("VideoToolbox H.264
>>> Encoder"),
>>> 
>> 
>> The norm seems to be using "h264_videotoolbox" (like "h264_qsv") so that
>> potential future extensions to VideoToolbox can be supported without
>> changing the name of the codec.
>> 
> 
> Good point.
Ok. I’d also like to make configure —enable-videotoolbox apply to the 
VideoToolbox external library, not just the hwaccel. The VideoToolbox hwaccel 
build code will have to be updated to depend on the external library, but then 
disabling VideoToolbox-related code requires one parameter. The names of the 
hwaccels would stay the same, so I don’t see any backwards compatibility issues.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org 
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
> 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-03-01 Thread wm4
On Tue, 01 Mar 2016 14:57:29 +
Timothy Gu  wrote:

> Hi,
> 
> On Mon, Feb 29, 2016 at 9:42 PM Rick Kern  wrote:
> 
> > Autodetected by default. Encode using -codec:v vtenc.
> >
> > Signed-off-by: Rick Kern 
> > ---
> >  MAINTAINERS|1 +
> >  configure  |   19 +
> >  libavcodec/Makefile|1 +
> >  libavcodec/allcodecs.c |1 +
> >  libavcodec/vtenc.c | 1339
> > 
> >  5 files changed, 1361 insertions(+)
> >  create mode 100644 libavcodec/vtenc.c
> >  
> 
> We already have videotoolbox AVHWAccel. Maybe it would be better to change
> the name of the file to videotoolboxenc.c so that it's easier to associate
> these two files?

I don't mind. They're pretty different after all.

> 
> > +AVCodec ff_vtenc_encoder = {  
> 
> > +.name = "vtenc",
> > +.long_name= NULL_IF_CONFIG_SMALL("VideoToolbox H.264
> > Encoder"),
> >  
> 
> The norm seems to be using "h264_videotoolbox" (like "h264_qsv") so that
> potential future extensions to VideoToolbox can be supported without
> changing the name of the codec.
> 

Good point.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-03-01 Thread Timothy Gu
Hi,

On Mon, Feb 29, 2016 at 9:42 PM Rick Kern  wrote:

> Autodetected by default. Encode using -codec:v vtenc.
>
> Signed-off-by: Rick Kern 
> ---
>  MAINTAINERS|1 +
>  configure  |   19 +
>  libavcodec/Makefile|1 +
>  libavcodec/allcodecs.c |1 +
>  libavcodec/vtenc.c | 1339
> 
>  5 files changed, 1361 insertions(+)
>  create mode 100644 libavcodec/vtenc.c
>

We already have videotoolbox AVHWAccel. Maybe it would be better to change
the name of the file to videotoolboxenc.c so that it's easier to associate
these two files?

> +AVCodec ff_vtenc_encoder = {

> +.name = "vtenc",
> +.long_name= NULL_IF_CONFIG_SMALL("VideoToolbox H.264
> Encoder"),
>

The norm seems to be using "h264_videotoolbox" (like "h264_qsv") so that
potential future extensions to VideoToolbox can be supported without
changing the name of the codec.

Timothy
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-03-01 Thread wm4
On Tue, 1 Mar 2016 11:31:18 +0100
Michael Niedermayer  wrote:

> On Tue, Mar 01, 2016 at 01:40:53PM +0800, Rick Kern wrote:
> > Autodetected by default. Encode using -codec:v vtenc.  
> [...]
> > +static void set_async_error(VTEncContext *vtctx, int err)
> > +{
> > +BufNode *info;
> > +
> > +pthread_mutex_lock(>lock);
> > +
> > +vtctx->async_error = err;
> > +
> > +info = vtctx->q_head;
> > +vtctx->q_head = vtctx->q_tail = NULL;
> > +
> > +while (info) {
> > +BufNode *next = info->next;
> > +CFRelease(info->cm_buffer);
> > +free(info);  
> 
> should probably av_free()
> 
> > +info = next;
> > +}
> > +
> > +pthread_mutex_unlock(>lock);
> > +}
> > +
> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> > *buf)
> > +{
> > +BufNode *info;
> > +
> > +pthread_mutex_lock(>lock);
> > +
> > +if (vtctx->async_error) {
> > +pthread_mutex_unlock(>lock);
> > +return vtctx->async_error;
> > +}
> > +
> > +if (vtctx->flushing && vtctx->frame_ct_in == vtctx->frame_ct_out) {
> > +*buf = NULL;
> > +
> > +pthread_mutex_unlock(>lock);
> > +return 0;
> > +}
> > +
> > +while (!vtctx->q_head && !vtctx->async_error && wait) {
> > +pthread_cond_wait(>cv_sample_sent, >lock);
> > +}
> > +
> > +if (!vtctx->q_head) {
> > +pthread_mutex_unlock(>lock);
> > +*buf = NULL;
> > +return 0;
> > +}
> > +
> > +info = vtctx->q_head;
> > +vtctx->q_head = vtctx->q_head->next;
> > +if (!vtctx->q_head) {
> > +vtctx->q_tail = NULL;
> > +}
> > +
> > +pthread_mutex_unlock(>lock);
> > +
> > +*buf = info->cm_buffer;  
> 
> > +free(info);  
> 
> same
> 
> [...]

PS: I'll change them locally to av_free() and then push in some time.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-03-01 Thread wm4
On Tue, 1 Mar 2016 11:31:18 +0100
Michael Niedermayer  wrote:

> On Tue, Mar 01, 2016 at 01:40:53PM +0800, Rick Kern wrote:
> > Autodetected by default. Encode using -codec:v vtenc.  
> [...]
> > +static void set_async_error(VTEncContext *vtctx, int err)
> > +{
> > +BufNode *info;
> > +
> > +pthread_mutex_lock(>lock);
> > +
> > +vtctx->async_error = err;
> > +
> > +info = vtctx->q_head;
> > +vtctx->q_head = vtctx->q_tail = NULL;
> > +
> > +while (info) {
> > +BufNode *next = info->next;
> > +CFRelease(info->cm_buffer);
> > +free(info);  
> 
> should probably av_free()
> 
> > +info = next;
> > +}
> > +
> > +pthread_mutex_unlock(>lock);
> > +}
> > +
> > +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> > *buf)
> > +{
> > +BufNode *info;
> > +
> > +pthread_mutex_lock(>lock);
> > +
> > +if (vtctx->async_error) {
> > +pthread_mutex_unlock(>lock);
> > +return vtctx->async_error;
> > +}
> > +
> > +if (vtctx->flushing && vtctx->frame_ct_in == vtctx->frame_ct_out) {
> > +*buf = NULL;
> > +
> > +pthread_mutex_unlock(>lock);
> > +return 0;
> > +}
> > +
> > +while (!vtctx->q_head && !vtctx->async_error && wait) {
> > +pthread_cond_wait(>cv_sample_sent, >lock);
> > +}
> > +
> > +if (!vtctx->q_head) {
> > +pthread_mutex_unlock(>lock);
> > +*buf = NULL;
> > +return 0;
> > +}
> > +
> > +info = vtctx->q_head;
> > +vtctx->q_head = vtctx->q_head->next;
> > +if (!vtctx->q_head) {
> > +vtctx->q_tail = NULL;
> > +}
> > +
> > +pthread_mutex_unlock(>lock);
> > +
> > +*buf = info->cm_buffer;  
> 
> > +free(info);  
> 
> same

Indeed, it should be.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-03-01 Thread Michael Niedermayer
On Tue, Mar 01, 2016 at 01:40:53PM +0800, Rick Kern wrote:
> Autodetected by default. Encode using -codec:v vtenc.
[...]
> +static void set_async_error(VTEncContext *vtctx, int err)
> +{
> +BufNode *info;
> +
> +pthread_mutex_lock(>lock);
> +
> +vtctx->async_error = err;
> +
> +info = vtctx->q_head;
> +vtctx->q_head = vtctx->q_tail = NULL;
> +
> +while (info) {
> +BufNode *next = info->next;
> +CFRelease(info->cm_buffer);
> +free(info);

should probably av_free()

> +info = next;
> +}
> +
> +pthread_mutex_unlock(>lock);
> +}
> +
> +static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef 
> *buf)
> +{
> +BufNode *info;
> +
> +pthread_mutex_lock(>lock);
> +
> +if (vtctx->async_error) {
> +pthread_mutex_unlock(>lock);
> +return vtctx->async_error;
> +}
> +
> +if (vtctx->flushing && vtctx->frame_ct_in == vtctx->frame_ct_out) {
> +*buf = NULL;
> +
> +pthread_mutex_unlock(>lock);
> +return 0;
> +}
> +
> +while (!vtctx->q_head && !vtctx->async_error && wait) {
> +pthread_cond_wait(>cv_sample_sent, >lock);
> +}
> +
> +if (!vtctx->q_head) {
> +pthread_mutex_unlock(>lock);
> +*buf = NULL;
> +return 0;
> +}
> +
> +info = vtctx->q_head;
> +vtctx->q_head = vtctx->q_head->next;
> +if (!vtctx->q_head) {
> +vtctx->q_tail = NULL;
> +}
> +
> +pthread_mutex_unlock(>lock);
> +
> +*buf = info->cm_buffer;

> +free(info);

same

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-02-29 Thread Rick Kern
Autodetected by default. Encode using -codec:v vtenc.

Signed-off-by: Rick Kern 
---
 MAINTAINERS|1 +
 configure  |   19 +
 libavcodec/Makefile|1 +
 libavcodec/allcodecs.c |1 +
 libavcodec/vtenc.c | 1339 
 5 files changed, 1361 insertions(+)
 create mode 100644 libavcodec/vtenc.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 155642b..650da3c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -289,6 +289,7 @@ Codecs:
   vp8   David Conrad, Jason Garrett-Glaser, 
Ronald Bultje
   vp9   Ronald Bultje, Clément Bœsch
   vqavideo.cMike Melanson
+  vtenc.c   Rick Kern
   wavpack.c Kostya Shishkov
   wmaprodec.c   Sascha Sommer
   wmavoice.cRonald S. Bultje
diff --git a/configure b/configure
index 8491fa1..c7af891 100755
--- a/configure
+++ b/configure
@@ -289,6 +289,7 @@ External library support:
   --disable-sdldisable sdl [autodetect]
   --disable-securetransport disable Secure Transport, needed for TLS support
on OSX if openssl and gnutls are not used 
[autodetect]
+  --disable-vtenc  disable VideoToolbox H.264 encoder [autodetect]
   --enable-x11grab enable X11 grabbing (legacy) [no]
   --disable-xlib   disable xlib [autodetect]
   --disable-zlib   disable zlib [autodetect]
@@ -1509,6 +1510,7 @@ EXTERNAL_LIBRARY_LIST="
 schannel
 sdl
 securetransport
+vtenc
 x11grab
 xlib
 zlib
@@ -2672,6 +2674,9 @@ libzvbi_teletext_decoder_deps="libzvbi"
 nvenc_encoder_deps="nvenc"
 nvenc_h264_encoder_deps="nvenc"
 nvenc_hevc_encoder_deps="nvenc"
+vtenc_encoder_deps="vtenc VideoToolbox_VideoToolbox_h pthreads"
+vtenc_encoder_select="bzlib zlib iconv"
+vtenc_encoder_extralibs="-framework CoreFoundation -framework VideoToolbox 
-framework CoreMedia"
 
 # demuxers / muxers
 ac3_demuxer_select="ac3_parser"
@@ -5695,6 +5700,20 @@ enabled openssl   && { use_pkg_config openssl 
openssl/ssl.h SSL_library_
check_lib openssl/ssl.h SSL_library_init -lssl 
-lcrypto -lws2_32 -lgdi32 ||
die "ERROR: openssl not found"; }
 enabled qtkit_indev  && { check_header_objcc QTKit/QTKit.h || disable 
qtkit_indev; }
+{ disabled vtenc_encoder && disable vtenc; } || 
+{ disabled vtenc && 
+  disable vtenc_encoder; } ||
+{ enabled vtenc &&
+  require VideoToolbox 
VideoToolbox/VTCompressionSession.h VTCompressionSessionPrepareToEncodeFrames 
-framework VideoToolbox &&
+  enable vtenc_encoder; } ||
+{ enabled vtenc_encoder &&
+  check_lib VideoToolbox/VTCompressionSession.h 
VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox &&
+  enable vtenc; } ||
+{ disable vtenc && 
+  disable vtenc_encoder; }
+enabled vtenc_encoder&& check_header "TargetConditionals.h" &&
+{ check_cpp_condition "TargetConditionals.h" 
"TARGET_OS_MAC && !TARGET_OS_IPHONE" &&
+  vtenc_encoder_extralibs+=" -framework 
VideoDecodeAcceleration"; }
 
 # libdc1394 check
 if enabled libdc1394; then
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 667e257..8249def 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -120,6 +120,7 @@ OBJS-$(CONFIG_TEXTUREDSPENC)   += texturedspenc.o
 OBJS-$(CONFIG_TPELDSP) += tpeldsp.o
 OBJS-$(CONFIG_VC1DSP)  += vc1dsp.o
 OBJS-$(CONFIG_VIDEODSP)+= videodsp.o
+OBJS-$(CONFIG_VTENC)   += vtenc.o
 OBJS-$(CONFIG_VP3DSP)  += vp3dsp.o
 OBJS-$(CONFIG_VP56DSP) += vp56dsp.o
 OBJS-$(CONFIG_VP8DSP)  += vp8dsp.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2097db0..29724bb 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -610,6 +610,7 @@ void avcodec_register_all(void)
 REGISTER_ENCODER(HEVC_QSV,  hevc_qsv);
 REGISTER_ENCODER(LIBKVAZAAR,libkvazaar);
 REGISTER_ENCODER(MPEG2_QSV, mpeg2_qsv);
+REGISTER_ENCODER(VTENC, vtenc);
 
 /* parsers */
 REGISTER_PARSER(AAC,aac);
diff --git a/libavcodec/vtenc.c b/libavcodec/vtenc.c
new file mode 100644
index 000..f653d8d
--- /dev/null
+++ b/libavcodec/vtenc.c
@@ -0,0 +1,1339 @@
+/*
+ * copyright (c) 2015 Rick Kern 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the 

[FFmpeg-devel] [PATCH v9] VideoToolbox H.264 Encoder

2016-02-29 Thread Rick Kern
Replaced color_range with av_frame_get_color_range().

Rick Kern (1):
  VideoToolbox H.264 Encoder

 MAINTAINERS|1 +
 configure  |   19 +
 libavcodec/Makefile|1 +
 libavcodec/allcodecs.c |1 +
 libavcodec/vtenc.c | 1339 
 5 files changed, 1361 insertions(+)
 create mode 100644 libavcodec/vtenc.c

-- 
2.5.4 (Apple Git-61)

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel