Re: [FFmpeg-devel] [PATCH] Add spherical_mapping command-line argument to ffmpeg.
On Mon, Jun 5, 2017 at 4:46 PM Aaron Colwell wrote > Attached a new patch that fixes a bug and the indentation in the previous > patch. This should be good now. Sorry for the spam. > > Aaron > > On Mon, Jun 5, 2017 at 12:32 PM Aaron Colwell wrote: > [...] Yeah this version looks much better, thanks for the update. -- Vittorio ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] Add spherical_mapping command-line argument to ffmpeg.
Attached a new patch that fixes a bug and the indentation in the previous patch. This should be good now. Sorry for the spam. Aaron On Mon, Jun 5, 2017 at 12:32 PM Aaron Colwellwrote: > Comments below.. > > On Mon, Jun 5, 2017 at 12:02 PM Vittorio Giovara < > vittorio.giov...@gmail.com> wrote: > >> Hey Aaron >> > This allows adding AVSphericalMapping information to files >> > that don't already have it. >> > --- >> > ffmpeg.h | 3 ++ >> > ffmpeg_opt.c | 29 - >> > libavutil/spherical.c | 113 >> ++ >> > libavutil/spherical.h | 14 +++ >> > 4 files changed, 158 insertions(+), 1 deletion(-) >> > >> > diff --git a/ffmpeg.h b/ffmpeg.h >> > index a806445e0d..43a28d874f 100644 >> > --- a/ffmpeg.h >> > +++ b/ffmpeg.h >> > @@ -44,6 +44,7 @@ >> > #include "libavutil/fifo.h" >> > #include "libavutil/pixfmt.h" >> > #include "libavutil/rational.h" >> > +#include "libavutil/spherical.h" >> > #include "libavutil/threadmessage.h" >> > >> > #include "libswresample/swresample.h" >> > @@ -228,6 +229,8 @@ typedef struct OptionsContext { >> > intnb_time_bases; >> > SpecifierOpt *enc_time_bases; >> > intnb_enc_time_bases; >> > +SpecifierOpt *spherical_mappings; >> > +intnb_spherical_mappings; >> > } OptionsContext; >> > >> > typedef struct InputFilter { >> > diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c >> > index c997ea8faf..666b3791b7 100644 >> > --- a/ffmpeg_opt.c >> > +++ b/ffmpeg_opt.c >> > @@ -1514,12 +1514,29 @@ static void >> check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, >> > } >> > } >> > >> > +static int set_spherical_mapping(const char* opt, AVStream* st) { >> > + size_t spherical_mapping_size = 0; >> > + AVSphericalMapping *spherical_mapping = NULL; >> > + >> > + int ret = av_spherical_parse_option(opt, _mapping, >> > + _mapping_size); >> > + if (ret >= 0) { >> > +ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, >> spherical_mapping, spherical_mapping_size); >> > + >> > +if (ret < 0) { >> > + av_freep(_mapping); >> > +} >> > + } >> > + >> > + return ret; >> > +} >> > + >> > static OutputStream *new_video_stream(OptionsContext *o, >> AVFormatContext *oc, int source_index) >> > { >> > AVStream *st; >> > OutputStream *ost; >> > AVCodecContext *video_enc; >> > -char *frame_rate = NULL, *frame_aspect_ratio = NULL; >> > +char *frame_rate = NULL, *frame_aspect_ratio = NULL, >> *spherical_mapping = NULL; >> > >> > ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); >> > st = ost->st; >> > @@ -1546,6 +1563,12 @@ static OutputStream >> *new_video_stream(OptionsContext *o, AVFormatContext *oc, in >> > >> > MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, >> st); >> > MATCH_PER_STREAM_OPT(filters,str, ost->filters,oc, >> st); >> > +MATCH_PER_STREAM_OPT(spherical_mappings, str, spherical_mapping, >> oc, st); >> > + >> > +if (spherical_mapping && set_spherical_mapping(spherical_mapping, >> st) < 0) { >> > +av_log(NULL, AV_LOG_FATAL, "Invalid spherical_mapping: %s\n", >> spherical_mapping); >> > +exit_program(1); >> > +} >> > >> > if (!ost->stream_copy) { >> > const char *p = NULL; >> > @@ -3569,6 +3592,10 @@ const OptionDef options[] = { >> > "automatically insert correct rotate filters" }, >> > { "hwaccel_lax_profile_check", OPT_BOOL | OPT_EXPERT, >> { _lax_profile_check}, >> > "attempt to decode anyway if HW accelerated decoder's >> supported profiles do not exactly match the stream" }, >> > +{ "spherical_mapping", OPT_VIDEO | HAS_ARG | OPT_STRING | >> OPT_SPEC | >> > + OPT_OUTPUT, >>{ .off = OFFSET(spherical_mappings) }, >> > +"set spherical mapping for video stream", "spherical_mapping" >> }, >> > + >> > >> > /* audio options */ >> > { "aframes",OPT_AUDIO | HAS_ARG | OPT_PERFILE | >> OPT_OUTPUT, { .func_arg = opt_audio_frames }, >> >> this part looks ok >> >> > diff --git a/libavutil/spherical.c b/libavutil/spherical.c >> > index 4be55f36cf..508584d61f 100644 >> > --- a/libavutil/spherical.c >> > +++ b/libavutil/spherical.c >> > @@ -19,6 +19,7 @@ >> > */ >> > >> > #include "mem.h" >> > +#include "opt.h" >> > #include "spherical.h" >> > >> > AVSphericalMapping *av_spherical_alloc(size_t *size) >> > @@ -77,3 +78,115 @@ int av_spherical_from_name(const char *name) >> > >> > return -1; >> > } >> > + >> > +static const char *spherical_mapping_context_to_name(void *ptr) >> > +{ >> > +return "spherical_mapping"; >> > +} >> > + >> > +typedef struct { >> > +const AVClass* spherical_class; >> > +int projection; >> > + >> > +double yaw; >> > +double pitch; >> > +double roll; >> > + >> > +int64_t
Re: [FFmpeg-devel] [PATCH] Add spherical_mapping command-line argument to ffmpeg.
Comments below.. On Mon, Jun 5, 2017 at 12:02 PM Vittorio Giovarawrote: > Hey Aaron > > This allows adding AVSphericalMapping information to files > > that don't already have it. > > --- > > ffmpeg.h | 3 ++ > > ffmpeg_opt.c | 29 - > > libavutil/spherical.c | 113 > ++ > > libavutil/spherical.h | 14 +++ > > 4 files changed, 158 insertions(+), 1 deletion(-) > > > > diff --git a/ffmpeg.h b/ffmpeg.h > > index a806445e0d..43a28d874f 100644 > > --- a/ffmpeg.h > > +++ b/ffmpeg.h > > @@ -44,6 +44,7 @@ > > #include "libavutil/fifo.h" > > #include "libavutil/pixfmt.h" > > #include "libavutil/rational.h" > > +#include "libavutil/spherical.h" > > #include "libavutil/threadmessage.h" > > > > #include "libswresample/swresample.h" > > @@ -228,6 +229,8 @@ typedef struct OptionsContext { > > intnb_time_bases; > > SpecifierOpt *enc_time_bases; > > intnb_enc_time_bases; > > +SpecifierOpt *spherical_mappings; > > +intnb_spherical_mappings; > > } OptionsContext; > > > > typedef struct InputFilter { > > diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c > > index c997ea8faf..666b3791b7 100644 > > --- a/ffmpeg_opt.c > > +++ b/ffmpeg_opt.c > > @@ -1514,12 +1514,29 @@ static void > check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, > > } > > } > > > > +static int set_spherical_mapping(const char* opt, AVStream* st) { > > + size_t spherical_mapping_size = 0; > > + AVSphericalMapping *spherical_mapping = NULL; > > + > > + int ret = av_spherical_parse_option(opt, _mapping, > > + _mapping_size); > > + if (ret >= 0) { > > +ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, > spherical_mapping, spherical_mapping_size); > > + > > +if (ret < 0) { > > + av_freep(_mapping); > > +} > > + } > > + > > + return ret; > > +} > > + > > static OutputStream *new_video_stream(OptionsContext *o, > AVFormatContext *oc, int source_index) > > { > > AVStream *st; > > OutputStream *ost; > > AVCodecContext *video_enc; > > -char *frame_rate = NULL, *frame_aspect_ratio = NULL; > > +char *frame_rate = NULL, *frame_aspect_ratio = NULL, > *spherical_mapping = NULL; > > > > ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); > > st = ost->st; > > @@ -1546,6 +1563,12 @@ static OutputStream > *new_video_stream(OptionsContext *o, AVFormatContext *oc, in > > > > MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, > st); > > MATCH_PER_STREAM_OPT(filters,str, ost->filters,oc, > st); > > +MATCH_PER_STREAM_OPT(spherical_mappings, str, spherical_mapping, > oc, st); > > + > > +if (spherical_mapping && set_spherical_mapping(spherical_mapping, > st) < 0) { > > +av_log(NULL, AV_LOG_FATAL, "Invalid spherical_mapping: %s\n", > spherical_mapping); > > +exit_program(1); > > +} > > > > if (!ost->stream_copy) { > > const char *p = NULL; > > @@ -3569,6 +3592,10 @@ const OptionDef options[] = { > > "automatically insert correct rotate filters" }, > > { "hwaccel_lax_profile_check", OPT_BOOL | OPT_EXPERT, > { _lax_profile_check}, > > "attempt to decode anyway if HW accelerated decoder's supported > profiles do not exactly match the stream" }, > > +{ "spherical_mapping", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC > | > > + OPT_OUTPUT, > { .off = OFFSET(spherical_mappings) }, > > +"set spherical mapping for video stream", "spherical_mapping" }, > > + > > > > /* audio options */ > > { "aframes",OPT_AUDIO | HAS_ARG | OPT_PERFILE | > OPT_OUTPUT, { .func_arg = opt_audio_frames }, > > this part looks ok > > > diff --git a/libavutil/spherical.c b/libavutil/spherical.c > > index 4be55f36cf..508584d61f 100644 > > --- a/libavutil/spherical.c > > +++ b/libavutil/spherical.c > > @@ -19,6 +19,7 @@ > > */ > > > > #include "mem.h" > > +#include "opt.h" > > #include "spherical.h" > > > > AVSphericalMapping *av_spherical_alloc(size_t *size) > > @@ -77,3 +78,115 @@ int av_spherical_from_name(const char *name) > > > > return -1; > > } > > + > > +static const char *spherical_mapping_context_to_name(void *ptr) > > +{ > > +return "spherical_mapping"; > > +} > > + > > +typedef struct { > > +const AVClass* spherical_class; > > +int projection; > > + > > +double yaw; > > +double pitch; > > +double roll; > > + > > +int64_t bound_left; > > +int64_t bound_top; > > +int64_t bound_right; > > +int64_t bound_bottom; > > + > > +int64_t padding; > > +} SphericalMappingContext; > > + > > +#define OFFSET(x) offsetof(SphericalMappingContext, x) > > +#define DEFAULT 0 > > +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM > > + > > +static const AVOption spherical_mapping_options[] = { > >
Re: [FFmpeg-devel] [PATCH] Add spherical_mapping command-line argument to ffmpeg.
Hey Aaron > This allows adding AVSphericalMapping information to files > that don't already have it. > --- > ffmpeg.h | 3 ++ > ffmpeg_opt.c | 29 - > libavutil/spherical.c | 113 > ++ > libavutil/spherical.h | 14 +++ > 4 files changed, 158 insertions(+), 1 deletion(-) > > diff --git a/ffmpeg.h b/ffmpeg.h > index a806445e0d..43a28d874f 100644 > --- a/ffmpeg.h > +++ b/ffmpeg.h > @@ -44,6 +44,7 @@ > #include "libavutil/fifo.h" > #include "libavutil/pixfmt.h" > #include "libavutil/rational.h" > +#include "libavutil/spherical.h" > #include "libavutil/threadmessage.h" > > #include "libswresample/swresample.h" > @@ -228,6 +229,8 @@ typedef struct OptionsContext { > intnb_time_bases; > SpecifierOpt *enc_time_bases; > intnb_enc_time_bases; > +SpecifierOpt *spherical_mappings; > +intnb_spherical_mappings; > } OptionsContext; > > typedef struct InputFilter { > diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c > index c997ea8faf..666b3791b7 100644 > --- a/ffmpeg_opt.c > +++ b/ffmpeg_opt.c > @@ -1514,12 +1514,29 @@ static void check_streamcopy_filters(OptionsContext > *o, AVFormatContext *oc, > } > } > > +static int set_spherical_mapping(const char* opt, AVStream* st) { > + size_t spherical_mapping_size = 0; > + AVSphericalMapping *spherical_mapping = NULL; > + > + int ret = av_spherical_parse_option(opt, _mapping, > + _mapping_size); > + if (ret >= 0) { > +ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, > spherical_mapping, spherical_mapping_size); > + > +if (ret < 0) { > + av_freep(_mapping); > +} > + } > + > + return ret; > +} > + > static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext > *oc, int source_index) > { > AVStream *st; > OutputStream *ost; > AVCodecContext *video_enc; > -char *frame_rate = NULL, *frame_aspect_ratio = NULL; > +char *frame_rate = NULL, *frame_aspect_ratio = NULL, *spherical_mapping > = NULL; > > ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); > st = ost->st; > @@ -1546,6 +1563,12 @@ static OutputStream *new_video_stream(OptionsContext > *o, AVFormatContext *oc, in > > MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); > MATCH_PER_STREAM_OPT(filters,str, ost->filters,oc, st); > +MATCH_PER_STREAM_OPT(spherical_mappings, str, spherical_mapping, oc, st); > + > +if (spherical_mapping && set_spherical_mapping(spherical_mapping, st) < > 0) { > +av_log(NULL, AV_LOG_FATAL, "Invalid spherical_mapping: %s\n", > spherical_mapping); > +exit_program(1); > +} > > if (!ost->stream_copy) { > const char *p = NULL; > @@ -3569,6 +3592,10 @@ const OptionDef options[] = { > "automatically insert correct rotate filters" }, > { "hwaccel_lax_profile_check", OPT_BOOL | OPT_EXPERT, > { _lax_profile_check}, > "attempt to decode anyway if HW accelerated decoder's supported > profiles do not exactly match the stream" }, > +{ "spherical_mapping", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC | > + OPT_OUTPUT, > { .off = OFFSET(spherical_mappings) }, > +"set spherical mapping for video stream", "spherical_mapping" }, > + > > /* audio options */ > { "aframes",OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, > { .func_arg = opt_audio_frames }, this part looks ok > diff --git a/libavutil/spherical.c b/libavutil/spherical.c > index 4be55f36cf..508584d61f 100644 > --- a/libavutil/spherical.c > +++ b/libavutil/spherical.c > @@ -19,6 +19,7 @@ > */ > > #include "mem.h" > +#include "opt.h" > #include "spherical.h" > > AVSphericalMapping *av_spherical_alloc(size_t *size) > @@ -77,3 +78,115 @@ int av_spherical_from_name(const char *name) > > return -1; > } > + > +static const char *spherical_mapping_context_to_name(void *ptr) > +{ > +return "spherical_mapping"; > +} > + > +typedef struct { > +const AVClass* spherical_class; > +int projection; > + > +double yaw; > +double pitch; > +double roll; > + > +int64_t bound_left; > +int64_t bound_top; > +int64_t bound_right; > +int64_t bound_bottom; > + > +int64_t padding; > +} SphericalMappingContext; > + > +#define OFFSET(x) offsetof(SphericalMappingContext, x) > +#define DEFAULT 0 > +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM > + > +static const AVOption spherical_mapping_options[] = { > +{ "projection", "projection", OFFSET(projection), AV_OPT_TYPE_INT, > +{ .i64 = -1 }, -1, AV_SPHERICAL_EQUIRECTANGULAR_TILE, FLAGS, > "projection" }, > +{ "equirectangular", "equirectangular projection", OFFSET(projection), > AV_OPT_TYPE_CONST, > +{ .i64 = AV_SPHERICAL_EQUIRECTANGULAR }, INT_MIN,
[FFmpeg-devel] [PATCH] Add spherical_mapping command-line argument to ffmpeg.
Add spherical_mapping command-line argument to ffmpeg. This allows adding AVSphericalMapping information to files that don't already have it. From eaa84a5f86d37e7de8bd0d6f72a308af57f3ef1d Mon Sep 17 00:00:00 2001 From: Aaron ColwellDate: Fri, 2 Jun 2017 16:11:21 -0700 Subject: [PATCH] Add spherical_mapping command-line argument to ffmpeg. This allows adding AVSphericalMapping information to files that don't already have it. --- ffmpeg.h | 3 ++ ffmpeg_opt.c | 29 - libavutil/spherical.c | 113 ++ libavutil/spherical.h | 14 +++ 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/ffmpeg.h b/ffmpeg.h index a806445e0d..43a28d874f 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -44,6 +44,7 @@ #include "libavutil/fifo.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" +#include "libavutil/spherical.h" #include "libavutil/threadmessage.h" #include "libswresample/swresample.h" @@ -228,6 +229,8 @@ typedef struct OptionsContext { intnb_time_bases; SpecifierOpt *enc_time_bases; intnb_enc_time_bases; +SpecifierOpt *spherical_mappings; +intnb_spherical_mappings; } OptionsContext; typedef struct InputFilter { diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index c997ea8faf..666b3791b7 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -1514,12 +1514,29 @@ static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, } } +static int set_spherical_mapping(const char* opt, AVStream* st) { + size_t spherical_mapping_size = 0; + AVSphericalMapping *spherical_mapping = NULL; + + int ret = av_spherical_parse_option(opt, _mapping, + _mapping_size); + if (ret >= 0) { +ret = av_stream_add_side_data(st, AV_PKT_DATA_SPHERICAL, spherical_mapping, spherical_mapping_size); + +if (ret < 0) { + av_freep(_mapping); +} + } + + return ret; +} + static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index) { AVStream *st; OutputStream *ost; AVCodecContext *video_enc; -char *frame_rate = NULL, *frame_aspect_ratio = NULL; +char *frame_rate = NULL, *frame_aspect_ratio = NULL, *spherical_mapping = NULL; ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); st = ost->st; @@ -1546,6 +1563,12 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); MATCH_PER_STREAM_OPT(filters,str, ost->filters,oc, st); +MATCH_PER_STREAM_OPT(spherical_mappings, str, spherical_mapping, oc, st); + +if (spherical_mapping && set_spherical_mapping(spherical_mapping, st) < 0) { +av_log(NULL, AV_LOG_FATAL, "Invalid spherical_mapping: %s\n", spherical_mapping); +exit_program(1); +} if (!ost->stream_copy) { const char *p = NULL; @@ -3569,6 +3592,10 @@ const OptionDef options[] = { "automatically insert correct rotate filters" }, { "hwaccel_lax_profile_check", OPT_BOOL | OPT_EXPERT,{ _lax_profile_check}, "attempt to decode anyway if HW accelerated decoder's supported profiles do not exactly match the stream" }, +{ "spherical_mapping", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC | + OPT_OUTPUT, { .off = OFFSET(spherical_mappings) }, +"set spherical mapping for video stream", "spherical_mapping" }, + /* audio options */ { "aframes",OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames }, diff --git a/libavutil/spherical.c b/libavutil/spherical.c index 4be55f36cf..508584d61f 100644 --- a/libavutil/spherical.c +++ b/libavutil/spherical.c @@ -19,6 +19,7 @@ */ #include "mem.h" +#include "opt.h" #include "spherical.h" AVSphericalMapping *av_spherical_alloc(size_t *size) @@ -77,3 +78,115 @@ int av_spherical_from_name(const char *name) return -1; } + +static const char *spherical_mapping_context_to_name(void *ptr) +{ +return "spherical_mapping"; +} + +typedef struct { +const AVClass* spherical_class; +int projection; + +double yaw; +double pitch; +double roll; + +int64_t bound_left; +int64_t bound_top; +int64_t bound_right; +int64_t bound_bottom; + +int64_t padding; +} SphericalMappingContext; + +#define OFFSET(x) offsetof(SphericalMappingContext, x) +#define DEFAULT 0 +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM + +static const AVOption spherical_mapping_options[] = { +{ "projection", "projection", OFFSET(projection), AV_OPT_TYPE_INT, +{ .i64 = -1 }, -1, AV_SPHERICAL_EQUIRECTANGULAR_TILE, FLAGS, "projection" }, +{ "equirectangular", "equirectangular projection", OFFSET(projection), AV_OPT_TYPE_CONST, +{ .i64 =