Re: [FFmpeg-devel] [PATCH] swscale/ppc: Move VSX-using code to its own file

2018-11-29 Thread Lauri Kasanen
On Mon, 26 Nov 2018 14:24:15 +0200
Lauri Kasanen  wrote:

> Passes fate on LE (with "lavc/jrevdct: Avoid an aliasing violation" applied). 
> Can anyone test BE?

Ping.

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


Re: [FFmpeg-devel] [PATCH v2] lavf/dashenc: Write media trailers when DASH trailer is written.

2018-11-29 Thread Jeyapal, Karthick

On 11/29/18 11:58 PM, Andrey Semashev wrote:
> This commit ensures that all (potentially, long) filesystem activity is
> performed when the user calls av_write_trailer on the DASH libavformat
> context, not when freeing the context. Also, this defers media segment
> deletion until after the media trailers are written.
> ---
>  libavformat/dashenc.c | 82 ++-
>  1 file changed, 58 insertions(+), 24 deletions(-)
>
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 6ce70e0076..ecfd84a32c 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -424,8 +424,6 @@ static void dash_free(AVFormatContext *s)
>  return;
>  for (i = 0; i < s->nb_streams; i++) {
>  OutputStream *os = >streams[i];
> -if (os->ctx && os->ctx_inited)
> -av_write_trailer(os->ctx);
>  if (os->ctx && os->ctx->pb)
>  ffio_free_dyn_buf(>ctx->pb);
>  ff_format_io_close(s, >out);
> @@ -1331,6 +1329,47 @@ static void dashenc_delete_file(AVFormatContext *s, 
> char *filename) {
>  }
>  }
>  
> +static int dashenc_delete_segment_file(AVFormatContext *s, const char* file)
> +{
> +DASHContext *c = s->priv_data;
> +size_t dirname_len, file_len;
> +char filename[1024];
> +
> +dirname_len = strlen(c->dirname);
> +if (dirname_len >= sizeof(filename)) {
> +av_log(s, AV_LOG_WARNING, "Cannot delete segments as the directory 
> path is too long: %"PRIu64" characters: %s\n",
> +(uint64_t)dirname_len, c->dirname);
> +return AVERROR(ENAMETOOLONG);
> +}
> +
> +memcpy(filename, c->dirname, dirname_len);
> +
> +file_len = strlen(file);
> +if ((dirname_len + file_len) >= sizeof(filename)) {
> +av_log(s, AV_LOG_WARNING, "Cannot delete segments as the path is too 
> long: %"PRIu64" characters: %s%s\n",
> +(uint64_t)(dirname_len + file_len), c->dirname, file);
> +return AVERROR(ENAMETOOLONG);
> +}
> +
> +memcpy(filename + dirname_len, file, file_len + 1); // include the 
> terminating zero
> +dashenc_delete_file(s, filename);
> +
> +return 0;
> +}
> +
> +static inline void dashenc_delete_media_segments(AVFormatContext *s, 
> OutputStream *os, int remove_count)
> +{
> +for (int i = 0; i < remove_count; ++i) {
> +dashenc_delete_segment_file(s, os->segments[i]->file);
> +
> +// Delete the segment regardless of whether the file was 
> successfully deleted
> +av_free(os->segments[i]);
> +}
> +
> +os->nb_segments -= remove_count;
> +memmove(os->segments, os->segments + remove_count, os->nb_segments * 
> sizeof(*os->segments));
> +}
> +
>  static int dash_flush(AVFormatContext *s, int final, int stream)
>  {
>  DASHContext *c = s->priv_data;
> @@ -1420,23 +1459,12 @@ static int dash_flush(AVFormatContext *s, int final, 
> int stream)
>  os->pos += range_length;
>  }
>  
> -if (c->window_size || (final && c->remove_at_exit)) {
> +if (c->window_size) {
>  for (i = 0; i < s->nb_streams; i++) {
>  OutputStream *os = >streams[i];
> -int j;
> -int remove = os->nb_segments - c->window_size - 
> c->extra_window_size;
> -if (final && c->remove_at_exit)
> -remove = os->nb_segments;
> -if (remove > 0) {
> -for (j = 0; j < remove; j++) {
> -char filename[1024];
> -snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
> os->segments[j]->file);
> -dashenc_delete_file(s, filename);
> -av_free(os->segments[j]);
> -}
> -os->nb_segments -= remove;
> -memmove(os->segments, os->segments + remove, os->nb_segments 
> * sizeof(*os->segments));
> -}
> +int remove_count = os->nb_segments - c->window_size - 
> c->extra_window_size;
> +if (remove_count > 0)
> +dashenc_delete_media_segments(s, os, remove_count);
>  }
>  }
>  
> @@ -1584,6 +1612,7 @@ static int dash_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
>  static int dash_write_trailer(AVFormatContext *s)
>  {
>  DASHContext *c = s->priv_data;
> +int i;
>  
>  if (s->nb_streams > 0) {
>  OutputStream *os = >streams[0];
> @@ -1599,14 +1628,19 @@ static int dash_write_trailer(AVFormatContext *s)
>  }
>  dash_flush(s, 1, -1);
>  
> -if (c->remove_at_exit) {
> -char filename[1024];
> -int i;
> -for (i = 0; i < s->nb_streams; i++) {
> -OutputStream *os = >streams[i];
> -snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
> os->initfile);
> -dashenc_delete_file(s, filename);
> +for (i = 0; i < s->nb_streams; ++i) {
> +OutputStream *os = >streams[i];
> +if (os->ctx && os->ctx_inited) {
> +av_write_trailer(os->ctx);
> + 

Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Fix file URI handling when deleting files.

2018-11-29 Thread Jeyapal, Karthick

On 11/29/18 11:49 PM, Andrey Semashev wrote:
> On 11/29/18 2:17 PM, Andrey Semashev wrote:
>> On 11/29/18 2:15 PM, Andrey Semashev wrote:
>>> On 11/28/18 7:47 PM, Jeyapal, Karthick wrote:

 On 11/28/18 4:46 PM, Andrey Semashev wrote:
> The URI used to open the output streams may be an actual URI with "file" 
> scheme,
> according to https://tools.ietf.org/html/rfc8089. This commit makes file
> deletion routine recognize file URIs and extract the actual filesystem 
> path
> from it. 
 There is already some code in ffmpeg to handle this. It is present in 
 file_delete() function in file.c.
 We will need to avoid code duplication for the same functionality. One 
 option could be to call avpriv_io_delete() function instead of calling 
 unlink, so that file_delete function gets called.
 Calling avpriv_io_delete will also make the delete functionality easily 
 extendable for other output protocols. 
>>>
>>> That would be fine with me, but I'm using Linux. Looking at file_delete (in 
>>> libavformat/file.c), it looks like it will only work on POSIX systems but 
>>> not on Windows, since it doesn't have unistd.h. Am I correct? And if so, is 
>>> avpriv_io_delete still the preferred approach? 
>>
>> Also, that code doesn't seem to support the URI with an authority field and 
>> doesn't check the special "localhost" case. 
>
> I've sent a new set of patches that updates both file.c and dashenc.c.
Thanks for your understanding. Looks like that will be the clean approach for 
fixing this problem.
> ___
> 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 2/2] lavf/dashenc: Use avpriv_io_delete to delete files.

2018-11-29 Thread Jeyapal, Karthick

On 11/29/18 11:48 PM, Andrey Semashev wrote:
> This fixes incorrect handling of file URIs (i.e. when the filename starts
> with "file:", possibly followed by URI authority).
> ---
>  libavformat/dashenc.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 6ce70e0076..426dc91bcc 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -25,6 +25,7 @@
>  #include 
>  #endif
>  
> +#include "libavutil/error.h"
I guess this include is redundant. error.h is already included from avutil.h. I 
don't know the ffmpeg coding policy for such redundant includes. 
But in case the coding policy mandates you include it, I would suggest you add 
this include after "libavutil/avstring.h" so that the alphabetical order is 
maintained.
Apart from this minor issue the patch looks fine.
>  #include "libavutil/avassert.h"
>  #include "libavutil/avutil.h"
>  #include "libavutil/avstring.h"
> @@ -1326,8 +1327,13 @@ static void dashenc_delete_file(AVFormatContext *s, 
> char *filename) {
>  
>  av_dict_free(_opts);
>  ff_format_io_close(s, );
> -} else if (unlink(filename) < 0) {
> -av_log(s, AV_LOG_ERROR, "failed to delete %s: %s\n", filename, 
> strerror(errno));
> +} else {
> +int res = avpriv_io_delete(filename);
> +if (res < 0) {
> +char errbuf[AV_ERROR_MAX_STRING_SIZE];
> +av_strerror(res, errbuf, sizeof(errbuf));
> +av_log(s, (res == AVERROR(ENOENT) ? AV_LOG_WARNING : 
> AV_LOG_ERROR), "failed to delete %s: %s\n", filename, errbuf);
> +}
>  }
>  }
>  

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


Re: [FFmpeg-devel] [PATCH v2] avformat/movenc : Don't write sidx for empty urls

2018-11-29 Thread Jeyapal, Karthick

On 11/29/18 11:08 PM, Michael Niedermayer wrote:
> On Wed, Nov 28, 2018 at 09:45:24PM +0530, Karthick J wrote:
>> When movenc is used by other segmenting muxers such as dashenc, url field is 
>> always empty.
>> In such cases it is better to not write sidx, instead of throwing errors.
>> ---
>>  libavformat/movenc.c | 3 +++
>>  1 file changed, 3 insertions(+)
>
> please correct me if i misunderstand but
> dashenc enables global sidx, skiping writing the sidx then always seems a bit
> odd
Your understanding is correct. 
But the motive of dashenc is to disable writing of sidx atom for every moof 
atom (Let's call this as local sidx for the sake of discussion).
We wanted to disable local sidx as it was adding significant bitrate overhead 
for chunked streaming(where each frame is a moof).
To disable local sidx we enabled global sidx. And global sidx was not writing 
any sidx at all from dashenc due to lack of url. 
This behavior of not writing any sidx at all is also acceptable for dash. But 
we just wanted to remove the error, and hence this patch.
Maybe one could add a new option no_sidx in movenc for this functionality. But 
since global_sidx was already achieving the same functionality new option 
seemed a bit redundant.
>
> [...]
>
> ___
> 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] lavf/dashenc: Remove global_sidx from movenc params for live streaming.

2018-11-29 Thread Jeyapal, Karthick

On 11/29/18 8:28 PM, Andrey Semashev wrote:
> On 11/28/18 7:25 PM, Jeyapal, Karthick wrote:
>>
>> On 11/28/18 4:41 PM, Andrey Semashev wrote:
>>> The global_sidx flag causes errors like the following in movenc when media
>>> segment removal is enabled via windos_size or remove_at_exit:
>>>
>>> Non-consecutive fragments, writing incorrect sidx
>>> Unable to re-open  output file for the second pass (faststart) 
>> Removing global_sidx flag adds sidx atom to each moof fragment adding 
>> significant bitrate overhead.
>> Instead I have submitted a patch to handle this case cleanly in movenc. 
>> http://ffmpeg.org/pipermail/ffmpeg-devel/2018-November/236873.html
>> Please try the above patch and let me know if that will work for you. 
>
> Yes, that patch seems to fix the errors. Thanks.
>
> On a slightly unrelated note, during testing, I've also seen different errors 
> like these:
>
> [AVFormatContext] Application provided duration: -1 / timestamp: 243456 is 
> out of range for mov/mp4 format
> [AVFormatContext] pts has no value
>
> These happen when media segments are rotated and file deletion is enabled. 
> They don't seem to happen on every file rotation, though, and I can't find 
> what could be causing them. These errors are present regardless of the 
> global_sidx flag or your movenc patch. Do you have an idea what could be 
> causing them?
No, I have never faced this issue so far. If could share a sample command line 
for reproducing this issue, I will have a look at it when I am free.
> ___
> 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 v2 2/2] avformat/dashenc: Added an option to ignore io errors

2018-11-29 Thread Jeyapal, Karthick

On 11/29/18 8:07 PM, Andrey Semashev wrote:
> On 11/28/18 8:06 PM, Karthick J wrote:
>> When dashenc has to run for long duration(say 24x7 live stream), one can 
>> enable this option to ignore the io failure of few segment's upload due to 
>> an intermittent network issues.
>> When the network connection recovers dashenc will continue with the upload 
>> of the current segments, leading to the recovery of the stream.
>> ---
>>   doc/muxers.texi   |  3 +++
>>   libavformat/dashenc.c | 17 +++--
>>   2 files changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index a02ac01b55..f1cc6f5fee 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -300,6 +300,9 @@ If this flag is set, the dash segment files will be in 
>> in ISOBMFF format.
>>   @item webm
>>   If this flag is set, the dash segment files will be in in WebM format.
>>   +@item -ignore_io_errors @var{ignore_io_errors}
>> +Ignore IO errors during open and write. Useful for long-duration runs with 
>> network output.
>> +
>>   @end table
>> @anchor{framecrc}
>> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
>> index 2f403257c0..04218af6a6 100644
>> --- a/libavformat/dashenc.c
>> +++ b/libavformat/dashenc.c
>> @@ -138,6 +138,7 @@ typedef struct DASHContext {
>>   int index_correction;
>>   char *format_options_str;
>>   SegmentType segment_type_option;  /* segment type as specified in 
>> options */
>> +int ignore_io_errors;
>>   } DASHContext;
>> static struct codec_string {
>> @@ -846,7 +847,7 @@ static int write_manifest(AVFormatContext *s, int final)
>>   av_dict_free();
>>   if (ret < 0) {
>>   av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
>> temp_filename);
>> -return ret;
>> +return c->ignore_io_errors ? 0 : ret;
>>   }
>>   out = c->mpd_out;
>>   avio_printf(out, "\n");
>> @@ -937,7 +938,7 @@ static int write_manifest(AVFormatContext *s, int final)
>>   av_dict_free();
>>   if (ret < 0) {
>>   av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
>> temp_filename);
>> -return ret;
>> +return c->ignore_io_errors ? 0 : ret;
>>   }
>> ff_hls_write_playlist_version(c->m3u8_out, 7);
>> @@ -1565,8 +1566,9 @@ static int dash_write_packet(AVFormatContext *s, 
>> AVPacket *pkt)
>>   set_http_options(, c);
>>   ret = dashenc_io_open(s, >out, os->temp_path, );
>>   av_dict_free();
>> -if (ret < 0)
>> -return ret;
>> +if (ret < 0) { 
>
> Please, add error logging as well:
>
> char errbuf[AV_ERROR_MAX_STRING_SIZE];
> av_strerror(ret, errbuf, sizeof(errbuf));
> av_log(s, (c->ignore_io_errors ? AV_LOG_WARNING : AV_LOG_ERROR), 
> "Unable to open %s for writing: %s\n", os->temp_path, errbuf);
Thank you very much for your review comments. And thanks for providing the 
sample code as well.
I have sent a separate patch addressing your comments 
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-November/236955.html 
>
>> +return c->ignore_io_errors ? 0 : ret;
>> +}
>>   }
>> //write out the data immediately in streaming mode
>> @@ -1577,9 +1579,11 @@ static int dash_write_packet(AVFormatContext *s, 
>> AVPacket *pkt)
>>   write_styp(os->ctx->pb);
>>   avio_flush(os->ctx->pb);
>>   len = avio_get_dyn_buf (os->ctx->pb, );
>> -avio_write(os->out, buf + os->written_len, len - os->written_len);
>> +if (os->out) {
>> +avio_write(os->out, buf + os->written_len, len - 
>> os->written_len);
>> +avio_flush(os->out);
>> +}
>>   os->written_len = len;
>> -avio_flush(os->out);
>>   }
>> return ret;
>> @@ -1670,6 +1674,7 @@ static const AVOption options[] = {
>>   { "auto", "select segment file format based on codec", 0, 
>> AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_AUTO }, 0, UINT_MAX,   E, 
>> "segment_type"},
>>   { "mp4", "make segment file in ISOBMFF format", 0, AV_OPT_TYPE_CONST, 
>> {.i64 = SEGMENT_TYPE_MP4 }, 0, UINT_MAX,   E, "segment_type"},
>>   { "webm", "make segment file in WebM format", 0, AV_OPT_TYPE_CONST, 
>> {.i64 = SEGMENT_TYPE_WEBM }, 0, UINT_MAX,   E, "segment_type"},
>> +{ "ignore_io_errors", "Ignore IO errors during open and write. Useful 
>> for long-duration runs with network output", OFFSET(ignore_io_errors), 
>> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
>>   { NULL },
>>   };
>>   
>
> ___
> 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] avformat/dashenc: Added proper logging when io_open fails for write

2018-11-29 Thread Karthick J
---
 libavformat/dashenc.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 04218af6a6..09207dcf44 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -209,6 +209,15 @@ static const char *get_format_str(SegmentType 
segment_type) {
 return NULL;
 }
 
+static int handle_io_open_error(AVFormatContext *s, int err, char *url) {
+DASHContext *c = s->priv_data;
+char errbuf[AV_ERROR_MAX_STRING_SIZE];
+av_strerror(err, errbuf, sizeof(errbuf));
+av_log(s, c->ignore_io_errors ? AV_LOG_WARNING : AV_LOG_ERROR,
+   "Unable to open %s for writing: %s\n", url, errbuf);
+return c->ignore_io_errors ? 0 : err;
+}
+
 static inline SegmentType select_segment_type(SegmentType segment_type, enum 
AVCodecID codec_id)
 {
 if (segment_type == SEGMENT_TYPE_AUTO) {
@@ -531,7 +540,7 @@ static void output_segment_list(OutputStream *os, 
AVIOContext *out, AVFormatCont
 ret = dashenc_io_open(s, >m3u8_out, temp_filename_hls, _opts);
 av_dict_free(_opts);
 if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
temp_filename_hls);
+handle_io_open_error(s, ret, temp_filename_hls);
 return;
 }
 for (i = start_index; i < os->nb_segments; i++) {
@@ -846,8 +855,7 @@ static int write_manifest(AVFormatContext *s, int final)
 ret = dashenc_io_open(s, >mpd_out, temp_filename, );
 av_dict_free();
 if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
temp_filename);
-return c->ignore_io_errors ? 0 : ret;
+return handle_io_open_error(s, ret, temp_filename);
 }
 out = c->mpd_out;
 avio_printf(out, "\n");
@@ -937,8 +945,7 @@ static int write_manifest(AVFormatContext *s, int final)
 ret = dashenc_io_open(s, >m3u8_out, temp_filename, );
 av_dict_free();
 if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
temp_filename);
-return c->ignore_io_errors ? 0 : ret;
+return handle_io_open_error(s, ret, temp_filename);
 }
 
 ff_hls_write_playlist_version(c->m3u8_out, 7);
@@ -1567,7 +1574,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 ret = dashenc_io_open(s, >out, os->temp_path, );
 av_dict_free();
 if (ret < 0) {
-return c->ignore_io_errors ? 0 : ret;
+return handle_io_open_error(s, ret, os->temp_path);
 }
 }
 
-- 
2.17.1 (Apple Git-112)

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


Re: [FFmpeg-devel] [PATCH] [RFC] channel_layout: add support for ambisonics

2018-11-29 Thread Michael Niedermayer
On Thu, Nov 29, 2018 at 02:02:43AM +, Rostislav Pehlivanov wrote:
> This is an RFC to add support for tagging channel layouts as ambisonics
> in a backward-compatible way.
> For now ambisonics up to third order are supported.
> The functions have been updated to support and propagate the
> AV_CH_LAYOUT_AMBISONICS flag.
> This is messy but does not require a new API for layouts. Perhaps the
> new proposed API might be a better solution, comments are welcome.
> ---
>  doc/APIchanges |  4 ++
>  libavutil/channel_layout.c | 85 +-
>  libavutil/channel_layout.h | 19 -
>  libavutil/version.h|  4 +-
>  4 files changed, 72 insertions(+), 40 deletions(-)

breaks make fate
make: *** [fate-filter-join] Error 1
make: *** [fate-filter-channelsplit] Error 1


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

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


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


Re: [FFmpeg-devel] [PATCH] lavc/libaomenc: Add a maximum constraint of 64 encoder threads.

2018-11-29 Thread James Almer
On 11/27/2018 6:18 AM, Jun Zhao wrote:
> fixed the error in Intel(R) Xeon(R) Gold 6152 CPU like:
> [libaom-av1 @ 0x469f340] Failed to initialize encoder: Invalid parameter
> [libaom-av1 @ 0x469f340]   Additional information: g_threads out of range 
> [..MAX_NUM_THREADS]
> 
> Signed-off-by: Jun Zhao 
> ---
>  libavcodec/libaomenc.c |3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index cb31c55..ccb0cf9 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -504,7 +504,8 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  enccfg.g_h= avctx->height;
>  enccfg.g_timebase.num = avctx->time_base.num;
>  enccfg.g_timebase.den = avctx->time_base.den;
> -enccfg.g_threads  = avctx->thread_count ? avctx->thread_count : 
> av_cpu_count();
> +enccfg.g_threads  =
> + FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64);
>  
>  if (ctx->lag_in_frames >= 0)
>  enccfg.g_lag_in_frames = ctx->lag_in_frames;
> 

Applied. Better to clip the value than to let initialization using
default values fail in the user's face because they have a computer with
a lot logical cores.

libaom should nonetheless either do this clipping internally, or make
this limit clear in the API and/or the documentation.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/hevc_parser: add 4 bytes startcode condition in hevc_find_frame_end

2018-11-29 Thread Michael Niedermayer
On Thu, Nov 29, 2018 at 04:14:29AM +, Fu, Linjie wrote:
> > -Original Message-
> > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> > Of Michael Niedermayer
> > Sent: Thursday, November 29, 2018 02:14
> > To: FFmpeg development discussions and patches  > de...@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH] lavc/hevc_parser: add 4 bytes
> > startcode condition in hevc_find_frame_end
> > 
> > On Tue, Nov 27, 2018 at 08:16:55PM +0800, Linjie Fu wrote:
> > > The startcode before VPS,SPS,PPS and the first NALU in an AU is 4 bytes.
> > > Blindly taking the startcode as 3 bytes will leave 0x00 in last packet
> > > and may lead to some warnings in parse_nal_units when s->flags is set to
> > > PARSER_FLAG_COMPLETE_FRAMES.
> > >
> > > Add 4 bytes startcode condition in hevc_find_frame_end.
> > > Modify the code to print the buf_size like in H264 and reduce the
> > duplication.
> > >
> > > Signed-off-by: Linjie Fu 
> > > ---
> > >  libavcodec/hevc_parser.c | 15 ++-
> > >  1 file changed, 10 insertions(+), 5 deletions(-)
> > 
> > breaks
> >  make fate-hevc-bsf-mp4toannexb
> > TESThevc-bsf-mp4toannexb
> > --- -   2018-11-28 19:12:47.869732022 +0100
> > +++ tests/data/fate/hevc-bsf-mp4toannexb2018-11-28
> > 19:12:47.864276885 +0100
> > @@ -1 +1 @@
> > -1873662a3af1848c37e4eb25722c8df9
> > +73019329ed7f81c24f9af67c34c640c0
> > Test hevc-bsf-mp4toannexb failed. Look at tests/data/fate/hevc-bsf-
> > mp4toannexb.err for details.
> > make: *** [fate-hevc-bsf-mp4toannexb] Error 1
> > 
> 
> Investigate the root cause:
> 
> In fate test:
> Step 1. ffmpeg -i hevc-conformance/WPP_A_ericsson_MAIN10_2.bit -c copy -flags 
> +bitexact hevc-mp4.mov
> Step 2. ffmpeg -i hevc-mp4_after.mov -c:v copy -fflags +bitexact -f hevc 
> hevc.out
> Step3. md5sum and compared with the reference
> 
> Compare the output file in Step 1 before and after the patch, and found it 
> changed:
> -rw-r--r-- 1 root root 68460 11月 29 11:23 hevc-mp4_after.mov
> -rw-r--r-- 1 root root 68507 11月 29 11:31 hevc-mp4_before.mov
> 
> Compare the original file with two output files:
> SUFFIX_SEI bit information in  the first frame for example :
> 
> WPP_A_ericsson_MAIN10_2.bit: { 50 01 84 31 00 19 39 77 d0 7b 3f bd 1e 09 38 
> 9a 79 41 c0 16 11 da 18 aa 0a db 2b 19 fa 47 3f 0f 67 4a 91 9c a1 12 72 67 d6 
> f0 8f 66 ee 95 f9 e2 b9 ba 23 9a e8 80 }
> 
> hevc-mp4_before.mov: { 50 01 84 31 00 19 39 77 d0 7b 3f bd 1e 09 38 9a 79 41 
> c0 16 11 da 18 aa 0a db 2b 19 fa 47 3f 0f 67 4a 91 9c a1 12 72 67 d6 f0 8f 66 
> ee 95 f9 e2 b9 ba 23 9a e8 80 00 }
> 
> hevc-mp4_after.mov: { 50 01 84 31 00 19 39 77 d0 7b 3f bd 1e 09 38 9a 79 41 
> c0 16 11 da 18 aa 0a db 2b 19 fa 47 3f 0f 67 4a 91 9c a1 12 72 67 d6 f0 8f 66 
> ee 95 f9 e2 b9 ba 23 9a e8 80 }
> 
> Before applying the patch, the output file has an extra 0x00 at the end of 
> SUFFIX_SEI (because of blindly taking startcode as 3 bytes and left one byte).
> After applying the patch, the output file has the same bit info like the 
> original file.
> So, I think this patch works.

if the patch break make fate then it doesnt work.
If a change cause by a patch is correct it needs to update the 
test / its checksum
This is also important so that anyone looking at the patch knows which tests
change and anyone testing knows how to detect a test failure vs a passed test


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

Those who are best at talking, realize last or never when they are wrong.


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


Re: [FFmpeg-devel] [PATCH] [RFC] channel_layout: add support for ambisonics

2018-11-29 Thread Marton Balint



On Thu, 29 Nov 2018, Rostislav Pehlivanov wrote:


This is an RFC to add support for tagging channel layouts as ambisonics
in a backward-compatible way.
For now ambisonics up to third order are supported.
The functions have been updated to support and propagate the
AV_CH_LAYOUT_AMBISONICS flag.
This is messy but does not require a new API for layouts. Perhaps the
new proposed API might be a better solution, comments are welcome.
---
doc/APIchanges |  4 ++
libavutil/channel_layout.c | 85 +-
libavutil/channel_layout.h | 19 -
libavutil/version.h|  4 +-
4 files changed, 72 insertions(+), 40 deletions(-)


Using separate channel_layout bits for each (up to 16) ambisonic channel 
seems a lot cleaner.


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


Re: [FFmpeg-devel] [PATCH] avformat/ac3dec: always skip junk bytes before sync bytes

2018-11-29 Thread Paul B Mahol
On 11/27/18, Paul B Mahol  wrote:
> Fixes #7278.
>
> Signed-off-by: Paul B Mahol 
> ---
>  libavcodec/ac3dec.c  | 20 +---
>  libavformat/ac3dec.c |  2 +-
>  2 files changed, 18 insertions(+), 4 deletions(-)
>

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


Re: [FFmpeg-devel] [PATCH 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Andrey Semashev

On 11/29/18 10:16 PM, Nicolas George wrote:

Andrey Semashev (2018-11-29):

 Nowdays, there is one common interface
for interacting with ffmpeg, and this interface is URIs (or raw local
paths). There is no third pseudo-URI option, AFAICT. So, in my humble
opinion the docs are correct, it is the implementation that needs to catch
up.


You are wrong. There is one common interface: that is pseudi-URI. URI is
not an option.


If an application passes a URI and expects that it is not interpreted as
such is already broken.


And it always was. Breaking something that works is worse than having
something that never worked still not work.


  I could make a patch adding support for escape
sequences as well, but it seems you would not accept it. Am I correct?


As is, "fixing" the file: protocol paths to be treated as URIs would be
an API break, it is not acceptable.

You can propose patches to make FFmpeg support real URIs instead / in
addition to its old pseudo-URI syntax, but you would need to design with
API compatibility in mind.


Ok, thanks for your comments.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Nicolas George
Andrey Semashev (2018-11-29):
>Nowdays, there is one common interface
> for interacting with ffmpeg, and this interface is URIs (or raw local
> paths). There is no third pseudo-URI option, AFAICT. So, in my humble
> opinion the docs are correct, it is the implementation that needs to catch
> up.

You are wrong. There is one common interface: that is pseudi-URI. URI is
not an option.

> If an application passes a URI and expects that it is not interpreted as
> such is already broken.

And it always was. Breaking something that works is worse than having
something that never worked still not work.

> I could make a patch adding support for escape
> sequences as well, but it seems you would not accept it. Am I correct?

As is, "fixing" the file: protocol paths to be treated as URIs would be
an API break, it is not acceptable.

You can propose patches to make FFmpeg support real URIs instead / in
addition to its old pseudo-URI syntax, but you would need to design with
API compatibility in mind.

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 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Andrey Semashev

On 11/29/18 9:47 PM, Nicolas George wrote:

Andrey Semashev (2018-11-29):

It does. avformat_open_input, avio_open and ffurl_open[_whitelist] docs all
say it's an URL and they don't perform any conversion. So the file backend
should be prepared to receive a URL, with a scheme and authority.


So either the docs are slightly wrong or the code is. Do you have an
argument to decide it is one rather than the other?

I do:


It will probably currently fail because of the escape sequence.


Exactly. Since escaping, a very basic feature of URIs, is not handled at
all, it is a clear indication that the paths are NOT meant to be
considered URIs. The documentation was added much later, and made the
same mistake you are doing now; same goes for a few private function
names.


I condider the lack of support for escape sequences a bug, which is 
probably a rudiment of the past, when ffmpeg was primarily targeted for 
working with local files. The fact that all these functions also accept 
raw filesystem paths instead of URIs is also there for the same reason, 
only with additional benefit of convenience. Nowdays, there is one 
common interface for interacting with ffmpeg, and this interface is URIs 
(or raw local paths). There is no third pseudo-URI option, AFAICT. So, 
in my humble opinion the docs are correct, it is the implementation that 
needs to catch up.



Escape sequences, if needed, can be fixed separately.


That would break a lot of working applications and is therefore not a
good idea.


If an application passes a URI and expects that it is not interpreted as 
such is already broken. I could make a patch adding support for escape 
sequences as well, but it seems you would not accept it. Am I correct?

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


Re: [FFmpeg-devel] [PATCH 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Nicolas George
Andrey Semashev (2018-11-29):
> It does. avformat_open_input, avio_open and ffurl_open[_whitelist] docs all
> say it's an URL and they don't perform any conversion. So the file backend
> should be prepared to receive a URL, with a scheme and authority.

So either the docs are slightly wrong or the code is. Do you have an
argument to decide it is one rather than the other?

I do:

> It will probably currently fail because of the escape sequence.

Exactly. Since escaping, a very basic feature of URIs, is not handled at
all, it is a clear indication that the paths are NOT meant to be
considered URIs. The documentation was added much later, and made the
same mistake you are doing now; same goes for a few private function
names.

> Escape sequences, if needed, can be fixed separately.

That would break a lot of working applications and is therefore not a
good idea.

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 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Andrey Semashev

On 11/29/18 9:24 PM, Nicolas George wrote:

Andrey Semashev (2018-11-29):

Previously, URIs with authority field were incorrectly interpreted as if
the authority was part of the path.


The "file:" prefix does not indicate a file:// URI but a path for the
file: protocol of FFmpeg.


It does. avformat_open_input, avio_open and ffurl_open[_whitelist] docs 
all say it's an URL and they don't perform any conversion. So the file 
backend should be prepared to receive a URL, with a scheme and authority.



You can check by yourself that they are not URIs by trying to get FFmpeg
to open file:///dev/nul%6c for example.


It will probably currently fail because of the escape sequence. But even 
if it weren't for this reason, it would still be interpreting the URI 
the wrong way because of the authority part, which is what this patch fixes.


Escape sequences, if needed, can be fixed separately.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2] lavf/dashenc: Write media trailers when DASH trailer is written.

2018-11-29 Thread Andrey Semashev
This commit ensures that all (potentially, long) filesystem activity is
performed when the user calls av_write_trailer on the DASH libavformat
context, not when freeing the context. Also, this defers media segment
deletion until after the media trailers are written.
---
 libavformat/dashenc.c | 82 ++-
 1 file changed, 58 insertions(+), 24 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 6ce70e0076..ecfd84a32c 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -424,8 +424,6 @@ static void dash_free(AVFormatContext *s)
 return;
 for (i = 0; i < s->nb_streams; i++) {
 OutputStream *os = >streams[i];
-if (os->ctx && os->ctx_inited)
-av_write_trailer(os->ctx);
 if (os->ctx && os->ctx->pb)
 ffio_free_dyn_buf(>ctx->pb);
 ff_format_io_close(s, >out);
@@ -1331,6 +1329,47 @@ static void dashenc_delete_file(AVFormatContext *s, char 
*filename) {
 }
 }
 
+static int dashenc_delete_segment_file(AVFormatContext *s, const char* file)
+{
+DASHContext *c = s->priv_data;
+size_t dirname_len, file_len;
+char filename[1024];
+
+dirname_len = strlen(c->dirname);
+if (dirname_len >= sizeof(filename)) {
+av_log(s, AV_LOG_WARNING, "Cannot delete segments as the directory 
path is too long: %"PRIu64" characters: %s\n",
+(uint64_t)dirname_len, c->dirname);
+return AVERROR(ENAMETOOLONG);
+}
+
+memcpy(filename, c->dirname, dirname_len);
+
+file_len = strlen(file);
+if ((dirname_len + file_len) >= sizeof(filename)) {
+av_log(s, AV_LOG_WARNING, "Cannot delete segments as the path is too 
long: %"PRIu64" characters: %s%s\n",
+(uint64_t)(dirname_len + file_len), c->dirname, file);
+return AVERROR(ENAMETOOLONG);
+}
+
+memcpy(filename + dirname_len, file, file_len + 1); // include the 
terminating zero
+dashenc_delete_file(s, filename);
+
+return 0;
+}
+
+static inline void dashenc_delete_media_segments(AVFormatContext *s, 
OutputStream *os, int remove_count)
+{
+for (int i = 0; i < remove_count; ++i) {
+dashenc_delete_segment_file(s, os->segments[i]->file);
+
+// Delete the segment regardless of whether the file was successfully 
deleted
+av_free(os->segments[i]);
+}
+
+os->nb_segments -= remove_count;
+memmove(os->segments, os->segments + remove_count, os->nb_segments * 
sizeof(*os->segments));
+}
+
 static int dash_flush(AVFormatContext *s, int final, int stream)
 {
 DASHContext *c = s->priv_data;
@@ -1420,23 +1459,12 @@ static int dash_flush(AVFormatContext *s, int final, 
int stream)
 os->pos += range_length;
 }
 
-if (c->window_size || (final && c->remove_at_exit)) {
+if (c->window_size) {
 for (i = 0; i < s->nb_streams; i++) {
 OutputStream *os = >streams[i];
-int j;
-int remove = os->nb_segments - c->window_size - 
c->extra_window_size;
-if (final && c->remove_at_exit)
-remove = os->nb_segments;
-if (remove > 0) {
-for (j = 0; j < remove; j++) {
-char filename[1024];
-snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
os->segments[j]->file);
-dashenc_delete_file(s, filename);
-av_free(os->segments[j]);
-}
-os->nb_segments -= remove;
-memmove(os->segments, os->segments + remove, os->nb_segments * 
sizeof(*os->segments));
-}
+int remove_count = os->nb_segments - c->window_size - 
c->extra_window_size;
+if (remove_count > 0)
+dashenc_delete_media_segments(s, os, remove_count);
 }
 }
 
@@ -1584,6 +1612,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 static int dash_write_trailer(AVFormatContext *s)
 {
 DASHContext *c = s->priv_data;
+int i;
 
 if (s->nb_streams > 0) {
 OutputStream *os = >streams[0];
@@ -1599,14 +1628,19 @@ static int dash_write_trailer(AVFormatContext *s)
 }
 dash_flush(s, 1, -1);
 
-if (c->remove_at_exit) {
-char filename[1024];
-int i;
-for (i = 0; i < s->nb_streams; i++) {
-OutputStream *os = >streams[i];
-snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
os->initfile);
-dashenc_delete_file(s, filename);
+for (i = 0; i < s->nb_streams; ++i) {
+OutputStream *os = >streams[i];
+if (os->ctx && os->ctx_inited) {
+av_write_trailer(os->ctx);
+}
+
+if (c->remove_at_exit) {
+dashenc_delete_media_segments(s, os, os->nb_segments);
+dashenc_delete_segment_file(s, os->initfile);
 }
+}
+
+if (c->remove_at_exit) {
 dashenc_delete_file(s, s->url);
 }
 
-- 
2.19.1


Re: [FFmpeg-devel] [PATCH 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Nicolas George
Andrey Semashev (2018-11-29):
> Previously, URIs with authority field were incorrectly interpreted as if
> the authority was part of the path.

The "file:" prefix does not indicate a file:// URI but a path for the
file: protocol of FFmpeg.

You can check by yourself that they are not URIs by trying to get FFmpeg
to open file:///dev/nul%6c for example.

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] lavf/dashenc: Fix file URI handling when deleting files.

2018-11-29 Thread Andrey Semashev

On 11/29/18 2:17 PM, Andrey Semashev wrote:

On 11/29/18 2:15 PM, Andrey Semashev wrote:

On 11/28/18 7:47 PM, Jeyapal, Karthick wrote:


On 11/28/18 4:46 PM, Andrey Semashev wrote:
The URI used to open the output streams may be an actual URI with 
"file" scheme,
according to https://tools.ietf.org/html/rfc8089. This commit makes 
file
deletion routine recognize file URIs and extract the actual 
filesystem path

from it.
There is already some code in ffmpeg to handle this. It is present in 
file_delete() function in file.c.
We will need to avoid code duplication for the same functionality. 
One option could be to call avpriv_io_delete() function instead of 
calling unlink, so that file_delete function gets called.
Calling avpriv_io_delete will also make the delete functionality 
easily extendable for other output protocols.


That would be fine with me, but I'm using Linux. Looking at 
file_delete (in libavformat/file.c), it looks like it will only work 
on POSIX systems but not on Windows, since it doesn't have unistd.h. 
Am I correct? And if so, is avpriv_io_delete still the preferred 
approach?


Also, that code doesn't seem to support the URI with an authority field 
and doesn't check the special "localhost" case.


I've sent a new set of patches that updates both file.c and dashenc.c.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] lavf/file: Add proper support for authority in file URIs.

2018-11-29 Thread Andrey Semashev
Previously, URIs with authority field were incorrectly interpreted as if
the authority was part of the path. This commit adds more complete file URI
parsing according to https://tools.ietf.org/html/rfc8089. In particular, the
file backend now recognizes URIs with authority field and ensures that it is
either empty or contains the special value "localhost". The file backend will
return EINVAL if the user attempts to use it with a URI referring to
a remote host.

Also, enable file_delete() on Windows as it provides equivalents of unlink()
and rmdir(). The compatibility glue is already provided by os_support.h.
---
 libavformat/file.c | 55 --
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git a/libavformat/file.c b/libavformat/file.c
index 1d321c4205..040197d50d 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -19,6 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/log.h"
+#include "libavutil/error.h"
 #include "libavutil/avstring.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
@@ -104,6 +106,31 @@ static const AVClass pipe_class = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
+static int file_get_path(const char* filename, const char** ppath)
+{
+const char* path = filename;
+// Check if the filename is a file URI. 
https://tools.ietf.org/html/rfc8089#section-2
+if (av_strncasecmp(path, "file:", sizeof("file:") - 1) == 0) {
+path += sizeof("file:") - 1;
+if (path[0] == '/' && path[1] == '/') {
+// The URI may have an authority part. Check that the authority 
does not contain
+// a remote host name. We cannot access filesystem on a different 
host.
+path += 2;
+if (path[0] != '/') {
+if (strncmp(path, "localhost/", sizeof("localhost/") - 1) == 
0) {
+path += sizeof("localhost") - 1;
+} else {
+av_log(NULL, AV_LOG_ERROR, "File URIs referencing a remote 
host are not supported: %s\n", filename);
+return AVERROR(EINVAL);
+}
+}
+}
+}
+
+*ppath = path;
+return 0;
+}
+
 static int file_read(URLContext *h, unsigned char *buf, int size)
 {
 FileContext *c = h->priv_data;
@@ -136,7 +163,9 @@ static int file_check(URLContext *h, int mask)
 {
 int ret = 0;
 const char *filename = h->filename;
-av_strstart(filename, "file:", );
+ret = file_get_path(filename, );
+if (ret < 0)
+return ret;
 
 {
 #if HAVE_ACCESS && defined(R_OK)
@@ -167,10 +196,12 @@ static int file_check(URLContext *h, int mask)
 
 static int file_delete(URLContext *h)
 {
-#if HAVE_UNISTD_H
+#if HAVE_UNISTD_H || defined(_WIN32)
 int ret;
 const char *filename = h->filename;
-av_strstart(filename, "file:", );
+ret = file_get_path(filename, );
+if (ret < 0)
+return ret;
 
 ret = rmdir(filename);
 if (ret < 0 && errno == ENOTDIR)
@@ -188,8 +219,12 @@ static int file_move(URLContext *h_src, URLContext *h_dst)
 {
 const char *filename_src = h_src->filename;
 const char *filename_dst = h_dst->filename;
-av_strstart(filename_src, "file:", _src);
-av_strstart(filename_dst, "file:", _dst);
+int ret = file_get_path(filename_src, _src);
+if (ret < 0)
+return ret;
+ret = file_get_path(filename_dst, _dst);
+if (ret < 0)
+return ret;
 
 if (rename(filename_src, filename_dst) < 0)
 return AVERROR(errno);
@@ -206,7 +241,9 @@ static int file_open(URLContext *h, const char *filename, 
int flags)
 int fd;
 struct stat st;
 
-av_strstart(filename, "file:", );
+int ret = file_get_path(filename, );
+if (ret < 0)
+return ret;
 
 if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) {
 access = O_CREAT | O_RDWR;
@@ -264,8 +301,12 @@ static int file_open_dir(URLContext *h)
 {
 #if HAVE_LSTAT
 FileContext *c = h->priv_data;
+const char* dirname = h->filename;
+int ret = file_get_path(dirname, );
+if (ret < 0)
+return ret;
 
-c->dir = opendir(h->filename);
+c->dir = opendir(dirname);
 if (!c->dir)
 return AVERROR(errno);
 
-- 
2.19.1

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


[FFmpeg-devel] [PATCH 2/2] lavf/dashenc: Use avpriv_io_delete to delete files.

2018-11-29 Thread Andrey Semashev
This fixes incorrect handling of file URIs (i.e. when the filename starts
with "file:", possibly followed by URI authority).
---
 libavformat/dashenc.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 6ce70e0076..426dc91bcc 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -25,6 +25,7 @@
 #include 
 #endif
 
+#include "libavutil/error.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avutil.h"
 #include "libavutil/avstring.h"
@@ -1326,8 +1327,13 @@ static void dashenc_delete_file(AVFormatContext *s, char 
*filename) {
 
 av_dict_free(_opts);
 ff_format_io_close(s, );
-} else if (unlink(filename) < 0) {
-av_log(s, AV_LOG_ERROR, "failed to delete %s: %s\n", filename, 
strerror(errno));
+} else {
+int res = avpriv_io_delete(filename);
+if (res < 0) {
+char errbuf[AV_ERROR_MAX_STRING_SIZE];
+av_strerror(res, errbuf, sizeof(errbuf));
+av_log(s, (res == AVERROR(ENOENT) ? AV_LOG_WARNING : 
AV_LOG_ERROR), "failed to delete %s: %s\n", filename, errbuf);
+}
 }
 }
 
-- 
2.19.1

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


Re: [FFmpeg-devel] [PATCH]lavc/mpeg12dec: Read Closed Captions from second field

2018-11-29 Thread Devin Heitmueller
On Thu, Nov 29, 2018 at 12:55 PM Michael Niedermayer
 wrote:

> > +if (s1->a53_caption) {
> > +AVFrameSideData *sd;
> > +av_frame_remove_side_data(s->current_picture_ptr->f, 
> > AV_FRAME_DATA_A53_CC);
> > +sd = av_frame_new_side_data(
> > +s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
> > +s1->a53_caption_size);
> > +if (sd)
> > +memcpy(sd->data, s1->a53_caption, s1->a53_caption_size);
> > +av_freep(>a53_caption);
> > +}
>
> This is probably ok if only one field has data Attached to it, but if both
> have then both should be exported. Also the user should have some way to
> find out which of 2 fields data came from

Yeah, this will cause the captions from the first field to get lost.
It probably makes sense to look at the H.264 decoder, where this is
done properly (i.e. creating a side data that contains the captions
from both fields).

Devin

-- 
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH]lavc/mpeg12dec: Read Closed Captions from second field

2018-11-29 Thread Michael Niedermayer
On Wed, Nov 28, 2018 at 10:48:17PM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes reading Closed Captions from a field-encoded
> mpeg2video sample from the libav-user mailing list.
> 
> Please review, Carl Eugen

>  mpeg12dec.c |   11 +++
>  1 file changed, 11 insertions(+)
> 777c30f845680de35a26279d23206baf4d4b4dfd  
> 0001-lavc-mpeg12dec-Read-Closed-Captions-from-second-fiel.patch
> From 045a485ffedb3344560070a58a2def659be81700 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos 
> Date: Wed, 28 Nov 2018 22:45:00 +0100
> Subject: [PATCH] lavc/mpeg12dec: Read Closed Captions from second field.
> 
> ---
>  libavcodec/mpeg12dec.c |   11 +++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 83e5378..c0a54a8 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -1664,6 +1664,17 @@ static int mpeg_field_start(MpegEncContext *s, const 
> uint8_t *buf, int buf_size)
>  return AVERROR_INVALIDDATA;
>  }
>  
> +if (s1->a53_caption) {
> +AVFrameSideData *sd;
> +av_frame_remove_side_data(s->current_picture_ptr->f, 
> AV_FRAME_DATA_A53_CC);
> +sd = av_frame_new_side_data(
> +s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
> +s1->a53_caption_size);
> +if (sd)
> +memcpy(sd->data, s1->a53_caption, s1->a53_caption_size);
> +av_freep(>a53_caption);
> +}

This is probably ok if only one field has data Attached to it, but if both
have then both should be exported. Also the user should have some way to
find out which of 2 fields data came from


[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes


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


Re: [FFmpeg-devel] [PATCH v2] avformat/movenc : Don't write sidx for empty urls

2018-11-29 Thread Michael Niedermayer
On Wed, Nov 28, 2018 at 09:45:24PM +0530, Karthick J wrote:
> When movenc is used by other segmenting muxers such as dashenc, url field is 
> always empty.
> In such cases it is better to not write sidx, instead of throwing errors.
> ---
>  libavformat/movenc.c | 3 +++
>  1 file changed, 3 insertions(+)

please correct me if i misunderstand but
dashenc enables global sidx, skiping writing the sidx then always seems a bit
odd

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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


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


Re: [FFmpeg-devel] [PATCH 2/3] lavf/avidec: don't treat I/O errors as EOF

2018-11-29 Thread Michael Niedermayer
On Wed, Nov 28, 2018 at 01:19:58AM -0600, Rodger Combs wrote:
> ---
>  libavformat/avidec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> index 3f074795a7..1d131b299c 100644
> --- a/libavformat/avidec.c
> +++ b/libavformat/avidec.c
> @@ -1383,8 +1383,8 @@ static int ni_prepare_read(AVFormatContext *s)
>  if (i >= 0) {
>  int64_t pos = best_st->index_entries[i].pos;
>  pos += best_ast->packet_size - best_ast->remaining;
> -if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
> -  return AVERROR_EOF;
> +if ((pos = avio_seek(s->pb, pos + 8, SEEK_SET)) < 0)
> +  return pos;

should be ok if tested with a case that triggers this codepath

thanks

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

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope


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


Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension for NV12 and P010 textures - split planes

2018-11-29 Thread Mironov, Mikhail
HI,
I've wrote a small sample you can use: 
https://www.dropbox.com/s/c8m8evoao731tbm/OCLDX11Interop.zip?dl=0
If it doesn’t work - you have conflict of drivers with Intel - saw this before.
Thanks,
Mikhail

> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Mark Thompson
> Sent: November 27, 2018 7:05 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop extension
> for NV12 and P010 textures - split planes
> 
> On 26/11/2018 15:32, Mironov, Mikhail wrote:
> > You assume that device ID returned from regular enumeration is the same
> as device ID returned from clGetDeviceIDsFromD3D11KHR. It is not
> guaranteed and I didn't try this.
> 
> Ok, that's fair I suppose.  Fixing it hasn't changed anything, though.
> 
> > Also I would add tracing to ensure that CL_CONTEXT_D3D11_DEVICE_KHR
> is actually set and clGetDeviceIDsFromD3D11KHR is called.
> 
> The first was always true (Intel requires it too), the second is now.
> 
> > In AMF code I always set CL_CONTEXT_INTEROP_USER_SYNC to true.
> 
> I'm not completely sure of the precise semantics of D3D11, but I don't think
> we want that here - the clEnqueueAcquireD3D11ObjectsKHR() call should be
> the first synchronisation point following the previous component (generally a
> decoder).
> 
> I tried setting it anyway, but the behaviour doesn't change - I still get
> CL_INVALID_D3D11_RESOURCE_KHR.
> 
> > Also I would trace other parameters to clCreateFromD3D11Texture2DKHR:
> memory flags and texture descriptor.
> 
> For the flags, I tried all of CL_MEM_READ_WRITE / CL_MEM_WRITE_ONLY /
> CL_MEM_READ_ONLY, which are the only allowed values.  The texture
> descriptor is just the one created for the decoder.
> 
> > BTW: does the interop work for NV or Intel?
> 
> The D3D11 interop works on Intel, though not directly in the ffmpeg utility
> without a little change because it requires the textures to be created with
> D3D11_RESOURCE_MISC_FLAG (as described in the extension document
>  _nv12_media_sharing.txt>).  Intel doesn't care whether
> clGetDeviceIDsFromD3D11KHR() is used or not (though I've fixed that
> anyway), but it does require the CL_CONTEXT_D3D11_DEVICE_KHR option to
> clCreateContext() (fails with CL_INVALID_CONTEXT if it isn't).
> 
> It can't work on Nvidia because they don't offer any way to share NV12
> textures.
> 
> The DXVA2/D3D9 interop works correctly on both AMD and Intel with only
> the common standard extension.  The one Nvidia device I can find easily
> doesn't have cl_khr_dx9_media_sharing at all, so that doesn't work.
> 
> Thanks,
> 
> - Mark
> 
> 
> >> -Original Message-
> >> From: ffmpeg-devel  On Behalf Of
> >> Mark Thompson
> >> Sent: November 25, 2018 5:22 PM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: Re: [FFmpeg-devel] [INFO]AMD D3D11 to OpenCL interop
> >> extension for NV12 and P010 textures - split planes
> >>
> >> On 25/11/2018 21:28, Mironov, Mikhail wrote:
> >>> It seem that the failure is not in the new extension but before, in
> >>> the
> >> interop from D3D11 to OCL. It can happen in two cases: OCL
> >> device/context are created without D3D11 device or format of the texture
> is not supported.
> >> NV12 is supported. I went through the latest ffmpeg snapshot and
> >> found that function opencl_enumerate_d3d11_devices() looks correct,
> >> pointer to the function is set to
> >> OpenCLDeviceSelector::enumerate_devices member but I cannot find a
> >> call to selector->enumerate_devices(). Instead
> >> opencl_enumerate_devices() is called directly. So my guess is that
> >> created OCL device is not created from D3D11.
> >>
> >> Hmm, right - patch just sent to fix the selection call.
> >>
> >> It doesn't actually make any difference to this case, though, since
> >> the filter made it choose the right device anyway and
> >> CL_CONTEXT_D3D11_DEVICE_KHR was always set when deriving from
> D3D11.
> >> (It could only have made a difference if there were other conflicting
> >> D3D11 devices it could have picked incorrectly.)
> >>
> >>> Just in case OCL device creation sample:
> >>> https://github.com/GPUOpen-
> >> LibrariesAndSDKs/AMF/blob/master/amf/public
> >>> /samples/CPPSamples/common/DeviceOpenCL.cpp
> >>>
> >>> Regarding the new split extension: here is a working snippet:
> >>> cl_mem clImage2D = 0;
> >>> cl_mem clImages[AMF_SURFACE_MAX_PLANES]; // index can be not 0 if
> >>> texture is allocated as an array.
> >>>  clImage2D = clCreateFromD3D11Texture2DKHR(m_clContext, memflags,
> >>> pTexture, index, );
> >>
> >> Where is the comment about index being nonzero coming from there?
> >> Other callers to this definitely start from a zero index.  (I tried
> >> adding one to my index values but it didn't change the result.)
> >>
> >>>
> >>>  for(int i = 0; i < planesNumber; i++)
> >>>   {
> >>>   clImages[i] = clGetPlaneFromImageAMD(m_clContext, clImage2D,
> >>> (cl_uint)i, );
> >>>
> >>> }

Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Remove global_sidx from movenc params for live streaming.

2018-11-29 Thread Andrey Semashev

On 11/28/18 7:25 PM, Jeyapal, Karthick wrote:


On 11/28/18 4:41 PM, Andrey Semashev wrote:

The global_sidx flag causes errors like the following in movenc when media
segment removal is enabled via windos_size or remove_at_exit:

Non-consecutive fragments, writing incorrect sidx
Unable to re-open  output file for the second pass (faststart)

Removing global_sidx flag adds sidx atom to each moof fragment adding 
significant bitrate overhead.
Instead I have submitted a patch to handle this case cleanly in movenc. 
http://ffmpeg.org/pipermail/ffmpeg-devel/2018-November/236873.html
Please try the above patch and let me know if that will work for you.


Yes, that patch seems to fix the errors. Thanks.

On a slightly unrelated note, during testing, I've also seen different 
errors like these:


[AVFormatContext] Application provided duration: -1 / timestamp: 243456 
is out of range for mov/mp4 format

[AVFormatContext] pts has no value

These happen when media segments are rotated and file deletion is 
enabled. They don't seem to happen on every file rotation, though, and I 
can't find what could be causing them. These errors are present 
regardless of the global_sidx flag or your movenc patch. Do you have an 
idea what could be causing them?

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


Re: [FFmpeg-devel] [PATCH v2 2/2] avformat/dashenc: Added an option to ignore io errors

2018-11-29 Thread Andrey Semashev

On 11/28/18 8:06 PM, Karthick J wrote:

When dashenc has to run for long duration(say 24x7 live stream), one can enable 
this option to ignore the io failure of few segment's upload due to an 
intermittent network issues.
When the network connection recovers dashenc will continue with the upload of 
the current segments, leading to the recovery of the stream.
---
  doc/muxers.texi   |  3 +++
  libavformat/dashenc.c | 17 +++--
  2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a02ac01b55..f1cc6f5fee 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -300,6 +300,9 @@ If this flag is set, the dash segment files will be in in 
ISOBMFF format.
  @item webm
  If this flag is set, the dash segment files will be in in WebM format.
  
+@item -ignore_io_errors @var{ignore_io_errors}

+Ignore IO errors during open and write. Useful for long-duration runs with 
network output.
+
  @end table
  
  @anchor{framecrc}

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 2f403257c0..04218af6a6 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -138,6 +138,7 @@ typedef struct DASHContext {
  int index_correction;
  char *format_options_str;
  SegmentType segment_type_option;  /* segment type as specified in options 
*/
+int ignore_io_errors;
  } DASHContext;
  
  static struct codec_string {

@@ -846,7 +847,7 @@ static int write_manifest(AVFormatContext *s, int final)
  av_dict_free();
  if (ret < 0) {
  av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
temp_filename);
-return ret;
+return c->ignore_io_errors ? 0 : ret;
  }
  out = c->mpd_out;
  avio_printf(out, "\n");
@@ -937,7 +938,7 @@ static int write_manifest(AVFormatContext *s, int final)
  av_dict_free();
  if (ret < 0) {
  av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", 
temp_filename);
-return ret;
+return c->ignore_io_errors ? 0 : ret;
  }
  
  ff_hls_write_playlist_version(c->m3u8_out, 7);

@@ -1565,8 +1566,9 @@ static int dash_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  set_http_options(, c);
  ret = dashenc_io_open(s, >out, os->temp_path, );
  av_dict_free();
-if (ret < 0)
-return ret;
+if (ret < 0) {


Please, add error logging as well:

char errbuf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, errbuf, sizeof(errbuf));
av_log(s, (c->ignore_io_errors ? AV_LOG_WARNING : 
AV_LOG_ERROR), "Unable to open %s for writing: %s\n", os->temp_path, 
errbuf);



+return c->ignore_io_errors ? 0 : ret;
+}
  }
  
  //write out the data immediately in streaming mode

@@ -1577,9 +1579,11 @@ static int dash_write_packet(AVFormatContext *s, 
AVPacket *pkt)
  write_styp(os->ctx->pb);
  avio_flush(os->ctx->pb);
  len = avio_get_dyn_buf (os->ctx->pb, );
-avio_write(os->out, buf + os->written_len, len - os->written_len);
+if (os->out) {
+avio_write(os->out, buf + os->written_len, len - os->written_len);
+avio_flush(os->out);
+}
  os->written_len = len;
-avio_flush(os->out);
  }
  
  return ret;

@@ -1670,6 +1674,7 @@ static const AVOption options[] = {
  { "auto", "select segment file format based on codec", 0, AV_OPT_TYPE_CONST, {.i64 
= SEGMENT_TYPE_AUTO }, 0, UINT_MAX,   E, "segment_type"},
  { "mp4", "make segment file in ISOBMFF format", 0, AV_OPT_TYPE_CONST, {.i64 = 
SEGMENT_TYPE_MP4 }, 0, UINT_MAX,   E, "segment_type"},
  { "webm", "make segment file in WebM format", 0, AV_OPT_TYPE_CONST, {.i64 = 
SEGMENT_TYPE_WEBM }, 0, UINT_MAX,   E, "segment_type"},
+{ "ignore_io_errors", "Ignore IO errors during open and write. Useful for 
long-duration runs with network output", OFFSET(ignore_io_errors), AV_OPT_TYPE_BOOL, { .i64 = 
0 }, 0, 1, E },
  { NULL },
  };
  



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


Re: [FFmpeg-devel] [PATCH 2/2] avformat/mpegenc: extend muxing PCM-DVD to other depths

2018-11-29 Thread Paul B Mahol
On 11/29/18, Gyan Doshi  wrote:
> On 29-11-2018 05:09 PM, Paul B Mahol wrote:
>> Fixes #6783.
>>
>> Signed-off-by: Paul B Mahol 
>> ---
>>   libavformat/mpegenc.c | 27 +--
>>   1 file changed, 21 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
>> index 4c6fa67fb8..1389288b7f 100644
>> --- a/libavformat/mpegenc.c
>> +++ b/libavformat/mpegenc.c
>
>> +
>> +switch (st->codecpar->sample_rate) {
>> +case 48000: freq = 0; break;
>> +case 96000: freq = 1; break;
>> +case 44100: freq = 2; break;
>> +case 32000: freq = 3; break;
>> +default:
>> +av_log(ctx, AV_LOG_ERROR, "Unsupported sample
>> rate.\n");
>> +return AVERROR(EINVAL);
>> +}
> It will be helpful to the users to mention the supported rates.

Already mentioned in encoder.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avformat/mpegenc: extend muxing PCM-DVD to other depths

2018-11-29 Thread Gyan Doshi

On 29-11-2018 05:09 PM, Paul B Mahol wrote:

Fixes #6783.

Signed-off-by: Paul B Mahol 
---
  libavformat/mpegenc.c | 27 +--
  1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 4c6fa67fb8..1389288b7f 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c



+
+switch (st->codecpar->sample_rate) {
+case 48000: freq = 0; break;
+case 96000: freq = 1; break;
+case 44100: freq = 2; break;
+case 32000: freq = 3; break;
+default:
+av_log(ctx, AV_LOG_ERROR, "Unsupported sample rate.\n");
+return AVERROR(EINVAL);
+}

It will be helpful to the users to mention the supported rates.

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


Re: [FFmpeg-devel] [PATCH] lavc/opusenc: add frame_alloc and frame_count check to quit encode

2018-11-29 Thread Fu, Linjie
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Hendrik Leppkes
> Sent: Thursday, November 29, 2018 19:40
> To: FFmpeg development discussions and patches  de...@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] lavc/opusenc: add frame_alloc and
> frame_count check to quit encode
> 
> On Thu, Nov 29, 2018 at 10:14 AM Linjie Fu  wrote:
> >
> > Add frame_alloc and frame_count check in opus_encode_frame to avoid
> > the infinite loop issue.
> >
> > Fix #7578.
> >
> > Signed-off-by: Linjie Fu 
> > ---
> >  libavcodec/opusenc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
> > index 578785f4b4..7146968fc8 100644
> > --- a/libavcodec/opusenc.c
> > +++ b/libavcodec/opusenc.c
> > @@ -543,7 +543,7 @@ static int opus_encode_frame(AVCodecContext
> *avctx, AVPacket *avpkt,
> >  ff_bufqueue_add(avctx, >bufqueue, av_frame_clone(frame));
> >  } else {
> >  ff_opus_psy_signal_eof(>psyctx);
> > -if (!s->afq.remaining_samples)
> > +if (!s->afq.remaining_samples || (!s->afq.frame_alloc && !s-
> >afq.frame_count))
> >  return 0; /* We've been flushed and there's nothing left to 
> > encode
> */
> >  }
> 
> What does remaining_samples contain if it wasn't even allocated?

remaining_samples equals 120 in this case.

Investigate this:
remaining_samples was initialized in ff_af_queue_init():
afq->remaining_samples = avctx->initial_padding;

And avctx->initial_padding is a hardcode which equals 120  in 
opus_encode_init():
avctx->initial_padding = 120;

Thanks,
- Linjie

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


Re: [FFmpeg-devel] [PATCH] lavc/opusenc: add frame_alloc and frame_count check to quit encode

2018-11-29 Thread Hendrik Leppkes
On Thu, Nov 29, 2018 at 10:14 AM Linjie Fu  wrote:
>
> Add frame_alloc and frame_count check in opus_encode_frame to avoid
> the infinite loop issue.
>
> Fix #7578.
>
> Signed-off-by: Linjie Fu 
> ---
>  libavcodec/opusenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
> index 578785f4b4..7146968fc8 100644
> --- a/libavcodec/opusenc.c
> +++ b/libavcodec/opusenc.c
> @@ -543,7 +543,7 @@ static int opus_encode_frame(AVCodecContext *avctx, 
> AVPacket *avpkt,
>  ff_bufqueue_add(avctx, >bufqueue, av_frame_clone(frame));
>  } else {
>  ff_opus_psy_signal_eof(>psyctx);
> -if (!s->afq.remaining_samples)
> +if (!s->afq.remaining_samples || (!s->afq.frame_alloc && 
> !s->afq.frame_count))
>  return 0; /* We've been flushed and there's nothing left to 
> encode */
>  }

What does remaining_samples contain if it wasn't even allocated?

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


[FFmpeg-devel] [PATCH 1/2] avcodec: add PCM-DVD encoder

2018-11-29 Thread Paul B Mahol
Fixes #6784.

Signed-off-by: Paul B Mahol 
---
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/pcm-dvdenc.c | 197 
 3 files changed, 199 insertions(+)
 create mode 100644 libavcodec/pcm-dvdenc.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2840a8069f..5feadac729 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -737,6 +737,7 @@ OBJS-$(CONFIG_PCM_ALAW_DECODER)   += pcm.o
 OBJS-$(CONFIG_PCM_ALAW_ENCODER)   += pcm.o
 OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o
 OBJS-$(CONFIG_PCM_DVD_DECODER)+= pcm-dvd.o
+OBJS-$(CONFIG_PCM_DVD_ENCODER)+= pcm-dvdenc.o
 OBJS-$(CONFIG_PCM_F16LE_DECODER)  += pcm.o
 OBJS-$(CONFIG_PCM_F24LE_DECODER)  += pcm.o
 OBJS-$(CONFIG_PCM_F32BE_DECODER)  += pcm.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2c17db5a70..d70646e91a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -494,6 +494,7 @@ extern AVCodec ff_xma2_decoder;
 extern AVCodec ff_pcm_alaw_encoder;
 extern AVCodec ff_pcm_alaw_decoder;
 extern AVCodec ff_pcm_bluray_decoder;
+extern AVCodec ff_pcm_dvd_encoder;
 extern AVCodec ff_pcm_dvd_decoder;
 extern AVCodec ff_pcm_f16le_decoder;
 extern AVCodec ff_pcm_f24le_decoder;
diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c
new file mode 100644
index 00..d26eaf071c
--- /dev/null
+++ b/libavcodec/pcm-dvdenc.c
@@ -0,0 +1,197 @@
+/*
+ * LPCM codecs for PCM formats found in Video DVD streams
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "internal.h"
+
+typedef struct PCMDVDContext {
+uint8_t header[3];   // Header added to every frame
+int block_size;  // Size of a block of samples in bytes
+int samples_per_block;   // Number of samples per channel per block
+int groups_per_block;// Number of 20/24-bit sample groups per block
+uint8_t *extra_samples;  // Pointer to leftover samples from a frame
+int extra_sample_count;  // Number of leftover samples in the buffer
+} PCMDVDContext;
+
+static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
+{
+PCMDVDContext *s = avctx->priv_data;
+int quant, freq, frame_size;
+
+switch (avctx->sample_rate) {
+case 48000:
+freq = 0;
+break;
+case 96000:
+freq = 1;
+break;
+}
+
+switch (avctx->sample_fmt) {
+case AV_SAMPLE_FMT_S16:
+avctx->bits_per_coded_sample = 16;
+quant = 0;
+break;
+case AV_SAMPLE_FMT_S32:
+avctx->bits_per_coded_sample = 24;
+quant = 2;
+break;
+}
+
+avctx->bits_per_coded_sample = 16 + quant * 4;
+avctx->block_align   = avctx->channels * 
avctx->bits_per_coded_sample / 8;
+avctx->bit_rate  = avctx->block_align * 8LL * 
avctx->sample_rate;
+if (avctx->bit_rate > 980) {
+av_log(avctx, AV_LOG_ERROR, "Too big bitrate: reduce sample rate, 
bitdepth or channels.\n");
+return AVERROR(EINVAL);
+}
+
+if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
+s->samples_per_block = 1;
+s->block_size= avctx->channels * 2;
+frame_size   = 2008 / s->block_size;
+} else {
+switch (avctx->channels) {
+case 1:
+case 2:
+case 4:
+/* one group has all the samples needed */
+s->block_size= 4 * avctx->bits_per_coded_sample / 8;
+s->samples_per_block = 4 / avctx->channels;
+s->groups_per_block  = 1;
+break;
+case 8:
+/* two groups have all the samples needed */
+s->block_size= 8 * avctx->bits_per_coded_sample / 8;
+s->samples_per_block = 1;
+s->groups_per_block  = 2;
+break;
+default:
+/* need avctx->channels groups */
+s->block_size= 4 * avctx->channels *
+   avctx->bits_per_coded_sample / 8;
+s->samples_per_block = 4;
+s->groups_per_block  = avctx->channels;
+break;
+   

[FFmpeg-devel] [PATCH 2/2] avformat/mpegenc: extend muxing PCM-DVD to other depths

2018-11-29 Thread Paul B Mahol
Fixes #6783.

Signed-off-by: Paul B Mahol 
---
 libavformat/mpegenc.c | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 4c6fa67fb8..1389288b7f 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -364,12 +364,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
 stream->id = ac3_id++;
 } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) {
 stream->id = dts_id++;
-} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ||
-   st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
-if (st->codecpar->bits_per_coded_sample != 16) {
-av_log(ctx, AV_LOG_ERROR, "Only 16 bit LPCM streams can be 
muxed.\n");
-goto fail;
-}
+} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {
 stream->id = lpcm_id++;
 for (j = 0; j < 4; j++) {
 if (lpcm_freq_tab[j] == st->codecpar->sample_rate)
@@ -392,6 +387,26 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
 stream->lpcm_header[1] = (st->codecpar->channels - 1) | (j << 
4);
 stream->lpcm_header[2] = 0x80;
 stream->lpcm_align = st->codecpar->channels * 2;
+} else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
+int freq;
+
+switch (st->codecpar->sample_rate) {
+case 48000: freq = 0; break;
+case 96000: freq = 1; break;
+case 44100: freq = 2; break;
+case 32000: freq = 3; break;
+default:
+av_log(ctx, AV_LOG_ERROR, "Unsupported sample rate.\n");
+return AVERROR(EINVAL);
+}
+
+stream->lpcm_header[0] = 0x0c;
+stream->lpcm_header[1] = (freq << 4) |
+ 
(((st->codecpar->bits_per_coded_sample - 16) / 4) << 6) |
+ st->codecpar->channels - 1;
+stream->lpcm_header[2] = 0x80;
+stream->id = lpcm_id++;
+stream->lpcm_align = st->codecpar->channels * 
st->codecpar->bits_per_coded_sample / 8;
 } else {
 stream->id = mpa_id++;
 }
-- 
2.17.1

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


Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Fix file URI handling when deleting files.

2018-11-29 Thread Andrey Semashev

On 11/29/18 2:15 PM, Andrey Semashev wrote:

On 11/28/18 7:47 PM, Jeyapal, Karthick wrote:


On 11/28/18 4:46 PM, Andrey Semashev wrote:
The URI used to open the output streams may be an actual URI with 
"file" scheme,

according to https://tools.ietf.org/html/rfc8089. This commit makes file
deletion routine recognize file URIs and extract the actual 
filesystem path

from it.
There is already some code in ffmpeg to handle this. It is present in 
file_delete() function in file.c.
We will need to avoid code duplication for the same functionality. One 
option could be to call avpriv_io_delete() function instead of calling 
unlink, so that file_delete function gets called.
Calling avpriv_io_delete will also make the delete functionality 
easily extendable for other output protocols.


That would be fine with me, but I'm using Linux. Looking at file_delete 
(in libavformat/file.c), it looks like it will only work on POSIX 
systems but not on Windows, since it doesn't have unistd.h. Am I 
correct? And if so, is avpriv_io_delete still the preferred approach?


Also, that code doesn't seem to support the URI with an authority field 
and doesn't check the special "localhost" case.

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


Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Fix file URI handling when deleting files.

2018-11-29 Thread Andrey Semashev

On 11/28/18 7:47 PM, Jeyapal, Karthick wrote:


On 11/28/18 4:46 PM, Andrey Semashev wrote:

The URI used to open the output streams may be an actual URI with "file" scheme,
according to https://tools.ietf.org/html/rfc8089. This commit makes file
deletion routine recognize file URIs and extract the actual filesystem path
from it.

There is already some code in ffmpeg to handle this. It is present in 
file_delete() function in file.c.
We will need to avoid code duplication for the same functionality. One option 
could be to call avpriv_io_delete() function instead of calling unlink, so that 
file_delete function gets called.
Calling avpriv_io_delete will also make the delete functionality easily 
extendable for other output protocols.


That would be fine with me, but I'm using Linux. Looking at file_delete 
(in libavformat/file.c), it looks like it will only work on POSIX 
systems but not on Windows, since it doesn't have unistd.h. Am I 
correct? And if so, is avpriv_io_delete still the preferred approach?

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


Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Write media trailers when DASH trailer is written.

2018-11-29 Thread Andrey Semashev

On 11/29/18 9:27 AM, Jeyapal, Karthick wrote:


On 11/28/18 5:13 PM, Andrey Semashev wrote:

This commit ensures that all (potentially, long) filesystem activity is
performed when the user calls av_write_trailer on the DASH libavformat
context, not when freeing the context. Also, this defers media segment
deletion until after the media trailers are written.
---
  libavformat/dashenc.c | 19 ++-
  1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 6ce70e0076..e1c959dc89 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -424,8 +424,6 @@ static void dash_free(AVFormatContext *s)
  return;
  for (i = 0; i < s->nb_streams; i++) {
  OutputStream *os = >streams[i];
-if (os->ctx && os->ctx_inited)
-av_write_trailer(os->ctx);
  if (os->ctx && os->ctx->pb)
  ffio_free_dyn_buf(>ctx->pb);
  ff_format_io_close(s, >out);
@@ -1420,13 +1418,11 @@ static int dash_flush(AVFormatContext *s, int final, 
int stream)
  os->pos += range_length;
  }
  
-if (c->window_size || (final && c->remove_at_exit)) {

+if (c->window_size) {
  for (i = 0; i < s->nb_streams; i++) {
  OutputStream *os = >streams[i];
  int j;
  int remove = os->nb_segments - c->window_size - 
c->extra_window_size;
-if (final && c->remove_at_exit)
-remove = os->nb_segments;

Is there any reason for deferring the delete after write_trailer.
Because if the file is getting deleted immediately, why should we bother about 
write_trailer? Is it causing any issues?
I am asking this, because the segment deletion code is getting duplicated due 
to this change. I am trying to avoid code duplication as much as possible.


This was partly in attempt to resolve the movenc errors caused by 
global_sidx. It did not completely remove the errors, but it seemed to 
have reduced them.


But mostly it is a logic sanity change. I believe it is incorrect to try 
writing a trailer to a non-existant file, and the downstream writer 
would be right to complain. If there is no file then you shouldn't be 
writing the trailer, but, AFAIK, that is not correct by libavformat 
usage protocol (i.e. you must write a trailer if you have written the 
header). Thus this change.


If you're worried about code duplication, I could move the segment 
deletion loop to a separate function.

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


Re: [FFmpeg-devel] [PATCH] lavc/opusenc: add frame_alloc and frame_count check to quit encode

2018-11-29 Thread Paul B Mahol
On 11/29/18, Linjie Fu  wrote:
> Add frame_alloc and frame_count check in opus_encode_frame to avoid
> the infinite loop issue.
>
> Fix #7578.
>
> Signed-off-by: Linjie Fu 
> ---
>  libavcodec/opusenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
> index 578785f4b4..7146968fc8 100644
> --- a/libavcodec/opusenc.c
> +++ b/libavcodec/opusenc.c
> @@ -543,7 +543,7 @@ static int opus_encode_frame(AVCodecContext *avctx,
> AVPacket *avpkt,
>  ff_bufqueue_add(avctx, >bufqueue, av_frame_clone(frame));
>  } else {
>  ff_opus_psy_signal_eof(>psyctx);
> -if (!s->afq.remaining_samples)
> +if (!s->afq.remaining_samples || (!s->afq.frame_alloc &&
> !s->afq.frame_count))
>  return 0; /* We've been flushed and there's nothing left to
> encode */

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


[FFmpeg-devel] [PATCH] configure: enable mipsfpu for loongson platform.

2018-11-29 Thread Shiyou Yin
mipsfpu supported by loongson 3a2000,3a3000,3a4000,2k1000, Fate tests passed.
---
 configure | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configure b/configure
index 3e9222e..54b7e11 100755
--- a/configure
+++ b/configure
@@ -4848,7 +4848,6 @@ elif enabled mips; then
 enable fast_cmov
 enable fast_unaligned
 disable aligned_stack
-disable mipsfpu
 disable mipsdsp
 disable mipsdspr2
 # When gcc version less than 5.3.0, add 
-fno-expensive-optimizations flag.
-- 
2.1.0


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


Re: [FFmpeg-devel] [PATCH] lavf/dashenc: Write media trailers when DASH trailer is written.

2018-11-29 Thread Andrey Semashev

On 11/29/18 9:27 AM, Jeyapal, Karthick wrote:


On 11/28/18 5:13 PM, Andrey Semashev wrote:

This commit ensures that all (potentially, long) filesystem activity is
performed when the user calls av_write_trailer on the DASH libavformat
context, not when freeing the context. Also, this defers media segment
deletion until after the media trailers are written.
---
  libavformat/dashenc.c | 19 ++-
  1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 6ce70e0076..e1c959dc89 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -424,8 +424,6 @@ static void dash_free(AVFormatContext *s)
  return;
  for (i = 0; i < s->nb_streams; i++) {
  OutputStream *os = >streams[i];
-if (os->ctx && os->ctx_inited)
-av_write_trailer(os->ctx);
  if (os->ctx && os->ctx->pb)
  ffio_free_dyn_buf(>ctx->pb);
  ff_format_io_close(s, >out);
@@ -1420,13 +1418,11 @@ static int dash_flush(AVFormatContext *s, int final, 
int stream)
  os->pos += range_length;
  }
  
-if (c->window_size || (final && c->remove_at_exit)) {

+if (c->window_size) {
  for (i = 0; i < s->nb_streams; i++) {
  OutputStream *os = >streams[i];
  int j;
  int remove = os->nb_segments - c->window_size - 
c->extra_window_size;
-if (final && c->remove_at_exit)
-remove = os->nb_segments;

Is there any reason for deferring the delete after write_trailer.
Because if the file is getting deleted immediately, why should we bother about 
write_trailer? Is it causing any issues?
I am asking this, because the segment deletion code is getting duplicated due 
to this change. I am trying to avoid code duplication as much as possible.

  if (remove > 0) {
  for (j = 0; j < remove; j++) {
  char filename[1024];
@@ -1599,11 +1595,24 @@ static int dash_write_trailer(AVFormatContext *s)
  }
  dash_flush(s, 1, -1);
  
+for (int i = 0; i < s->nb_streams; ++i) {

Can we merge this loop with the below loop for deleting init segments. The "if" 
condition for remove_at_exit, could be moved inside the merged loop.


I usually don't like conditions on constants inside loops, but I can do 
that.



+OutputStream *os = >streams[i];
+if (os->ctx && os->ctx_inited) {
+av_write_trailer(os->ctx);
+}
+}
+
  if (c->remove_at_exit) {
  char filename[1024];
  int i;
  for (i = 0; i < s->nb_streams; i++) {
  OutputStream *os = >streams[i];
+for (int j = 0; j < os->nb_segments; ++j) {
+snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
os->segments[j]->file);
+dashenc_delete_file(s, filename);
+av_free(os->segments[j]);
+}
+os->nb_segments = 0;
  snprintf(filename, sizeof(filename), "%s%s", c->dirname, 
os->initfile);
  dashenc_delete_file(s, filename);
  }




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


[FFmpeg-devel] [PATCH] lavc/opusenc: add frame_alloc and frame_count check to quit encode

2018-11-29 Thread Linjie Fu
Add frame_alloc and frame_count check in opus_encode_frame to avoid
the infinite loop issue.

Fix #7578.

Signed-off-by: Linjie Fu 
---
 libavcodec/opusenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index 578785f4b4..7146968fc8 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -543,7 +543,7 @@ static int opus_encode_frame(AVCodecContext *avctx, 
AVPacket *avpkt,
 ff_bufqueue_add(avctx, >bufqueue, av_frame_clone(frame));
 } else {
 ff_opus_psy_signal_eof(>psyctx);
-if (!s->afq.remaining_samples)
+if (!s->afq.remaining_samples || (!s->afq.frame_alloc && 
!s->afq.frame_count))
 return 0; /* We've been flushed and there's nothing left to encode 
*/
 }
 
-- 
2.17.1

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


[FFmpeg-devel] [PATCH v4 9/9] lavc/qsvenc: add BRC sliding window setting

2018-11-29 Thread Zhong Li
WinBRCMaxAvgKbps is to specify maximum average bitrate over a
sliding window with size of WinBRCSize

WinBRCMaxAvgKbps will be ignored in CBR mode and equal to TargetKbps.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c  | 7 +++
 libavcodec/qsvenc.h  | 3 +++
 libavcodec/qsvenc_h264.c | 5 +
 3 files changed, 15 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2dd41d7..9c2f2a7 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -263,6 +263,11 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 #endif
 #endif
 
+#if QSV_HAVE_CO3
+av_log(avctx, AV_LOG_VERBOSE,"WinBRCMaxAvgKbps: %"PRIu32"; WinBRCSize: 
%"PRId32"\n",
+   co3->WinBRCMaxAvgKbps, co3->WinBRCSize);
+#endif
+
 if (avctx->codec_id == AV_CODEC_ID_H264) {
 av_log(avctx, AV_LOG_VERBOSE, "Entropy coding: %s; 
MaxDecFrameBuffering: %"PRIu16"\n",
co->CAVLC == MFX_CODINGOPTION_ON ? "CAVLC" : "CABAC", 
co->MaxDecFrameBuffering);
@@ -723,6 +728,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #if QSV_HAVE_CO3
 q->extco3.Header.BufferId  = MFX_EXTBUFF_CODING_OPTION3;
 q->extco3.Header.BufferSz  = sizeof(q->extco3);
+q->extco3.WinBRCMaxAvgKbps = q->win_brc_max_avg_kbps;
+q->extco3.WinBRCSize   = q->win_brc_size;
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco3;
 #endif
 }
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 075c86b..1f9769e 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -168,6 +168,9 @@ typedef struct QSVEncContext {
 int repeat_pps;
 int num_mb_per_slice;
 
+int win_brc_max_avg_kbps;
+int win_brc_size;
+
 int a53_cc;
 
 #if QSV_HAVE_MF
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 693a9e3..d943ede 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -158,6 +158,11 @@ static const AVOption options[] = {
 { "repeat_pps", "repeat pps for every frame", OFFSET(qsv.repeat_pps), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
 { "num_mb_per_slice","Suggested macroblocks numbers of each slice", 
OFFSET(qsv.num_mb_per_slice), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 
+#if QSV_HAVE_CO3
+{ "win_max_rate", "maximum average bitrate (in kbps) over a sliding 
window", OFFSET(qsv.win_brc_max_avg_kbps), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 
INT_MAX, VE },
+{ "win_brc_size", "sliding window size of win_max_rate", 
OFFSET(qsv.win_brc_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
+#endif
+
 { NULL },
 };
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 5/9] lavc/qsvenc: dump log for frame rate

2018-11-29 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 781498c..91b8905 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -263,6 +263,10 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
print_threestate(co->NalHrdConformance), 
print_threestate(co->SingleSeiNalUnit),
print_threestate(co->VuiVclHrdParameters), 
print_threestate(co->VuiNalHrdParameters));
 }
+
+av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: 
%"PRIu32" \n",
+   info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
+
 }
 
 static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)
-- 
2.7.4

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


[FFmpeg-devel] [PATCH] ff_connect_parallel: do not fail when getsockopt(SO_ERROR) returns EISCONN

2018-11-29 Thread Peter Ross
for O_NONBLOCK connect(), the watt32 socket library returns EISCONN when 
connection is established
---

watt32 is a DOS/Windows BSD socket library.

it seems iOS suffers this EISCON problem too, but i am unsure why it hasn't 
been reported here before.
i don't have iOS device to test.
https://github.com/warmcat/libwebsockets/issues/17


 libavformat/network.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index 5664455d18..783de34a98 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -475,7 +475,7 @@ int ff_connect_parallel(struct addrinfo *addrs, int 
timeout_ms_per_address,
 last_err = ff_neterrno();
 else if (last_err != 0)
 last_err = AVERROR(last_err);
-if (last_err == 0) {
+if (last_err == 0 || last_err == AVERROR(EISCONN)) {
 // Everything is ok, we seem to have a successful
 // connection. Close other sockets and return this one.
 for (j = 0; j < nb_attempts; j++)
-- 
2.17.1

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


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


[FFmpeg-devel] [PATCH v4 6/9] lavc/qsvenc: add an option to set h264 pps for every frame

2018-11-29 Thread Zhong Li
RepeatPPS is enabled by default in mfx. It is not necessary mostly and
wasting encoding bits.
Add an option to control it and disable it by default.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c  | 1 +
 libavcodec/qsvenc.h  | 2 ++
 libavcodec/qsvenc_h264.c | 2 ++
 libavcodec/version.h | 2 +-
 4 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 91b8905..c2e7030 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -654,6 +654,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 #if QSV_VERSION_ATLEAST(1, 8)
 q->extco2.LookAheadDS = q->look_ahead_downsampling;
+q->extco2.RepeatPPS   = q->repeat_pps ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
 
 #if FF_API_PRIVATE_OPT
 FF_DISABLE_DEPRECATION_WARNINGS
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index fbdc199..4316a10 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -162,6 +162,8 @@ typedef struct QSVEncContext {
 int int_ref_qp_delta;
 int recovery_point_sei;
 
+int repeat_pps;
+
 int a53_cc;
 
 #if QSV_HAVE_MF
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index ac7023e..13217b4 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -155,6 +155,8 @@ static const AVOption options[] = {
 { "auto"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_AUTO }, 
INT_MIN, INT_MAX, VE, "mfmode" },
 #endif
 
+{ "repeat_pps", "repeat pps for every frame", OFFSET(qsv.repeat_pps), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+
 { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 5e0b188..fbfe1fb 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  40
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 7/9] lavc/qsvenc: add an option to set MB numbers of each slice

2018-11-29 Thread Zhong Li
This option specifies suggested macroblocks numbers in each slice.
MSDK may adjust it based on platform capability.
And slice_number will be ignored if this option set to a non-zero
value.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c  | 1 +
 libavcodec/qsvenc.h  | 1 +
 libavcodec/qsvenc_h264.c | 1 +
 3 files changed, 3 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index c2e7030..ba74821 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -655,6 +655,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #if QSV_VERSION_ATLEAST(1, 8)
 q->extco2.LookAheadDS = q->look_ahead_downsampling;
 q->extco2.RepeatPPS   = q->repeat_pps ? MFX_CODINGOPTION_ON : 
MFX_CODINGOPTION_OFF;
+q->extco2.NumMbPerSlice = q->num_mb_per_slice;
 
 #if FF_API_PRIVATE_OPT
 FF_DISABLE_DEPRECATION_WARNINGS
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 4316a10..c2aa88e 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -163,6 +163,7 @@ typedef struct QSVEncContext {
 int recovery_point_sei;
 
 int repeat_pps;
+int num_mb_per_slice;
 
 int a53_cc;
 
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 13217b4..693a9e3 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -156,6 +156,7 @@ static const AVOption options[] = {
 #endif
 
 { "repeat_pps", "repeat pps for every frame", OFFSET(qsv.repeat_pps), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+{ "num_mb_per_slice","Suggested macroblocks numbers of each slice", 
OFFSET(qsv.num_mb_per_slice), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
 
 { NULL },
 };
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 4/9] lavc/qsvenc: make hevc alignment same as h264 for 1.19+ version

2018-11-29 Thread Zhong Li
It is to clean up to the code and To-Do list.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 3b10980..781498c 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -446,6 +446,12 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 int ret;
 mfxVersion ver;
 
+ret = MFXQueryVersion(q->session,);
+if (ret != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error getting the session handle\n");
+return AVERROR_UNKNOWN;
+}
+
 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
 if (ret < 0)
 return AVERROR_BUG;
@@ -494,10 +500,10 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 q->param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
 q->param.mfx.FrameInfo.Shift  = desc->comp[0].depth > 8;
 
-// TODO:  detect version of MFX--if the minor version is greater than
-// or equal to 19, then can use the same alignment settings as H.264
-// for HEVC
-q->width_align = avctx->codec_id == AV_CODEC_ID_HEVC ? 32 : 16;
+// If the minor version is greater than or equal to 19,
+// then can use the same alignment settings as H.264 for HEVC
+q->width_align = (avctx->codec_id != AV_CODEC_ID_HEVC ||
+  QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 19)) ? 16 : 32;
 q->param.mfx.FrameInfo.Width = FFALIGN(avctx->width, q->width_align);
 
 if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
@@ -677,8 +683,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
 #if QSV_HAVE_MF
-ret = MFXQueryVersion(q->session,);
-if (ret >= MFX_ERR_NONE && QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 
25)) {
+if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
 q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
 q->extmfp.Header.BufferSz = sizeof(q->extmfp);
 
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 3/9] lavc/qsvenc: remove redundant code

2018-11-29 Thread Zhong Li
Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 3946c1d..3b10980 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -444,6 +444,7 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 const AVPixFmtDescriptor *desc;
 float quant;
 int ret;
+mfxVersion ver;
 
 ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
 if (ret < 0)
@@ -611,8 +612,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco;
 
-#if QSV_HAVE_CO2
 if (avctx->codec_id == AV_CODEC_ID_H264) {
+#if QSV_HAVE_CO2
 q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
 q->extco2.Header.BufferSz = sizeof(q->extco2);
 
@@ -641,11 +642,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 q->extco2.Trellis = q->trellis;
 #endif
 
-#if QSV_HAVE_LA_DS
+#if QSV_VERSION_ATLEAST(1, 8)
 q->extco2.LookAheadDS = q->look_ahead_downsampling;
-#endif
 
-#if QSV_HAVE_BREF_TYPE
 #if FF_API_PRIVATE_OPT
 FF_DISABLE_DEPRECATION_WARNINGS
 if (avctx->b_frame_strategy >= 0)
@@ -675,11 +674,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 #endif
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco2;
-}
 #endif
+
 #if QSV_HAVE_MF
-if (avctx->codec_id == AV_CODEC_ID_H264) {
-mfxVersionver;
 ret = MFXQueryVersion(q->session,);
 if (ret >= MFX_ERR_NONE && QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 
25)) {
 q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
@@ -689,8 +686,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_log(avctx,AV_LOG_VERBOSE,"MFMode:%d\n", q->extmfp.MFMode);
 q->extparam_internal[q->nb_extparam_internal++] = 
(mfxExtBuffer *)>extmfp;
 }
-}
 #endif
+}
 }
 
 if (!check_enc_param(avctx,q)) {
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 1/9] lavc/qsvenc: enable ICQ and ICQ_LA on Linux

2018-11-29 Thread Zhong Li
ICQ/ICQ_LA are enabled with MSDK V1.28

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 50cc426..055b4a6 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -53,7 +53,7 @@
 #define QSV_HAVE_MF 0
 #else
 #define QSV_HAVE_AVBR   0
-#define QSV_HAVE_ICQ0
+#define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 28)
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   0
 #define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 2/9] lavc/qsvenc: add forced_idr option

2018-11-29 Thread Zhong Li
This option can be used to repect original input I/IDR frame type.

Signed-off-by: Zhong Li 
---
 libavcodec/qsvenc.c | 7 +++
 libavcodec/qsvenc.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 948751d..3946c1d 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1192,6 +1192,13 @@ static int encode_frame(AVCodecContext *avctx, 
QSVEncContext *q,
 if (qsv_frame) {
 surf = _frame->surface;
 enc_ctrl = _frame->enc_ctrl;
+memset(enc_ctrl, 0, sizeof(mfxEncodeCtrl));
+
+if (frame->pict_type == AV_PICTURE_TYPE_I) {
+enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
+if (q->forced_idr)
+enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
+}
 }
 
 ret = av_new_packet(_pkt, q->packet_size);
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 055b4a6..fbdc199 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -87,6 +87,7 @@
 { "adaptive_i", "Adaptive I-frame placement", 
OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "adaptive_b", "Adaptive B-frame placement", 
OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
 { "b_strategy", "Strategy to choose between I/P/B-frames", 
OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1, VE 
}, \
+{ "forced_idr", "Forcing I frames as IDR frames", 
OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0  },  0,  1, VE 
}, \
 
 typedef int SetEncodeCtrlCB (AVCodecContext *avctx,
  const AVFrame *frame, mfxEncodeCtrl* enc_ctrl);
@@ -168,6 +169,7 @@ typedef struct QSVEncContext {
 #endif
 char *load_plugins;
 SetEncodeCtrlCB *set_encode_ctrl_cb;
+int forced_idr;
 } QSVEncContext;
 
 int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);
-- 
2.7.4

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


[FFmpeg-devel] [PATCH v4 0/9] qsv encoder enhancement and code refine

2018-11-29 Thread Zhong Li
v4: add QVBR mode support and BRC sliding window setting

Zhong Li (9):
  lavc/qsvenc: enable ICQ and ICQ_LA on Linux
  lavc/qsvenc: add forced_idr option
  lavc/qsvenc: remove redundant code
  lavc/qsvenc: make hevc alignment same as h264 for 1.19+ version
  lavc/qsvenc: dump log for frame rate
  lavc/qsvenc: add an option to set h264 pps for every frame
  lavc/qsvenc: add an option to set MB numbers of each slice
  lavc/qsvenc: enable QVBR mode
  lavc/qsvenc: add BRC sliding window setting

 libavcodec/qsvenc.c  | 87 +++-
 libavcodec/qsvenc.h  | 17 --
 libavcodec/qsvenc_h264.c |  8 +
 libavcodec/version.h |  2 +-
 4 files changed, 95 insertions(+), 19 deletions(-)

-- 
2.7.4

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