Re: [FFmpeg-devel] [PATCH] avcodec/utils: do_decode: Assert that the decoder return value is not larger than the packet size

2016-04-22 Thread wm4
On Fri, 22 Apr 2016 05:14:30 +0200
Michael Niedermayer  wrote:

> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/utils.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 52e0d92..b35fabc 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2738,6 +2738,7 @@ static int do_decode(AVCodecContext *avctx, AVPacket 
> *pkt)
>  avctx->internal->draining_done = 1;
>  
>  if (ret >= pkt->size) {
> +av_assert0(ret == pkt->size);
>  av_packet_unref(avctx->internal->buffer_pkt);
>  } else {
>  int consumed = ret;

Basically all code using the "old" API expects that the decoder can
read beyond the buffer (making use of input padding I suppose). So I
think this is expected.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/utils: do_decode: Assert that the decoder return value is not larger than the packet size

2016-04-22 Thread Michael Niedermayer
On Fri, Apr 22, 2016 at 09:11:52AM +0200, wm4 wrote:
> On Fri, 22 Apr 2016 05:14:30 +0200
> Michael Niedermayer  wrote:
> 
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/utils.c |1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > index 52e0d92..b35fabc 100644
> > --- a/libavcodec/utils.c
> > +++ b/libavcodec/utils.c
> > @@ -2738,6 +2738,7 @@ static int do_decode(AVCodecContext *avctx, AVPacket 
> > *pkt)
> >  avctx->internal->draining_done = 1;
> >  
> >  if (ret >= pkt->size) {
> > +av_assert0(ret == pkt->size);
> >  av_packet_unref(avctx->internal->buffer_pkt);
> >  } else {
> >  int consumed = ret;
> 
> Basically all code using the "old" API expects that the decoder can
> read beyond the buffer (making use of input padding I suppose). So I
> think this is expected.

iam not aware of any decoder that would return such a overread size
also to double check this yesterday i tested this with a bunch of
fuzzed files before posting the patch and failed to find anything that
triggers the assert

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

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates


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


Re: [FFmpeg-devel] libavfilter API design in a realtime environment

2016-04-22 Thread Paul B Mahol
On 4/19/16, Nicolas George  wrote:
> Le septidi 27 ventose, an CCXXIV, Kieran Kunhya a ecrit :
>> I want to try and use the libavfilter API to overlay bitmap subtitles on
>> video from a realtime source. This seems difficult/impossible to do with
>> the current API hence asking on the main devel list.
>
> Have you looked at what the command-line tool ffmpeg does? It is not
> optimized for ultra-low latency, but it should already achieve reasonable
> results.
>
>> 1: How do I know the end to end latency of the pipeline? Is it fixed,
>> does
>> it vary? This matters because my wallclock PTS needs addition of this
>> latency.
>
> You can not know that in the general case, since the latency of some
> filters
> depends on the frame contents and arbitrary user-provided formulas.
>
> On a particular case, the rule of thumb is that filters produce output as
> soon as they have enough input information to do so. But note that for
> filters that require syncing between several video streams will likely
> require one extra frame on some or all stream. This happens because frames
> have no duration (and I am convinced they should not have one), and
> therefore the next frame is required to know the end timestamp.

This is really, really bad. Frame do should have duration. And audio
ones do have.

>
>> 2: Do I need to interleave video and subtitles (e.g VSVSVSVS) in
>> monotonically increasing order? What happens if the subtitles stop for a
>> bit (magic queues are bad in a realtime environment)? My timestamps are
>> guaranteed to be the same though.
>
> libavfilter can deal with streams slightly out of sync by buffering, but it
> takes a lot of memory of course, and will eventually lead to OOM or
> dropping
> frames if the desync is too large.
>
>> 3: My world is CFR but libavfilter is VFR - how does the API know when to
>> start releasing frames? Does this add one frame of video latency then
>> until
>> it waits for the next video frame to arrive?
>
> Knowing you have CFR gives you an assumption at the frame duration, and
> therefore can save you the wait for the next frame. The difficulty is
> integrating that elegantly in the scheduling. See below.
>
>> 4: What are the differences between the FFmpeg and libav implementations?
>> FFmpeg uses a framesync and libav doesn't?
>
> If your graph has a single output and you never have a choice about which
> input to feed (for example because the frames arrive interleaved), then I
> believe the difference do not matter for you.
>
>> 5: I know exactly which frames have associated subtitle bitmaps or not,
>> is
>> there a way I can overlay without an extra frame delay?
>
> As wm4 explained, the hard part with subtitles is that they are sparse: you
> have a start event, then ~2 seconds, or ~50 frames worth of video, then an
> end event, and then maybe several hours before the next start event. If any
> filter requires an end timestamp and syncs with video, then you have a huge
> latency and a huge buffer.
>
> If the subtitles come from a separate on-demand file, there is no problem,
> since the next event is available whenever necessary, and the scheduling
> (at
> least in the FFmpeg version) will tell you when it is.
>
> On the other hand, if your subtitles events are not available on demand,
> either because they are interleaved with the video in a muxed format or
> because they arrive in real time, it does not work.
>
> You need assumptions about the timestamps properties of your streams. For
> example, video players reading index-less streams will assume that
> subtitles
> are not muxed too much after the video, or they will be ignored.
>
> To take that into account for the support of bitmap subtitles in ffmpeg, I
> used heartbeat frames: whenever a frame is decoded and injected on a
> non-subtitle input, on all subtitle inputs connected to the same input
> stream the current (possibly empty) frame is duplicated and injected.
>
> When proper subtitle support will be implemented in lavfi, I suppose a
> similar solution should be adopted. The application will need to let lavfi
> know what streams are interleaved together, probably with a filter with N+n
> inputs and as many outputs. But in that case, the heartbeat frames can be
> really dummy frames, they may need no duplication.
>
> The same trick can be used to inform lavfi about CFR, although it feels
> really hacky: when you have a subtitle frame at pts=5, duplicate it to
> pts=5.99, it should allow processing the video frame at pts=5.
>
> Another solution for CFR would be to add some kind of "min_frame_duration"
> option to the framesync utility.
>
> Hope this helps.
>
> Regards,
>
> --
>   Nicolas George
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] configure: Do not create/install versioned DLLs on OS/2.

2016-04-22 Thread Dmitriy Kuminov

On 2016-04-21 00:05:57 +, Michael Niedermayer said:


On Thu, Apr 21, 2016 at 01:48:22AM +0300, Dmitriy Kuminov wrote:

you all want the same, a perfect solution
iam sure you can reach some consensus about what to do and work
together to do it.
Iam happy to apply whatever patch the OS/2 people agree about.


Ok, expected this answer. That sounds fair and sane.


We can also give direct write access to some OS/2 developer
to simplify OS/2 maintaince when theres agreement/consensus on who
will do the OS/2 - FFmpeg maintaince work


Okay, I hope we will sort that out and let you know then.

--
Kind regards,
Dmitriy Kuminov
CPO of bww bitwise works GmbH


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


Re: [FFmpeg-devel] Line endings in Makefiles

2016-04-22 Thread compn
On Fri, 22 Apr 2016 07:52:56 +0200
Andreas Weis  wrote:

> here) there are no drawbacks arising from the change.

if we have mismatched line endings in makefiles it might screw up
anyone wishing to make patches if their git has changed the line
endings.

i cant remember if this is a problem however, probably not.

generally its ffmpeg rule to not apply hacks for broken build systems
(of which, msys/mingw's outdated libs count as this). 

i am for your patch, but i am not maintainer. ;)

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


Re: [FFmpeg-devel] [PATCH] avcodec/utils: do_decode: Assert that the decoder return value is not larger than the packet size

2016-04-22 Thread wm4
On Fri, 22 Apr 2016 11:59:14 +0200
Michael Niedermayer  wrote:

> On Fri, Apr 22, 2016 at 09:11:52AM +0200, wm4 wrote:
> > On Fri, 22 Apr 2016 05:14:30 +0200
> > Michael Niedermayer  wrote:
> >   
> > > Signed-off-by: Michael Niedermayer 
> > > ---
> > >  libavcodec/utils.c |1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > > index 52e0d92..b35fabc 100644
> > > --- a/libavcodec/utils.c
> > > +++ b/libavcodec/utils.c
> > > @@ -2738,6 +2738,7 @@ static int do_decode(AVCodecContext *avctx, 
> > > AVPacket *pkt)
> > >  avctx->internal->draining_done = 1;
> > >  
> > >  if (ret >= pkt->size) {
> > > +av_assert0(ret == pkt->size);
> > >  av_packet_unref(avctx->internal->buffer_pkt);
> > >  } else {
> > >  int consumed = ret;  
> > 
> > Basically all code using the "old" API expects that the decoder can
> > read beyond the buffer (making use of input padding I suppose). So I
> > think this is expected.  
> 
> iam not aware of any decoder that would return such a overread size
> also to double check this yesterday i tested this with a bunch of
> fuzzed files before posting the patch and failed to find anything that
> triggers the assert
> 
> [...]

I'm talking about code like this:

 ret = FFMIN(ret, pkt->size); /* guard against bogus return values */
 pkt->data += ret;
 pkt->size -= ret;

(currently found in ffprobe)

Checks like this are all over the place.

If you're confident that these checks are unnecessary and that
avcodec_decode_audio4 should never return a larger value than the
packet size, the assert should be added to avcodec_decode_audio4.

Why do you want to add it specifically to do_decode?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Line endings in Makefiles

2016-04-22 Thread Dave Yeo

On 04/22/16 05:45 AM, compn wrote:

On Fri, 22 Apr 2016 07:52:56 +0200
Andreas Weis  wrote:


here) there are no drawbacks arising from the change.


if we have mismatched line endings in makefiles it might screw up
anyone wishing to make patches if their git has changed the line
endings.

i cant remember if this is a problem however, probably not.


Here if stray DOS line endings accidentally find their way into the 
tree, git always commits the correct line endings with a warning.




generally its ffmpeg rule to not apply hacks for broken build systems
(of which, msys/mingw's outdated libs count as this).

i am for your patch, but i am not maintainer. ;)



Who are the build maintainer[s] now? The Maintainer file still lists 
Diego and Mans

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


Re: [FFmpeg-devel] libavfilter API design in a realtime environment

2016-04-22 Thread Nicolas George
Le quartidi 4 floréal, an CCXXIV, Paul B Mahol a écrit :
> This is really, really bad. Frame do should have duration. And audio
> ones do have.

I used to think that, but after more careful thought I no longer do.

Audio frames have a number samples, they can not work without and that gives
us the duration. It makes some of the problems I will indicate go away, but
not all of them.

There are two sides to the problem.

First, cur_frame.pts, cur_frame.duration and next_frame.pts have a
consistency constraint. Consistency constraints are always trouble, they are
an endless source of bugs because there will always be part of code that
update one field without updating the other.

Second, the duration is often not available immediately, and deriving it is
burdensome.

A few more specific examples:

What happens if the duration and timestamps do not match? Some filters will
behave one way, some filters will behave another. Filters that trust the
duration may accumulate rounding errors if the timebase is not chosen
correctly (think matroska timebase 1/1000 versus NTSC frame rate), etc.

Is the duration mandatory? If it is not, then all filters must be able to
work without it, and we are back to square one. If it is, what happens when
it is not available? Who is responsible for computing it?

A lot of formats do not store the duration. And even when they do, it is not
always reliable. Should the application demux another frame just to fill it?

What about the select filter? In order to compute the duration, it would
essentially have to process the next frames until one is selected.

More generally, in order to reduce the latency in a few cases (filters that
use framesync), you would have to increase the latency at a lot more places.

Much simpler to not have a duration. Filters that really need it wait an
extra frame, that is not a problem.

Regards,

-- 
  Nicolas George


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


Re: [FFmpeg-devel] [PATCH v10 2/3][GSOC] avformat/tee: Fix leaks in tee muxer when open_slave fails

2016-04-22 Thread Nicolas George
Le duodi 2 floréal, an CCXXIV, sebechlebsky...@gmail.com a écrit :
> From: Jan Sebechlebsky 
> 
> In open_slave failure can happen before bsfs array is initialized,
> close_slave must check that bsfs is not NULL before accessing
> tee_slave->bsfs[i] element.
> 
> Slave muxer expects write_trailer to be called if it's
> write_header suceeded (so resources allocated in write_header
> are freed). Therefore if failure happens after successfull
> write_header call, we must ensure that write_trailer of
> that particular slave is called.
> 
> Some cleanups are made by Marton Balint.
> 
> Signed-off-by: Jan Sebechlebsky 
> Signed-off-by: Marton Balint 

Looks ok.

Regards,

-- 
  Nicolas George


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


Re: [FFmpeg-devel] [PATCH 12/13] lavc/videotoolboxenc: Support pixel aspect ratio

2016-04-22 Thread Richard Kern

> On Apr 10, 2016, at 12:24 AM, Carl Eugen Hoyos  wrote:
> 
> Rick Kern  gmail.com> writes:
> 
>> +if (status) {
>> +av_log(
>> +   avctx,
>> +   AV_LOG_ERROR,
>> +   "Error setting pixel aspect ratio to %d:%d: %d.\n",
> 
> Why would the function call fail?
> 
> I would expect that the pixel aspect ratio has max 
> values, if yes, you first have to av_reduce the sar.
Some encoders enforce specific pixel aspect ratios. The vt docs don’t mention a 
max value, but I’ll call av_reduce.

> 
>> +   avctx->sample_aspect_ratio.num,
>> +   avctx->sample_aspect_ratio.den,
>> +   status);
>> +
>> +return AVERROR_EXTERNAL;
> 
> In any case, printing the error should be enough imo.
> 
> Carl Eugen
> 
> ___
> 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 13/13] lavc/videotoolboxenc: Set colorimetry values

2016-04-22 Thread Richard Kern

> On Apr 10, 2016, at 12:27 AM, Carl Eugen Hoyos  wrote:
> 
> Rick Kern  gmail.com> writes:
> 
>> +enabled kCVImageBufferColorPrimaries_ITU_R_2020 && 
>> add_cppflags -DHAVE_VT_BT2020_KEYS
> 
> This is not ok, the define should be added to config.h.
> 
>> +#ifndef HAVE_VT_BT2020_KEYS
>> +# define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
>> +# define kCVImageBufferTransferFunction_ITU_R_2020 CFSTR("ITU_R_2020")
>> +# define kCVImageBufferYCbCrMatrix_ITU_R_2020  CFSTR("ITU_R_2020")
>> +#endif
> 
> Is this safer than #ifndef kCVImageBufferYCbCrMatrix_ITU_R_2020?
These aren’t macros in the system header file.

> 
> Carl Eugen
> 
> ___
> 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


[FFmpeg-devel] [PATCH v2 03/12] lavc/videotoolboxenc: Require hardware encoding

2016-04-22 Thread Rick Kern
Software encoding can be allowed by setting allow_sw to 1.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 42 +-
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 7b52073..ec69bb1 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -70,6 +70,10 @@ typedef struct VTEncContext {
 int64_t profile;
 int64_t level;
 
+#if !TARGET_OS_IPHONE
+int64_t allow_sw;
+#endif
+
 bool flushing;
 bool has_b_frames;
 bool warned_color_range;
@@ -637,8 +641,11 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 if (!enc_info) return AVERROR(ENOMEM);
 
 #if !TARGET_OS_IPHONE
-CFDictionarySetValue(enc_info, 
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder, 
kCFBooleanTrue);
-CFDictionarySetValue(enc_info, 
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,  
kCFBooleanTrue);
+if (vtctx->allow_sw != 1) {
+CFDictionarySetValue(enc_info, 
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder, 
kCFBooleanTrue);
+} else {
+CFDictionarySetValue(enc_info, 
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,  
kCFBooleanTrue);
+}
 #endif
 
 if (avctx->pix_fmt != AV_PIX_FMT_VIDEOTOOLBOX) {
@@ -664,30 +671,18 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 &vtctx->session
 );
 
-#if !TARGET_OS_IPHONE
-if (status != 0 || !vtctx->session) {
-CFDictionaryRemoveValue(enc_info, 
kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder);
-
-status = VTCompressionSessionCreate(
-kCFAllocatorDefault,
-avctx->width,
-avctx->height,
-codec_type,
-enc_info,
-NULL,
-kCFAllocatorDefault,
-vtenc_output_callback,
-avctx,
-&vtctx->session
-);
-}
-#endif
-
 if (pixel_buffer_info) CFRelease(pixel_buffer_info);
 CFRelease(enc_info);
 
 if (status || !vtctx->session) {
 av_log(avctx, AV_LOG_ERROR, "Error: cannot create compression session: 
%d\n", status);
+
+#if !TARGET_OS_IPHONE
+if (!vtctx->allow_sw) {
+av_log(avctx, AV_LOG_ERROR, "Try -allow_sw 1. The hardware encoder 
may be busy, or not supported.\n");
+}
+#endif
+
 return AVERROR_EXTERNAL;
 }
 
@@ -1484,6 +1479,11 @@ static const AVOption options[] = {
 { "5.1", "Level 5.1", 0, AV_OPT_TYPE_CONST, { .i64 = 51 }, INT_MIN, 
INT_MAX, VE, "level" },
 { "5.2", "Level 5.2", 0, AV_OPT_TYPE_CONST, { .i64 = 52 }, INT_MIN, 
INT_MAX, VE, "level" },
 
+#if !TARGET_OS_IPHONE
+{ "allow_sw", "Allow software encoding", OFFSET(allow_sw), 
AV_OPT_TYPE_BOOL,
+{ .i64 = -1 }, -1, 1, VE },
+#endif
+
 { NULL },
 };
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 00/12] videotoolbox encoder features and fixes

2016-04-22 Thread Rick Kern
Sorry for the delay. The commit for the keyframes_only property was removed - 
this was already supported with -g 1.

Rick Kern (12):
  lavc/videotoolboxenc: Use shared pixel buffer pool
  lavc/videotoolboxenc: Handle hwaccel format as input
  lavc/videotoolboxenc: Require hardware encoding
  lavc/videotoolboxenc: Add entropy setting
  lavc/videotoolboxenc: Fix AVCodecContext.has_b_frames usage.
  lavc/videotoolboxenc: Fix DTS
  lavc/videotoolboxenc: Handle out-of-memory and fix memory leak
  lavc/videotoolboxenc: Add realtime encoding property
  lavc/videotoolboxenc: add concatentation properties
  lavc/videotoolboxenc: Support for forced I-frames
  lavc/videotoolboxenc: Support pixel aspect ratio
  lavc/videotoolboxenc: Set colorimetry values

 configure|   5 +-
 libavcodec/videotoolboxenc.c | 682 ++-
 2 files changed, 619 insertions(+), 68 deletions(-)

-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 01/12] lavc/videotoolboxenc: Use shared pixel buffer pool

2016-04-22 Thread Rick Kern
This reduces the chance of a memcpy in the media server.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 224 ++-
 1 file changed, 180 insertions(+), 44 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 3177074..b578260 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -29,6 +29,7 @@
 #include "libavutil/atomic.h"
 #include "libavutil/avstring.h"
 #include "libavcodec/avcodec.h"
+#include "libavutil/pixdesc.h"
 #include "internal.h"
 #include 
 
@@ -74,6 +75,15 @@ typedef struct VTEncContext {
 bool warned_color_range;
 } VTEncContext;
 
+/**
+ * NULL-safe release of *refPtr, and sets value to NULL.
+ */
+static void vt_release_num(CFNumberRef* refPtr){
+if(!*refPtr) return;
+CFRelease(*refPtr);
+*refPtr = NULL;
+}
+
 static void set_async_error(VTEncContext *vtctx, int err)
 {
 BufNode *info;
@@ -477,9 +487,123 @@ static bool get_vt_profile_level(AVCodecContext *avctx,
 return true;
 }
 
+static int get_cv_pixel_format(
+   AVCodecContext* avctx,
+   enum AVPixelFormat fmt,
+   enum AVColorRange range,
+   int* av_pixel_format,
+   int* range_guessed)
+{
+if (range_guessed) *range_guessed = 0;
+
+switch (fmt) {
+case AV_PIX_FMT_NV12:
+switch (range) {
+case AVCOL_RANGE_MPEG:
+*av_pixel_format = 
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
+break;
+
+case AVCOL_RANGE_JPEG:
+*av_pixel_format = 
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
+break;
+
+default:
+if (range_guessed) *range_guessed = 1;
+*av_pixel_format = 
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
+}
+break;
+
+case AV_PIX_FMT_YUV420P:
+switch (range) {
+case AVCOL_RANGE_MPEG:
+*av_pixel_format = kCVPixelFormatType_420YpCbCr8Planar;
+break;
+
+case AVCOL_RANGE_JPEG:
+*av_pixel_format = 
kCVPixelFormatType_420YpCbCr8PlanarFullRange;
+break;
+
+default:
+if(range_guessed) *range_guessed = 1;
+*av_pixel_format = kCVPixelFormatType_420YpCbCr8Planar;
+}
+break;
+
+default: return AVERROR(EINVAL);
+}
+
+return 0;
+}
+
+static int create_cv_pixel_buffer_info(AVCodecContext* avctx,
+   CFMutableDictionaryRef* dict)
+{
+CFNumberRef cv_color_format_num = NULL;
+CFNumberRef width_num = NULL;
+CFNumberRef height_num = NULL;
+CFMutableDictionaryRef pixel_buffer_info = NULL;
+int cv_color_format;
+int status = get_cv_pixel_format(avctx,
+ avctx->pix_fmt,
+ avctx->color_range,
+ &cv_color_format,
+ NULL);
+if (status) return status;
+
+pixel_buffer_info = CFDictionaryCreateMutable(
+kCFAllocatorDefault,
+20,
+&kCFCopyStringDictionaryKeyCallBacks,
+&kCFTypeDictionaryValueCallBacks);
+
+if (!pixel_buffer_info) goto pbinfo_nomem;
+
+cv_color_format_num = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberSInt32Type,
+ &cv_color_format);
+if (!cv_color_format_num) goto pbinfo_nomem;
+
+CFDictionarySetValue(pixel_buffer_info,
+ kCVPixelBufferPixelFormatTypeKey,
+ cv_color_format_num);
+vt_release_num(&cv_color_format_num);
+
+width_num = CFNumberCreate(kCFAllocatorDefault,
+   kCFNumberSInt32Type,
+   &avctx->width);
+if (!width_num) return AVERROR(ENOMEM);
+
+CFDictionarySetValue(pixel_buffer_info,
+ kCVPixelBufferWidthKey,
+ width_num);
+vt_release_num(&width_num);
+
+height_num = CFNumberCreate(kCFAllocatorDefault,
+kCFNumberSInt32Type,
+&avctx->height);
+if (!height_num) goto pbinfo_nomem;
+
+CFDictionarySetValue(pixel_buffer_info,
+ kCVPixelBufferHeightKey,
+ height_num);
+vt_release_num(&height_num);
+
+*dict = pixel_buffer_info;
+return 0;
+
+pbinfo_nomem:
+vt_release_num(&cv_color_format_num);
+vt_release_num(&width_num);
+vt_release_num(&height_num);
+if (pixel_buffer_info) CFRelease(pixel_b

[FFmpeg-devel] [PATCH v2 02/12] lavc/videotoolboxenc: Handle hwaccel format as input

2016-04-22 Thread Rick Kern
Handle AV_PIX_FMT_VIDEOTOOLBOX.
This results in better energy usage and faster encoding, especially on iOS.
When the buffer comes from the media server, no memcpy's are needed.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index b578260..7b52073 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -641,10 +641,14 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 CFDictionarySetValue(enc_info, 
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,  
kCFBooleanTrue);
 #endif
 
-status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info);
-if (status) {
-CFRelease(enc_info);
-return status;
+if (avctx->pix_fmt != AV_PIX_FMT_VIDEOTOOLBOX) {
+status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info);
+if (status) {
+CFRelease(enc_info);
+return status;
+}
+} else {
+pixel_buffer_info = NULL;
 }
 
 status = VTCompressionSessionCreate(
@@ -679,7 +683,7 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 }
 #endif
 
-CFRelease(pixel_buffer_info);
+if (pixel_buffer_info) CFRelease(pixel_buffer_info);
 CFRelease(enc_info);
 
 if (status || !vtctx->session) {
@@ -1247,6 +1251,17 @@ static int create_cv_pixel_buffer(AVCodecContext   
*avctx,
 CVPixelBufferPoolRef pix_buf_pool;
 VTEncContext* vtctx = avctx->priv_data;
 
+
+if (avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX) {
+av_assert0(frame->format == AV_PIX_FMT_VIDEOTOOLBOX);
+
+*cv_img = (CVPixelBufferRef)frame->data[3];
+av_assert0(*cv_img);
+
+CFRetain(*cv_img);
+return 0;
+}
+
 memset(widths,  0, sizeof(widths));
 memset(heights, 0, sizeof(heights));
 memset(strides, 0, sizeof(strides));
@@ -1443,6 +1458,7 @@ static av_cold int vtenc_close(AVCodecContext *avctx)
 }
 
 static const enum AVPixelFormat pix_fmts[] = {
+AV_PIX_FMT_VIDEOTOOLBOX,
 AV_PIX_FMT_NV12,
 AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_NONE
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 04/12] lavc/videotoolboxenc: Add entropy setting

2016-04-22 Thread Rick Kern
Add an entropy setting to choose between CAVLC and CABAC.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index ec69bb1..07577b6 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -41,6 +41,12 @@ typedef enum VT_H264Profile {
 H264_PROF_COUNT
 } VT_H264Profile;
 
+typedef enum VTH264Entropy{
+VT_ENTROPY_NOT_SET,
+VT_CAVLC,
+VT_CABAC
+} VTH264Entropy;
+
 static const uint8_t start_code[] = { 0, 0, 0, 1 };
 
 typedef struct BufNode {
@@ -69,6 +75,7 @@ typedef struct VTEncContext {
 
 int64_t profile;
 int64_t level;
+int64_t entropy;
 
 #if !TARGET_OS_IPHONE
 int64_t allow_sw;
@@ -627,6 +634,11 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 vtctx->has_b_frames = false;
 }
 
+if (vtctx->entropy == VT_CABAC && vtctx->profile == H264_PROF_BASELINE) {
+av_log(avctx, AV_LOG_WARNING, "CABAC entropy requires 'main' or 'high' 
profile, but baseline was requested. Encode will not use CABAC entropy.\n");
+vtctx->entropy = VT_ENTROPY_NOT_SET;
+}
+
 if (!get_vt_profile_level(avctx, &profile_level)) return AVERROR(EINVAL);
 
 vtctx->session = NULL;
@@ -736,6 +748,21 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 }
 }
 
+if (vtctx->entropy != VT_ENTROPY_NOT_SET) {
+CFStringRef entropy = vtctx->entropy == VT_CABAC ?
+kVTH264EntropyMode_CABAC:
+kVTH264EntropyMode_CAVLC;
+
+status = VTSessionSetProperty(vtctx->session,
+  
kVTCompressionPropertyKey_H264EntropyMode,
+  entropy);
+
+if (status) {
+av_log(avctx, AV_LOG_ERROR, "Error setting entropy property: 
%d\n", status);
+return AVERROR_EXTERNAL;
+}
+}
+
 status = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
 if (status) {
 av_log(avctx, AV_LOG_ERROR, "Error: cannot prepare encoder: %d\n", 
status);
@@ -1484,6 +1511,10 @@ static const AVOption options[] = {
 { .i64 = -1 }, -1, 1, VE },
 #endif
 
+{ "entropy", "Entropy coding", OFFSET(entropy), AV_OPT_TYPE_INT, { .i64 = 
VT_ENTROPY_NOT_SET }, VT_ENTROPY_NOT_SET, VT_CABAC, VE, "entropy" },
+{ "cavlc", "CAVLC entropy coding", 0, AV_OPT_TYPE_CONST, { .i64 = VT_CAVLC 
}, INT_MIN, INT_MAX, VE, "entropy" },
+{ "cabac", "CABAC entropy coding", 0, AV_OPT_TYPE_CONST, { .i64 = VT_CABAC 
}, INT_MIN, INT_MAX, VE, "entropy" },
+
 { NULL },
 };
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 08/12] lavc/videotoolboxenc: Add realtime encoding property

2016-04-22 Thread Rick Kern
Hint to the encoder that encoding should be done in real-time, even at the
expense of quality.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 073b87a..a30a3ca 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -76,6 +76,7 @@ typedef struct VTEncContext {
 int64_t profile;
 int64_t level;
 int64_t entropy;
+int64_t realtime;
 
 #if !TARGET_OS_IPHONE
 int64_t allow_sw;
@@ -767,6 +768,16 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 }
 }
 
+if (vtctx->realtime) {
+status = VTSessionSetProperty(vtctx->session,
+  kVTCompressionPropertyKey_RealTime,
+  kCFBooleanTrue);
+
+if (status) {
+av_log(avctx, AV_LOG_ERROR, "Error setting realtime property: 
%d\n", status);
+}
+}
+
 status = VTCompressionSessionPrepareToEncodeFrames(vtctx->session);
 if (status) {
 av_log(avctx, AV_LOG_ERROR, "Error: cannot prepare encoder: %d\n", 
status);
@@ -1540,6 +1551,9 @@ static const AVOption options[] = {
 { "cavlc", "CAVLC entropy coding", 0, AV_OPT_TYPE_CONST, { .i64 = VT_CAVLC 
}, INT_MIN, INT_MAX, VE, "entropy" },
 { "cabac", "CABAC entropy coding", 0, AV_OPT_TYPE_CONST, { .i64 = VT_CABAC 
}, INT_MIN, INT_MAX, VE, "entropy" },
 
+{ "realtime", "Hint that encoding should happen in real-time if not faster 
(e.g. capturing from camera).",
+OFFSET(realtime), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
+
 { NULL },
 };
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 09/12] lavc/videotoolboxenc: add concatentation properties

2016-04-22 Thread Rick Kern
Add frames_before and frames_after as hints that there will be frames before
or after the frames produced in this session. This may help with
concatenation issues like bit rate spikes.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index a30a3ca..c630825 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -77,6 +77,8 @@ typedef struct VTEncContext {
 int64_t level;
 int64_t entropy;
 int64_t realtime;
+int64_t frames_before;
+int64_t frames_after;
 
 #if !TARGET_OS_IPHONE
 int64_t allow_sw;
@@ -742,6 +744,30 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 }
 }
 
+if (vtctx->frames_before == 1) {
+status = VTSessionSetProperty(vtctx->session,
+  
kVTCompressionPropertyKey_MoreFramesBeforeStart,
+  kCFBooleanTrue);
+
+if (status == kVTPropertyNotSupportedErr) {
+av_log(avctx, AV_LOG_WARNING, "frames_before property is not 
supported on this device. Ignoring.\n");
+} else if (status) {
+av_log(avctx, AV_LOG_ERROR, "Error setting frames_before property: 
%d\n", status);
+}
+}
+
+if (vtctx->frames_after == 1) {
+status = VTSessionSetProperty(vtctx->session,
+  
kVTCompressionPropertyKey_MoreFramesAfterEnd,
+  kCFBooleanTrue);
+
+if (status == kVTPropertyNotSupportedErr) {
+av_log(avctx, AV_LOG_WARNING, "frames_after property is not 
supported on this device. Ignoring.\n");
+} else if (status) {
+av_log(avctx, AV_LOG_ERROR, "Error setting frames_after property: 
%d\n", status);
+}
+}
+
 if (!vtctx->has_b_frames) {
 status = VTSessionSetProperty(vtctx->session,
   
kVTCompressionPropertyKey_AllowFrameReordering,
@@ -1553,6 +1579,10 @@ static const AVOption options[] = {
 
 { "realtime", "Hint that encoding should happen in real-time if not faster 
(e.g. capturing from camera).",
 OFFSET(realtime), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
+{ "frames_before", "Other frames will come before the frames in this 
session. This helps smooth concatenation issues.",
+OFFSET(frames_before), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
+{ "frames_after", "Other frames will come after the frames in this 
session. This helps smooth concatenation issues.",
+OFFSET(frames_after), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
 
 { NULL },
 };
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 05/12] lavc/videotoolboxenc: Fix AVCodecContext.has_b_frames usage.

2016-04-22 Thread Rick Kern
Now set by the encoder, not used as an input parameter.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 07577b6..6a9a2fe 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -620,6 +620,7 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 CFStringRefprofile_level;
 SInt32 bit_rate = avctx->bit_rate;
 CFNumberRefbit_rate_num;
+CFBooleanRef   has_b_frames_cfbool;
 intstatus;
 
 codec_type = get_cm_codec_type(avctx->codec_id);
@@ -628,7 +629,7 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-vtctx->has_b_frames = avctx->has_b_frames || avctx->max_b_frames > 0;
+vtctx->has_b_frames = avctx->max_b_frames > 0;
 if(vtctx->has_b_frames && vtctx->profile == H264_PROF_BASELINE){
 av_log(avctx, AV_LOG_WARNING, "Cannot use B-frames with baseline 
profile. Output will not contain B-frames.\n");
 vtctx->has_b_frames = false;
@@ -773,6 +774,18 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 pthread_cond_init(&vtctx->cv_sample_sent, NULL);
 vtctx->dts_delta = vtctx->has_b_frames ? -1 : 0;
 
+status = VTSessionCopyProperty(vtctx->session,
+   
kVTCompressionPropertyKey_AllowFrameReordering,
+   kCFAllocatorDefault,
+   &has_b_frames_cfbool);
+
+if (!status) {
+//Some devices don't output B-frames for main profile, even if 
requested.
+vtctx->has_b_frames = CFBooleanGetValue(has_b_frames_cfbool);
+CFRelease(has_b_frames_cfbool);
+}
+avctx->has_b_frames = vtctx->has_b_frames;
+
 return 0;
 }
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 10/12] lavc/videotoolboxenc: Support for forced I-frames

2016-04-22 Thread Rick Kern
Setting AVFrame.pic_type to AV_PICTURE_TYPE_I will force an I-frame.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index c630825..5935d09 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1434,27 +1434,51 @@ static int create_cv_pixel_buffer(AVCodecContext   
*avctx,
 return 0;
 }
 
+static int create_encoder_dict_h264(const AVFrame *frame,
+CFDictionaryRef* dict_out)
+{
+CFDictionaryRef dict = NULL;
+if (frame->pict_type == AV_PICTURE_TYPE_I) {
+const void *keys[] = { kVTEncodeFrameOptionKey_ForceKeyFrame };
+const void *vals[] = { kCFBooleanTrue };
+
+dict = CFDictionaryCreate(NULL, keys, vals, 1, NULL, NULL);
+if(!dict) return AVERROR(ENOMEM);
+}
+
+*dict_out = dict;
+return 0;
+}
+
 static int vtenc_send_frame(AVCodecContext *avctx,
 VTEncContext   *vtctx,
 const AVFrame  *frame)
 {
 CMTime time;
+CFDictionaryRef frame_dict;
 CVPixelBufferRef cv_img = NULL;
 int status = create_cv_pixel_buffer(avctx, frame, &cv_img);
 
 if (status) return status;
 
+status = create_encoder_dict_h264(frame, &frame_dict);
+if (status) {
+CFRelease(cv_img);
+return status;
+}
+
 time = CMTimeMake(frame->pts * avctx->time_base.num, avctx->time_base.den);
 status = VTCompressionSessionEncodeFrame(
 vtctx->session,
 cv_img,
 time,
 kCMTimeInvalid,
-NULL,
+frame_dict,
 NULL,
 NULL
 );
 
+if (frame_dict) CFRelease(frame_dict);
 CFRelease(cv_img);
 
 if (status) {
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 07/12] lavc/videotoolboxenc: Handle out-of-memory and fix memory leak

2016-04-22 Thread Rick Kern
Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 5594e69..073b87a 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -728,9 +728,12 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 CFNumberRef interval = CFNumberCreate(kCFAllocatorDefault,
   kCFNumberIntType,
   &avctx->gop_size);
+if (!interval) return AVERROR(ENOMEM);
+
 status = VTSessionSetProperty(vtctx->session,
   
kVTCompressionPropertyKey_MaxKeyFrameInterval,
   interval);
+CFRelease(interval);
 
 if (status) {
 av_log(avctx, AV_LOG_ERROR, "Error setting 'max key-frame 
interval' property: %d\n", status);
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 11/12] lavc/videotoolboxenc: Support pixel aspect ratio

2016-04-22 Thread Rick Kern
Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 63 
 1 file changed, 63 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 5935d09..768405d 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -768,6 +768,69 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
 }
 }
 
+if (avctx->sample_aspect_ratio.num != 0) {
+CFNumberRef num;
+CFNumberRef den;
+CFMutableDictionaryRef par;
+AVRational *avpar = &avctx->sample_aspect_ratio;
+
+av_reduce(&avpar->num, &avpar->den,
+   avpar->num,  avpar->den,
+  0x);
+
+num = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberIntType,
+ &avpar->num);
+
+den = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberIntType,
+ &avpar->den);
+
+
+
+par = CFDictionaryCreateMutable(kCFAllocatorDefault,
+2,
+&kCFCopyStringDictionaryKeyCallBacks,
+&kCFTypeDictionaryValueCallBacks);
+
+if (!par || !num || !den) {
+if (par) CFRelease(par);
+if (num) CFRelease(num);
+if (den) CFRelease(den);
+
+return AVERROR(ENOMEM);
+}
+
+CFDictionarySetValue(
+par,
+kCMFormatDescriptionKey_PixelAspectRatioHorizontalSpacing,
+num);
+
+CFDictionarySetValue(
+par,
+kCMFormatDescriptionKey_PixelAspectRatioVerticalSpacing,
+den);
+
+status = VTSessionSetProperty(vtctx->session,
+  
kVTCompressionPropertyKey_PixelAspectRatio,
+  par);
+
+CFRelease(par);
+CFRelease(num);
+CFRelease(den);
+
+if (status) {
+av_log(avctx,
+   AV_LOG_ERROR,
+   "Error setting pixel aspect ratio to %d:%d: %d.\n",
+   avctx->sample_aspect_ratio.num,
+   avctx->sample_aspect_ratio.den,
+   status);
+
+return AVERROR_EXTERNAL;
+}
+}
+
 if (!vtctx->has_b_frames) {
 status = VTSessionSetProperty(vtctx->session,
   
kVTCompressionPropertyKey_AllowFrameReordering,
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v2 12/12] lavc/videotoolboxenc: Set colorimetry values

2016-04-22 Thread Rick Kern
Signed-off-by: Rick Kern 
---
 configure|   5 +-
 libavcodec/videotoolboxenc.c | 209 +++
 2 files changed, 213 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 97f374b..c484a10 100755
--- a/configure
+++ b/configure
@@ -2078,6 +2078,7 @@ CONFIG_EXTRA="
 vp3dsp
 vp56dsp
 vp8dsp
+vt_bt2020
 wma_freqs
 wmv2dsp
 "
@@ -2740,6 +2741,7 @@ videotoolbox_deps="VideoToolbox_VideoToolbox_h"
 videotoolbox_extralibs="-framework CoreFoundation -framework VideoToolbox 
-framework CoreMedia -framework CoreVideo"
 videotoolbox_encoder_deps="videotoolbox 
VTCompressionSessionPrepareToEncodeFrames"
 videotoolbox_encoder_suggest="vda_framework"
+vt_bt2020_deps="kCVImageBufferColorPrimaries_ITU_R_2020"
 
 # demuxers / muxers
 ac3_demuxer_select="ac3_parser"
@@ -3128,7 +3130,7 @@ enable audiotoolbox
 enable d3d11va dxva2 vaapi vda vdpau videotoolbox_hwaccel xvmc
 enable xlib
 
-enable vda_framework videotoolbox videotoolbox_encoder
+enable vda_framework videotoolbox videotoolbox_encoder vt_bt2020
 
 # build settings
 SHFLAGS='-shared -Wl,-soname,$$(@F)'
@@ -5441,6 +5443,7 @@ check_header vdpau/vdpau_x11.h
 check_header VideoDecodeAcceleration/VDADecoder.h
 check_header VideoToolbox/VideoToolbox.h
 check_func_headers VideoToolbox/VTCompressionSession.h 
VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox
+check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferColorPrimaries_ITU_R_2020 -framework CoreVideo
 check_header windows.h
 check_header X11/extensions/XvMClib.h
 check_header asm/types.h
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 768405d..1201004 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -33,6 +33,12 @@
 #include "internal.h"
 #include 
 
+#if !CONFIG_VT_BT2020
+# define kCVImageBufferColorPrimaries_ITU_R_2020   CFSTR("ITU_R_2020")
+# define kCVImageBufferTransferFunction_ITU_R_2020 CFSTR("ITU_R_2020")
+# define kCVImageBufferYCbCrMatrix_ITU_R_2020  CFSTR("ITU_R_2020")
+#endif
+
 typedef enum VT_H264Profile {
 H264_PROF_AUTO,
 H264_PROF_BASELINE,
@@ -58,6 +64,9 @@ typedef struct BufNode {
 typedef struct VTEncContext {
 AVClass *class;
 VTCompressionSessionRef session;
+CFStringRef ycbcr_matrix;
+CFStringRef color_primaries;
+CFStringRef transfer_function;
 
 pthread_mutex_t lock;
 pthread_cond_t  cv_sample_sent;
@@ -549,6 +558,28 @@ static int get_cv_pixel_format(
 return 0;
 }
 
+static void add_color_attr(AVCodecContext *avctx, CFMutableDictionaryRef dict) 
{
+VTEncContext *vtctx = avctx->priv_data;
+
+if (vtctx->color_primaries) {
+CFDictionarySetValue(dict,
+ kCVImageBufferColorPrimariesKey,
+ vtctx->color_primaries);
+}
+
+if (vtctx->transfer_function) {
+CFDictionarySetValue(dict,
+ kCVImageBufferTransferFunctionKey,
+ vtctx->transfer_function);
+}
+
+if (vtctx->ycbcr_matrix) {
+CFDictionarySetValue(dict,
+ kCVImageBufferYCbCrMatrixKey,
+ vtctx->ycbcr_matrix);
+}
+}
+
 static int create_cv_pixel_buffer_info(AVCodecContext* avctx,
CFMutableDictionaryRef* dict)
 {
@@ -602,6 +633,8 @@ static int create_cv_pixel_buffer_info(AVCodecContext* 
avctx,
  height_num);
 vt_release_num(&height_num);
 
+add_color_attr(avctx, pixel_buffer_info);
+
 *dict = pixel_buffer_info;
 return 0;
 
@@ -614,6 +647,110 @@ pbinfo_nomem:
 return AVERROR(ENOMEM);
 }
 
+static int get_cv_color_primaries(AVCodecContext *avctx,
+  CFStringRef *primaries)
+{
+enum AVColorPrimaries pri = avctx->color_primaries;
+switch (pri) {
+case AVCOL_PRI_UNSPECIFIED:
+*primaries = NULL;
+break;
+
+case AVCOL_PRI_BT709:
+*primaries = kCVImageBufferColorPrimaries_ITU_R_709_2;
+break;
+
+case AVCOL_PRI_BT2020:
+*primaries = kCVImageBufferColorPrimaries_ITU_R_2020;
+break;
+
+default:
+av_log(avctx, AV_LOG_ERROR, "Color primaries %s is not 
supported.\n", av_color_primaries_name(pri));
+*primaries = NULL;
+return -1;
+}
+
+return 0;
+}
+
+static int get_cv_transfer_function(AVCodecContext *avctx,
+CFStringRef *transfer_fnc,
+CFNumberRef *gamma_level)
+{
+enum AVColorTransferCharacteristic trc = avctx->color_trc;
+Float32 gamma;
+*gamma_level = NULL;
+
+switch (trc) {
+case AVCOL_TRC_UNSPECIFIED:
+*transfer_fnc = NULL;
+break;
+
+case AVCOL_TRC_BT709:
+*transfer_fnc = kCVImageBufferTransferFunction_ITU_R_709_2;

[FFmpeg-devel] [PATCH v2 06/12] lavc/videotoolboxenc: Fix DTS

2016-04-22 Thread Rick Kern
Some devices output an invalid DTS when B-frames aren't used. Using PTS for
the DTS in this case.

Signed-off-by: Rick Kern 
---
 libavcodec/videotoolboxenc.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 6a9a2fe..5594e69 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1056,6 +1056,15 @@ static int vtenc_cm_to_avpacket(
 pts = CMSampleBufferGetPresentationTimeStamp(sample_buffer);
 dts = CMSampleBufferGetDecodeTimeStamp  (sample_buffer);
 
+if (CMTIME_IS_INVALID(dts)) {
+if (!vtctx->has_b_frames) {
+dts = pts;
+} else {
+av_log(avctx, AV_LOG_ERROR, "DTS is invalid.\n");
+return AVERROR_EXTERNAL;
+}
+}
+
 dts_delta = vtctx->dts_delta >= 0 ? vtctx->dts_delta : 0;
 time_base_num = avctx->time_base.num;
 pkt->pts = pts.value / time_base_num;
-- 
2.7.4

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


Re: [FFmpeg-devel] [PATCH 3/3] configure: Remove -Wredundant-decls on OS/2 to suppress noise.

2016-04-22 Thread Dave Yeo

On 04/20/16 11:46 PM, Reimar Döffinger wrote:

On 21.04.2016, at 06:02, Dave Yeo  wrote:


On 04/20/16 07:40 PM, Michael Niedermayer wrote:

On Thu, Apr 14, 2016 at 07:31:48PM -0700, Dave Yeo wrote:

 From a417fdf752bd7c704ed5ba0c94c5cea96e1a91ff Mon Sep 17 00:00:00 2001
From: Dmitriy Kuminov 
Date: Thu, 14 Apr 2016 01:53:46 +0400
Subject: [PATCH 3/3] configure: Remove -Wredundant-decls on OS/2 to suppress
  noise.

This warning causes too much noise in libc 0.6.6- headers due to
duplicate function decls here and there.

Signed-off-by: Dave Yeo 
---
  configure | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

[...]


maybe iam missing someting but
gcc doesnt/shouldnt report warnings for "system headers" AFAIK

[...]


It's strange. If I build under /usr/local/src with the standard environment 
(just tested with trunk), the warnings don't happen.
When I built 3.0.1 in its own directory with the environment set up to find the 
libraries I'm linking against, eg $C_INCLUDE_PATH, $LIBRARY_PATH etc defined, I 
get warnings such as


Have something that results in adding -I/usr/include to the compile options or 
to C_INCLUDE_PATH? Probably your compiler is misconfigured to not consider that 
a system include path.
Adding -isystem /usr/include should fix it.


Actually it didn't though according to the documentation, it looks like 
it should have. Even tried -isysroot which broke compilation.

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


[FFmpeg-devel] [PATCH] make debug output for bitrate more meaningful

2016-04-22 Thread Gerion Entrup
Currently on audio tracks:
Applying option b:a (video bitrate (please use -b:v)) with argument 240k.

but b:a is the recommendation:
Applying option ab (audio bitrate (please use -b:a)) with argument 240k.

Feel free to change the new string.

Gerion>From ddc4a7af0b355a03775ea76fa192004028cead27 Mon Sep 17 00:00:00 2001
From: Gerion Entrup 
Date: Fri, 22 Apr 2016 18:37:41 +0200
Subject: [PATCH] make debug output for bitrate more meaningful

Currently the b:v hint appears also on audiotracks.
---
 ffmpeg_opt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 00d91c8..7700f8d 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -3341,7 +3341,7 @@ const OptionDef options[] = {
 { "ab",   OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT,{ .func_arg = opt_bitrate },
 "audio bitrate (please use -b:a)", "bitrate" },
 { "b",OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT,{ .func_arg = opt_bitrate },
-"video bitrate (please use -b:v)", "bitrate" },
+"set the bitrate", "bitrate" },
 { "hwaccel",  OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
   OPT_SPEC | OPT_INPUT,  { .off = OFFSET(hwaccels) },
 "use HW accelerated decoding", "hwaccel name" },
-- 
2.7.3

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


Re: [FFmpeg-devel] [PATCH v10 2/3][GSOC] avformat/tee: Fix leaks in tee muxer when open_slave fails

2016-04-22 Thread Marton Balint


On Fri, 22 Apr 2016, Nicolas George wrote:


Le duodi 2 floréal, an CCXXIV, sebechlebsky...@gmail.com a écrit :

From: Jan Sebechlebsky 

In open_slave failure can happen before bsfs array is initialized,
close_slave must check that bsfs is not NULL before accessing
tee_slave->bsfs[i] element.

Slave muxer expects write_trailer to be called if it's
write_header suceeded (so resources allocated in write_header
are freed). Therefore if failure happens after successfull
write_header call, we must ensure that write_trailer of
that particular slave is called.

Some cleanups are made by Marton Balint.

Signed-off-by: Jan Sebechlebsky 
Signed-off-by: Marton Balint 


Looks ok.



Thanks applied.

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


Re: [FFmpeg-devel] [PATCH v11 3/3][GSOC] avformat/tee: Handling slave failure in tee muxer

2016-04-22 Thread Marton Balint


On Thu, 21 Apr 2016, sebechlebsky...@gmail.com wrote:


From: Jan Sebechlebsky 

Adds per slave option 'onfail' to the tee muxer allowing an output to
fail,so other slave outputs can continue.

Signed-off-by: Jan Sebechlebsky 
---

Changes from last version:
  -> Use av_err2str in tee_process_slave_failure instead of combination
 of av_strerror and strerror

doc/muxers.texi   | 14 +
libavformat/tee.c | 91 ---
2 files changed, 94 insertions(+), 11 deletions(-)



Thanks, applied.

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


[FFmpeg-devel] [PATCH] pgssubdec: fix subpicture output colorspace and range

2016-04-22 Thread Jan Ekström
Functionality used before didn't widen the values from limited to
full range. Additionally, now the decoder uses BT.709 where it
should be used according to the video resolution.

Default for not yet set colorimetry is BT.709 due to most observed
HDMV content being HD.

BT.709 coefficients were gathered from the first two parts of BT.709
to BT.2020 conversion guide in ARIB STD-B62 (Pt. 1, Chapter 6.2.2).

Based on a patch by Carl Eugen Hoyos.
---
 libavcodec/pgssubdec.c | 20 ++--
 libavutil/colorspace.h | 10 ++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 07a2a78..4145f1c 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -96,6 +96,7 @@ typedef struct PGSSubContext {
 PGSSubPalettes palettes;
 PGSSubObjects  objects;
 int forced_subs_only;
+int hdtv;
 } PGSSubContext;
 
 static void flush_cache(AVCodecContext *avctx)
@@ -136,6 +137,9 @@ static PGSSubPalette * find_palette(int id, PGSSubPalettes 
*palettes)
 
 static av_cold int init_decoder(AVCodecContext *avctx)
 {
+PGSSubContext *ctx = avctx->priv_data;
+ctx->hdtv  = -1;
+
 avctx->pix_fmt = AV_PIX_FMT_PAL8;
 
 return 0;
@@ -354,8 +358,14 @@ static int parse_palette_segment(AVCodecContext *avctx,
 cb= bytestream_get_byte(&buf);
 alpha = bytestream_get_byte(&buf);
 
-YUV_TO_RGB1(cb, cr);
-YUV_TO_RGB2(r, g, b, y);
+/* Default to HDTV (-1 or 1) */
+if (ctx->hdtv) {
+YUV_TO_RGB1_CCIR_BT709(cb, cr);
+} else {
+YUV_TO_RGB1_CCIR(cb, cr);
+}
+
+YUV_TO_RGB2_CCIR(r, g, b, y);
 
 ff_dlog(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, 
alpha);
 
@@ -388,6 +398,12 @@ static int parse_presentation_segment(AVCodecContext 
*avctx,
 int w = bytestream_get_be16(&buf);
 int h = bytestream_get_be16(&buf);
 
+// Set colorimetry according to resolution
+if (h > 576)
+ctx->hdtv = 1;
+else
+ctx->hdtv = 0;
+
 ctx->presentation.pts = pts;
 
 ff_dlog(avctx, "Video Dimensions %dx%d\n",
diff --git a/libavutil/colorspace.h b/libavutil/colorspace.h
index 826ffd5..7d3f711 100644
--- a/libavutil/colorspace.h
+++ b/libavutil/colorspace.h
@@ -41,6 +41,16 @@
 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
 }
 
+#define YUV_TO_RGB1_CCIR_BT709(cb1, cr1)\
+{\
+cb = (cb1) - 128;\
+cr = (cr1) - 128;\
+r_add = FIX(1.5747*255.0/224.0) * cr + ONE_HALF;\
+g_add = - FIX(0.1873*255.0/224.0) * cb - FIX(0.4682*255.0/224.0) * cr + \
+ONE_HALF;\
+b_add = FIX(1.8556*255.0/224.0) * cb + ONE_HALF;\
+}
+
 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\
 {\
 y = ((y1) - 16) * FIX(255.0/219.0);\
-- 
2.5.5

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


[FFmpeg-devel] CONFIG_W64_DEMUXER and dead-code elimination

2016-04-22 Thread Bruce Dawson
I've noticed that when CONFIG_W64_DEMUXER is defined to zero that ffmpeg
compiles in a reference to ff_w64_guid_data but doesn't not link w64.o
(which defines that symbol).

This normally works because most optimizers discard the reference
to ff_w64_guid_data early enough to not cause a linker failure. However
this assumption means that /Od (debug, unoptimized) and /GL (Link Time Code
Generation - super optimized) builds with VC++ don't work.

The patch below is a simple code change to fix this specific issue:

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 7176cd6..8301748 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -654,9 +654,11 @@ smv_out:
 if (wav->ignore_length)
 left = INT_MAX;
 if (left <= 0) {
+#if CONFIG_W64_DEMUXER
 if (CONFIG_W64_DEMUXER && wav->w64)
 left = find_guid(s->pb, ff_w64_guid_data) - 24;
 else
+#endif
 left = find_tag(wav, s->pb, MKTAG('d', 'a', 't', 'a'));
 if (left < 0) {
 wav->audio_eof = 1;



An alternate fix would be to update Makefile to always include w64.o when
wavdec.o is linked, like this:

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 51260f4..d290c9a 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -479,7 +479,7 @@ OBJS-$(CONFIG_VPLAYER_DEMUXER)   +=
vplayerdec.o subtitles.o
 OBJS-$(CONFIG_VQF_DEMUXER)   += vqf.o
 OBJS-$(CONFIG_W64_DEMUXER)   += wavdec.o w64.o pcm.o
 OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
-OBJS-$(CONFIG_WAV_DEMUXER)   += wavdec.o pcm.o
+OBJS-$(CONFIG_WAV_DEMUXER)   += wavdec.o w64.o pcm.o
 OBJS-$(CONFIG_WAV_MUXER) += wavenc.o
 OBJS-$(CONFIG_WC3_DEMUXER)   += wc3movie.o
 OBJS-$(CONFIG_WEBM_MUXER)+= matroskaenc.o matroska.o \

Any thoughts/preferences on this particular fix? I might be interested in
cleaning up all instances of this in order to allow usage of /Od and /GL in
Chromium builds of ffmpeg but I want to start small.

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


Re: [FFmpeg-devel] CONFIG_W64_DEMUXER and dead-code elimination

2016-04-22 Thread Hendrik Leppkes
On Sat, Apr 23, 2016 at 1:02 AM, Bruce Dawson
 wrote:
> I've noticed that when CONFIG_W64_DEMUXER is defined to zero that ffmpeg
> compiles in a reference to ff_w64_guid_data but doesn't not link w64.o
> (which defines that symbol).
>
> This normally works because most optimizers discard the reference
> to ff_w64_guid_data early enough to not cause a linker failure. However
> this assumption means that /Od (debug, unoptimized) and /GL (Link Time Code
> Generation - super optimized) builds with VC++ don't work.
>

We require dead code elimination to be available in all build modes,
therefor such build settings that do not have it are not supported.
This is not the only place that uses this, and its a design decision
to rely on it, therefor we won't be accepting patches to change that
at this time, sorry.

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


Re: [FFmpeg-devel] Libavcodec/exr : add support for tile

2016-04-22 Thread James Almer
On 4/4/2016 3:40 PM, Paul B Mahol wrote:
> On 4/4/16, Martin Vignali  wrote:
>> 2016-04-03 17:38 GMT+02:00 Paul B Mahol :
>>
>>> On 4/3/16, Martin Vignali  wrote:
 2016-04-03 17:12 GMT+02:00 Paul B Mahol :

> On 4/3/16, Martin Vignali  wrote:
>> Hello,
>>
>> In attach a patch in order to add support for exr Tile (One Level)
>>
>> Some samples can be found here : https://we.tl/IC4XTrEJf4
>> Theses samples can also be add to ./fate-suite/exr/
>> (i will make a fate test soon).
>>
>> Details of the sample files :
>> rgb_tile_half_raw_12x8.exr : uncompress half float file, in tile
>> (only
> one
>> tile in the file)
>> rgb_tile_float_raw_12x8.exr : uncompress float file, in tile (only
>> one
> tile
>> in the file)
>> rgb_tile_float_raw_150x130.exr : uncompress float file, in tile
>> (multiple
>> tile in the file)
>>
>> In this patch, compression in tile is not enabled. (i will make new
> patchs
>> for that after making more tests)
>>
>> I tried to keep the most code common with the scanline mode (reason
>>> why,
>> scanline code part have had some modifications).
>> Tile data are reorganized, to be more like scanline uncompress data.
>>
>> Pass fate-exr tests.
>>
>> More information about tile in exr can be found here :
>> http://www.openexr.com/TechnicalIntroduction.pdf
>>
>> Comments welcome.
>>
>> Martin
>> Jokyo Images
>>
>
> Pushed. Note that tile with PIZ compression crashes
>>>
>>
>> In tile :
>> RLE, ZIP1, ZIP16, PXR24 will work fine without modification, because they
>> don't use s->xdelta (the datawindow width)
>>
>> PIZ, B44, B44A, use s->xdelta, so now, they will have some trouble for
>> datawindow bigger than tile size in X.
>>
>> I will make a patch soon, for this.
>>
>> Can you send me your PIZ sample who make ffmpeg crash to check  (with
>> wetransfer or something similar) ?
> 
> Its standard sample available in openexr-images-1.7.0/Tiles/GoldenGate.exr
> 
> available from OpenEXR site.
> 

This patch (commit 25a01c52b889d64e77fb3f8f7e519d183d7635b8) broke decoding 
using
slice threading and > 1 threads.

See http://fate.ffmpeg.org/history.cgi?slot=x86_64-archlinux-gcc-threads-misc
Simply run for example "make fate-exr-slice-zip16 THREADS=auto 
THREAD_TYPE=slice",
but any of the tests listed there as failing will do.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel